diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 13:34:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 13:34:06 +0300 |
commit | 859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 (patch) | |
tree | d7f2700abe6b4ffcb2dcfc80631b2d87d0609239 /spec/frontend/integrations/integration_settings_form_spec.js | |
parent | 446d496a6d000c73a304be52587cd9bbc7493136 (diff) |
Add latest changes from gitlab-org/gitlab@13-9-stable-eev13.9.0-rc42
Diffstat (limited to 'spec/frontend/integrations/integration_settings_form_spec.js')
-rw-r--r-- | spec/frontend/integrations/integration_settings_form_spec.js | 81 |
1 files changed, 80 insertions, 1 deletions
diff --git a/spec/frontend/integrations/integration_settings_form_spec.js b/spec/frontend/integrations/integration_settings_form_spec.js index bba851ad796..348b942703f 100644 --- a/spec/frontend/integrations/integration_settings_form_spec.js +++ b/spec/frontend/integrations/integration_settings_form_spec.js @@ -1,6 +1,6 @@ import MockAdaptor from 'axios-mock-adapter'; -import axios from '~/lib/utils/axios_utils'; import IntegrationSettingsForm from '~/integrations/integration_settings_form'; +import axios from '~/lib/utils/axios_utils'; import toast from '~/vue_shared/plugins/global_toast'; jest.mock('~/vue_shared/plugins/global_toast'); @@ -132,4 +132,83 @@ describe('IntegrationSettingsForm', () => { expect(dispatchSpy).toHaveBeenCalledWith('setIsTesting', false); }); }); + + describe('getJiraIssueTypes', () => { + let integrationSettingsForm; + let formData; + let mock; + + beforeEach(() => { + mock = new MockAdaptor(axios); + + jest.spyOn(axios, 'put'); + + integrationSettingsForm = new IntegrationSettingsForm('.js-integration-settings-form'); + integrationSettingsForm.init(); + + // eslint-disable-next-line no-jquery/no-serialize + formData = integrationSettingsForm.$form.serialize(); + }); + + afterEach(() => { + mock.restore(); + }); + + it('should always dispatch `requestJiraIssueTypes`', async () => { + const dispatchSpy = jest.fn(); + + mock.onPut(integrationSettingsForm.testEndPoint).networkError(); + + integrationSettingsForm.vue.$store = { dispatch: dispatchSpy }; + + await integrationSettingsForm.getJiraIssueTypes(); + + expect(dispatchSpy).toHaveBeenCalledWith('requestJiraIssueTypes'); + }); + + it('should make an ajax request with provided `formData`', async () => { + await integrationSettingsForm.getJiraIssueTypes(formData); + + expect(axios.put).toHaveBeenCalledWith(integrationSettingsForm.testEndPoint, formData); + }); + + it('should dispatch `receiveJiraIssueTypesSuccess` with the correct payload if ajax request is successful', async () => { + const mockData = ['ISSUE', 'EPIC']; + const dispatchSpy = jest.fn(); + + mock.onPut(integrationSettingsForm.testEndPoint).reply(200, { + error: false, + issuetypes: mockData, + }); + + integrationSettingsForm.vue.$store = { dispatch: dispatchSpy }; + + await integrationSettingsForm.getJiraIssueTypes(formData); + + expect(dispatchSpy).toHaveBeenCalledWith('receiveJiraIssueTypesSuccess', mockData); + }); + + it.each(['something went wrong', undefined])( + 'should dispatch "receiveJiraIssueTypesError" with a message if the backend responds with error', + async (responseErrorMessage) => { + const defaultErrorMessage = 'Connection failed. Please check your settings.'; + const expectedErrorMessage = responseErrorMessage || defaultErrorMessage; + const dispatchSpy = jest.fn(); + + mock.onPut(integrationSettingsForm.testEndPoint).reply(200, { + error: true, + message: responseErrorMessage, + }); + + integrationSettingsForm.vue.$store = { dispatch: dispatchSpy }; + + await integrationSettingsForm.getJiraIssueTypes(formData); + + expect(dispatchSpy).toHaveBeenCalledWith( + 'receiveJiraIssueTypesError', + expectedErrorMessage, + ); + }, + ); + }); }); |