diff options
Diffstat (limited to 'spec/frontend/jira_connect/subscriptions/components/add_namespace_modal/groups_list_item_spec.js')
-rw-r--r-- | spec/frontend/jira_connect/subscriptions/components/add_namespace_modal/groups_list_item_spec.js | 116 |
1 files changed, 78 insertions, 38 deletions
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 3d7bf7acb41..5df54abfc05 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 @@ -7,21 +7,35 @@ 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; - const mockSubscriptionPath = 'subscriptionPath'; + let store; + + const mockAddSubscriptionsPath = '/addSubscriptionsPath'; + + const createComponent = ({ mountFn = shallowMount, provide } = {}) => { + store = createStore(); + + jest.spyOn(store, 'dispatch').mockImplementation(); - const createComponent = ({ mountFn = shallowMount } = {}) => { wrapper = mountFn(GroupsListItem, { + store, propsData: { group: mockGroup1, }, provide: { - subscriptionsPath: mockSubscriptionPath, + addSubscriptionsPath: mockAddSubscriptionsPath, + ...provide, }, }); }; @@ -51,62 +65,88 @@ describe('GroupsListItem', () => { }); describe('on Link button click', () => { - let addSubscriptionSpy; + describe('when jiraConnectOauth feature flag is disabled', () => { + let addSubscriptionSpy; - beforeEach(() => { - createComponent({ mountFn: mount }); + beforeEach(() => { + createComponent({ mountFn: mount }); - addSubscriptionSpy = jest.spyOn(JiraConnectApi, 'addSubscription').mockResolvedValue(); - }); + addSubscriptionSpy = jest.spyOn(JiraConnectApi, 'addSubscription').mockResolvedValue(); + }); - it('sets button to loading and sends request', async () => { - expect(findLinkButton().props('loading')).toBe(false); + it('sets button to loading and sends request', async () => { + expect(findLinkButton().props('loading')).toBe(false); + + clickLinkButton(); + await nextTick(); - clickLinkButton(); + expect(findLinkButton().props('loading')).toBe(true); + await waitForPromises(); - await nextTick(); + 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', + }); + }); - expect(findLinkButton().props('loading')).toBe(true); + describe('when request is successful', () => { + it('reloads the page', async () => { + clickLinkButton(); - await waitForPromises(); + await waitForPromises(); - expect(addSubscriptionSpy).toHaveBeenCalledWith(mockSubscriptionPath, mockGroup1.full_path); - expect(persistAlert).toHaveBeenCalledWith({ - linkUrl: '/help/integration/jira_development_panel.html#use-the-integration', - message: - 'You should now see GitLab.com activity inside your Jira Cloud issues. %{linkStart}Learn more%{linkEnd}', - title: 'Namespace successfully linked', - variant: 'success', + expect(reloadPage).toHaveBeenCalled(); + }); }); - }); - describe('when request is successful', () => { - it('reloads the page', async () => { - clickLinkButton(); + describe('when request has errors', () => { + const mockErrorMessage = 'error message'; + const mockError = { response: { data: { error: mockErrorMessage } } }; - await waitForPromises(); + beforeEach(() => { + addSubscriptionSpy = jest + .spyOn(JiraConnectApi, 'addSubscription') + .mockRejectedValue(mockError); + }); - expect(reloadPage).toHaveBeenCalled(); + it('emits `error` event', async () => { + clickLinkButton(); + + await waitForPromises(); + + expect(reloadPage).not.toHaveBeenCalled(); + expect(wrapper.emitted('error')[0][0]).toBe(mockErrorMessage); + }); }); }); - describe('when request has errors', () => { - const mockErrorMessage = 'error message'; - const mockError = { response: { data: { error: mockErrorMessage } } }; + describe('when jiraConnectOauth feature flag is enabled', () => { + const mockSubscriptionsPath = '/subscriptions'; beforeEach(() => { - addSubscriptionSpy = jest - .spyOn(JiraConnectApi, 'addSubscription') - .mockRejectedValue(mockError); + createComponent({ + mountFn: mount, + provide: { + subscriptionsPath: mockSubscriptionsPath, + glFeatures: { jiraConnectOauth: true }, + }, + }); }); - it('emits `error` event', async () => { + it('dispatches `addSubscription` action', async () => { clickLinkButton(); + await nextTick(); - await waitForPromises(); - - expect(reloadPage).not.toHaveBeenCalled(); - expect(wrapper.emitted('error')[0][0]).toBe(mockErrorMessage); + expect(store.dispatch).toHaveBeenCalledWith('addSubscription', { + namespacePath: mockGroup1.full_path, + subscriptionsPath: mockSubscriptionsPath, + }); }); }); }); |