diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-18 03:09:24 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-18 03:09:24 +0000 |
commit | 95f5aad5aa99577555f01476f771e581957934f1 (patch) | |
tree | 3ce10768748ac63c5b42dfbfde989983afa54973 /spec/frontend | |
parent | ccefff8087799bc076737ad080f18cf98e6fe114 (diff) | |
download | gitlab-ce-95f5aad5aa99577555f01476f771e581957934f1.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend')
3 files changed, 91 insertions, 12 deletions
diff --git a/spec/frontend/batch_comments/components/draft_note_spec.js b/spec/frontend/batch_comments/components/draft_note_spec.js index eea7f25dbc1..99980c98f8b 100644 --- a/spec/frontend/batch_comments/components/draft_note_spec.js +++ b/spec/frontend/batch_comments/components/draft_note_spec.js @@ -1,4 +1,5 @@ import { shallowMount, createLocalVue } from '@vue/test-utils'; +import { getByRole } from '@testing-library/dom'; import DraftNote from '~/batch_comments/components/draft_note.vue'; import { createStore } from '~/batch_comments/stores'; import NoteableNote from '~/notes/components/noteable_note.vue'; @@ -8,21 +9,34 @@ import { createDraft } from '../mock_data'; const localVue = createLocalVue(); describe('Batch comments draft note component', () => { + let store; let wrapper; let draft; + const LINE_RANGE = {}; + const draftWithLineRange = { + position: { + line_range: LINE_RANGE, + }, + }; - beforeEach(() => { - const store = createStore(); - - draft = createDraft(); + const getList = () => getByRole(wrapper.element, 'list'); + const createComponent = (propsData = { draft }, features = {}) => { wrapper = shallowMount(localVue.extend(DraftNote), { store, - propsData: { draft }, + propsData, localVue, + provide: { + glFeatures: { multilineComments: true, ...features }, + }, }); jest.spyOn(wrapper.vm.$store, 'dispatch').mockImplementation(); + }; + + beforeEach(() => { + store = createStore(); + draft = createDraft(); }); afterEach(() => { @@ -30,6 +44,7 @@ describe('Batch comments draft note component', () => { }); it('renders template', () => { + createComponent(); expect(wrapper.find('.draft-pending-label').exists()).toBe(true); const note = wrapper.find(NoteableNote); @@ -40,6 +55,7 @@ describe('Batch comments draft note component', () => { describe('add comment now', () => { it('dispatches publishSingleDraft when clicking', () => { + createComponent(); const publishNowButton = wrapper.find({ ref: 'publishNowButton' }); publishNowButton.vm.$emit('click'); @@ -50,6 +66,7 @@ describe('Batch comments draft note component', () => { }); it('sets as loading when draft is publishing', done => { + createComponent(); wrapper.vm.$store.state.batchComments.currentlyPublishingDrafts.push(1); wrapper.vm.$nextTick(() => { @@ -64,6 +81,7 @@ describe('Batch comments draft note component', () => { describe('update', () => { it('dispatches updateDraft', done => { + createComponent(); const note = wrapper.find(NoteableNote); note.vm.$emit('handleEdit'); @@ -91,6 +109,7 @@ describe('Batch comments draft note component', () => { describe('deleteDraft', () => { it('dispatches deleteDraft', () => { + createComponent(); jest.spyOn(window, 'confirm').mockImplementation(() => true); const note = wrapper.find(NoteableNote); @@ -103,6 +122,7 @@ describe('Batch comments draft note component', () => { describe('quick actions', () => { it('renders referenced commands', done => { + createComponent(); wrapper.setProps({ draft: { ...draft, @@ -122,4 +142,26 @@ describe('Batch comments draft note component', () => { }); }); }); + + describe('multiline comments', () => { + describe.each` + desc | props | features | event | expectedCalls + ${'with `draft.position`'} | ${draftWithLineRange} | ${{}} | ${'mouseenter'} | ${[['setSelectedCommentPositionHover', LINE_RANGE]]} + ${'with `draft.position`'} | ${draftWithLineRange} | ${{}} | ${'mouseleave'} | ${[['setSelectedCommentPositionHover']]} + ${'with `draft.position`'} | ${draftWithLineRange} | ${{ multilineComments: false }} | ${'mouseenter'} | ${[]} + ${'with `draft.position`'} | ${draftWithLineRange} | ${{ multilineComments: false }} | ${'mouseleave'} | ${[]} + ${'without `draft.position`'} | ${{}} | ${{}} | ${'mouseenter'} | ${[]} + ${'without `draft.position`'} | ${{}} | ${{}} | ${'mouseleave'} | ${[]} + `('$desc and features $features', ({ props, event, features, expectedCalls }) => { + beforeEach(() => { + createComponent({ draft: { ...draft, ...props } }, features); + jest.spyOn(store, 'dispatch'); + }); + + it(`calls store ${expectedCalls.length} times on ${event}`, () => { + getList().dispatchEvent(new MouseEvent(event, { bubbles: true })); + expect(store.dispatch.mock.calls).toEqual(expectedCalls); + }); + }); + }); }); diff --git a/spec/frontend/notes/components/discussion_notes_spec.js b/spec/frontend/notes/components/discussion_notes_spec.js index 5a10deefd09..8cc98f978c2 100644 --- a/spec/frontend/notes/components/discussion_notes_spec.js +++ b/spec/frontend/notes/components/discussion_notes_spec.js @@ -1,4 +1,5 @@ import { shallowMount } from '@vue/test-utils'; +import { getByRole } from '@testing-library/dom'; import '~/behaviors/markdown/render_gfm'; import { SYSTEM_NOTE } from '~/notes/constants'; import DiscussionNotes from '~/notes/components/discussion_notes.vue'; @@ -9,14 +10,20 @@ import SystemNote from '~/vue_shared/components/notes/system_note.vue'; import createStore from '~/notes/stores'; import { noteableDataMock, discussionMock, notesDataMock } from '../mock_data'; +const LINE_RANGE = {}; +const DISCUSSION_WITH_LINE_RANGE = { + ...discussionMock, + position: { + line_range: LINE_RANGE, + }, +}; + describe('DiscussionNotes', () => { + let store; let wrapper; - const createComponent = props => { - const store = createStore(); - store.dispatch('setNoteableData', noteableDataMock); - store.dispatch('setNotesData', notesDataMock); - + const getList = () => getByRole(wrapper.element, 'list'); + const createComponent = (props, features = {}) => { wrapper = shallowMount(DiscussionNotes, { store, propsData: { @@ -31,11 +38,21 @@ describe('DiscussionNotes', () => { slots: { 'avatar-badge': '<span class="avatar-badge-slot-content" />', }, + provide: { + glFeatures: { multilineComments: true, ...features }, + }, }); }; + beforeEach(() => { + store = createStore(); + store.dispatch('setNoteableData', noteableDataMock); + store.dispatch('setNotesData', notesDataMock); + }); + afterEach(() => { wrapper.destroy(); + wrapper = null; }); describe('rendering', () => { @@ -160,6 +177,26 @@ describe('DiscussionNotes', () => { }); }); + describe.each` + desc | props | features | event | expectedCalls + ${'with `discussion.position`'} | ${{ discussion: DISCUSSION_WITH_LINE_RANGE }} | ${{}} | ${'mouseenter'} | ${[['setSelectedCommentPositionHover', LINE_RANGE]]} + ${'with `discussion.position`'} | ${{ discussion: DISCUSSION_WITH_LINE_RANGE }} | ${{}} | ${'mouseleave'} | ${[['setSelectedCommentPositionHover']]} + ${'with `discussion.position`'} | ${{ discussion: DISCUSSION_WITH_LINE_RANGE }} | ${{ multilineComments: false }} | ${'mouseenter'} | ${[]} + ${'with `discussion.position`'} | ${{ discussion: DISCUSSION_WITH_LINE_RANGE }} | ${{ multilineComments: false }} | ${'mouseleave'} | ${[]} + ${'without `discussion.position`'} | ${{}} | ${{}} | ${'mouseenter'} | ${[]} + ${'without `discussion.position`'} | ${{}} | ${{}} | ${'mouseleave'} | ${[]} + `('$desc and features $features', ({ props, event, features, expectedCalls }) => { + beforeEach(() => { + createComponent(props, features); + jest.spyOn(store, 'dispatch'); + }); + + it(`calls store ${expectedCalls.length} times on ${event}`, () => { + getList().dispatchEvent(new MouseEvent(event)); + expect(store.dispatch.mock.calls).toEqual(expectedCalls); + }); + }); + describe('componentData', () => { beforeEach(() => { createComponent(); diff --git a/spec/frontend/notes/components/noteable_note_spec.js b/spec/frontend/notes/components/noteable_note_spec.js index fc238feb974..b0b43075c3d 100644 --- a/spec/frontend/notes/components/noteable_note_spec.js +++ b/spec/frontend/notes/components/noteable_note_spec.js @@ -92,8 +92,8 @@ describe('issue_note', () => { }); }); - it('should not render multiline comment form unless it is the discussion root', () => { - wrapper.setProps({ discussionRoot: false }); + it('should only render multiline comment form if it has everything it needs', () => { + wrapper.setProps({ line: { line_code: '' } }); wrapper.vm.isEditing = true; return wrapper.vm.$nextTick().then(() => { |