diff options
Diffstat (limited to 'spec/frontend/snippets/components/edit_spec.js')
-rw-r--r-- | spec/frontend/snippets/components/edit_spec.js | 71 |
1 files changed, 6 insertions, 65 deletions
diff --git a/spec/frontend/snippets/components/edit_spec.js b/spec/frontend/snippets/components/edit_spec.js index 2b6d3ca8c2a..efdb52cfcd9 100644 --- a/spec/frontend/snippets/components/edit_spec.js +++ b/spec/frontend/snippets/components/edit_spec.js @@ -5,10 +5,9 @@ import { nextTick } from 'vue'; import VueApollo, { ApolloMutation } from 'vue-apollo'; import { useFakeDate } from 'helpers/fake_date'; import createMockApollo from 'helpers/mock_apollo_helper'; -import { stubComponent } from 'helpers/stub_component'; import waitForPromises from 'helpers/wait_for_promises'; import GetSnippetQuery from 'shared_queries/snippet/snippet.query.graphql'; -import CaptchaModal from '~/captcha/captcha_modal.vue'; +import UnsolvedCaptchaError from '~/captcha/unsolved_captcha_error'; import { deprecatedCreateFlash as Flash } from '~/flash'; import * as urlUtils from '~/lib/utils/url_utility'; import SnippetEditApp from '~/snippets/components/edit.vue'; @@ -30,9 +29,8 @@ jest.mock('~/flash'); const TEST_UPLOADED_FILES = ['foo/bar.txt', 'alpha/beta.js']; const TEST_API_ERROR = new Error('TEST_API_ERROR'); +const TEST_CAPTCHA_ERROR = new UnsolvedCaptchaError(); const TEST_MUTATION_ERROR = 'Test mutation error'; -const TEST_CAPTCHA_RESPONSE = 'i-got-a-captcha'; -const TEST_CAPTCHA_SITE_KEY = 'abc123'; const TEST_ACTIONS = { NO_CONTENT: merge({}, testEntries.created.diff, { content: '' }), NO_PATH: merge({}, testEntries.created.diff, { filePath: '' }), @@ -59,9 +57,6 @@ const createMutationResponse = (key, obj = {}) => ({ __typename: 'Snippet', webUrl: TEST_WEB_URL, }, - spamLogId: null, - needsCaptchaResponse: false, - captchaSiteKey: null, }, obj, ), @@ -71,13 +66,6 @@ const createMutationResponse = (key, obj = {}) => ({ const createMutationResponseWithErrors = (key) => createMutationResponse(key, { errors: [TEST_MUTATION_ERROR] }); -const createMutationResponseWithRecaptcha = (key) => - createMutationResponse(key, { - errors: ['ignored captcha error message'], - needsCaptchaResponse: true, - captchaSiteKey: TEST_CAPTCHA_SITE_KEY, - }); - const getApiData = ({ id, title = '', @@ -126,7 +114,6 @@ describe('Snippet Edit app', () => { }); const findBlobActions = () => wrapper.find(SnippetBlobActionsEdit); - const findCaptchaModal = () => wrapper.find(CaptchaModal); const findSubmitButton = () => wrapper.find('[data-testid="snippet-submit-btn"]'); const findCancelButton = () => wrapper.find('[data-testid="snippet-cancel-btn"]'); const hasDisabledSubmit = () => Boolean(findSubmitButton().attributes('disabled')); @@ -159,7 +146,6 @@ describe('Snippet Edit app', () => { stubs: { ApolloMutation, FormFooterActions, - CaptchaModal: stubComponent(CaptchaModal), }, provide: { selectedLevel, @@ -209,7 +195,6 @@ describe('Snippet Edit app', () => { }); it('should render components', () => { - expect(wrapper.find(CaptchaModal).exists()).toBe(true); expect(wrapper.find(TitleField).exists()).toBe(true); expect(wrapper.find(SnippetDescriptionEdit).exists()).toBe(true); expect(wrapper.find(SnippetVisibilityEdit).exists()).toBe(true); @@ -338,10 +323,10 @@ describe('Snippet Edit app', () => { }, ); - describe('with apollo network error', () => { + describe.each([TEST_API_ERROR, TEST_CAPTCHA_ERROR])('with apollo network error', (error) => { beforeEach(async () => { jest.spyOn(console, 'error').mockImplementation(); - mutateSpy.mockRejectedValue(TEST_API_ERROR); + mutateSpy.mockRejectedValue(error); await createComponentAndSubmit(); }); @@ -353,7 +338,7 @@ describe('Snippet Edit app', () => { it('should flash', () => { // Apollo automatically wraps the resolver's error in a NetworkError expect(Flash).toHaveBeenCalledWith( - `Can't update snippet: Network error: ${TEST_API_ERROR.message}`, + `Can't update snippet: Network error: ${error.message}`, ); }); @@ -363,54 +348,10 @@ describe('Snippet Edit app', () => { // eslint-disable-next-line no-console expect(console.error).toHaveBeenCalledWith( '[gitlab] unexpected error while updating snippet', - expect.objectContaining({ message: `Network error: ${TEST_API_ERROR.message}` }), + expect.objectContaining({ message: `Network error: ${error.message}` }), ); }); }); - - describe('when needsCaptchaResponse is true', () => { - let modal; - - beforeEach(async () => { - mutateSpy - .mockResolvedValueOnce(createMutationResponseWithRecaptcha('updateSnippet')) - .mockResolvedValueOnce(createMutationResponseWithErrors('updateSnippet')); - - await createComponentAndSubmit(); - - modal = findCaptchaModal(); - - mutateSpy.mockClear(); - }); - - it('should display captcha modal', () => { - expect(urlUtils.redirectTo).not.toHaveBeenCalled(); - expect(modal.props()).toEqual({ - needsCaptchaResponse: true, - captchaSiteKey: TEST_CAPTCHA_SITE_KEY, - }); - }); - - describe.each` - response | expectedCalls - ${null} | ${[]} - ${TEST_CAPTCHA_RESPONSE} | ${[['updateSnippet', { input: { ...getApiData(createSnippet()), captchaResponse: TEST_CAPTCHA_RESPONSE } }]]} - `('when captcha response is $response', ({ response, expectedCalls }) => { - beforeEach(async () => { - modal.vm.$emit('receivedCaptchaResponse', response); - - await nextTick(); - }); - - it('sets needsCaptchaResponse to false', () => { - expect(modal.props('needsCaptchaResponse')).toEqual(false); - }); - - it(`expected to call times = ${expectedCalls.length}`, () => { - expect(mutateSpy.mock.calls).toEqual(expectedCalls); - }); - }); - }); }); }); |