diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-04-14 21:08:53 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-04-14 21:08:53 +0300 |
commit | 5b62f8e3ee531f63ce3c49cae03e2a618ba51615 (patch) | |
tree | 2d2553232fe0663957ee4d1054211cc71cb07679 /spec/frontend/design_management | |
parent | cdb41961fd2bc233d36c5b30f89d087c2efa9818 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/design_management')
-rw-r--r-- | spec/frontend/design_management/components/design_notes/design_reply_form_spec.js | 57 | ||||
-rw-r--r-- | spec/frontend/design_management/mock_data/apollo_mock.js | 102 |
2 files changed, 72 insertions, 87 deletions
diff --git a/spec/frontend/design_management/components/design_notes/design_reply_form_spec.js b/spec/frontend/design_management/components/design_notes/design_reply_form_spec.js index d82b6c5fec0..c8fa02cb6aa 100644 --- a/spec/frontend/design_management/components/design_notes/design_reply_form_spec.js +++ b/spec/frontend/design_management/components/design_notes/design_reply_form_spec.js @@ -1,7 +1,9 @@ import { GlAlert } from '@gitlab/ui'; import { mount } from '@vue/test-utils'; -import { nextTick } from 'vue'; +import Vue from 'vue'; +import VueApollo from 'vue-apollo'; import Autosave from '~/autosave'; +import createMockApollo from 'helpers/mock_apollo_helper'; import waitForPromises from 'helpers/wait_for_promises'; import { confirmAction } from '~/lib/utils/confirm_via_gl_modal/confirm_via_gl_modal'; import createNoteMutation from '~/design_management/graphql/mutations/create_note.mutation.graphql'; @@ -17,11 +19,14 @@ import { mockNoteSubmitFailureMutationResponse, } from '../../mock_data/apollo_mock'; +Vue.use(VueApollo); + jest.mock('~/lib/utils/confirm_via_gl_modal/confirm_via_gl_modal'); jest.mock('~/autosave'); describe('Design reply form component', () => { let wrapper; + let mockApollo; const findTextarea = () => wrapper.find('textarea'); const findSubmitButton = () => wrapper.findComponent({ ref: 'submitButton' }); @@ -32,14 +37,10 @@ describe('Design reply form component', () => { const mockComment = 'New comment'; const mockDiscussionId = 'gid://gitlab/Discussion/6466a72f35b163f3c3e52d7976a09387f2c573e8'; const createNoteMutationData = { - mutation: createNoteMutation, - update: expect.anything(), - variables: { - input: { - noteableId: mockNoteableId, - discussionId: mockDiscussionId, - body: mockComment, - }, + input: { + noteableId: mockNoteableId, + discussionId: mockDiscussionId, + body: mockComment, }, }; @@ -49,14 +50,15 @@ describe('Design reply form component', () => { const metaKey = { metaKey: true, }; - const mutationHandler = jest.fn().mockResolvedValue(); + const mockMutationHandler = jest.fn().mockResolvedValue(mockNoteSubmitSuccessMutationResponse); function createComponent({ props = {}, mountOptions = {}, data = {}, - mutation = mutationHandler, + mutationHandler = mockMutationHandler, } = {}) { + mockApollo = createMockApollo([[createNoteMutation, mutationHandler]]); wrapper = mount(DesignReplyForm, { propsData: { designNoteMutation: createNoteMutation, @@ -67,11 +69,7 @@ describe('Design reply form component', () => { ...props, }, ...mountOptions, - mocks: { - $apollo: { - mutate: mutation, - }, - }, + apolloProvider: mockApollo, data() { return { ...data, @@ -85,6 +83,7 @@ describe('Design reply form component', () => { }); afterEach(() => { + mockApollo = null; confirmAction.mockReset(); }); @@ -127,7 +126,6 @@ describe('Design reply form component', () => { 'initializes autosave support on discussion with proper key', async ({ discussionId, shortDiscussionId }) => { createComponent({ props: { discussionId } }); - await nextTick(); expect(Autosave).toHaveBeenCalledWith(expect.any(Element), [ 'Discussion', @@ -140,7 +138,6 @@ describe('Design reply form component', () => { describe('when form has no text', () => { beforeEach(async () => { createComponent(); - await nextTick(); }); it('submit button is disabled', () => { @@ -154,8 +151,7 @@ describe('Design reply form component', () => { `('does not perform mutation on textarea $key+enter keydown', async ({ keyData }) => { findTextarea().trigger('keydown.enter', keyData); - await nextTick(); - expect(mutationHandler).not.toHaveBeenCalled(); + expect(mockMutationHandler).not.toHaveBeenCalled(); }); it('emits cancelForm event on pressing escape button on textarea', () => { @@ -182,22 +178,20 @@ describe('Design reply form component', () => { noteableId: mockNoteableId, discussionId: mockDiscussionId, }; - const successfulMutation = jest.fn().mockResolvedValue(mockNoteSubmitSuccessMutationResponse); + createComponent({ props: { - designNoteMutation: createNoteMutation, mutationVariables: mockMutationVariables, value: mockComment, }, - mutation: successfulMutation, }); findSubmitButton().vm.$emit('click'); - await nextTick(); - expect(successfulMutation).toHaveBeenCalledWith(createNoteMutationData); + expect(mockMutationHandler).toHaveBeenCalledWith(createNoteMutationData); await waitForPromises(); + expect(wrapper.emitted('note-submit-complete')).toEqual([ [mockNoteSubmitSuccessMutationResponse], ]); @@ -212,20 +206,17 @@ describe('Design reply form component', () => { noteableId: mockNoteableId, discussionId: mockDiscussionId, }; - const successfulMutation = jest.fn().mockResolvedValue(mockNoteSubmitSuccessMutationResponse); + createComponent({ props: { - designNoteMutation: createNoteMutation, mutationVariables: mockMutationVariables, value: mockComment, }, - mutation: successfulMutation, }); findTextarea().trigger('keydown.enter', keyData); - await nextTick(); - expect(successfulMutation).toHaveBeenCalledWith(createNoteMutationData); + expect(mockMutationHandler).toHaveBeenCalledWith(createNoteMutationData); await waitForPromises(); expect(wrapper.emitted('note-submit-complete')).toEqual([ @@ -240,7 +231,7 @@ describe('Design reply form component', () => { designNoteMutation: createNoteMutation, value: mockComment, }, - mutation: failedMutation, + mutationHandler: failedMutation, data: { errorMessage: 'error', }, @@ -280,7 +271,6 @@ describe('Design reply form component', () => { findTextarea().setValue(mockComment); - await nextTick(); findTextarea().trigger('keyup.esc'); expect(confirmAction).toHaveBeenCalled(); @@ -292,7 +282,6 @@ describe('Design reply form component', () => { createComponent({ props: { value: mockComment } }); findTextarea().setValue('Comment changed'); - await nextTick(); findTextarea().trigger('keyup.esc'); expect(confirmAction).toHaveBeenCalled(); @@ -306,10 +295,8 @@ describe('Design reply form component', () => { createComponent({ props: { value: mockComment } }); findTextarea().setValue('Comment changed'); - await nextTick(); findTextarea().trigger('keyup.esc'); - await nextTick(); expect(confirmAction).toHaveBeenCalled(); await waitForPromises(); diff --git a/spec/frontend/design_management/mock_data/apollo_mock.js b/spec/frontend/design_management/mock_data/apollo_mock.js index a7355719141..f8214558d74 100644 --- a/spec/frontend/design_management/mock_data/apollo_mock.js +++ b/spec/frontend/design_management/mock_data/apollo_mock.js @@ -214,64 +214,62 @@ export const getDesignQueryResponse = { }, }; -export const mockNoteSubmitSuccessMutationResponse = [ - { - data: { - createNote: { - note: { - id: 'gid://gitlab/DiffNote/468', - author: { - id: 'gid://gitlab/User/1', - avatarUrl: - 'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', - name: 'Administrator', - username: 'root', - webUrl: 'http://127.0.0.1:3000/root', - __typename: 'UserCore', - }, - body: 'New comment', - bodyHtml: "<p data-sourcepos='1:1-1:4' dir='auto'>asdd</p>", - createdAt: '2023-02-24T06:49:20Z', - resolved: false, - position: { - diffRefs: { - baseSha: 'f63ae53ed82d8765477c191383e1e6a000c10375', - startSha: 'f63ae53ed82d8765477c191383e1e6a000c10375', - headSha: 'f348c652f1a737151fc79047895e695fbe81464c', - __typename: 'DiffRefs', - }, - x: 441, - y: 128, - height: 152, - width: 695, - __typename: 'DiffPosition', - }, - userPermissions: { - adminNote: true, - repositionNote: true, - __typename: 'NotePermissions', +export const mockNoteSubmitSuccessMutationResponse = { + data: { + createNote: { + note: { + id: 'gid://gitlab/DiffNote/468', + author: { + id: 'gid://gitlab/User/1', + avatarUrl: + 'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', + name: 'Administrator', + username: 'root', + webUrl: 'http://127.0.0.1:3000/root', + __typename: 'UserCore', + }, + body: 'New comment', + bodyHtml: "<p data-sourcepos='1:1-1:4' dir='auto'>asdd</p>", + createdAt: '2023-02-24T06:49:20Z', + resolved: false, + position: { + diffRefs: { + baseSha: 'f63ae53ed82d8765477c191383e1e6a000c10375', + startSha: 'f63ae53ed82d8765477c191383e1e6a000c10375', + headSha: 'f348c652f1a737151fc79047895e695fbe81464c', + __typename: 'DiffRefs', }, - discussion: { - id: 'gid://gitlab/Discussion/6466a72f35b163f3c3e52d7976a09387f2c573e8', - notes: { - nodes: [ - { - id: 'gid://gitlab/DiffNote/459', - __typename: 'Note', - }, - ], - __typename: 'NoteConnection', - }, - __typename: 'Discussion', + x: 441, + y: 128, + height: 152, + width: 695, + __typename: 'DiffPosition', + }, + userPermissions: { + adminNote: true, + repositionNote: true, + __typename: 'NotePermissions', + }, + discussion: { + id: 'gid://gitlab/Discussion/6466a72f35b163f3c3e52d7976a09387f2c573e8', + notes: { + nodes: [ + { + id: 'gid://gitlab/DiffNote/459', + __typename: 'Note', + }, + ], + __typename: 'NoteConnection', }, - __typename: 'Note', + __typename: 'Discussion', }, - errors: [], - __typename: 'CreateNotePayload', + __typename: 'Note', }, + errors: [], + __typename: 'CreateNotePayload', }, }, -]; +}; export const mockNoteSubmitFailureMutationResponse = [ { |