diff options
Diffstat (limited to 'spec/frontend/jira_connect/subscriptions')
21 files changed, 300 insertions, 648 deletions
diff --git a/spec/frontend/jira_connect/subscriptions/api_spec.js b/spec/frontend/jira_connect/subscriptions/api_spec.js index e2a14a9102f..36e2c7bbab2 100644 --- a/spec/frontend/jira_connect/subscriptions/api_spec.js +++ b/spec/frontend/jira_connect/subscriptions/api_spec.js @@ -1,7 +1,6 @@ import MockAdapter from 'axios-mock-adapter'; import { axiosInstance, - addSubscription, removeSubscription, fetchGroups, getCurrentUser, @@ -17,10 +16,8 @@ jest.mock('~/jira_connect/subscriptions/utils', () => ({ describe('JiraConnect API', () => { let axiosMock; - let originalGon; let response; - const mockAddPath = 'addPath'; const mockRemovePath = 'removePath'; const mockNamespace = 'namespace'; const mockJwt = 'jwt'; @@ -29,39 +26,14 @@ describe('JiraConnect API', () => { beforeEach(() => { axiosMock = new MockAdapter(axiosInstance); - originalGon = window.gon; window.gon = { api_version: 'v4' }; }); afterEach(() => { axiosMock.restore(); - window.gon = originalGon; response = null; }); - describe('addSubscription', () => { - const makeRequest = () => addSubscription(mockAddPath, mockNamespace); - - it('returns success response', async () => { - jest.spyOn(axiosInstance, 'post'); - axiosMock - .onPost(mockAddPath, { - jwt: mockJwt, - namespace_path: mockNamespace, - }) - .replyOnce(HTTP_STATUS_OK, mockResponse); - - response = await makeRequest(); - - expect(getJwt).toHaveBeenCalled(); - expect(axiosInstance.post).toHaveBeenCalledWith(mockAddPath, { - jwt: mockJwt, - namespace_path: mockNamespace, - }); - expect(response.data).toEqual(mockResponse); - }); - }); - describe('removeSubscription', () => { const makeRequest = () => removeSubscription(mockRemovePath); diff --git a/spec/frontend/jira_connect/subscriptions/components/add_namespace_button_spec.js b/spec/frontend/jira_connect/subscriptions/components/add_namespace_button_spec.js index 9f92ad2adc1..934473c15ba 100644 --- a/spec/frontend/jira_connect/subscriptions/components/add_namespace_button_spec.js +++ b/spec/frontend/jira_connect/subscriptions/components/add_namespace_button_spec.js @@ -11,7 +11,7 @@ describe('AddNamespaceButton', () => { const createComponent = () => { wrapper = shallowMount(AddNamespaceButton, { directives: { - glModal: createMockDirective(), + glModal: createMockDirective('gl-modal'), }, }); }; @@ -23,10 +23,6 @@ describe('AddNamespaceButton', () => { createComponent(); }); - afterEach(() => { - wrapper.destroy(); - }); - it('displays a button', () => { expect(findButton().exists()).toBe(true); }); diff --git a/spec/frontend/jira_connect/subscriptions/components/add_namespace_modal/add_namespace_modal_spec.js b/spec/frontend/jira_connect/subscriptions/components/add_namespace_modal/add_namespace_modal_spec.js index d80381107f2..dbe8a734bb4 100644 --- a/spec/frontend/jira_connect/subscriptions/components/add_namespace_modal/add_namespace_modal_spec.js +++ b/spec/frontend/jira_connect/subscriptions/components/add_namespace_modal/add_namespace_modal_spec.js @@ -17,10 +17,6 @@ describe('AddNamespaceModal', () => { createComponent(); }); - afterEach(() => { - wrapper.destroy(); - }); - it('displays modal with correct props', () => { const modal = findModal(); expect(modal.exists()).toBe(true); diff --git a/spec/frontend/jira_connect/subscriptions/components/add_namespace_modal/groups_list_item_spec.js b/spec/frontend/jira_connect/subscriptions/components/add_namespace_modal/groups_list_item_spec.js index 5df54abfc05..c5035a12bd1 100644 --- a/spec/frontend/jira_connect/subscriptions/components/add_namespace_modal/groups_list_item_spec.js +++ b/spec/frontend/jira_connect/subscriptions/components/add_namespace_modal/groups_list_item_spec.js @@ -1,28 +1,15 @@ import { GlButton } from '@gitlab/ui'; import { mount, shallowMount } from '@vue/test-utils'; -import { nextTick } from 'vue'; -import waitForPromises from 'helpers/wait_for_promises'; -import * as JiraConnectApi from '~/jira_connect/subscriptions/api'; import GroupItemName from '~/jira_connect/subscriptions/components/group_item_name.vue'; import GroupsListItem from '~/jira_connect/subscriptions/components/add_namespace_modal/groups_list_item.vue'; -import { persistAlert, reloadPage } from '~/jira_connect/subscriptions/utils'; -import { - I18N_ADD_SUBSCRIPTION_SUCCESS_ALERT_TITLE, - I18N_ADD_SUBSCRIPTION_SUCCESS_ALERT_MESSAGE, - INTEGRATIONS_DOC_LINK, -} from '~/jira_connect/subscriptions/constants'; import createStore from '~/jira_connect/subscriptions/store'; import { mockGroup1 } from '../../mock_data'; -jest.mock('~/jira_connect/subscriptions/utils'); - describe('GroupsListItem', () => { let wrapper; let store; - const mockAddSubscriptionsPath = '/addSubscriptionsPath'; - const createComponent = ({ mountFn = shallowMount, provide } = {}) => { store = createStore(); @@ -34,16 +21,11 @@ describe('GroupsListItem', () => { group: mockGroup1, }, provide: { - addSubscriptionsPath: mockAddSubscriptionsPath, ...provide, }, }); }; - afterEach(() => { - wrapper.destroy(); - }); - const findGroupItemName = () => wrapper.findComponent(GroupItemName); const findLinkButton = () => wrapper.findComponent(GlButton); const clickLinkButton = () => findLinkButton().trigger('click'); @@ -65,88 +47,24 @@ describe('GroupsListItem', () => { }); describe('on Link button click', () => { - describe('when jiraConnectOauth feature flag is disabled', () => { - let addSubscriptionSpy; - - beforeEach(() => { - createComponent({ mountFn: mount }); - - addSubscriptionSpy = jest.spyOn(JiraConnectApi, 'addSubscription').mockResolvedValue(); - }); - - it('sets button to loading and sends request', async () => { - expect(findLinkButton().props('loading')).toBe(false); - - clickLinkButton(); - await nextTick(); - - expect(findLinkButton().props('loading')).toBe(true); - await waitForPromises(); - - expect(addSubscriptionSpy).toHaveBeenCalledWith( - mockAddSubscriptionsPath, - mockGroup1.full_path, - ); - expect(persistAlert).toHaveBeenCalledWith({ - linkUrl: INTEGRATIONS_DOC_LINK, - message: I18N_ADD_SUBSCRIPTION_SUCCESS_ALERT_MESSAGE, - title: I18N_ADD_SUBSCRIPTION_SUCCESS_ALERT_TITLE, - variant: 'success', - }); - }); - - describe('when request is successful', () => { - it('reloads the page', async () => { - clickLinkButton(); + const mockSubscriptionsPath = '/subscriptions'; - await waitForPromises(); - - expect(reloadPage).toHaveBeenCalled(); - }); - }); - - describe('when request has errors', () => { - const mockErrorMessage = 'error message'; - const mockError = { response: { data: { error: mockErrorMessage } } }; - - beforeEach(() => { - addSubscriptionSpy = jest - .spyOn(JiraConnectApi, 'addSubscription') - .mockRejectedValue(mockError); - }); - - it('emits `error` event', async () => { - clickLinkButton(); - - await waitForPromises(); - - expect(reloadPage).not.toHaveBeenCalled(); - expect(wrapper.emitted('error')[0][0]).toBe(mockErrorMessage); - }); + beforeEach(() => { + createComponent({ + mountFn: mount, + provide: { + subscriptionsPath: mockSubscriptionsPath, + }, }); }); - describe('when jiraConnectOauth feature flag is enabled', () => { - const mockSubscriptionsPath = '/subscriptions'; - - beforeEach(() => { - createComponent({ - mountFn: mount, - provide: { - subscriptionsPath: mockSubscriptionsPath, - glFeatures: { jiraConnectOauth: true }, - }, - }); - }); - - it('dispatches `addSubscription` action', async () => { - clickLinkButton(); - await nextTick(); + it('dispatches `addSubscription` action', () => { + clickLinkButton(); - expect(store.dispatch).toHaveBeenCalledWith('addSubscription', { - namespacePath: mockGroup1.full_path, - subscriptionsPath: mockSubscriptionsPath, - }); + expect(store.dispatch).toHaveBeenCalledTimes(1); + expect(store.dispatch).toHaveBeenCalledWith('addSubscription', { + namespacePath: mockGroup1.full_path, + subscriptionsPath: mockSubscriptionsPath, }); }); }); diff --git a/spec/frontend/jira_connect/subscriptions/components/add_namespace_modal/groups_list_spec.js b/spec/frontend/jira_connect/subscriptions/components/add_namespace_modal/groups_list_spec.js index 97038a2a231..9d5bc8dff2a 100644 --- a/spec/frontend/jira_connect/subscriptions/components/add_namespace_modal/groups_list_spec.js +++ b/spec/frontend/jira_connect/subscriptions/components/add_namespace_modal/groups_list_spec.js @@ -48,10 +48,6 @@ describe('GroupsList', () => { ); }; - afterEach(() => { - wrapper.destroy(); - }); - const findGlAlert = () => wrapper.findComponent(GlAlert); const findGlLoadingIcon = () => wrapper.findComponent(GlLoadingIcon); const findAllItems = () => wrapper.findAllComponents(GroupsListItem); diff --git a/spec/frontend/jira_connect/subscriptions/components/app_spec.js b/spec/frontend/jira_connect/subscriptions/components/app_spec.js index 369ddda8dbe..26a9d07321c 100644 --- a/spec/frontend/jira_connect/subscriptions/components/app_spec.js +++ b/spec/frontend/jira_connect/subscriptions/components/app_spec.js @@ -1,6 +1,6 @@ -import { GlLink } from '@gitlab/ui'; +import { GlLink, GlSprintf } from '@gitlab/ui'; import { nextTick } from 'vue'; -import { mountExtended, shallowMountExtended } from 'helpers/vue_test_utils_helper'; +import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; import JiraConnectApp from '~/jira_connect/subscriptions/components/app.vue'; import SignInPage from '~/jira_connect/subscriptions/pages/sign_in/sign_in_page.vue'; @@ -10,228 +10,214 @@ import BrowserSupportAlert from '~/jira_connect/subscriptions/components/browser import createStore from '~/jira_connect/subscriptions/store'; import { SET_ALERT } from '~/jira_connect/subscriptions/store/mutation_types'; import { I18N_DEFAULT_SIGN_IN_ERROR_MESSAGE } from '~/jira_connect/subscriptions/constants'; +import { retrieveAlert } from '~/jira_connect/subscriptions/utils'; import { __ } from '~/locale'; import AccessorUtilities from '~/lib/utils/accessor'; import * as api from '~/jira_connect/subscriptions/api'; import { mockSubscription } from '../mock_data'; -jest.mock('~/jira_connect/subscriptions/utils', () => ({ - retrieveAlert: jest.fn().mockReturnValue({ message: 'error message' }), - getGitlabSignInURL: jest.fn(), -})); +jest.mock('~/jira_connect/subscriptions/utils'); describe('JiraConnectApp', () => { let wrapper; let store; + const mockCurrentUser = { name: 'root' }; + const findAlert = () => wrapper.findByTestId('jira-connect-persisted-alert'); + const findJiraConnectApp = () => wrapper.findByTestId('jira-connect-app'); const findAlertLink = () => findAlert().findComponent(GlLink); const findSignInPage = () => wrapper.findComponent(SignInPage); const findSubscriptionsPage = () => wrapper.findComponent(SubscriptionsPage); const findUserLink = () => wrapper.findComponent(UserLink); const findBrowserSupportAlert = () => wrapper.findComponent(BrowserSupportAlert); - const createComponent = ({ provide, mountFn = shallowMountExtended, initialState = {} } = {}) => { + const createComponent = ({ provide, initialState = {} } = {}) => { store = createStore({ ...initialState, subscriptions: [mockSubscription] }); jest.spyOn(store, 'dispatch').mockImplementation(); - wrapper = mountFn(JiraConnectApp, { + wrapper = shallowMountExtended(JiraConnectApp, { store, provide, + stubs: { + GlSprintf, + }, }); }; - afterEach(() => { - wrapper.destroy(); - }); - describe('template', () => { - describe.each` - scenario | usersPath | shouldRenderSignInPage | shouldRenderSubscriptionsPage - ${'user is not signed in'} | ${'/users'} | ${true} | ${false} - ${'user is signed in'} | ${undefined} | ${false} | ${true} - `('when $scenario', ({ usersPath, shouldRenderSignInPage, shouldRenderSubscriptionsPage }) => { - beforeEach(() => { - createComponent({ - provide: { - usersPath, - }, - }); - }); - - it(`${shouldRenderSignInPage ? 'renders' : 'does not render'} sign in page`, () => { - expect(findSignInPage().isVisible()).toBe(shouldRenderSignInPage); - if (shouldRenderSignInPage) { - expect(findSignInPage().props('hasSubscriptions')).toBe(true); - } - }); - - it(`${ - shouldRenderSubscriptionsPage ? 'renders' : 'does not render' - } subscriptions page`, () => { - expect(findSubscriptionsPage().exists()).toBe(shouldRenderSubscriptionsPage); - if (shouldRenderSubscriptionsPage) { - expect(findSubscriptionsPage().props('hasSubscriptions')).toBe(true); - } - }); + beforeEach(() => { + jest.spyOn(AccessorUtilities, 'canUseCrypto').mockReturnValue(true); }); - it('renders UserLink component', () => { - createComponent({ - provide: { - usersPath: '/user', - }, - }); + it('renders only Jira Connect app', () => { + createComponent(); - const userLink = findUserLink(); - expect(userLink.exists()).toBe(true); - expect(userLink.props()).toEqual({ - hasSubscriptions: true, - user: null, - userSignedIn: false, - }); + expect(findBrowserSupportAlert().exists()).toBe(false); + expect(findJiraConnectApp().exists()).toBe(true); }); - }); - - describe('alert', () => { - it.each` - message | variant | alertShouldRender - ${'Test error'} | ${'danger'} | ${true} - ${'Test notice'} | ${'info'} | ${true} - ${''} | ${undefined} | ${false} - ${undefined} | ${undefined} | ${false} - `( - 'renders correct alert when message is `$message` and variant is `$variant`', - async ({ message, alertShouldRender, variant }) => { - createComponent(); - - store.commit(SET_ALERT, { message, variant }); - await nextTick(); - const alert = findAlert(); + it('renders only BrowserSupportAlert when canUseCrypto is false', () => { + jest.spyOn(AccessorUtilities, 'canUseCrypto').mockReturnValue(false); - expect(alert.exists()).toBe(alertShouldRender); - if (alertShouldRender) { - expect(alert.isVisible()).toBe(alertShouldRender); - expect(alert.html()).toContain(message); - expect(alert.props('variant')).toBe(variant); - expect(findAlertLink().exists()).toBe(false); - } - }, - ); - - it('hides alert on @dismiss event', async () => { createComponent(); - store.commit(SET_ALERT, { message: 'test message' }); - await nextTick(); - - findAlert().vm.$emit('dismiss'); - await nextTick(); - - expect(findAlert().exists()).toBe(false); + expect(findBrowserSupportAlert().exists()).toBe(true); + expect(findJiraConnectApp().exists()).toBe(false); }); - it('renders link when `linkUrl` is set', async () => { - createComponent({ provide: { usersPath: '' }, mountFn: mountExtended }); + describe.each` + scenario | currentUser | expectUserLink | expectSignInPage | expectSubscriptionsPage + ${'user is not signed in'} | ${undefined} | ${false} | ${true} | ${false} + ${'user is signed in'} | ${mockCurrentUser} | ${true} | ${false} | ${true} + `( + 'when $scenario', + ({ currentUser, expectUserLink, expectSignInPage, expectSubscriptionsPage }) => { + beforeEach(() => { + createComponent({ + initialState: { + currentUser, + }, + }); + }); - store.commit(SET_ALERT, { - message: __('test message %{linkStart}test link%{linkEnd}'), - linkUrl: 'https://gitlab.com', - }); - await nextTick(); + it(`${expectUserLink ? 'renders' : 'does not render'} user link`, () => { + expect(findUserLink().exists()).toBe(expectUserLink); + if (expectUserLink) { + expect(findUserLink().props('user')).toBe(mockCurrentUser); + } + }); - const alertLink = findAlertLink(); + it(`${expectSignInPage ? 'renders' : 'does not render'} sign in page`, () => { + expect(findSignInPage().isVisible()).toBe(expectSignInPage); + if (expectSignInPage) { + expect(findSignInPage().props('hasSubscriptions')).toBe(true); + } + }); - expect(alertLink.exists()).toBe(true); - expect(alertLink.text()).toContain('test link'); - expect(alertLink.attributes('href')).toBe('https://gitlab.com'); - }); + it(`${expectSubscriptionsPage ? 'renders' : 'does not render'} subscriptions page`, () => { + expect(findSubscriptionsPage().exists()).toBe(expectSubscriptionsPage); + if (expectSubscriptionsPage) { + expect(findSubscriptionsPage().props('hasSubscriptions')).toBe(true); + } + }); + }, + ); - describe('when alert is set in localStoage', () => { - it('renders alert on mount', () => { + describe('when sign in page emits `error` event', () => { + beforeEach(() => { createComponent(); + findSignInPage().vm.$emit('error'); + }); + it('displays alert', () => { const alert = findAlert(); expect(alert.exists()).toBe(true); - expect(alert.html()).toContain('error message'); + expect(alert.text()).toContain(I18N_DEFAULT_SIGN_IN_ERROR_MESSAGE); + expect(alert.props('variant')).toBe('danger'); }); }); - }); - describe('when user signed out', () => { - describe('when sign in page emits `error` event', () => { - beforeEach(async () => { + describe('when sign in page emits `sign-in-oauth` event', () => { + const mockSubscriptionsPath = '/mockSubscriptionsPath'; + + beforeEach(() => { + jest.spyOn(api, 'fetchSubscriptions').mockResolvedValue({ data: { subscriptions: [] } }); + createComponent({ + initialState: { + currentUser: mockCurrentUser, + }, provide: { - usersPath: '/mock', + subscriptionsPath: mockSubscriptionsPath, }, }); - findSignInPage().vm.$emit('error'); - await nextTick(); + findSignInPage().vm.$emit('sign-in-oauth'); }); - it('displays alert', () => { - const alert = findAlert(); - - expect(alert.exists()).toBe(true); - expect(alert.html()).toContain(I18N_DEFAULT_SIGN_IN_ERROR_MESSAGE); - expect(alert.props('variant')).toBe('danger'); + it('dispatches `fetchSubscriptions` action', () => { + expect(store.dispatch).toHaveBeenCalledWith('fetchSubscriptions', mockSubscriptionsPath); }); }); - }); - describe.each` - jiraConnectOauthEnabled | canUseCrypto | shouldShowAlert - ${false} | ${false} | ${false} - ${false} | ${true} | ${false} - ${true} | ${false} | ${true} - ${true} | ${true} | ${false} - `( - 'when `jiraConnectOauth` feature flag is $jiraConnectOauthEnabled and `AccessorUtilities.canUseCrypto` returns $canUseCrypto', - ({ jiraConnectOauthEnabled, canUseCrypto, shouldShowAlert }) => { - beforeEach(() => { - jest.spyOn(AccessorUtilities, 'canUseCrypto').mockReturnValue(canUseCrypto); + describe('alert', () => { + const mockAlertData = { message: 'error message' }; - createComponent({ provide: { glFeatures: { jiraConnectOauth: jiraConnectOauthEnabled } } }); - }); + describe.each` + alertData | expectAlert + ${undefined} | ${false} + ${mockAlertData} | ${true} + `('when retrieveAlert returns $alertData', ({ alertData, expectAlert }) => { + beforeEach(() => { + retrieveAlert.mockReturnValue(alertData); - it(`does ${shouldShowAlert ? '' : 'not'} render BrowserSupportAlert component`, () => { - expect(findBrowserSupportAlert().exists()).toBe(shouldShowAlert); - }); + createComponent(); + }); + + it(`${expectAlert ? 'renders' : 'does not render'} alert on mount`, () => { + const alert = findAlert(); - it(`does ${!shouldShowAlert ? '' : 'not'} render the main Jira Connect app template`, () => { - expect(wrapper.findByTestId('jira-connect-app').exists()).toBe(!shouldShowAlert); + expect(alert.exists()).toBe(expectAlert); + if (expectAlert) { + expect(alert.text()).toContain(mockAlertData.message); + } + }); }); - }, - ); - describe('when `jiraConnectOauth` feature flag is enabled', () => { - const mockSubscriptionsPath = '/mockSubscriptionsPath'; + it.each` + message | variant | alertShouldRender + ${'Test error'} | ${'danger'} | ${true} + ${'Test notice'} | ${'info'} | ${true} + ${''} | ${undefined} | ${false} + ${undefined} | ${undefined} | ${false} + `( + 'renders correct alert when message is `$message` and variant is `$variant`', + async ({ message, alertShouldRender, variant }) => { + createComponent(); + + store.commit(SET_ALERT, { message, variant }); + await nextTick(); + + const alert = findAlert(); + + expect(alert.exists()).toBe(alertShouldRender); + if (alertShouldRender) { + expect(alert.isVisible()).toBe(alertShouldRender); + expect(alert.text()).toContain(message); + expect(alert.props('variant')).toBe(variant); + expect(findAlertLink().exists()).toBe(false); + } + }, + ); - beforeEach(async () => { - jest.spyOn(api, 'fetchSubscriptions').mockResolvedValue({ data: { subscriptions: [] } }); - jest.spyOn(AccessorUtilities, 'canUseCrypto').mockReturnValue(true); + it('hides alert on @dismiss event', async () => { + createComponent(); - createComponent({ - initialState: { - currentUser: { name: 'root' }, - }, - provide: { - glFeatures: { jiraConnectOauth: true }, - subscriptionsPath: mockSubscriptionsPath, - }, + store.commit(SET_ALERT, { message: 'test message' }); + await nextTick(); + + findAlert().vm.$emit('dismiss'); + await nextTick(); + + expect(findAlert().exists()).toBe(false); }); - findSignInPage().vm.$emit('sign-in-oauth'); - await nextTick(); - }); + it('renders link when `linkUrl` is set', async () => { + createComponent(); - describe('when oauth button emits `sign-in-oauth` event', () => { - it('dispatches `fetchSubscriptions` action', () => { - expect(store.dispatch).toHaveBeenCalledWith('fetchSubscriptions', mockSubscriptionsPath); + store.commit(SET_ALERT, { + message: __('test message %{linkStart}test link%{linkEnd}'), + linkUrl: 'https://gitlab.com', + }); + await nextTick(); + + const alertLink = findAlertLink(); + + expect(alertLink.exists()).toBe(true); + expect(alertLink.text()).toContain('test link'); + expect(alertLink.attributes('href')).toBe('https://gitlab.com'); }); }); }); diff --git a/spec/frontend/jira_connect/subscriptions/components/browser_support_alert_spec.js b/spec/frontend/jira_connect/subscriptions/components/browser_support_alert_spec.js index aa93a6be3c8..a8aa383d917 100644 --- a/spec/frontend/jira_connect/subscriptions/components/browser_support_alert_spec.js +++ b/spec/frontend/jira_connect/subscriptions/components/browser_support_alert_spec.js @@ -12,10 +12,6 @@ describe('BrowserSupportAlert', () => { const findAlert = () => wrapper.findComponent(GlAlert); const findLink = () => wrapper.findComponent(GlLink); - afterEach(() => { - wrapper.destroy(); - }); - it('displays a non-dismissible alert', () => { createComponent(); diff --git a/spec/frontend/jira_connect/subscriptions/components/group_item_name_spec.js b/spec/frontend/jira_connect/subscriptions/components/group_item_name_spec.js index b5fe08486b1..e4da10569f3 100644 --- a/spec/frontend/jira_connect/subscriptions/components/group_item_name_spec.js +++ b/spec/frontend/jira_connect/subscriptions/components/group_item_name_spec.js @@ -14,10 +14,6 @@ describe('GroupItemName', () => { }); }; - afterEach(() => { - wrapper.destroy(); - }); - describe('template', () => { it('matches the snapshot', () => { createComponent(); diff --git a/spec/frontend/jira_connect/subscriptions/components/sign_in_legacy_button_spec.js b/spec/frontend/jira_connect/subscriptions/components/sign_in_legacy_button_spec.js deleted file mode 100644 index 4ebfaed261e..00000000000 --- a/spec/frontend/jira_connect/subscriptions/components/sign_in_legacy_button_spec.js +++ /dev/null @@ -1,58 +0,0 @@ -import { GlButton } from '@gitlab/ui'; -import { shallowMount } from '@vue/test-utils'; -import { getGitlabSignInURL } from '~/jira_connect/subscriptions/utils'; -import SignInLegacyButton from '~/jira_connect/subscriptions/components/sign_in_legacy_button.vue'; -import waitForPromises from 'helpers/wait_for_promises'; - -const MOCK_USERS_PATH = '/user'; - -jest.mock('~/jira_connect/subscriptions/utils'); - -describe('SignInLegacyButton', () => { - let wrapper; - - const createComponent = ({ slots } = {}) => { - wrapper = shallowMount(SignInLegacyButton, { - propsData: { - usersPath: MOCK_USERS_PATH, - }, - slots, - }); - }; - - const findButton = () => wrapper.findComponent(GlButton); - - afterEach(() => { - wrapper.destroy(); - }); - - it('displays a button', () => { - createComponent(); - - expect(findButton().exists()).toBe(true); - expect(findButton().text()).toBe(SignInLegacyButton.i18n.defaultButtonText); - }); - - describe.each` - expectedHref - ${MOCK_USERS_PATH} - ${`${MOCK_USERS_PATH}?return_to=${encodeURIComponent('https://test.jira.com')}`} - `('when getGitlabSignInURL resolves with `$expectedHref`', ({ expectedHref }) => { - it(`sets button href to ${expectedHref}`, async () => { - getGitlabSignInURL.mockResolvedValue(expectedHref); - createComponent(); - - await waitForPromises(); - - expect(findButton().attributes('href')).toBe(expectedHref); - }); - }); - - describe('with slot', () => { - const mockSlotContent = 'custom button content!'; - it('renders slot content in button', () => { - createComponent({ slots: { default: mockSlotContent } }); - expect(wrapper.text()).toMatchInterpolatedText(mockSlotContent); - }); - }); -}); 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 e20c4b62e77..ee272d55e0e 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 @@ -56,10 +56,6 @@ describe('SignInOauthButton', () => { }); }; - afterEach(() => { - wrapper.destroy(); - }); - const findButton = () => wrapper.findComponent(GlButton); describe('when `gitlabBasePath` is GitLab.com', () => { it('displays a button', () => { @@ -161,6 +157,7 @@ describe('SignInOauthButton', () => { const mockEvent = { origin: messageOrigin, data: { + type: 'jiraConnectOauthCallback', state: messageState, code: '1234', }, @@ -186,6 +183,7 @@ describe('SignInOauthButton', () => { const mockEvent = { origin: window.origin, data: { + type: 'jiraConnectOauthCallback', state: mockOauthMetadata.state, code: '1234', }, diff --git a/spec/frontend/jira_connect/subscriptions/components/subscriptions_list_spec.js b/spec/frontend/jira_connect/subscriptions/components/subscriptions_list_spec.js index 2d7c58fc278..5337575d5ef 100644 --- a/spec/frontend/jira_connect/subscriptions/components/subscriptions_list_spec.js +++ b/spec/frontend/jira_connect/subscriptions/components/subscriptions_list_spec.js @@ -29,10 +29,6 @@ describe('SubscriptionsList', () => { }); }; - afterEach(() => { - wrapper.destroy(); - }); - const findUnlinkButton = () => wrapper.findComponent(GlButton); const clickUnlinkButton = () => findUnlinkButton().trigger('click'); diff --git a/spec/frontend/jira_connect/subscriptions/components/user_link_spec.js b/spec/frontend/jira_connect/subscriptions/components/user_link_spec.js index e16121243a0..77bc1d2004c 100644 --- a/spec/frontend/jira_connect/subscriptions/components/user_link_spec.js +++ b/spec/frontend/jira_connect/subscriptions/components/user_link_spec.js @@ -1,13 +1,7 @@ import { GlSprintf } from '@gitlab/ui'; import UserLink from '~/jira_connect/subscriptions/components/user_link.vue'; -import SignInOauthButton from '~/jira_connect/subscriptions/components/sign_in_oauth_button.vue'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; -import waitForPromises from 'helpers/wait_for_promises'; - -jest.mock('~/jira_connect/subscriptions/utils', () => ({ - getGitlabSignInURL: jest.fn().mockImplementation((path) => Promise.resolve(path)), -})); describe('UserLink', () => { let wrapper; @@ -18,76 +12,17 @@ describe('UserLink', () => { provide, stubs: { GlSprintf, - SignInOauthButton, }, }); }; - const findSignInLink = () => wrapper.findByTestId('sign-in-link'); const findGitlabUserLink = () => wrapper.findByTestId('gitlab-user-link'); const findSprintf = () => wrapper.findComponent(GlSprintf); - const findOauthButton = () => wrapper.findComponent(SignInOauthButton); - - afterEach(() => { - wrapper.destroy(); - }); - - describe.each` - userSignedIn | hasSubscriptions | expectGlSprintf | expectGlLink | expectOauthButton | jiraConnectOauthEnabled - ${true} | ${false} | ${true} | ${false} | ${false} | ${false} - ${false} | ${true} | ${false} | ${true} | ${false} | ${false} - ${true} | ${true} | ${true} | ${false} | ${false} | ${false} - ${false} | ${false} | ${false} | ${false} | ${false} | ${false} - ${false} | ${true} | ${false} | ${false} | ${true} | ${true} - `( - 'when `userSignedIn` is $userSignedIn, `hasSubscriptions` is $hasSubscriptions, `jiraConnectOauthEnabled` is $jiraConnectOauthEnabled', - ({ - userSignedIn, - hasSubscriptions, - expectGlSprintf, - expectGlLink, - expectOauthButton, - jiraConnectOauthEnabled, - }) => { - it('renders template correctly', () => { - createComponent( - { - userSignedIn, - hasSubscriptions, - }, - { - provide: { - glFeatures: { - jiraConnectOauth: jiraConnectOauthEnabled, - }, - oauthMetadata: {}, - }, - }, - ); - expect(findSprintf().exists()).toBe(expectGlSprintf); - expect(findSignInLink().exists()).toBe(expectGlLink); - expect(findOauthButton().exists()).toBe(expectOauthButton); - }); - }, - ); + it('renders template correctly', () => { + createComponent(); - describe('sign in link', () => { - it('renders with correct href', async () => { - const mockUsersPath = '/user'; - createComponent( - { - userSignedIn: false, - hasSubscriptions: true, - }, - { provide: { usersPath: mockUsersPath } }, - ); - - await waitForPromises(); - - expect(findSignInLink().exists()).toBe(true); - expect(findSignInLink().attributes('href')).toBe(mockUsersPath); - }); + expect(findSprintf().exists()).toBe(true); }); describe('gitlab user link', () => { @@ -102,14 +37,7 @@ describe('UserLink', () => { beforeEach(() => { window.gon = { current_username, relative_root_url: '' }; - createComponent( - { - userSignedIn: true, - hasSubscriptions: true, - user, - }, - { provide: { gitlabUserPath } }, - ); + createComponent({ user }, { provide: { gitlabUserPath } }); }); it(`sets href to ${expectedUserLink}`, () => { diff --git a/spec/frontend/jira_connect/subscriptions/pages/sign_in/sign_in_gitlab_com_spec.js b/spec/frontend/jira_connect/subscriptions/pages/sign_in/sign_in_gitlab_com_spec.js index b9a8451f3b3..4cfd925db34 100644 --- a/spec/frontend/jira_connect/subscriptions/pages/sign_in/sign_in_gitlab_com_spec.js +++ b/spec/frontend/jira_connect/subscriptions/pages/sign_in/sign_in_gitlab_com_spec.js @@ -1,7 +1,6 @@ import { shallowMount } from '@vue/test-utils'; import SignInGitlabCom from '~/jira_connect/subscriptions/pages/sign_in/sign_in_gitlab_com.vue'; -import SignInLegacyButton from '~/jira_connect/subscriptions/components/sign_in_legacy_button.vue'; import SignInOauthButton from '~/jira_connect/subscriptions/components/sign_in_oauth_button.vue'; import SubscriptionsList from '~/jira_connect/subscriptions/components/subscriptions_list.vue'; import createStore from '~/jira_connect/subscriptions/store'; @@ -9,100 +8,69 @@ import { I18N_DEFAULT_SIGN_IN_BUTTON_TEXT } from '~/jira_connect/subscriptions/c jest.mock('~/jira_connect/subscriptions/utils'); -const mockUsersPath = '/test'; const defaultProvide = { oauthMetadata: {}, - usersPath: mockUsersPath, }; describe('SignInGitlabCom', () => { let wrapper; let store; - const findSignInLegacyButton = () => wrapper.findComponent(SignInLegacyButton); const findSignInOauthButton = () => wrapper.findComponent(SignInOauthButton); const findSubscriptionsList = () => wrapper.findComponent(SubscriptionsList); - const createComponent = ({ props, jiraConnectOauthEnabled } = {}) => { + const createComponent = ({ props } = {}) => { store = createStore(); wrapper = shallowMount(SignInGitlabCom, { store, provide: { ...defaultProvide, - glFeatures: { - jiraConnectOauth: jiraConnectOauthEnabled, - }, }, propsData: props, stubs: { - SignInLegacyButton, SignInOauthButton, }, }); }; - afterEach(() => { - wrapper.destroy(); - }); - describe('template', () => { describe.each` scenario | hasSubscriptions | signInButtonText ${'with subscriptions'} | ${true} | ${SignInGitlabCom.i18n.signInButtonTextWithSubscriptions} ${'without subscriptions'} | ${false} | ${I18N_DEFAULT_SIGN_IN_BUTTON_TEXT} `('$scenario', ({ hasSubscriptions, signInButtonText }) => { - describe('when `jiraConnectOauthEnabled` feature flag is disabled', () => { - beforeEach(() => { - createComponent({ - jiraConnectOauthEnabled: false, - props: { - hasSubscriptions, - }, - }); - }); - - it('renders legacy sign in button', () => { - const button = findSignInLegacyButton(); - expect(button.props('usersPath')).toBe(mockUsersPath); - expect(button.text()).toMatchInterpolatedText(signInButtonText); + beforeEach(() => { + createComponent({ + props: { + hasSubscriptions, + }, }); }); - describe('when `jiraConnectOauthEnabled` feature flag is enabled', () => { - beforeEach(() => { - createComponent({ - jiraConnectOauthEnabled: true, - props: { - hasSubscriptions, - }, - }); + describe('oauth sign in button', () => { + it('renders oauth sign in button', () => { + const button = findSignInOauthButton(); + expect(button.text()).toMatchInterpolatedText(signInButtonText); }); - describe('oauth sign in button', () => { - it('renders oauth sign in button', () => { + describe('when button emits `sign-in` event', () => { + it('emits `sign-in-oauth` event', () => { const button = findSignInOauthButton(); - expect(button.text()).toMatchInterpolatedText(signInButtonText); - }); - - describe('when button emits `sign-in` event', () => { - it('emits `sign-in-oauth` event', () => { - const button = findSignInOauthButton(); - const mockUser = { name: 'test' }; - button.vm.$emit('sign-in', mockUser); + const mockUser = { name: 'test' }; + button.vm.$emit('sign-in', mockUser); - expect(wrapper.emitted('sign-in-oauth')[0]).toEqual([mockUser]); - }); + expect(wrapper.emitted('sign-in-oauth')[0]).toEqual([mockUser]); }); + }); - describe('when button emits `error` event', () => { - it('emits `error` event', () => { - const button = findSignInOauthButton(); - button.vm.$emit('error'); + describe('when button emits `error` event', () => { + it('emits `error` event', () => { + const button = findSignInOauthButton(); + button.vm.$emit('error'); - expect(wrapper.emitted('error')).toHaveLength(1); - }); + expect(wrapper.emitted('error')).toHaveLength(1); }); }); }); diff --git a/spec/frontend/jira_connect/subscriptions/pages/sign_in/sign_in_gitlab_multiversion/index_spec.js b/spec/frontend/jira_connect/subscriptions/pages/sign_in/sign_in_gitlab_multiversion/index_spec.js index e98c6ff1054..93663319e6d 100644 --- a/spec/frontend/jira_connect/subscriptions/pages/sign_in/sign_in_gitlab_multiversion/index_spec.js +++ b/spec/frontend/jira_connect/subscriptions/pages/sign_in/sign_in_gitlab_multiversion/index_spec.js @@ -1,12 +1,11 @@ import { nextTick } from 'vue'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; -import SetupInstructions from '~/jira_connect/subscriptions/pages/sign_in/sign_in_gitlab_multiversion/setup_instructions.vue'; import SignInGitlabMultiversion from '~/jira_connect/subscriptions/pages/sign_in/sign_in_gitlab_multiversion/index.vue'; import SignInOauthButton from '~/jira_connect/subscriptions/components/sign_in_oauth_button.vue'; import VersionSelectForm from '~/jira_connect/subscriptions/pages/sign_in/sign_in_gitlab_multiversion/version_select_form.vue'; -import { updateInstallation } from '~/jira_connect/subscriptions/api'; +import { updateInstallation, setApiBaseURL } from '~/jira_connect/subscriptions/api'; import { reloadPage, persistBaseUrl, retrieveBaseUrl } from '~/jira_connect/subscriptions/utils'; import { GITLAB_COM_BASE_PATH } from '~/jira_connect/subscriptions/constants'; @@ -23,7 +22,6 @@ describe('SignInGitlabMultiversion', () => { const mockBasePath = 'gitlab.mycompany.com'; - const findSetupInstructions = () => wrapper.findComponent(SetupInstructions); const findSignInOauthButton = () => wrapper.findComponent(SignInOauthButton); const findVersionSelectForm = () => wrapper.findComponent(VersionSelectForm); const findSubtitle = () => wrapper.findByTestId('subtitle'); @@ -32,10 +30,6 @@ describe('SignInGitlabMultiversion', () => { wrapper = shallowMountExtended(SignInGitlabMultiversion); }; - afterEach(() => { - wrapper.destroy(); - }); - describe('when version is not selected', () => { describe('VersionSelectForm', () => { it('renders version select form', () => { @@ -72,23 +66,12 @@ describe('SignInGitlabMultiversion', () => { expect(findSubtitle().text()).toBe(SignInGitlabMultiversion.i18n.signInSubtitle); }); - it('renders setup instructions', () => { - expect(findSetupInstructions().exists()).toBe(true); + it('renders sign in button', () => { + expect(findSignInOauthButton().props('gitlabBasePath')).toBe(mockBasePath); }); - describe('when SetupInstructions emits `next` event', () => { - beforeEach(async () => { - findSetupInstructions().vm.$emit('next'); - await nextTick(); - }); - - it('renders sign in button', () => { - expect(findSignInOauthButton().props('gitlabBasePath')).toBe(mockBasePath); - }); - - it('hides setup instructions', () => { - expect(findSetupInstructions().exists()).toBe(false); - }); + it('calls setApiBaseURL with correct params', () => { + expect(setApiBaseURL).toHaveBeenCalledWith(mockBasePath); }); }); @@ -98,14 +81,14 @@ describe('SignInGitlabMultiversion', () => { createComponent(); }); - it('does not render setup instructions', () => { - expect(findSetupInstructions().exists()).toBe(false); - }); - it('renders sign in button', () => { expect(findSignInOauthButton().props('gitlabBasePath')).toBe(GITLAB_COM_BASE_PATH); }); + it('does not call setApiBaseURL', () => { + expect(setApiBaseURL).not.toHaveBeenCalled(); + }); + describe('when button emits `sign-in` event', () => { it('emits `sign-in-oauth` event', () => { const button = findSignInOauthButton(); diff --git a/spec/frontend/jira_connect/subscriptions/pages/sign_in/sign_in_gitlab_multiversion/setup_instructions_spec.js b/spec/frontend/jira_connect/subscriptions/pages/sign_in/sign_in_gitlab_multiversion/setup_instructions_spec.js index 5496cf008c5..40ea6058c70 100644 --- a/spec/frontend/jira_connect/subscriptions/pages/sign_in/sign_in_gitlab_multiversion/setup_instructions_spec.js +++ b/spec/frontend/jira_connect/subscriptions/pages/sign_in/sign_in_gitlab_multiversion/setup_instructions_spec.js @@ -7,8 +7,9 @@ import SetupInstructions from '~/jira_connect/subscriptions/pages/sign_in/sign_i describe('SetupInstructions', () => { let wrapper; - const findGlButton = () => wrapper.findComponent(GlButton); const findGlLink = () => wrapper.findComponent(GlLink); + const findBackButton = () => wrapper.findAllComponents(GlButton).at(0); + const findNextButton = () => wrapper.findAllComponents(GlButton).at(1); const createComponent = () => { wrapper = shallowMount(SetupInstructions); @@ -23,12 +24,23 @@ describe('SetupInstructions', () => { expect(findGlLink().attributes('href')).toBe(OAUTH_SELF_MANAGED_DOC_LINK); }); - describe('when button is clicked', () => { + describe('when "Next" button is clicked', () => { it('emits "next" event', () => { expect(wrapper.emitted('next')).toBeUndefined(); - findGlButton().vm.$emit('click'); + findNextButton().vm.$emit('click'); expect(wrapper.emitted('next')).toHaveLength(1); + expect(wrapper.emitted('back')).toBeUndefined(); + }); + }); + + describe('when "Back" button is clicked', () => { + it('emits "back" event', () => { + expect(wrapper.emitted('back')).toBeUndefined(); + findBackButton().vm.$emit('click'); + + expect(wrapper.emitted('back')).toHaveLength(1); + expect(wrapper.emitted('next')).toBeUndefined(); }); }); }); diff --git a/spec/frontend/jira_connect/subscriptions/pages/sign_in/sign_in_gitlab_multiversion/version_select_form_spec.js b/spec/frontend/jira_connect/subscriptions/pages/sign_in/sign_in_gitlab_multiversion/version_select_form_spec.js index 29e7fe7a5b2..2a08547b048 100644 --- a/spec/frontend/jira_connect/subscriptions/pages/sign_in/sign_in_gitlab_multiversion/version_select_form_spec.js +++ b/spec/frontend/jira_connect/subscriptions/pages/sign_in/sign_in_gitlab_multiversion/version_select_form_spec.js @@ -1,8 +1,9 @@ import { GlFormInput, GlFormRadioGroup, GlForm } from '@gitlab/ui'; -import { nextTick } from 'vue'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; import VersionSelectForm from '~/jira_connect/subscriptions/pages/sign_in/sign_in_gitlab_multiversion/version_select_form.vue'; +import SelfManagedAlert from '~/jira_connect/subscriptions/pages/sign_in/sign_in_gitlab_multiversion/self_managed_alert.vue'; +import SetupInstructions from '~/jira_connect/subscriptions/pages/sign_in/sign_in_gitlab_multiversion/setup_instructions.vue'; describe('VersionSelectForm', () => { let wrapper; @@ -10,30 +11,53 @@ describe('VersionSelectForm', () => { const findFormRadioGroup = () => wrapper.findComponent(GlFormRadioGroup); const findForm = () => wrapper.findComponent(GlForm); const findInput = () => wrapper.findComponent(GlFormInput); + const findSelfManagedAlert = () => wrapper.findComponent(SelfManagedAlert); + const findSetupInstructions = () => wrapper.findComponent(SetupInstructions); + const findBackButton = () => wrapper.findByTestId('back-button'); + const findSubmitButton = () => wrapper.findByTestId('submit-button'); const submitForm = () => findForm().vm.$emit('submit', new Event('submit')); + const expectSelfManagedFlowAtStep = (step) => { + // step 0 is for SaaS which doesn't have any of the self-managed elements + const expectSelfManagedAlert = step === 1; + const expectSetupInstructions = step === 2; + const expectSelfManagedInput = step === 3; + + it(`${expectSelfManagedAlert ? 'renders' : 'does not render'} self-managed alert`, () => { + expect(findSelfManagedAlert().exists()).toBe(expectSelfManagedAlert); + }); + + it(`${expectSetupInstructions ? 'renders' : 'does not render'} setup instructions`, () => { + expect(findSetupInstructions().exists()).toBe(expectSetupInstructions); + }); + + it(`${ + expectSelfManagedInput ? 'renders' : 'does not render' + } self-managed instance URL input`, () => { + expect(findInput().exists()).toBe(expectSelfManagedInput); + }); + }; + const createComponent = () => { wrapper = shallowMountExtended(VersionSelectForm); }; - afterEach(() => { - wrapper.destroy(); - }); - - describe('default state', () => { + describe('when "SaaS" radio option is selected (default state)', () => { beforeEach(() => { createComponent(); }); - it('selects saas radio option by default', () => { + it('selects "saas" radio option by default', () => { expect(findFormRadioGroup().vm.$attrs.checked).toBe(VersionSelectForm.radioOptions.saas); }); - it('does not render instance input', () => { - expect(findInput().exists()).toBe(false); + it('renders submit button as "Save"', () => { + expect(findSubmitButton().text()).toBe(VersionSelectForm.i18n.buttonSave); }); + expectSelfManagedFlowAtStep(0); + describe('when form is submitted', () => { it('emits "submit" event with gitlab.com as the payload', () => { submitForm(); @@ -43,26 +67,61 @@ describe('VersionSelectForm', () => { }); }); - describe('when "self-managed" radio option is selected', () => { - beforeEach(async () => { + describe('when "self-managed" radio option is selected (step 1 of 3)', () => { + beforeEach(() => { createComponent(); findFormRadioGroup().vm.$emit('input', VersionSelectForm.radioOptions.selfManaged); - await nextTick(); }); - it('reveals the self-managed input field', () => { - expect(findInput().exists()).toBe(true); + it('renders submit button as "Next"', () => { + expect(findSubmitButton().text()).toBe(VersionSelectForm.i18n.buttonNext); }); - describe('when form is submitted', () => { - it('emits "submit" event with the input field value as the payload', () => { - const mockInstanceUrl = 'https://gitlab.example.com'; + expectSelfManagedFlowAtStep(1); - findInput().vm.$emit('input', mockInstanceUrl); + describe('when user clicks "Next" button (next to step 2 of 3)', () => { + beforeEach(() => { submitForm(); + }); + + expectSelfManagedFlowAtStep(2); + + describe('when SetupInstructions emits `next` event (next to step 3 of 3)', () => { + beforeEach(() => { + findSetupInstructions().vm.$emit('next'); + }); + + expectSelfManagedFlowAtStep(3); + + describe('when form is submitted', () => { + it('emits "submit" event with the input field value as the payload', () => { + const mockInstanceUrl = 'https://gitlab.example.com'; + + findInput().vm.$emit('input', mockInstanceUrl); + submitForm(); + + expect(wrapper.emitted('submit')[0][0]).toBe(mockInstanceUrl); + }); + }); + + describe('when back button is clicked', () => { + beforeEach(() => { + findBackButton().vm.$emit('click', { + preventDefault: jest.fn(), // preventDefault is needed to prevent form submission + }); + }); + + expectSelfManagedFlowAtStep(1); + }); + }); + + describe('when SetupInstructions emits `back` event (back to step 1 of 3)', () => { + beforeEach(() => { + findSetupInstructions().vm.$emit('back'); + }); - expect(wrapper.emitted('submit')[0][0]).toBe(mockInstanceUrl); + expectSelfManagedFlowAtStep(1); }); }); }); diff --git a/spec/frontend/jira_connect/subscriptions/pages/sign_in/sign_in_page_spec.js b/spec/frontend/jira_connect/subscriptions/pages/sign_in/sign_in_page_spec.js index b27eba6b040..36e78ff309e 100644 --- a/spec/frontend/jira_connect/subscriptions/pages/sign_in/sign_in_page_spec.js +++ b/spec/frontend/jira_connect/subscriptions/pages/sign_in/sign_in_page_spec.js @@ -12,20 +12,11 @@ describe('SignInPage', () => { const findSignInGitlabCom = () => wrapper.findComponent(SignInGitlabCom); const findSignInGitabMultiversion = () => wrapper.findComponent(SignInGitlabMultiversion); - const createComponent = ({ - props = {}, - jiraConnectOauthEnabled, - publicKeyStorageEnabled, - } = {}) => { + const createComponent = ({ props = {}, publicKeyStorageEnabled } = {}) => { store = createStore(); wrapper = shallowMount(SignInPage, { store, - provide: { - glFeatures: { - jiraConnectOauth: jiraConnectOauthEnabled, - }, - }, propsData: { hasSubscriptions: false, publicKeyStorageEnabled, @@ -34,25 +25,14 @@ describe('SignInPage', () => { }); }; - afterEach(() => { - wrapper.destroy(); - }); - it.each` - jiraConnectOauthEnabled | publicKeyStorageEnabled | shouldRenderDotCom | shouldRenderMultiversion - ${false} | ${true} | ${true} | ${false} - ${false} | ${false} | ${true} | ${false} - ${true} | ${true} | ${false} | ${true} - ${true} | ${false} | ${true} | ${false} + publicKeyStorageEnabled | shouldRenderDotCom | shouldRenderMultiversion + ${true} | ${false} | ${true} + ${false} | ${true} | ${false} `( - 'renders correct component when jiraConnectOauth is $jiraConnectOauthEnabled', - ({ - jiraConnectOauthEnabled, - publicKeyStorageEnabled, - shouldRenderDotCom, - shouldRenderMultiversion, - }) => { - createComponent({ jiraConnectOauthEnabled, publicKeyStorageEnabled }); + 'renders correct component when publicKeyStorageEnabled is $publicKeyStorageEnabled', + ({ publicKeyStorageEnabled, shouldRenderDotCom, shouldRenderMultiversion }) => { + createComponent({ publicKeyStorageEnabled }); expect(findSignInGitlabCom().exists()).toBe(shouldRenderDotCom); expect(findSignInGitabMultiversion().exists()).toBe(shouldRenderMultiversion); diff --git a/spec/frontend/jira_connect/subscriptions/pages/subscriptions_page_spec.js b/spec/frontend/jira_connect/subscriptions/pages/subscriptions_page_spec.js index 4956af76ead..d262f4b2735 100644 --- a/spec/frontend/jira_connect/subscriptions/pages/subscriptions_page_spec.js +++ b/spec/frontend/jira_connect/subscriptions/pages/subscriptions_page_spec.js @@ -26,10 +26,6 @@ describe('SubscriptionsPage', () => { }); }; - afterEach(() => { - wrapper.destroy(); - }); - describe('template', () => { describe.each` scenario | subscriptionsLoading | hasSubscriptions | expectSubscriptionsList | expectEmptyState diff --git a/spec/frontend/jira_connect/subscriptions/store/actions_spec.js b/spec/frontend/jira_connect/subscriptions/store/actions_spec.js index 5e3c30269b5..e53c3e766d2 100644 --- a/spec/frontend/jira_connect/subscriptions/store/actions_spec.js +++ b/spec/frontend/jira_connect/subscriptions/store/actions_spec.js @@ -117,7 +117,7 @@ describe('JiraConnect actions', () => { }); describe('when API request succeeds', () => { - it('commits the SET_ACCESS_TOKEN and SET_CURRENT_USER mutations', async () => { + it('commits the SET_ALERT mutation', async () => { jest.spyOn(api, 'addJiraConnectSubscription').mockResolvedValue({ success: true }); await testAction( @@ -125,7 +125,6 @@ describe('JiraConnect actions', () => { { namespacePath: mockNamespace, subscriptionsPath: mockSubscriptionsPath }, mockedState, [ - { type: types.ADD_SUBSCRIPTION_LOADING, payload: true }, { type: types.SET_ALERT, payload: { @@ -135,7 +134,6 @@ describe('JiraConnect actions', () => { variant: 'success', }, }, - { type: types.ADD_SUBSCRIPTION_LOADING, payload: false }, ], [{ type: 'fetchSubscriptions', payload: mockSubscriptionsPath }], ); @@ -148,20 +146,18 @@ describe('JiraConnect actions', () => { }); describe('when API request fails', () => { - it('commits the SET_CURRENT_USER_ERROR mutation', async () => { + it('does not commit the SET_ALERT mutation', () => { jest.spyOn(api, 'addJiraConnectSubscription').mockRejectedValue(); - await testAction( + // We need the empty catch(), since we are testing rejecting the promise, + // which would otherwise cause the test to fail. + testAction( addSubscription, - mockNamespace, + { namespacePath: mockNamespace, subscriptionsPath: mockSubscriptionsPath }, mockedState, - [ - { type: types.ADD_SUBSCRIPTION_LOADING, payload: true }, - { type: types.ADD_SUBSCRIPTION_ERROR }, - { type: types.ADD_SUBSCRIPTION_LOADING, payload: false }, - ], [], - ); + [], + ).catch(() => {}); }); }); }); diff --git a/spec/frontend/jira_connect/subscriptions/store/mutations_spec.js b/spec/frontend/jira_connect/subscriptions/store/mutations_spec.js index aeb136a76b9..e41bcec19b7 100644 --- a/spec/frontend/jira_connect/subscriptions/store/mutations_spec.js +++ b/spec/frontend/jira_connect/subscriptions/store/mutations_spec.js @@ -51,22 +51,6 @@ describe('JiraConnect store mutations', () => { }); }); - describe('ADD_SUBSCRIPTION_LOADING', () => { - it('sets addSubscriptionLoading', () => { - mutations.ADD_SUBSCRIPTION_LOADING(localState, true); - - expect(localState.addSubscriptionLoading).toBe(true); - }); - }); - - describe('ADD_SUBSCRIPTION_ERROR', () => { - it('sets addSubscriptionError', () => { - mutations.ADD_SUBSCRIPTION_ERROR(localState, true); - - expect(localState.addSubscriptionError).toBe(true); - }); - }); - describe('SET_CURRENT_USER', () => { it('sets currentUser', () => { const mockUser = { name: 'root' }; diff --git a/spec/frontend/jira_connect/subscriptions/utils_spec.js b/spec/frontend/jira_connect/subscriptions/utils_spec.js index 762d9eb3443..d1588dbad2c 100644 --- a/spec/frontend/jira_connect/subscriptions/utils_spec.js +++ b/spec/frontend/jira_connect/subscriptions/utils_spec.js @@ -5,10 +5,8 @@ import { persistAlert, retrieveAlert, getJwt, - getLocation, reloadPage, sizeToParent, - getGitlabSignInURL, } from '~/jira_connect/subscriptions/utils'; describe('JiraConnect utils', () => { @@ -69,29 +67,6 @@ describe('JiraConnect utils', () => { }); }); - describe('getLocation', () => { - const mockLocation = 'test/location'; - const getLocationSpy = jest.fn((callback) => callback(mockLocation)); - - it('resolves to the function call when AP.getLocation is a function', async () => { - global.AP = { - getLocation: getLocationSpy, - }; - - const location = await getLocation(); - - expect(getLocationSpy).toHaveBeenCalled(); - expect(location).toBe(mockLocation); - }); - - it('resolves to undefined when AP.getLocation is not a function', async () => { - const location = await getLocation(); - - expect(getLocationSpy).not.toHaveBeenCalled(); - expect(location).toBeUndefined(); - }); - }); - describe('reloadPage', () => { const reloadSpy = jest.fn(); @@ -138,25 +113,4 @@ describe('JiraConnect utils', () => { }); }); }); - - describe('getGitlabSignInURL', () => { - const mockSignInURL = 'https://gitlab.com/sign_in'; - - it.each` - returnTo | expectResult - ${undefined} | ${mockSignInURL} - ${''} | ${mockSignInURL} - ${'/test/location'} | ${`${mockSignInURL}?return_to=${encodeURIComponent('/test/location')}`} - `( - 'returns `$expectResult` when `AP.getLocation` resolves to `$returnTo`', - async ({ returnTo, expectResult }) => { - global.AP = { - getLocation: jest.fn().mockImplementation((cb) => cb(returnTo)), - }; - - const url = await getGitlabSignInURL(mockSignInURL); - expect(url).toBe(expectResult); - }, - ); - }); }); |