diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-04 15:15:34 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-04 15:15:34 +0000 |
commit | 1b723130416e59bdaef5d662a33f22ac1d3ce953 (patch) | |
tree | 4c18e67d64b30065619300b3172332d8419d7110 /spec/frontend/integrations | |
parent | 9486811b62db7f35906bae75f912aa89804e721b (diff) | |
download | gitlab-ce-1b723130416e59bdaef5d662a33f22ac1d3ce953.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/integrations')
-rw-r--r-- | spec/frontend/integrations/edit/components/integration_form_spec.js | 359 |
1 files changed, 158 insertions, 201 deletions
diff --git a/spec/frontend/integrations/edit/components/integration_form_spec.js b/spec/frontend/integrations/edit/components/integration_form_spec.js index 2f123508c06..7e01b79383a 100644 --- a/spec/frontend/integrations/edit/components/integration_form_spec.js +++ b/spec/frontend/integrations/edit/components/integration_form_spec.js @@ -33,13 +33,6 @@ describe('IntegrationForm', () => { let wrapper; let dispatch; let mockAxios; - let mockForm; - let vueIntegrationFormFeatureFlag; - - const createForm = () => { - mockForm = document.createElement('form'); - jest.spyOn(document, 'querySelector').mockReturnValue(mockForm); - }; const createComponent = ({ customStateProps = {}, @@ -53,10 +46,6 @@ describe('IntegrationForm', () => { }); dispatch = jest.spyOn(store, 'dispatch').mockImplementation(); - if (!vueIntegrationFormFeatureFlag) { - createForm(); - } - wrapper = mountFn(IntegrationForm, { propsData: { ...props }, store, @@ -72,11 +61,6 @@ describe('IntegrationForm', () => { show: mockToastShow, }, }, - provide: { - glFeatures: { - vueIntegrationForm: vueIntegrationFormFeatureFlag, - }, - }, }); }; @@ -93,14 +77,8 @@ describe('IntegrationForm', () => { const findTriggerFields = () => wrapper.findComponent(TriggerFields); const findGlForm = () => wrapper.findComponent(GlForm); const findRedirectToField = () => wrapper.findByTestId('redirect-to-field'); - const findFormElement = () => (vueIntegrationFormFeatureFlag ? findGlForm().element : mockForm); const findDynamicField = () => wrapper.findComponent(DynamicField); - const mockFormFunctions = ({ checkValidityReturn }) => { - jest.spyOn(findFormElement(), 'checkValidity').mockReturnValue(checkValidityReturn); - jest.spyOn(findFormElement(), 'submit'); - }; - beforeEach(() => { mockAxios = new MockAdapter(axios); }); @@ -355,17 +333,14 @@ describe('IntegrationForm', () => { }); }); - describe('when `vueIntegrationForm` feature flag is $vueIntegrationFormEnabled', () => { - it('renders hidden fields', () => { - vueIntegrationFormFeatureFlag = true; - createComponent({ - customStateProps: { - redirectTo: '/services', - }, - }); - - expect(findRedirectToField().attributes('value')).toBe('/services'); + it('renders hidden fields', () => { + createComponent({ + customStateProps: { + redirectTo: '/services', + }, }); + + expect(findRedirectToField().attributes('value')).toBe('/services'); }); }); @@ -387,218 +362,200 @@ describe('IntegrationForm', () => { }); describe.each` - formActive | vueIntegrationFormEnabled | novalidate - ${true} | ${true} | ${null} - ${false} | ${true} | ${'novalidate'} - ${true} | ${false} | ${null} - ${false} | ${false} | ${'true'} + formActive | novalidate + ${true} | ${undefined} + ${false} | ${'true'} `( - 'when `vueIntegrationForm` feature flag is $vueIntegrationFormEnabled and `toggle-integration-active` is emitted with $formActive', - ({ formActive, vueIntegrationFormEnabled, novalidate }) => { + 'when `toggle-integration-active` is emitted with $formActive', + ({ formActive, novalidate }) => { beforeEach(async () => { - vueIntegrationFormFeatureFlag = vueIntegrationFormEnabled; - createComponent({ customStateProps: { showActive: true, initialActivated: false, }, - mountFn: mountExtended, }); - mockFormFunctions({ checkValidityReturn: false }); await findActiveCheckbox().vm.$emit('toggle-integration-active', formActive); }); it(`sets noValidate to ${novalidate}`, () => { - expect(findFormElement().getAttribute('novalidate')).toBe(novalidate); + expect(findGlForm().attributes('novalidate')).toBe(novalidate); }); }, ); }); - describe.each` - vueIntegrationFormEnabled - ${true} - ${false} - `( - 'when `vueIntegrationForm` feature flag is $vueIntegrationFormEnabled', - ({ vueIntegrationFormEnabled }) => { - beforeEach(() => { - vueIntegrationFormFeatureFlag = vueIntegrationFormEnabled; - }); - - describe('when `save` button is clicked', () => { - describe('buttons', () => { - beforeEach(async () => { - createComponent({ - customStateProps: { - showActive: true, - canTest: true, - initialActivated: true, - }, - mountFn: mountExtended, - }); - - await findProjectSaveButton().vm.$emit('click', new Event('click')); - }); + describe('when `save` button is clicked', () => { + describe('buttons', () => { + beforeEach(async () => { + createComponent({ + customStateProps: { + showActive: true, + canTest: true, + initialActivated: true, + }, + mountFn: mountExtended, + }); - it('sets save button `loading` prop to `true`', () => { - expect(findProjectSaveButton().props('loading')).toBe(true); - }); + await findProjectSaveButton().vm.$emit('click', new Event('click')); + }); - it('sets test button `disabled` prop to `true`', () => { - expect(findTestButton().props('disabled')).toBe(true); + it('sets save button `loading` prop to `true`', () => { + expect(findProjectSaveButton().props('loading')).toBe(true); + }); + + it('sets test button `disabled` prop to `true`', () => { + expect(findTestButton().props('disabled')).toBe(true); + }); + }); + + describe.each` + checkValidityReturn | integrationActive + ${true} | ${false} + ${true} | ${true} + ${false} | ${false} + `( + 'when form is valid (checkValidity returns $checkValidityReturn and integrationActive is $integrationActive)', + ({ integrationActive, checkValidityReturn }) => { + beforeEach(async () => { + createComponent({ + customStateProps: { + showActive: true, + canTest: true, + initialActivated: integrationActive, + }, + mountFn: mountExtended, }); + jest.spyOn(findGlForm().element, 'submit'); + jest.spyOn(findGlForm().element, 'checkValidity').mockReturnValue(checkValidityReturn); + + await findProjectSaveButton().vm.$emit('click', new Event('click')); + }); + + it('submit form', () => { + expect(findGlForm().element.submit).toHaveBeenCalledTimes(1); }); + }, + ); - describe.each` - checkValidityReturn | integrationActive - ${true} | ${false} - ${true} | ${true} - ${false} | ${false} - `( - 'when form is valid (checkValidity returns $checkValidityReturn and integrationActive is $integrationActive)', - ({ integrationActive, checkValidityReturn }) => { - beforeEach(async () => { - createComponent({ - customStateProps: { - showActive: true, - canTest: true, - initialActivated: integrationActive, - }, - mountFn: mountExtended, - }); - - mockFormFunctions({ checkValidityReturn }); - - await findProjectSaveButton().vm.$emit('click', new Event('click')); - }); - - it('submits form', () => { - expect(findFormElement().submit).toHaveBeenCalledTimes(1); - }); + describe('when form is invalid (checkValidity returns false and integrationActive is true)', () => { + beforeEach(async () => { + createComponent({ + customStateProps: { + showActive: true, + canTest: true, + initialActivated: true, + fields: [mockField], }, - ); - - describe('when form is invalid (checkValidity returns false and integrationActive is true)', () => { - beforeEach(async () => { - createComponent({ - customStateProps: { - showActive: true, - canTest: true, - initialActivated: true, - fields: [mockField], - }, - mountFn: mountExtended, - }); - mockFormFunctions({ checkValidityReturn: false }); - - await findProjectSaveButton().vm.$emit('click', new Event('click')); - }); + mountFn: mountExtended, + }); + jest.spyOn(findGlForm().element, 'submit'); + jest.spyOn(findGlForm().element, 'checkValidity').mockReturnValue(false); - it('does not submit form', () => { - expect(findFormElement().submit).not.toHaveBeenCalled(); - }); + await findProjectSaveButton().vm.$emit('click', new Event('click')); + }); - it('sets save button `loading` prop to `false`', () => { - expect(findProjectSaveButton().props('loading')).toBe(false); - }); + it('does not submit form', () => { + expect(findGlForm().element.submit).not.toHaveBeenCalled(); + }); - it('sets test button `disabled` prop to `false`', () => { - expect(findTestButton().props('disabled')).toBe(false); - }); + it('sets save button `loading` prop to `false`', () => { + expect(findProjectSaveButton().props('loading')).toBe(false); + }); - it('sets `isValidated` props on form fields', () => { - expect(findDynamicField().props('isValidated')).toBe(true); - }); + it('sets test button `disabled` prop to `false`', () => { + expect(findTestButton().props('disabled')).toBe(false); + }); + + it('sets `isValidated` props on form fields', () => { + expect(findDynamicField().props('isValidated')).toBe(true); + }); + }); + }); + + describe('when `test` button is clicked', () => { + describe('when form is invalid', () => { + it('sets `isValidated` props on form fields', async () => { + createComponent({ + customStateProps: { + showActive: true, + canTest: true, + fields: [mockField], + }, + mountFn: mountExtended, }); + jest.spyOn(findGlForm().element, 'checkValidity').mockReturnValue(false); + + await findTestButton().vm.$emit('click', new Event('click')); + + expect(findDynamicField().props('isValidated')).toBe(true); }); + }); - describe('when `test` button is clicked', () => { - describe('when form is invalid', () => { - it('sets `isValidated` props on form fields', async () => { - createComponent({ - customStateProps: { - showActive: true, - canTest: true, - fields: [mockField], - }, - mountFn: mountExtended, - }); - mockFormFunctions({ checkValidityReturn: false }); + describe('when form is valid', () => { + const mockTestPath = '/test'; - await findTestButton().vm.$emit('click', new Event('click')); + beforeEach(() => { + createComponent({ + customStateProps: { + showActive: true, + canTest: true, + testPath: mockTestPath, + }, + mountFn: mountExtended, + }); + jest.spyOn(findGlForm().element, 'checkValidity').mockReturnValue(true); + }); - expect(findDynamicField().props('isValidated')).toBe(true); - }); + describe('buttons', () => { + beforeEach(async () => { + await findTestButton().vm.$emit('click', new Event('click')); }); - describe('when form is valid', () => { - const mockTestPath = '/test'; + it('sets test button `loading` prop to `true`', () => { + expect(findTestButton().props('loading')).toBe(true); + }); - beforeEach(() => { - createComponent({ - customStateProps: { - showActive: true, - canTest: true, - testPath: mockTestPath, - }, - mountFn: mountExtended, - }); - mockFormFunctions({ checkValidityReturn: true }); + it('sets save button `disabled` prop to `true`', () => { + expect(findProjectSaveButton().props('disabled')).toBe(true); + }); + }); + + describe.each` + scenario | replyStatus | errorMessage | expectToast | expectSentry + ${'when "test settings" request fails'} | ${httpStatus.INTERNAL_SERVER_ERROR} | ${undefined} | ${I18N_DEFAULT_ERROR_MESSAGE} | ${true} + ${'when "test settings" returns an error'} | ${httpStatus.OK} | ${'an error'} | ${'an error'} | ${false} + ${'when "test settings" succeeds'} | ${httpStatus.OK} | ${undefined} | ${I18N_SUCCESSFUL_CONNECTION_MESSAGE} | ${false} + `('$scenario', ({ replyStatus, errorMessage, expectToast, expectSentry }) => { + beforeEach(async () => { + mockAxios.onPut(mockTestPath).replyOnce(replyStatus, { + error: Boolean(errorMessage), + message: errorMessage, }); - describe('buttons', () => { - beforeEach(async () => { - await findTestButton().vm.$emit('click', new Event('click')); - }); + await findTestButton().vm.$emit('click', new Event('click')); + await waitForPromises(); + }); - it('sets test button `loading` prop to `true`', () => { - expect(findTestButton().props('loading')).toBe(true); - }); + it(`calls toast with '${expectToast}'`, () => { + expect(mockToastShow).toHaveBeenCalledWith(expectToast); + }); - it('sets save button `disabled` prop to `true`', () => { - expect(findProjectSaveButton().props('disabled')).toBe(true); - }); - }); + it('sets `loading` prop of test button to `false`', () => { + expect(findTestButton().props('loading')).toBe(false); + }); - describe.each` - scenario | replyStatus | errorMessage | expectToast | expectSentry - ${'when "test settings" request fails'} | ${httpStatus.INTERNAL_SERVER_ERROR} | ${undefined} | ${I18N_DEFAULT_ERROR_MESSAGE} | ${true} - ${'when "test settings" returns an error'} | ${httpStatus.OK} | ${'an error'} | ${'an error'} | ${false} - ${'when "test settings" succeeds'} | ${httpStatus.OK} | ${undefined} | ${I18N_SUCCESSFUL_CONNECTION_MESSAGE} | ${false} - `('$scenario', ({ replyStatus, errorMessage, expectToast, expectSentry }) => { - beforeEach(async () => { - mockAxios.onPut(mockTestPath).replyOnce(replyStatus, { - error: Boolean(errorMessage), - message: errorMessage, - }); - - await findTestButton().vm.$emit('click', new Event('click')); - await waitForPromises(); - }); - - it(`calls toast with '${expectToast}'`, () => { - expect(mockToastShow).toHaveBeenCalledWith(expectToast); - }); - - it('sets `loading` prop of test button to `false`', () => { - expect(findTestButton().props('loading')).toBe(false); - }); - - it('sets save button `disabled` prop to `false`', () => { - expect(findProjectSaveButton().props('disabled')).toBe(false); - }); - - it(`${expectSentry ? 'does' : 'does not'} capture exception in Sentry`, () => { - expect(Sentry.captureException).toHaveBeenCalledTimes(expectSentry ? 1 : 0); - }); - }); + it('sets save button `disabled` prop to `false`', () => { + expect(findProjectSaveButton().props('disabled')).toBe(false); + }); + + it(`${expectSentry ? 'does' : 'does not'} capture exception in Sentry`, () => { + expect(Sentry.captureException).toHaveBeenCalledTimes(expectSentry ? 1 : 0); }); }); - }, - ); + }); + }); describe('when `reset-confirmation-modal` emits `reset` event', () => { const mockResetPath = '/reset'; |