diff options
Diffstat (limited to 'spec')
5 files changed, 176 insertions, 22 deletions
diff --git a/spec/features/nav/pinned_nav_items_spec.rb b/spec/features/nav/pinned_nav_items_spec.rb index a2428048a1a..a1137536dd5 100644 --- a/spec/features/nav/pinned_nav_items_spec.rb +++ b/spec/features/nav/pinned_nav_items_spec.rb @@ -170,6 +170,7 @@ RSpec.describe 'Navigation menu item pinning', :js, feature_category: :navigatio def add_pin(nav_item_title) nav_item = find("[data-testid=\"nav-item\"]", text: nav_item_title) + scroll_to(nav_item) nav_item.hover pin_button = nav_item.find("[data-testid=\"nav-item-pin\"]") pin_button.click @@ -178,6 +179,7 @@ RSpec.describe 'Navigation menu item pinning', :js, feature_category: :navigatio def remove_pin(nav_item_title) nav_item = find("[data-testid=\"nav-item\"]", text: nav_item_title) + scroll_to(nav_item) nav_item.hover unpin_button = nav_item.find("[data-testid=\"nav-item-unpin\"]") unpin_button.click diff --git a/spec/frontend/super_sidebar/components/organization_switcher_spec.js b/spec/frontend/super_sidebar/components/organization_switcher_spec.js new file mode 100644 index 00000000000..094cb4baedb --- /dev/null +++ b/spec/frontend/super_sidebar/components/organization_switcher_spec.js @@ -0,0 +1,148 @@ +import { GlAvatar, GlDisclosureDropdown, GlLoadingIcon } from '@gitlab/ui'; +import VueApollo from 'vue-apollo'; +import Vue from 'vue'; + +import { mountExtended } from 'helpers/vue_test_utils_helper'; +import OrganizationSwitcher from '~/super_sidebar/components/organization_switcher.vue'; +import { + defaultOrganization as currentOrganization, + organizations as nodes, + pageInfo, + pageInfoEmpty, +} from '~/organizations/mock_data'; +import organizationsQuery from '~/organizations/shared/graphql/queries/organizations.query.graphql'; +import { getIdFromGraphQLId } from '~/graphql_shared/utils'; +import createMockApollo from 'helpers/mock_apollo_helper'; +import waitForPromises from 'helpers/wait_for_promises'; + +Vue.use(VueApollo); + +describe('OrganizationSwitcher', () => { + let wrapper; + let mockApollo; + + const [, secondOrganization, thirdOrganization] = nodes; + + const organizations = { + nodes, + pageInfo, + }; + + const successHandler = jest.fn().mockResolvedValue({ + data: { + currentUser: { + id: 'gid://gitlab/User/1', + organizations, + }, + }, + }); + + const createComponent = (handler = successHandler) => { + mockApollo = createMockApollo([[organizationsQuery, handler]]); + + wrapper = mountExtended(OrganizationSwitcher, { + apolloProvider: mockApollo, + }); + }; + + const findDropdownItemByIndex = (index) => + wrapper.findAllByTestId('disclosure-dropdown-item').at(index); + const showDropdown = () => wrapper.findComponent(GlDisclosureDropdown).vm.$emit('shown'); + + afterEach(() => { + mockApollo = null; + }); + + it('renders disclosure dropdown with current organization selected', () => { + createComponent(); + + const toggleButton = wrapper.findByTestId('toggle-button'); + const dropdownItem = findDropdownItemByIndex(0); + + expect(toggleButton.text()).toContain(currentOrganization.name); + expect(toggleButton.findComponent(GlAvatar).props()).toMatchObject({ + src: currentOrganization.avatar_url, + entityId: currentOrganization.id, + entityName: currentOrganization.name, + }); + expect(dropdownItem.text()).toContain(currentOrganization.name); + expect(dropdownItem.findComponent(GlAvatar).props()).toMatchObject({ + src: currentOrganization.avatar_url, + entityId: currentOrganization.id, + entityName: currentOrganization.name, + }); + }); + + it('does not call GraphQL query', () => { + createComponent(); + + expect(successHandler).not.toHaveBeenCalled(); + }); + + describe('when dropdown is shown', () => { + it('calls GraphQL query and renders organizations that are available to switch to', async () => { + createComponent(); + showDropdown(); + + expect(wrapper.findComponent(GlLoadingIcon).exists()).toBe(true); + + await waitForPromises(); + + expect(findDropdownItemByIndex(1).text()).toContain(secondOrganization.name); + expect(findDropdownItemByIndex(1).element.firstChild.getAttribute('href')).toBe( + secondOrganization.webUrl, + ); + expect(findDropdownItemByIndex(1).findComponent(GlAvatar).props()).toMatchObject({ + src: secondOrganization.avatarUrl, + entityId: getIdFromGraphQLId(secondOrganization.id), + entityName: secondOrganization.name, + }); + + expect(findDropdownItemByIndex(2).text()).toContain(thirdOrganization.name); + expect(findDropdownItemByIndex(2).element.firstChild.getAttribute('href')).toBe( + thirdOrganization.webUrl, + ); + expect(findDropdownItemByIndex(2).findComponent(GlAvatar).props()).toMatchObject({ + src: thirdOrganization.avatarUrl, + entityId: getIdFromGraphQLId(thirdOrganization.id), + entityName: thirdOrganization.name, + }); + }); + + describe('when there are no organizations to switch to', () => { + beforeEach(async () => { + createComponent( + jest.fn().mockResolvedValue({ + data: { + currentUser: { + id: 'gid://gitlab/User/1', + organizations: { + nodes: [], + pageInfo: pageInfoEmpty, + }, + }, + }, + }), + ); + showDropdown(); + await waitForPromises(); + }); + + it('renders empty message', () => { + expect(findDropdownItemByIndex(1).text()).toBe('No organizations available to switch to.'); + }); + }); + + describe('when there is an error fetching organizations', () => { + beforeEach(async () => { + createComponent(jest.fn().mockRejectedValue()); + showDropdown(); + await waitForPromises(); + }); + + it('renders empty message', () => { + expect(findDropdownItemByIndex(1).text()).toBe('No organizations available to switch to.'); + }); + }); + }); +}); diff --git a/spec/frontend/super_sidebar/components/user_bar_spec.js b/spec/frontend/super_sidebar/components/user_bar_spec.js index 27d65f27007..fa2c6fdf165 100644 --- a/spec/frontend/super_sidebar/components/user_bar_spec.js +++ b/spec/frontend/super_sidebar/components/user_bar_spec.js @@ -9,16 +9,20 @@ import UserMenu from '~/super_sidebar/components/user_menu.vue'; import SearchModal from '~/super_sidebar/components/global_search/components/global_search.vue'; import BrandLogo from 'jh_else_ce/super_sidebar/components/brand_logo.vue'; import MergeRequestMenu from '~/super_sidebar/components/merge_request_menu.vue'; +import OrganizationSwitcher from '~/super_sidebar/components/organization_switcher.vue'; import UserBar from '~/super_sidebar/components/user_bar.vue'; import { createMockDirective, getBinding } from 'helpers/vue_mock_directive'; import waitForPromises from 'helpers/wait_for_promises'; import { userCounts } from '~/super_sidebar/user_counts_manager'; +import { stubComponent } from 'helpers/stub_component'; import { sidebarData as mockSidebarData, loggedOutSidebarData } from '../mock_data'; import { MOCK_DEFAULT_SEARCH_OPTIONS } from './global_search/mock_data'; describe('UserBar component', () => { let wrapper; + const OrganizationSwitcherStub = stubComponent(OrganizationSwitcher); + const findCreateMenu = () => wrapper.findComponent(CreateMenu); const findUserMenu = () => wrapper.findComponent(UserMenu); const findIssuesCounter = () => wrapper.findByTestId('issues-shortcut-button'); @@ -30,6 +34,7 @@ describe('UserBar component', () => { const findSearchButton = () => wrapper.findByTestId('super-sidebar-search-button'); const findSearchModal = () => wrapper.findComponent(SearchModal); const findStopImpersonationButton = () => wrapper.findByTestId('stop-impersonation-btn'); + const findOrganizationSwitcher = () => wrapper.findComponent(OrganizationSwitcherStub); Vue.use(Vuex); @@ -56,6 +61,9 @@ describe('UserBar component', () => { GlTooltip: createMockDirective('gl-tooltip'), }, store, + stubs: { + OrganizationSwitcher: OrganizationSwitcherStub, + }, }); }; @@ -252,4 +260,22 @@ describe('UserBar component', () => { expect(findTodosCounter().exists()).toBe(false); }); }); + + describe('when `ui_for_organizations` feature flag is enabled', () => { + it('renders `OrganizationSwitcher component', async () => { + createWrapper({ provideOverrides: { glFeatures: { uiForOrganizations: true } } }); + await waitForPromises(); + + expect(findOrganizationSwitcher().exists()).toBe(true); + }); + }); + + describe('when `ui_for_organizations` feature flag is disabled', () => { + it('renders `OrganizationSwitcher component', async () => { + createWrapper(); + await waitForPromises(); + + expect(findOrganizationSwitcher().exists()).toBe(false); + }); + }); }); diff --git a/spec/requests/api/graphql/merge_requests/codequality_reports_comparer_spec.rb b/spec/requests/api/graphql/merge_requests/codequality_reports_comparer_spec.rb index 09a229c2098..d9089538171 100644 --- a/spec/requests/api/graphql/merge_requests/codequality_reports_comparer_spec.rb +++ b/spec/requests/api/graphql/merge_requests/codequality_reports_comparer_spec.rb @@ -125,16 +125,6 @@ RSpec.describe 'Query.project.mergeRequest.codequalityReportsComparer', feature_ post_graphql(query, current_user: user) end - context 'when when sast_reports_in_inline_diff FF is disabled' do - before_all do - stub_feature_flags(sast_reports_in_inline_diff: false) - end - - it 'returns null for codequality_reports_comparer field' do - expect(result).to be_nil - end - end - it 'returns expected data' do expect(result).to match( a_hash_including( diff --git a/spec/serializers/codequality_degradation_entity_spec.rb b/spec/serializers/codequality_degradation_entity_spec.rb index 3d07564c5dc..dc15fa02a21 100644 --- a/spec/serializers/codequality_degradation_entity_spec.rb +++ b/spec/serializers/codequality_degradation_entity_spec.rb @@ -8,18 +8,6 @@ RSpec.describe CodequalityDegradationEntity, feature_category: :code_quality do describe '#as_json' do subject { entity.as_json } - context 'when sast_reports_in_inline_diff is disabled' do - before do - stub_feature_flags(sast_reports_in_inline_diff: false) - end - - let(:codequality_degradation) { build(:codequality_degradation_1) } - - it 'does not contain fingerprint' do - expect(subject[:fingerprint]).to be_nil - end - end - context 'when codequality contains an error' do context 'when line is included in location' do let(:codequality_degradation) { build(:codequality_degradation_2) } |