diff options
Diffstat (limited to 'spec/frontend/jira_connect')
4 files changed, 39 insertions, 105 deletions
diff --git a/spec/frontend/jira_connect/branches/components/project_dropdown_spec.js b/spec/frontend/jira_connect/branches/components/project_dropdown_spec.js index b0218a9df12..944854faab3 100644 --- a/spec/frontend/jira_connect/branches/components/project_dropdown_spec.js +++ b/spec/frontend/jira_connect/branches/components/project_dropdown_spec.js @@ -1,10 +1,4 @@ -import { - GlAvatarLabeled, - GlDropdown, - GlDropdownItem, - GlLoadingIcon, - GlSearchBoxByType, -} from '@gitlab/ui'; +import { GlAvatarLabeled, GlCollapsibleListbox, GlListboxItem } from '@gitlab/ui'; import { mount, shallowMount } from '@vue/test-utils'; import Vue, { nextTick } from 'vue'; import VueApollo from 'vue-apollo'; @@ -36,12 +30,8 @@ const mockQueryLoading = jest.fn().mockReturnValue(new Promise(() => {})); describe('ProjectDropdown', () => { let wrapper; - const findDropdown = () => wrapper.findComponent(GlDropdown); - const findAllDropdownItems = () => wrapper.findAllComponents(GlDropdownItem); - const findLoadingIcon = () => wrapper.findComponent(GlLoadingIcon); - const findDropdownItemByProjectId = (projectId) => - wrapper.find(`[data-testid="test-project-${projectId}"]`); - const findSearchBox = () => wrapper.findComponent(GlSearchBoxByType); + const findDropdown = () => wrapper.findComponent(GlCollapsibleListbox); + const findAllGlListboxItems = () => wrapper.findAllComponents(GlListboxItem); function createMockApolloProvider({ mockGetProjectsQuery = mockGetProjectsQuerySuccess } = {}) { Vue.use(VueApollo); @@ -55,6 +45,7 @@ describe('ProjectDropdown', () => { wrapper = mountFn(ProjectDropdown, { apolloProvider: mockApollo || createMockApolloProvider(), propsData: props, + stubs: { GlCollapsibleListbox }, }); } @@ -72,16 +63,11 @@ describe('ProjectDropdown', () => { it('sets dropdown `loading` prop to `true`', () => { expect(findDropdown().props('loading')).toBe(true); }); - - it('renders loading icon in dropdown', () => { - expect(findLoadingIcon().isVisible()).toBe(true); - }); }); describe('when projects query succeeds', () => { beforeEach(async () => { createComponent(); - await waitForPromises(); await nextTick(); }); @@ -90,12 +76,19 @@ describe('ProjectDropdown', () => { }); it('renders dropdown items with correct props', () => { - const dropdownItems = findAllDropdownItems(); - const avatars = dropdownItems.wrappers.map((item) => item.findComponent(GlAvatarLabeled)); + const dropdownItems = findDropdown().props('items'); + expect(dropdownItems).toHaveLength(mockProjects.length); + expect(dropdownItems).toMatchObject(mockProjects); + }); + + it('renders dropdown items with correct template', () => { + expect(findAllGlListboxItems()).toHaveLength(mockProjects.length); + const avatars = findAllGlListboxItems().wrappers.map((item) => + item.findComponent(GlAvatarLabeled), + ); const avatarAttributes = avatars.map((avatar) => avatar.attributes()); const avatarProps = avatars.map((avatar) => avatar.props()); - expect(dropdownItems.wrappers).toHaveLength(mockProjects.length); expect(avatarProps).toMatchObject( mockProjects.map((project) => ({ label: project.name, @@ -113,8 +106,7 @@ describe('ProjectDropdown', () => { describe('when selecting a dropdown item', () => { it('emits `change` event with the selected project', async () => { const mockProject = mockProjects[0]; - const itemToSelect = findDropdownItemByProjectId(mockProject.id); - await itemToSelect.vm.$emit('click'); + await findDropdown().vm.$emit('select', mockProject.id); expect(wrapper.emitted('change')[0]).toEqual([mockProject]); }); @@ -124,17 +116,11 @@ describe('ProjectDropdown', () => { const mockProject = mockProjects[0]; beforeEach(() => { - wrapper.setProps({ - selectedProject: mockProject, - }); - }); - - it('sets `isChecked` prop of the corresponding dropdown item to `true`', () => { - expect(findDropdownItemByProjectId(mockProject.id).props('isChecked')).toBe(true); + createComponent({ props: { selectedProject: mockProject } }); }); - it('sets dropdown text to `selectedBranchName` value', () => { - expect(findDropdown().props('text')).toBe(mockProject.nameWithNamespace); + it('selects the specified item', () => { + expect(findDropdown().props('selected')).toBe(mockProject.id); }); }); }); @@ -155,11 +141,10 @@ describe('ProjectDropdown', () => { describe('when searching branches', () => { it('triggers a refetch', async () => { createComponent({ mountFn: mount }); - await waitForPromises(); jest.clearAllMocks(); const mockSearchTerm = 'gitl'; - await findSearchBox().vm.$emit('input', mockSearchTerm); + await findDropdown().vm.$emit('search', mockSearchTerm); expect(mockGetProjectsQuerySuccess).toHaveBeenCalledWith({ after: '', diff --git a/spec/frontend/jira_connect/subscriptions/api_spec.js b/spec/frontend/jira_connect/subscriptions/api_spec.js index cf496d5836a..21636017f10 100644 --- a/spec/frontend/jira_connect/subscriptions/api_spec.js +++ b/spec/frontend/jira_connect/subscriptions/api_spec.js @@ -9,7 +9,7 @@ import { updateInstallation, } from '~/jira_connect/subscriptions/api'; import { getJwt } from '~/jira_connect/subscriptions/utils'; -import httpStatus from '~/lib/utils/http_status'; +import { HTTP_STATUS_OK } from '~/lib/utils/http_status'; jest.mock('~/jira_connect/subscriptions/utils', () => ({ getJwt: jest.fn().mockResolvedValue('jwt'), @@ -49,7 +49,7 @@ describe('JiraConnect API', () => { jwt: mockJwt, namespace_path: mockNamespace, }) - .replyOnce(httpStatus.OK, mockResponse); + .replyOnce(HTTP_STATUS_OK, mockResponse); response = await makeRequest(); @@ -67,7 +67,7 @@ describe('JiraConnect API', () => { it('returns success response', async () => { jest.spyOn(axiosInstance, 'delete'); - axiosMock.onDelete(mockRemovePath).replyOnce(httpStatus.OK, mockResponse); + axiosMock.onDelete(mockRemovePath).replyOnce(HTTP_STATUS_OK, mockResponse); response = await makeRequest(); @@ -99,7 +99,7 @@ describe('JiraConnect API', () => { page: mockPage, per_page: mockPerPage, }) - .replyOnce(httpStatus.OK, mockResponse); + .replyOnce(HTTP_STATUS_OK, mockResponse); response = await makeRequest(); @@ -121,7 +121,7 @@ describe('JiraConnect API', () => { jest.spyOn(axiosInstance, 'get'); - axiosMock.onGet(expectedUrl).replyOnce(httpStatus.OK, mockResponse); + axiosMock.onGet(expectedUrl).replyOnce(HTTP_STATUS_OK, mockResponse); response = await makeRequest(); @@ -139,7 +139,7 @@ describe('JiraConnect API', () => { jest.spyOn(axiosInstance, 'post'); - axiosMock.onPost(expectedUrl).replyOnce(httpStatus.OK, mockResponse); + axiosMock.onPost(expectedUrl).replyOnce(HTTP_STATUS_OK, mockResponse); response = await makeRequest(); @@ -175,7 +175,7 @@ describe('JiraConnect API', () => { instance_url: expectedInstanceUrl, }, }) - .replyOnce(httpStatus.OK, mockResponse); + .replyOnce(HTTP_STATUS_OK, mockResponse); response = await makeRequest(); diff --git a/spec/frontend/jira_connect/subscriptions/components/compatibility_alert_spec.js b/spec/frontend/jira_connect/subscriptions/components/compatibility_alert_spec.js deleted file mode 100644 index 5f38a0acb9d..00000000000 --- a/spec/frontend/jira_connect/subscriptions/components/compatibility_alert_spec.js +++ /dev/null @@ -1,56 +0,0 @@ -import { GlAlert, GlLink } from '@gitlab/ui'; -import { shallowMount, mount } from '@vue/test-utils'; -import CompatibilityAlert from '~/jira_connect/subscriptions/components/compatibility_alert.vue'; - -import LocalStorageSync from '~/vue_shared/components/local_storage_sync.vue'; - -describe('CompatibilityAlert', () => { - let wrapper; - - const createComponent = ({ mountFn = shallowMount } = {}) => { - wrapper = mountFn(CompatibilityAlert); - }; - - const findAlert = () => wrapper.findComponent(GlAlert); - const findLink = () => wrapper.findComponent(GlLink); - const findLocalStorageSync = () => wrapper.findComponent(LocalStorageSync); - - afterEach(() => { - wrapper.destroy(); - }); - - it('displays an alert', () => { - createComponent(); - - expect(findAlert().exists()).toBe(true); - }); - - it('renders help link with target="_blank" and rel="noopener noreferrer"', () => { - createComponent({ mountFn: mount }); - expect(findLink().attributes()).toMatchObject({ - target: '_blank', - rel: 'noopener', - }); - }); - - it('`local-storage-sync` value prop is initially false', () => { - createComponent(); - - expect(findLocalStorageSync().props('value')).toBe(false); - }); - - describe('when dismissed', () => { - beforeEach(async () => { - createComponent(); - await findAlert().vm.$emit('dismiss'); - }); - - it('hides alert', () => { - expect(findAlert().exists()).toBe(false); - }); - - it('updates value prop of `local-storage-sync`', () => { - expect(findLocalStorageSync().props('value')).toBe(true); - }); - }); -}); diff --git a/spec/frontend/jira_connect/subscriptions/components/sign_in_oauth_button_spec.js b/spec/frontend/jira_connect/subscriptions/components/sign_in_oauth_button_spec.js index 01317eb5dba..e20c4b62e77 100644 --- a/spec/frontend/jira_connect/subscriptions/components/sign_in_oauth_button_spec.js +++ b/spec/frontend/jira_connect/subscriptions/components/sign_in_oauth_button_spec.js @@ -4,6 +4,7 @@ import { nextTick } from 'vue'; import SignInOauthButton from '~/jira_connect/subscriptions/components/sign_in_oauth_button.vue'; import { + GITLAB_COM_BASE_PATH, I18N_DEFAULT_SIGN_IN_BUTTON_TEXT, OAUTH_WINDOW_OPTIONS, } from '~/jira_connect/subscriptions/constants'; @@ -36,6 +37,9 @@ describe('SignInOauthButton', () => { }, state: 'good-state', }; + const defaultProps = { + gitlabBasePath: GITLAB_COM_BASE_PATH, + }; const createComponent = ({ slots, props } = {}) => { store = createStore(); @@ -48,7 +52,7 @@ describe('SignInOauthButton', () => { provide: { oauthMetadata: mockOauthMetadata, }, - propsData: props, + propsData: { ...defaultProps, ...props }, }); }; @@ -57,16 +61,17 @@ describe('SignInOauthButton', () => { }); const findButton = () => wrapper.findComponent(GlButton); + describe('when `gitlabBasePath` is GitLab.com', () => { + it('displays a button', () => { + createComponent(); - it('displays a button', () => { - createComponent(); - - expect(findButton().exists()).toBe(true); - expect(findButton().text()).toBe(I18N_DEFAULT_SIGN_IN_BUTTON_TEXT); - expect(findButton().props('category')).toBe('primary'); + expect(findButton().exists()).toBe(true); + expect(findButton().text()).toBe(I18N_DEFAULT_SIGN_IN_BUTTON_TEXT); + expect(findButton().props('category')).toBe('primary'); + }); }); - describe('when `gitlabBasePath` is passed', () => { + describe('when `gitlabBasePath` is self-managed', () => { const mockBasePath = 'https://gitlab.mycompany.com'; it('uses custom text for button', () => { |