diff options
Diffstat (limited to 'spec/frontend/diffs/components')
5 files changed, 97 insertions, 57 deletions
diff --git a/spec/frontend/diffs/components/app_spec.js b/spec/frontend/diffs/components/app_spec.js index 0527c2153f4..d50ac0529d6 100644 --- a/spec/frontend/diffs/components/app_spec.js +++ b/spec/frontend/diffs/components/app_spec.js @@ -388,15 +388,24 @@ describe('diffs/components/app', () => { wrapper.vm.jumpToFile(+1); - expect(spy.mock.calls[spy.mock.calls.length - 1]).toEqual(['diffs/scrollToFile', '222.js']); + expect(spy.mock.calls[spy.mock.calls.length - 1]).toEqual([ + 'diffs/scrollToFile', + { path: '222.js' }, + ]); store.state.diffs.currentDiffFileId = '222'; wrapper.vm.jumpToFile(+1); - expect(spy.mock.calls[spy.mock.calls.length - 1]).toEqual(['diffs/scrollToFile', '333.js']); + expect(spy.mock.calls[spy.mock.calls.length - 1]).toEqual([ + 'diffs/scrollToFile', + { path: '333.js' }, + ]); store.state.diffs.currentDiffFileId = '333'; wrapper.vm.jumpToFile(-1); - expect(spy.mock.calls[spy.mock.calls.length - 1]).toEqual(['diffs/scrollToFile', '222.js']); + expect(spy.mock.calls[spy.mock.calls.length - 1]).toEqual([ + 'diffs/scrollToFile', + { path: '222.js' }, + ]); }); it('does not jump to previous file from the first one', async () => { @@ -702,23 +711,4 @@ describe('diffs/components/app', () => { ); }); }); - - describe('fluid layout', () => { - beforeEach(() => { - setFixtures( - '<div><div class="merge-request-container limit-container-width container-limited"></div></div>', - ); - }); - - it('removes limited container classes when on diffs tab', () => { - createComponent({ isFluidLayout: false, shouldShow: true }, () => {}, { - glFeatures: { mrChangesFluidLayout: true }, - }); - - const containerClassList = document.querySelector('.merge-request-container').classList; - - expect(containerClassList).not.toContain('container-limited'); - expect(containerClassList).not.toContain('limit-container-width'); - }); - }); }); diff --git a/spec/frontend/diffs/components/diff_discussions_spec.js b/spec/frontend/diffs/components/diff_discussions_spec.js index bd6f4cd2545..c847a79435a 100644 --- a/spec/frontend/diffs/components/diff_discussions_spec.js +++ b/spec/frontend/diffs/components/diff_discussions_spec.js @@ -1,6 +1,7 @@ import { GlIcon } from '@gitlab/ui'; import { mount, createLocalVue } from '@vue/test-utils'; import DiffDiscussions from '~/diffs/components/diff_discussions.vue'; +import { discussionIntersectionObserverHandlerFactory } from '~/diffs/utils/discussions'; import { createStore } from '~/mr_notes/stores'; import DiscussionNotes from '~/notes/components/discussion_notes.vue'; import NoteableDiscussion from '~/notes/components/noteable_discussion.vue'; @@ -19,6 +20,9 @@ describe('DiffDiscussions', () => { store = createStore(); wrapper = mount(localVue.extend(DiffDiscussions), { store, + provide: { + discussionObserverHandler: discussionIntersectionObserverHandlerFactory(), + }, propsData: { discussions: getDiscussionsMockData(), ...props, diff --git a/spec/frontend/diffs/components/diff_file_header_spec.js b/spec/frontend/diffs/components/diff_file_header_spec.js index b16ef8fe6b0..342b4bfcc50 100644 --- a/spec/frontend/diffs/components/diff_file_header_spec.js +++ b/spec/frontend/diffs/components/diff_file_header_spec.js @@ -7,7 +7,7 @@ import { mockTracking, triggerEvent } from 'helpers/tracking_helper'; import DiffFileHeader from '~/diffs/components/diff_file_header.vue'; import { DIFF_FILE_AUTOMATIC_COLLAPSE, DIFF_FILE_MANUAL_COLLAPSE } from '~/diffs/constants'; import { reviewFile } from '~/diffs/store/actions'; -import { SET_MR_FILE_REVIEWS } from '~/diffs/store/mutation_types'; +import { SET_DIFF_FILE_VIEWED, SET_MR_FILE_REVIEWS } from '~/diffs/store/mutation_types'; import { diffViewerModes } from '~/ide/constants'; import { scrollToElement } from '~/lib/utils/common_utils'; import { truncateSha } from '~/lib/utils/text_utility'; @@ -23,6 +23,7 @@ jest.mock('~/lib/utils/common_utils'); const diffFile = Object.freeze( Object.assign(diffDiscussionsMockData.diff_file, { id: '123', + file_hash: 'xyz', file_identifier_hash: 'abc', edit_path: 'link:/to/edit/path', blob: { @@ -58,7 +59,7 @@ describe('DiffFileHeader component', () => { toggleFileDiscussions: jest.fn(), toggleFileDiscussionWrappers: jest.fn(), toggleFullDiff: jest.fn(), - toggleActiveFileByHash: jest.fn(), + setCurrentFileHash: jest.fn(), setFileCollapsedByUser: jest.fn(), reviewFile: jest.fn(), }, @@ -240,18 +241,19 @@ describe('DiffFileHeader component', () => { }); describe('for any file', () => { - const otherModes = Object.keys(diffViewerModes).filter((m) => m !== 'mode_changed'); + const allModes = Object.keys(diffViewerModes).map((m) => [m]); - it('for mode_changed file mode displays mode changes', () => { + it.each(allModes)('for %s file mode displays mode changes', (mode) => { createComponent({ props: { diffFile: { ...diffFile, + mode_changed: true, a_mode: 'old-mode', b_mode: 'new-mode', viewer: { ...diffFile.viewer, - name: diffViewerModes.mode_changed, + name: diffViewerModes[mode], }, }, }, @@ -259,13 +261,14 @@ describe('DiffFileHeader component', () => { expect(findModeChangedLine().text()).toMatch(/old-mode.+new-mode/); }); - it.each(otherModes.map((m) => [m]))( + it.each(allModes.filter((m) => m[0] !== 'mode_changed'))( 'for %s file mode does not display mode changes', (mode) => { createComponent({ props: { diffFile: { ...diffFile, + mode_changed: false, a_mode: 'old-mode', b_mode: 'new-mode', viewer: { @@ -553,7 +556,13 @@ describe('DiffFileHeader component', () => { reviewFile, { file, reviewed: true }, {}, - [{ type: SET_MR_FILE_REVIEWS, payload: { [file.file_identifier_hash]: [file.id] } }], + [ + { type: SET_DIFF_FILE_VIEWED, payload: { id: file.file_hash, seen: true } }, + { + type: SET_MR_FILE_REVIEWS, + payload: { [file.file_identifier_hash]: [file.id, `hash:${file.file_hash}`] }, + }, + ], [], ); }); diff --git a/spec/frontend/diffs/components/diff_line_note_form_spec.js b/spec/frontend/diffs/components/diff_line_note_form_spec.js index a192f7e2e9a..0ccf996e220 100644 --- a/spec/frontend/diffs/components/diff_line_note_form_spec.js +++ b/spec/frontend/diffs/components/diff_line_note_form_spec.js @@ -1,10 +1,18 @@ import { shallowMount } from '@vue/test-utils'; +import { nextTick } from 'vue'; import DiffLineNoteForm from '~/diffs/components/diff_line_note_form.vue'; import { createStore } from '~/mr_notes/stores'; import NoteForm from '~/notes/components/note_form.vue'; +import { confirmAction } from '~/lib/utils/confirm_via_gl_modal/confirm_via_gl_modal'; import { noteableDataMock } from '../../notes/mock_data'; import diffFileMockData from '../mock_data/diff_file'; +jest.mock('~/lib/utils/confirm_via_gl_modal/confirm_via_gl_modal', () => { + return { + confirmAction: jest.fn(), + }; +}); + describe('DiffLineNoteForm', () => { let wrapper; let diffFile; @@ -24,57 +32,68 @@ describe('DiffLineNoteForm', () => { return shallowMount(DiffLineNoteForm, { store, propsData: { - diffFileHash: diffFile.file_hash, - diffLines, - line: diffLines[0], - noteTargetLine: diffLines[0], + ...{ + diffFileHash: diffFile.file_hash, + diffLines, + line: diffLines[1], + range: { start: diffLines[0], end: diffLines[1] }, + noteTargetLine: diffLines[1], + }, + ...(args.props || {}), }, }); }; + const findNoteForm = () => wrapper.findComponent(NoteForm); + describe('methods', () => { beforeEach(() => { wrapper = createComponent(); }); describe('handleCancelCommentForm', () => { + afterEach(() => { + confirmAction.mockReset(); + }); + it('should ask for confirmation when shouldConfirm and isDirty passed as truthy', () => { - jest.spyOn(window, 'confirm').mockReturnValue(false); + confirmAction.mockResolvedValueOnce(false); - wrapper.vm.handleCancelCommentForm(true, true); + findNoteForm().vm.$emit('cancelForm', true, true); - expect(window.confirm).toHaveBeenCalled(); + expect(confirmAction).toHaveBeenCalled(); }); - it('should ask for confirmation when one of the params false', () => { - jest.spyOn(window, 'confirm').mockReturnValue(false); + it('should not ask for confirmation when one of the params false', () => { + confirmAction.mockResolvedValueOnce(false); - wrapper.vm.handleCancelCommentForm(true, false); + findNoteForm().vm.$emit('cancelForm', true, false); - expect(window.confirm).not.toHaveBeenCalled(); + expect(confirmAction).not.toHaveBeenCalled(); - wrapper.vm.handleCancelCommentForm(false, true); + findNoteForm().vm.$emit('cancelForm', false, true); - expect(window.confirm).not.toHaveBeenCalled(); + expect(confirmAction).not.toHaveBeenCalled(); }); - it('should call cancelCommentForm with lineCode', (done) => { - jest.spyOn(window, 'confirm').mockImplementation(() => {}); + it('should call cancelCommentForm with lineCode', async () => { + confirmAction.mockResolvedValueOnce(true); jest.spyOn(wrapper.vm, 'cancelCommentForm').mockImplementation(() => {}); jest.spyOn(wrapper.vm, 'resetAutoSave').mockImplementation(() => {}); - wrapper.vm.handleCancelCommentForm(); - expect(window.confirm).not.toHaveBeenCalled(); - wrapper.vm.$nextTick(() => { - expect(wrapper.vm.cancelCommentForm).toHaveBeenCalledWith({ - lineCode: diffLines[0].line_code, - fileHash: wrapper.vm.diffFileHash, - }); + findNoteForm().vm.$emit('cancelForm', true, true); + + await nextTick(); + + expect(confirmAction).toHaveBeenCalled(); - expect(wrapper.vm.resetAutoSave).toHaveBeenCalled(); + await nextTick(); - done(); + expect(wrapper.vm.cancelCommentForm).toHaveBeenCalledWith({ + lineCode: diffLines[1].line_code, + fileHash: wrapper.vm.diffFileHash, }); + expect(wrapper.vm.resetAutoSave).toHaveBeenCalled(); }); }); @@ -88,13 +107,13 @@ describe('DiffLineNoteForm', () => { start: { line_code: wrapper.vm.commentLineStart.line_code, type: wrapper.vm.commentLineStart.type, - new_line: 1, + new_line: 2, old_line: null, }, end: { line_code: wrapper.vm.line.line_code, type: wrapper.vm.line.type, - new_line: 1, + new_line: 2, old_line: null, }, }; @@ -118,9 +137,25 @@ describe('DiffLineNoteForm', () => { }); }); + describe('created', () => { + it('should use the provided `range` of lines', () => { + wrapper = createComponent(); + + expect(wrapper.vm.lines.start).toBe(diffLines[0]); + expect(wrapper.vm.lines.end).toBe(diffLines[1]); + }); + + it("should fill the internal `lines` data with the provided `line` if there's no provided `range", () => { + wrapper = createComponent({ props: { range: null } }); + + expect(wrapper.vm.lines.start).toBe(diffLines[1]); + expect(wrapper.vm.lines.end).toBe(diffLines[1]); + }); + }); + describe('mounted', () => { it('should init autosave', () => { - const key = 'autosave/Note/Issue/98//DiffNote//1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_1'; + const key = 'autosave/Note/Issue/98//DiffNote//1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_2'; wrapper = createComponent(); expect(wrapper.vm.autosave).toBeDefined(); diff --git a/spec/frontend/diffs/components/tree_list_spec.js b/spec/frontend/diffs/components/tree_list_spec.js index f316a9fdf01..31044b0818c 100644 --- a/spec/frontend/diffs/components/tree_list_spec.js +++ b/spec/frontend/diffs/components/tree_list_spec.js @@ -113,7 +113,9 @@ describe('Diffs tree list component', () => { wrapper.find('.file-row').trigger('click'); - expect(wrapper.vm.$store.dispatch).toHaveBeenCalledWith('diffs/scrollToFile', 'app/index.js'); + expect(wrapper.vm.$store.dispatch).toHaveBeenCalledWith('diffs/scrollToFile', { + path: 'app/index.js', + }); }); it('renders as file list when renderTreeList is false', () => { |