From b8b2cb3675a38fa0460add7a1cab03abbaeb56fd Mon Sep 17 00:00:00 2001 From: Tim Zallmann Date: Sat, 1 Sep 2018 23:24:29 +0200 Subject: Fixed Problems with Inline View + Specs --- .../diffs/components/diff_line_gutter_content_spec.js | 10 ++++++++++ spec/javascripts/diffs/mock_data/diff_file.js | 15 +++++++++++++++ 2 files changed, 25 insertions(+) (limited to 'spec/javascripts/diffs') diff --git a/spec/javascripts/diffs/components/diff_line_gutter_content_spec.js b/spec/javascripts/diffs/components/diff_line_gutter_content_spec.js index a1a37b342b7..757de95d695 100644 --- a/spec/javascripts/diffs/components/diff_line_gutter_content_spec.js +++ b/spec/javascripts/diffs/components/diff_line_gutter_content_spec.js @@ -11,6 +11,16 @@ describe('DiffLineGutterContent', () => { const createComponent = (options = {}) => { const cmp = Vue.extend(DiffLineGutterContent); const props = Object.assign({}, options); + props.line = { + lineCode: 'LC_42', + type: 'new', + oldLine: null, + newLine: 1, + discussions: [], + text: '+ - Bad dates\n', + richText: '+ - Bad dates\n', + metaData: null, + }; props.fileHash = getDiffFileMock().fileHash; props.contextLinesPath = '/context/lines/path'; diff --git a/spec/javascripts/diffs/mock_data/diff_file.js b/spec/javascripts/diffs/mock_data/diff_file.js index cce36ecc91f..12de1bc4d51 100644 --- a/spec/javascripts/diffs/mock_data/diff_file.js +++ b/spec/javascripts/diffs/mock_data/diff_file.js @@ -49,6 +49,7 @@ export default { type: 'new', oldLine: null, newLine: 1, + discussions: [], text: '+ - Bad dates\n', richText: '+ - Bad dates\n', metaData: null, @@ -58,6 +59,7 @@ export default { type: 'new', oldLine: null, newLine: 2, + discussions: [], text: '+\n', richText: '+\n', metaData: null, @@ -67,6 +69,7 @@ export default { type: null, oldLine: 1, newLine: 3, + discussions: [], text: ' v6.8.0\n', richText: ' v6.8.0\n', metaData: null, @@ -76,6 +79,7 @@ export default { type: null, oldLine: 2, newLine: 4, + discussions: [], text: ' \n', richText: ' \n', metaData: null, @@ -85,6 +89,7 @@ export default { type: null, oldLine: 3, newLine: 5, + discussions: [], text: ' v6.7.0\n', richText: ' v6.7.0\n', metaData: null, @@ -112,6 +117,7 @@ export default { type: 'new', oldLine: null, newLine: 1, + discussions: [], text: '+ - Bad dates\n', richText: ' - Bad dates\n', metaData: null, @@ -126,6 +132,7 @@ export default { type: 'new', oldLine: null, newLine: 2, + discussions: [], text: '+\n', richText: '\n', metaData: null, @@ -137,6 +144,7 @@ export default { type: null, oldLine: 1, newLine: 3, + discussions: [], text: ' v6.8.0\n', richText: 'v6.8.0\n', metaData: null, @@ -146,6 +154,7 @@ export default { type: null, oldLine: 1, newLine: 3, + discussions: [], text: ' v6.8.0\n', richText: 'v6.8.0\n', metaData: null, @@ -157,6 +166,7 @@ export default { type: null, oldLine: 2, newLine: 4, + discussions: [], text: ' \n', richText: '\n', metaData: null, @@ -166,6 +176,7 @@ export default { type: null, oldLine: 2, newLine: 4, + discussions: [], text: ' \n', richText: '\n', metaData: null, @@ -177,6 +188,7 @@ export default { type: null, oldLine: 3, newLine: 5, + discussions: [], text: ' v6.7.0\n', richText: 'v6.7.0\n', metaData: null, @@ -186,6 +198,7 @@ export default { type: null, oldLine: 3, newLine: 5, + discussions: [], text: ' v6.7.0\n', richText: 'v6.7.0\n', metaData: null, @@ -197,6 +210,7 @@ export default { type: 'match', oldLine: null, newLine: null, + discussions: [], text: '', richText: '', metaData: { @@ -209,6 +223,7 @@ export default { type: 'match', oldLine: null, newLine: null, + discussions: [], text: '', richText: '', metaData: { -- cgit v1.2.1 From a424e8141bc42dec5d3caaf87ee08a7d6308866a Mon Sep 17 00:00:00 2001 From: Tim Zallmann Date: Sun, 2 Sep 2018 12:44:51 +0200 Subject: Fixes for Karma Tests --- .../components/diff_line_gutter_content_spec.js | 38 ++++++++-------------- spec/javascripts/diffs/mock_data/diff_file.js | 1 + spec/javascripts/diffs/store/utils_spec.js | 25 ++++++++++---- 3 files changed, 33 insertions(+), 31 deletions(-) (limited to 'spec/javascripts/diffs') diff --git a/spec/javascripts/diffs/components/diff_line_gutter_content_spec.js b/spec/javascripts/diffs/components/diff_line_gutter_content_spec.js index 757de95d695..7c2495600c8 100644 --- a/spec/javascripts/diffs/components/diff_line_gutter_content_spec.js +++ b/spec/javascripts/diffs/components/diff_line_gutter_content_spec.js @@ -6,13 +6,12 @@ import discussionsMockData from '../mock_data/diff_discussions'; import diffFileMockData from '../mock_data/diff_file'; describe('DiffLineGutterContent', () => { - const getDiscussionsMockData = () => [Object.assign({}, discussionsMockData)]; const getDiffFileMock = () => Object.assign({}, diffFileMockData); const createComponent = (options = {}) => { const cmp = Vue.extend(DiffLineGutterContent); const props = Object.assign({}, options); props.line = { - lineCode: 'LC_42', + code: 'LC_42', type: 'new', oldLine: null, newLine: 1, @@ -26,51 +25,42 @@ describe('DiffLineGutterContent', () => { return createComponentWithStore(cmp, store, props).$mount(); }; - const setDiscussions = component => { - component.$store.dispatch('setInitialNotes', getDiscussionsMockData()); - }; - - const resetDiscussions = component => { - component.$store.dispatch('setInitialNotes', []); - }; describe('computed', () => { describe('lineHref', () => { it('should prepend # to lineCode', () => { const lineCode = 'LC_42'; - const component = createComponent({ lineCode }); + const component = createComponent(); expect(component.lineHref).toEqual(`#${lineCode}`); }); it('should return # if there is no lineCode', () => { - const component = createComponent({ lineCode: null }); + const component = createComponent(); + component.line.code = ''; expect(component.lineHref).toEqual('#'); }); }); describe('discussions, hasDiscussions, shouldShowAvatarsOnGutter', () => { it('should return empty array when there is no discussion', () => { - const component = createComponent({ lineCode: 'LC_42' }); - expect(component.discussions).toEqual([]); + const component = createComponent(); expect(component.hasDiscussions).toEqual(false); expect(component.shouldShowAvatarsOnGutter).toEqual(false); }); it('should return discussions for the given lineCode', () => { - const { lineCode } = getDiffFileMock().highlightedDiffLines[1]; - const component = createComponent({ - lineCode, + const cmp = Vue.extend(DiffLineGutterContent); + const props = { + line: getDiffFileMock().highlightedDiffLines[1], + fileHash: getDiffFileMock().fileHash, showCommentButton: true, - discussions: getDiscussionsMockData(), - }); + contextLinesPath: '/context/lines/path', + }; + props.line.discussions = [Object.assign({}, discussionsMockData)]; + const component = createComponentWithStore(cmp, store, props).$mount(); - setDiscussions(component); - - expect(component.discussions).toEqual(getDiscussionsMockData()); expect(component.hasDiscussions).toEqual(true); expect(component.shouldShowAvatarsOnGutter).toEqual(true); - - resetDiscussions(component); }); }); }); @@ -114,9 +104,7 @@ describe('DiffLineGutterContent', () => { lineCode: getDiffFileMock().highlightedDiffLines[1].lineCode, }); - setDiscussions(component); expect(component.$el.querySelector('.diff-comment-avatar-holders')).toBeDefined(); - resetDiscussions(component); }); }); }); diff --git a/spec/javascripts/diffs/mock_data/diff_file.js b/spec/javascripts/diffs/mock_data/diff_file.js index 12de1bc4d51..372b8f066cf 100644 --- a/spec/javascripts/diffs/mock_data/diff_file.js +++ b/spec/javascripts/diffs/mock_data/diff_file.js @@ -99,6 +99,7 @@ export default { type: 'match', oldLine: null, newLine: null, + discussions: [], text: '', richText: '', metaData: { diff --git a/spec/javascripts/diffs/store/utils_spec.js b/spec/javascripts/diffs/store/utils_spec.js index 32136d9ebff..cd16d597c54 100644 --- a/spec/javascripts/diffs/store/utils_spec.js +++ b/spec/javascripts/diffs/store/utils_spec.js @@ -179,32 +179,45 @@ describe('DiffsStoreUtils', () => { describe('trimFirstCharOfLineContent', () => { it('trims the line when it starts with a space', () => { - expect(utils.trimFirstCharOfLineContent({ richText: ' diff' })).toEqual({ richText: 'diff' }); + expect(utils.trimFirstCharOfLineContent({ richText: ' diff' })).toEqual({ + discussions: [], + richText: 'diff', + }); }); it('trims the line when it starts with a +', () => { - expect(utils.trimFirstCharOfLineContent({ richText: '+diff' })).toEqual({ richText: 'diff' }); + expect(utils.trimFirstCharOfLineContent({ richText: '+diff' })).toEqual({ + discussions: [], + richText: 'diff', + }); }); it('trims the line when it starts with a -', () => { - expect(utils.trimFirstCharOfLineContent({ richText: '-diff' })).toEqual({ richText: 'diff' }); + expect(utils.trimFirstCharOfLineContent({ richText: '-diff' })).toEqual({ + discussions: [], + richText: 'diff', + }); }); it('does not trims the line when it starts with a letter', () => { - expect(utils.trimFirstCharOfLineContent({ richText: 'diff' })).toEqual({ richText: 'diff' }); + expect(utils.trimFirstCharOfLineContent({ richText: 'diff' })).toEqual({ + discussions: [], + richText: 'diff', + }); }); it('does not modify the provided object', () => { const lineObj = { + discussions: [], richText: ' diff', }; utils.trimFirstCharOfLineContent(lineObj); - expect(lineObj).toEqual({ richText: ' diff' }); + expect(lineObj).toEqual({ discussions: [], richText: ' diff' }); }); it('handles a undefined or null parameter', () => { - expect(utils.trimFirstCharOfLineContent()).toEqual({}); + expect(utils.trimFirstCharOfLineContent()).toEqual({ discussions: [] }); }); }); }); -- cgit v1.2.1 From 8563499b0faf5712ae12feaef086d8be9a692980 Mon Sep 17 00:00:00 2001 From: Tim Zallmann Date: Sun, 2 Sep 2018 23:26:25 +0200 Subject: Fix for Getter + Linting --- spec/javascripts/diffs/store/getters_spec.js | 39 +++------------------------- 1 file changed, 3 insertions(+), 36 deletions(-) (limited to 'spec/javascripts/diffs') diff --git a/spec/javascripts/diffs/store/getters_spec.js b/spec/javascripts/diffs/store/getters_spec.js index a59b26b2634..ce3dcba211c 100644 --- a/spec/javascripts/diffs/store/getters_spec.js +++ b/spec/javascripts/diffs/store/getters_spec.js @@ -184,27 +184,6 @@ describe('Diffs Module Getters', () => { }); }); - describe('singleDiscussionByLineCode', () => { - it('returns found discussion per line Code', () => { - const discussionsMock = {}; - discussionsMock.ABC = discussionMock; - - expect( - getters.singleDiscussionByLineCode(localState, {}, null, { - discussionsByLineCode: () => discussionsMock, - })('DEF'), - ).toEqual([]); - }); - - it('returns empty array when no discussions match', () => { - expect( - getters.singleDiscussionByLineCode(localState, {}, null, { - discussionsByLineCode: () => {}, - })('DEF'), - ).toEqual([]); - }); - }); - describe('shouldRenderParallelCommentRow', () => { let line; @@ -223,32 +202,20 @@ describe('Diffs Module Getters', () => { it('returns true when discussion is expanded', () => { discussionMock.expanded = true; - expect( - getters.shouldRenderParallelCommentRow(localState, { - singleDiscussionByLineCode: () => [discussionMock], - })(line), - ).toEqual(true); + expect(getters.shouldRenderParallelCommentRow(localState)(line)).toEqual(true); }); it('returns false when no discussion was found', () => { localState.diffLineCommentForms.ABC = false; localState.diffLineCommentForms.DEF = false; - expect( - getters.shouldRenderParallelCommentRow(localState, { - singleDiscussionByLineCode: () => [], - })(line), - ).toEqual(false); + expect(getters.shouldRenderParallelCommentRow(localState)(line)).toEqual(false); }); it('returns true when discussionForm was found', () => { localState.diffLineCommentForms.ABC = {}; - expect( - getters.shouldRenderParallelCommentRow(localState, { - singleDiscussionByLineCode: () => [discussionMock], - })(line), - ).toEqual(true); + expect(getters.shouldRenderParallelCommentRow(localState)(line)).toEqual(true); }); }); -- cgit v1.2.1 From 958cf02e91e7f715c2ce44a76dc264342fcadad0 Mon Sep 17 00:00:00 2001 From: Tim Zallmann Date: Mon, 3 Sep 2018 09:44:46 +0200 Subject: Fixes for Karma tests --- .../diffs/components/parallel_diff_view_spec.js | 8 ++--- spec/javascripts/diffs/store/getters_spec.js | 39 ++++++++++++---------- 2 files changed, 26 insertions(+), 21 deletions(-) (limited to 'spec/javascripts/diffs') diff --git a/spec/javascripts/diffs/components/parallel_diff_view_spec.js b/spec/javascripts/diffs/components/parallel_diff_view_spec.js index 165e4b69b6c..091e01868d3 100644 --- a/spec/javascripts/diffs/components/parallel_diff_view_spec.js +++ b/spec/javascripts/diffs/components/parallel_diff_view_spec.js @@ -18,11 +18,11 @@ describe('ParallelDiffView', () => { }).$mount(); }); - describe('computed', () => { - describe('parallelDiffLines', () => { + describe('assigned', () => { + describe('diffLines', () => { it('should normalize lines for empty cells', () => { - expect(component.parallelDiffLines[0].left.type).toEqual(constants.EMPTY_CELL_TYPE); - expect(component.parallelDiffLines[1].left.type).toEqual(constants.EMPTY_CELL_TYPE); + expect(component.diffLines[0].left.type).toEqual(constants.EMPTY_CELL_TYPE); + expect(component.diffLines[1].left.type).toEqual(constants.EMPTY_CELL_TYPE); }); }); }); diff --git a/spec/javascripts/diffs/store/getters_spec.js b/spec/javascripts/diffs/store/getters_spec.js index ce3dcba211c..4747e437c4e 100644 --- a/spec/javascripts/diffs/store/getters_spec.js +++ b/spec/javascripts/diffs/store/getters_spec.js @@ -190,22 +190,27 @@ describe('Diffs Module Getters', () => { beforeEach(() => { line = {}; + discussionMock.expanded = true; + line.left = { lineCode: 'ABC', + discussions: [discussionMock], }; line.right = { lineCode: 'DEF', + discussions: [discussionMock1], }; }); it('returns true when discussion is expanded', () => { - discussionMock.expanded = true; - expect(getters.shouldRenderParallelCommentRow(localState)(line)).toEqual(true); }); it('returns false when no discussion was found', () => { + line.left.discussions = []; + line.right.discussions = []; + localState.diffLineCommentForms.ABC = false; localState.diffLineCommentForms.DEF = false; @@ -220,32 +225,32 @@ describe('Diffs Module Getters', () => { }); describe('shouldRenderInlineCommentRow', () => { + let line; + + beforeEach(() => { + discussionMock.expanded = true; + + line = { + lineCode: 'ABC', + discussions: [discussionMock], + }; + }); + it('returns true when diffLineCommentForms has form', () => { localState.diffLineCommentForms.ABC = {}; - expect( - getters.shouldRenderInlineCommentRow(localState)({ - lineCode: 'ABC', - }), - ).toEqual(true); + expect(getters.shouldRenderInlineCommentRow(localState)(line)).toEqual(true); }); it('returns false when no line discussions were found', () => { - expect( - getters.shouldRenderInlineCommentRow(localState, { - singleDiscussionByLineCode: () => [], - })('DEF'), - ).toEqual(false); + line.discussions = []; + expect(getters.shouldRenderInlineCommentRow(localState)(line)).toEqual(false); }); it('returns true if all found discussions are expanded', () => { discussionMock.expanded = true; - expect( - getters.shouldRenderInlineCommentRow(localState, { - singleDiscussionByLineCode: () => [discussionMock], - })('ABC'), - ).toEqual(true); + expect(getters.shouldRenderInlineCommentRow(localState)(line)).toEqual(true); }); }); -- cgit v1.2.1 From d3cf0c247bcd665742047828aa8198ada43705f1 Mon Sep 17 00:00:00 2001 From: Tim Zallmann Date: Wed, 5 Sep 2018 13:23:42 +0200 Subject: Fix for Karma, Static Analysis and RSPec for MR Page --- spec/javascripts/diffs/components/diff_file_spec.js | 3 ++- spec/javascripts/diffs/components/diff_line_gutter_content_spec.js | 4 ++-- spec/javascripts/diffs/store/mutations_spec.js | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) (limited to 'spec/javascripts/diffs') diff --git a/spec/javascripts/diffs/components/diff_file_spec.js b/spec/javascripts/diffs/components/diff_file_spec.js index 44a38f7ca82..0917af23e84 100644 --- a/spec/javascripts/diffs/components/diff_file_spec.js +++ b/spec/javascripts/diffs/components/diff_file_spec.js @@ -51,7 +51,8 @@ describe('DiffFile', () => { }); it('should have collapsed text and link', done => { - vm.file.collapsed = true; + vm.file.collapsed = false; + vm.file.highlightedDiffLines = null; vm.$nextTick(() => { expect(vm.$el.innerText).toContain('This diff is collapsed'); diff --git a/spec/javascripts/diffs/components/diff_line_gutter_content_spec.js b/spec/javascripts/diffs/components/diff_line_gutter_content_spec.js index 7c2495600c8..663c0680845 100644 --- a/spec/javascripts/diffs/components/diff_line_gutter_content_spec.js +++ b/spec/javascripts/diffs/components/diff_line_gutter_content_spec.js @@ -11,7 +11,7 @@ describe('DiffLineGutterContent', () => { const cmp = Vue.extend(DiffLineGutterContent); const props = Object.assign({}, options); props.line = { - code: 'LC_42', + lineCode: 'LC_42', type: 'new', oldLine: null, newLine: 1, @@ -36,7 +36,7 @@ describe('DiffLineGutterContent', () => { it('should return # if there is no lineCode', () => { const component = createComponent(); - component.line.code = ''; + component.line.lineCode = ''; expect(component.lineHref).toEqual('#'); }); }); diff --git a/spec/javascripts/diffs/store/mutations_spec.js b/spec/javascripts/diffs/store/mutations_spec.js index 8f89984c6e5..a99e0a5a659 100644 --- a/spec/javascripts/diffs/store/mutations_spec.js +++ b/spec/javascripts/diffs/store/mutations_spec.js @@ -141,7 +141,7 @@ describe('DiffsStoreMutations', () => { const file = { fileHash }; const data = { diff_files: [{ file_hash: fileHash, extra_field: 1, existingField: 1 }] }; - mutations[types.ADD_COLLAPSED_DIFFS](state, { file, data }); + mutations[types.ADD_COLLAPSED_DIFFS](state, { file: state.diffFiles[1], data }); expect(spy).toHaveBeenCalledWith(data, { deep: true }); expect(state.diffFiles[1].fileHash).toEqual(fileHash); -- cgit v1.2.1 From a0dc392362d880fe80853258929678e75f9cc345 Mon Sep 17 00:00:00 2001 From: Tim Zallmann Date: Wed, 5 Sep 2018 15:31:05 +0200 Subject: Fix Linting Error --- spec/javascripts/diffs/store/mutations_spec.js | 1 - 1 file changed, 1 deletion(-) (limited to 'spec/javascripts/diffs') diff --git a/spec/javascripts/diffs/store/mutations_spec.js b/spec/javascripts/diffs/store/mutations_spec.js index a99e0a5a659..7dfab46ba4f 100644 --- a/spec/javascripts/diffs/store/mutations_spec.js +++ b/spec/javascripts/diffs/store/mutations_spec.js @@ -138,7 +138,6 @@ describe('DiffsStoreMutations', () => { const fileHash = 123; const state = { diffFiles: [{}, { fileHash, existingField: 0 }] }; - const file = { fileHash }; const data = { diff_files: [{ file_hash: fileHash, extra_field: 1, existingField: 1 }] }; mutations[types.ADD_COLLAPSED_DIFFS](state, { file: state.diffFiles[1], data }); -- cgit v1.2.1 From b8ecb2c7eb5eeb488e4532b9011d681b398f165d Mon Sep 17 00:00:00 2001 From: Tim Zallmann Date: Fri, 7 Sep 2018 01:27:21 +0200 Subject: Added new tests for newly added mutations, actions, utils --- spec/javascripts/diffs/store/actions_spec.js | 165 ++++++++++++++++++++++++- spec/javascripts/diffs/store/mutations_spec.js | 37 ++++++ spec/javascripts/diffs/store/utils_spec.js | 19 +++ 3 files changed, 218 insertions(+), 3 deletions(-) (limited to 'spec/javascripts/diffs') diff --git a/spec/javascripts/diffs/store/actions_spec.js b/spec/javascripts/diffs/store/actions_spec.js index c1560dac1a0..8b52c9bffc7 100644 --- a/spec/javascripts/diffs/store/actions_spec.js +++ b/spec/javascripts/diffs/store/actions_spec.js @@ -7,8 +7,11 @@ import { } from '~/diffs/constants'; import * as actions from '~/diffs/store/actions'; import * as types from '~/diffs/store/mutation_types'; +import { reduceDiscussionsToLineCodes } from '~/notes/stores/utils'; import axios from '~/lib/utils/axios_utils'; import testAction from '../../helpers/vuex_action_helper'; +import mockFile from '../mock_data/diff_file'; +import mockDiscussion from '../mock_data/diff_discussions'; describe('DiffsStoreActions', () => { describe('setBaseConfig', () => { @@ -53,6 +56,150 @@ describe('DiffsStoreActions', () => { }); }); + describe('assignDiscussionsToDiff', () => { + it('should merge discussions into diffs', done => { + const state = { diffFiles: [Object.assign({}, mockFile)] }; + const singleDiscussion = Object.assign({}, mockDiscussion); + const discussions = reduceDiscussionsToLineCodes([singleDiscussion]); + + testAction( + actions.assignDiscussionsToDiff, + discussions, + state, + [ + { + type: types.SET_LINE_DISCUSSIONS, + payload: { + line: { + lineCode: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_2', + type: 'new', + oldLine: null, + newLine: 2, + discussions: [], + text: '+\n', + richText: '\n', + metaData: null, + }, + discussions: discussions['1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_2'], + }, + }, + { + type: types.SET_LINE_DISCUSSIONS, + payload: { + line: { + lineCode: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_2', + type: 'new', + oldLine: null, + newLine: 2, + discussions: [], + text: '+\n', + richText: '+\n', + metaData: null, + }, + discussions: discussions['1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_2'], + }, + }, + ], + [], + () => { + done(); + }, + ); + }); + }); + + describe('removeDiscussionsFromDiff', () => { + it('should remove discussions from diffs', done => { + const state = { diffFiles: [Object.assign({}, mockFile)] }; + const singleDiscussion = Object.assign({}, mockDiscussion); + + reduceDiscussionsToLineCodes([singleDiscussion]); + + testAction( + actions.removeDiscussionsFromDiff, + singleDiscussion, + state, + [ + { + type: types.REMOVE_LINE_DISCUSSIONS, + payload: { + lineCode: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_2', + type: 'new', + oldLine: null, + newLine: 2, + discussions: [], + text: '+\n', + richText: '\n', + metaData: null, + }, + }, + { + type: types.REMOVE_LINE_DISCUSSIONS, + payload: { + lineCode: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_2', + type: 'new', + oldLine: null, + newLine: 2, + discussions: [], + text: '+\n', + richText: '+\n', + metaData: null, + }, + }, + ], + [], + () => { + done(); + }, + ); + }); + }); + + describe('startRenderDiffsQueue', () => { + it('should set all files to RENDER_FILE', done => { + const actualRAF = global.requestAnimationFrame; + global.requestAnimationFrame = cb => { + cb(); + }; + + const state = { + diffFiles: [ + { + id: 1, + renderIt: false, + collapsed: false, + }, + { + id: 2, + renderIt: false, + collapsed: false, + }, + ], + }; + + const pseudoCommit = (commitType, file) => { + expect(commitType).toBe(types.RENDER_FILE); + Object.assign(file, { + renderIt: true, + }); + }; + + actions + .startRenderDiffsQueue({ state, commit: pseudoCommit }) + .then(() => { + global.requestAnimationFrame = actualRAF; + + expect(state.diffFiles[0].renderIt).toBeTruthy(); + expect(state.diffFiles[1].renderIt).toBeTruthy(); + + done(); + }) + .catch(() => { + done.fail(); + }); + }); + }); + describe('setInlineDiffViewType', () => { it('should set diff view type to inline and also set the cookie properly', done => { testAction( @@ -204,7 +351,11 @@ describe('DiffsStoreActions', () => { actions.toggleFileDiscussions({ getters, dispatch }); - expect(dispatch).toHaveBeenCalledWith('collapseDiscussion', { discussionId: 1 }, { root: true }); + expect(dispatch).toHaveBeenCalledWith( + 'collapseDiscussion', + { discussionId: 1 }, + { root: true }, + ); }); it('should dispatch expandDiscussion when all discussions are collapsed', () => { @@ -218,7 +369,11 @@ describe('DiffsStoreActions', () => { actions.toggleFileDiscussions({ getters, dispatch }); - expect(dispatch).toHaveBeenCalledWith('expandDiscussion', { discussionId: 1 }, { root: true }); + expect(dispatch).toHaveBeenCalledWith( + 'expandDiscussion', + { discussionId: 1 }, + { root: true }, + ); }); it('should dispatch expandDiscussion when some discussions are collapsed and others are expanded for the collapsed discussion', () => { @@ -232,7 +387,11 @@ describe('DiffsStoreActions', () => { actions.toggleFileDiscussions({ getters, dispatch }); - expect(dispatch).toHaveBeenCalledWith('expandDiscussion', { discussionId: 1 }, { root: true }); + expect(dispatch).toHaveBeenCalledWith( + 'expandDiscussion', + { discussionId: 1 }, + { root: true }, + ); }); }); }); diff --git a/spec/javascripts/diffs/store/mutations_spec.js b/spec/javascripts/diffs/store/mutations_spec.js index 7dfab46ba4f..4a042b7675f 100644 --- a/spec/javascripts/diffs/store/mutations_spec.js +++ b/spec/javascripts/diffs/store/mutations_spec.js @@ -148,4 +148,41 @@ describe('DiffsStoreMutations', () => { expect(state.diffFiles[1].extraField).toEqual(1); }); }); + + describe('SET_LINE_DISCUSSIONS', () => { + it('should add discussions to the given line', () => { + const line = { fileHash: 'ABC', discussions: [] }; + const discussions = [ + { + id: 1, + }, + { + id: 2, + }, + ]; + + mutations[types.SET_LINE_DISCUSSIONS]({}, { line, discussions }); + expect(line.discussions.length).toEqual(2); + expect(line.discussions[1].id).toEqual(2); + }); + }); + + describe('REMOVE_LINE_DISCUSSIONS', () => { + it('should remove the existing discussions on the given line', () => { + const line = { + fileHash: 'ABC', + discussions: [ + { + id: 1, + }, + { + id: 2, + }, + ], + }; + + mutations[types.REMOVE_LINE_DISCUSSIONS]({}, line); + expect(line.discussions.length).toEqual(0); + }); + }); }); diff --git a/spec/javascripts/diffs/store/utils_spec.js b/spec/javascripts/diffs/store/utils_spec.js index cd16d597c54..bd9d63769a1 100644 --- a/spec/javascripts/diffs/store/utils_spec.js +++ b/spec/javascripts/diffs/store/utils_spec.js @@ -220,4 +220,23 @@ describe('DiffsStoreUtils', () => { expect(utils.trimFirstCharOfLineContent()).toEqual({ discussions: [] }); }); }); + + describe('prepareDiffData', () => { + it('sets the renderIt and collapsed attribute on files', () => { + const preparedDiff = { diffFiles: [getDiffFileMock()] }; + utils.prepareDiffData(preparedDiff); + + const firstParallelDiffLine = preparedDiff.diffFiles[0].parallelDiffLines[2]; + expect(firstParallelDiffLine.left.discussions.length).toBe(0); + expect(firstParallelDiffLine.left).not.toHaveAttr('text'); + expect(firstParallelDiffLine.right.discussions.length).toBe(0); + expect(firstParallelDiffLine.right).not.toHaveAttr('text'); + + expect(preparedDiff.diffFiles[0].highlightedDiffLines[0].discussions.length).toBe(0); + expect(preparedDiff.diffFiles[0].highlightedDiffLines[0]).not.toHaveAttr('text'); + + expect(preparedDiff.diffFiles[0].renderIt).toBeTruthy(); + expect(preparedDiff.diffFiles[0].collapsed).toBeFalsy(); + }); + }); }); -- cgit v1.2.1 From 982da16bf2960d13f7f67f45b29f53795d3dbd5c Mon Sep 17 00:00:00 2001 From: Tim Zallmann Date: Fri, 7 Sep 2018 09:56:49 +0200 Subject: Made the discussion tests artificial to have them stable, mocked RAF + RIC --- spec/javascripts/diffs/store/actions_spec.js | 143 ++++++++++++++++++--------- 1 file changed, 97 insertions(+), 46 deletions(-) (limited to 'spec/javascripts/diffs') diff --git a/spec/javascripts/diffs/store/actions_spec.js b/spec/javascripts/diffs/store/actions_spec.js index 8b52c9bffc7..44c2eb27e0d 100644 --- a/spec/javascripts/diffs/store/actions_spec.js +++ b/spec/javascripts/diffs/store/actions_spec.js @@ -10,10 +10,27 @@ import * as types from '~/diffs/store/mutation_types'; import { reduceDiscussionsToLineCodes } from '~/notes/stores/utils'; import axios from '~/lib/utils/axios_utils'; import testAction from '../../helpers/vuex_action_helper'; -import mockFile from '../mock_data/diff_file'; -import mockDiscussion from '../mock_data/diff_discussions'; describe('DiffsStoreActions', () => { + const originalMethods = { + requestAnimationFrame: global.requestAnimationFrame, + requestIdleCallback: global.requestIdleCallback, + }; + + beforeEach(() => { + ['requestAnimationFrame', 'requestIdleCallback'].forEach(method => { + global[method] = cb => { + cb(); + }; + }); + }); + + afterEach(() => { + ['requestAnimationFrame', 'requestIdleCallback'].forEach(method => { + global[method] = originalMethods[method]; + }); + }); + describe('setBaseConfig', () => { it('should set given endpoint and project path', done => { const endpoint = '/diffs/set/endpoint'; @@ -58,8 +75,40 @@ describe('DiffsStoreActions', () => { describe('assignDiscussionsToDiff', () => { it('should merge discussions into diffs', done => { - const state = { diffFiles: [Object.assign({}, mockFile)] }; - const singleDiscussion = Object.assign({}, mockDiscussion); + const state = { + diffFiles: [ + { + fileHash: 'ABC', + parallelDiffLines: [ + { + left: { + lineCode: 'ABC_1_1', + discussions: [], + }, + right: { + lineCode: 'ABC_1_1', + discussions: [], + }, + }, + ], + highlightedDiffLines: [ + { + lineCode: 'ABC_1_1', + discussions: [], + }, + ], + }, + ], + }; + const singleDiscussion = { + line_code: 'ABC_1_1', + diff_discussion: {}, + diff_file: { + file_hash: 'ABC', + }, + resolvable: true, + }; + const discussions = reduceDiscussionsToLineCodes([singleDiscussion]); testAction( @@ -71,32 +120,20 @@ describe('DiffsStoreActions', () => { type: types.SET_LINE_DISCUSSIONS, payload: { line: { - lineCode: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_2', - type: 'new', - oldLine: null, - newLine: 2, + lineCode: 'ABC_1_1', discussions: [], - text: '+\n', - richText: '\n', - metaData: null, }, - discussions: discussions['1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_2'], + discussions: [singleDiscussion], }, }, { type: types.SET_LINE_DISCUSSIONS, payload: { line: { - lineCode: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_2', - type: 'new', - oldLine: null, - newLine: 2, + lineCode: 'ABC_1_1', discussions: [], - text: '+\n', - richText: '+\n', - metaData: null, }, - discussions: discussions['1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_2'], + discussions: [singleDiscussion], }, }, ], @@ -110,10 +147,39 @@ describe('DiffsStoreActions', () => { describe('removeDiscussionsFromDiff', () => { it('should remove discussions from diffs', done => { - const state = { diffFiles: [Object.assign({}, mockFile)] }; - const singleDiscussion = Object.assign({}, mockDiscussion); - - reduceDiscussionsToLineCodes([singleDiscussion]); + const state = { + diffFiles: [ + { + fileHash: 'ABC', + parallelDiffLines: [ + { + left: { + lineCode: 'ABC_1_1', + discussions: [ + { + id: 1, + }, + ], + }, + right: { + lineCode: 'ABC_1_1', + discussions: [], + }, + }, + ], + highlightedDiffLines: [ + { + lineCode: 'ABC_1_1', + discussions: [], + }, + ], + }, + ], + }; + const singleDiscussion = { + fileHash: 'ABC', + line_code: 'ABC_1_1', + }; testAction( actions.removeDiscussionsFromDiff, @@ -123,27 +189,19 @@ describe('DiffsStoreActions', () => { { type: types.REMOVE_LINE_DISCUSSIONS, payload: { - lineCode: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_2', - type: 'new', - oldLine: null, - newLine: 2, - discussions: [], - text: '+\n', - richText: '\n', - metaData: null, + lineCode: 'ABC_1_1', + discussions: [ + { + id: 1, + }, + ], }, }, { type: types.REMOVE_LINE_DISCUSSIONS, payload: { - lineCode: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_2', - type: 'new', - oldLine: null, - newLine: 2, + lineCode: 'ABC_1_1', discussions: [], - text: '+\n', - richText: '+\n', - metaData: null, }, }, ], @@ -157,11 +215,6 @@ describe('DiffsStoreActions', () => { describe('startRenderDiffsQueue', () => { it('should set all files to RENDER_FILE', done => { - const actualRAF = global.requestAnimationFrame; - global.requestAnimationFrame = cb => { - cb(); - }; - const state = { diffFiles: [ { @@ -187,8 +240,6 @@ describe('DiffsStoreActions', () => { actions .startRenderDiffsQueue({ state, commit: pseudoCommit }) .then(() => { - global.requestAnimationFrame = actualRAF; - expect(state.diffFiles[0].renderIt).toBeTruthy(); expect(state.diffFiles[1].renderIt).toBeTruthy(); -- cgit v1.2.1 From d95c1f0335f7309114fcbb0d5413b28e1701a640 Mon Sep 17 00:00:00 2001 From: Jan Provaznik Date: Fri, 7 Sep 2018 13:39:20 +0000 Subject: Use ResourceLabelEvent for tracking label changes --- spec/javascripts/diffs/mock_data/diff_discussions.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'spec/javascripts/diffs') diff --git a/spec/javascripts/diffs/mock_data/diff_discussions.js b/spec/javascripts/diffs/mock_data/diff_discussions.js index 41d0dfd8939..b29a22da7c2 100644 --- a/spec/javascripts/diffs/mock_data/diff_discussions.js +++ b/spec/javascripts/diffs/mock_data/diff_discussions.js @@ -16,7 +16,7 @@ export default { expanded: true, notes: [ { - id: 1749, + id: '1749', type: 'DiffNote', attachment: null, author: { @@ -68,7 +68,7 @@ export default { '/gitlab-org/gitlab-test/issues/new?discussion_to_resolve=6b232e05bea388c6b043ccc243ba505faac04ea8&merge_request_to_resolve_discussions_of=20', }, { - id: 1753, + id: '1753', type: 'DiffNote', attachment: null, author: { @@ -120,7 +120,7 @@ export default { '/gitlab-org/gitlab-test/issues/new?discussion_to_resolve=6b232e05bea388c6b043ccc243ba505faac04ea8&merge_request_to_resolve_discussions_of=20', }, { - id: 1754, + id: '1754', type: 'DiffNote', attachment: null, author: { @@ -162,7 +162,7 @@ export default { '/gitlab-org/gitlab-test/issues/new?discussion_to_resolve=6b232e05bea388c6b043ccc243ba505faac04ea8&merge_request_to_resolve_discussions_of=20', }, { - id: 1755, + id: '1755', type: 'DiffNote', attachment: null, author: { @@ -204,7 +204,7 @@ export default { '/gitlab-org/gitlab-test/issues/new?discussion_to_resolve=6b232e05bea388c6b043ccc243ba505faac04ea8&merge_request_to_resolve_discussions_of=20', }, { - id: 1756, + id: '1756', type: 'DiffNote', attachment: null, author: { -- cgit v1.2.1 From d4d5ed59f98eb3218418c385327224d2512e518e Mon Sep 17 00:00:00 2001 From: Tim Zallmann Date: Fri, 7 Sep 2018 16:20:57 +0200 Subject: Fixes based on MR discussion around naming, mutations, handling of state --- spec/javascripts/diffs/components/diff_file_spec.js | 1 + 1 file changed, 1 insertion(+) (limited to 'spec/javascripts/diffs') diff --git a/spec/javascripts/diffs/components/diff_file_spec.js b/spec/javascripts/diffs/components/diff_file_spec.js index 0917af23e84..845fef23db6 100644 --- a/spec/javascripts/diffs/components/diff_file_spec.js +++ b/spec/javascripts/diffs/components/diff_file_spec.js @@ -51,6 +51,7 @@ describe('DiffFile', () => { }); it('should have collapsed text and link', done => { + vm.file.renderIt = true; vm.file.collapsed = false; vm.file.highlightedDiffLines = null; -- cgit v1.2.1 From d2cbe07398c3f824ffecbd78ff5749daca678d3e Mon Sep 17 00:00:00 2001 From: Tim Zallmann Date: Fri, 7 Sep 2018 17:13:11 +0200 Subject: Adapted so utils + actions don't include any mutations and mutations are always against state --- spec/javascripts/diffs/store/actions_spec.js | 34 ++-------- spec/javascripts/diffs/store/mutations_spec.js | 94 ++++++++++++++++++++++---- 2 files changed, 86 insertions(+), 42 deletions(-) (limited to 'spec/javascripts/diffs') diff --git a/spec/javascripts/diffs/store/actions_spec.js b/spec/javascripts/diffs/store/actions_spec.js index 44c2eb27e0d..c162fc965ba 100644 --- a/spec/javascripts/diffs/store/actions_spec.js +++ b/spec/javascripts/diffs/store/actions_spec.js @@ -100,6 +100,7 @@ describe('DiffsStoreActions', () => { }, ], }; + const singleDiscussion = { line_code: 'ABC_1_1', diff_discussion: {}, @@ -107,6 +108,7 @@ describe('DiffsStoreActions', () => { file_hash: 'ABC', }, resolvable: true, + fileHash: 'ABC', }; const discussions = reduceDiscussionsToLineCodes([singleDiscussion]); @@ -117,22 +119,9 @@ describe('DiffsStoreActions', () => { state, [ { - type: types.SET_LINE_DISCUSSIONS, + type: types.SET_LINE_DISCUSSIONS_FOR_FILE, payload: { - line: { - lineCode: 'ABC_1_1', - discussions: [], - }, - discussions: [singleDiscussion], - }, - }, - { - type: types.SET_LINE_DISCUSSIONS, - payload: { - line: { - lineCode: 'ABC_1_1', - discussions: [], - }, + fileHash: 'ABC', discussions: [singleDiscussion], }, }, @@ -187,21 +176,10 @@ describe('DiffsStoreActions', () => { state, [ { - type: types.REMOVE_LINE_DISCUSSIONS, - payload: { - lineCode: 'ABC_1_1', - discussions: [ - { - id: 1, - }, - ], - }, - }, - { - type: types.REMOVE_LINE_DISCUSSIONS, + type: types.REMOVE_LINE_DISCUSSIONS_FOR_FILE, payload: { + fileHash: 'ABC', lineCode: 'ABC_1_1', - discussions: [], }, }, ], diff --git a/spec/javascripts/diffs/store/mutations_spec.js b/spec/javascripts/diffs/store/mutations_spec.js index 4a042b7675f..9a89bc57404 100644 --- a/spec/javascripts/diffs/store/mutations_spec.js +++ b/spec/javascripts/diffs/store/mutations_spec.js @@ -149,40 +149,106 @@ describe('DiffsStoreMutations', () => { }); }); - describe('SET_LINE_DISCUSSIONS', () => { + describe('SET_LINE_DISCUSSIONS_FOR_FILE', () => { it('should add discussions to the given line', () => { - const line = { fileHash: 'ABC', discussions: [] }; + const state = { + diffFiles: [ + { + fileHash: 'ABC', + parallelDiffLines: [ + { + left: { + lineCode: 'ABC_1', + discussions: [], + }, + right: { + lineCode: 'ABC_1', + discussions: [], + }, + }, + ], + highlightedDiffLines: [ + { + lineCode: 'ABC_1', + discussions: [], + }, + ], + }, + ], + }; const discussions = [ { id: 1, + line_code: 'ABC_1', }, { id: 2, + line_code: 'ABC_1', }, ]; - mutations[types.SET_LINE_DISCUSSIONS]({}, { line, discussions }); - expect(line.discussions.length).toEqual(2); - expect(line.discussions[1].id).toEqual(2); + mutations[types.SET_LINE_DISCUSSIONS_FOR_FILE](state, { fileHash: 'ABC', discussions }); + + expect(state.diffFiles[0].parallelDiffLines[0].left.discussions.length).toEqual(2); + expect(state.diffFiles[0].parallelDiffLines[0].left.discussions[1].id).toEqual(2); + + expect(state.diffFiles[0].highlightedDiffLines[0].discussions.length).toEqual(2); + expect(state.diffFiles[0].highlightedDiffLines[0].discussions[1].id).toEqual(2); }); }); describe('REMOVE_LINE_DISCUSSIONS', () => { it('should remove the existing discussions on the given line', () => { - const line = { - fileHash: 'ABC', - discussions: [ - { - id: 1, - }, + const state = { + diffFiles: [ { - id: 2, + fileHash: 'ABC', + parallelDiffLines: [ + { + left: { + lineCode: 'ABC_1', + discussions: [ + { + id: 1, + line_code: 'ABC_1', + }, + { + id: 2, + line_code: 'ABC_1', + }, + ], + }, + right: { + lineCode: 'ABC_1', + discussions: [], + }, + }, + ], + highlightedDiffLines: [ + { + lineCode: 'ABC_1', + discussions: [ + { + id: 1, + line_code: 'ABC_1', + }, + { + id: 2, + line_code: 'ABC_1', + }, + ], + }, + ], }, ], }; - mutations[types.REMOVE_LINE_DISCUSSIONS]({}, line); - expect(line.discussions.length).toEqual(0); + mutations[types.REMOVE_LINE_DISCUSSIONS_FOR_FILE](state, { + fileHash: 'ABC', + lineCode: 'ABC_1', + }); + expect(state.diffFiles[0].parallelDiffLines[0].left.discussions.length).toEqual(0); + expect(state.diffFiles[0].highlightedDiffLines[0].discussions.length).toEqual(0); }); }); }); -- cgit v1.2.1 From 04c0d12d1a6cfaa54d2e5f510922b9d27c5c0a77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Lu=C3=ADs?= Date: Sat, 8 Sep 2018 06:37:41 +0000 Subject: Resolve "Merge requests show outdated discussions on changes tab" --- spec/javascripts/diffs/store/actions_spec.js | 38 +++++++++++++++++- spec/javascripts/diffs/store/mutations_spec.js | 36 ++++++++++++++++- spec/javascripts/diffs/store/utils_spec.js | 53 ++++++++++++++++++++++++++ 3 files changed, 125 insertions(+), 2 deletions(-) (limited to 'spec/javascripts/diffs') diff --git a/spec/javascripts/diffs/store/actions_spec.js b/spec/javascripts/diffs/store/actions_spec.js index c162fc965ba..cfb8f862598 100644 --- a/spec/javascripts/diffs/store/actions_spec.js +++ b/spec/javascripts/diffs/store/actions_spec.js @@ -95,20 +95,45 @@ describe('DiffsStoreActions', () => { { lineCode: 'ABC_1_1', discussions: [], + oldLine: 5, + newLine: null, }, ], + diffRefs: { + baseSha: 'abc', + headSha: 'def', + startSha: 'ghi', + }, + newPath: 'file1', + oldPath: 'file2', }, ], }; + const diffPosition = { + baseSha: 'abc', + headSha: 'def', + startSha: 'ghi', + newLine: null, + newPath: 'file1', + oldLine: 5, + oldPath: 'file2', + }; + const singleDiscussion = { line_code: 'ABC_1_1', diff_discussion: {}, diff_file: { file_hash: 'ABC', }, - resolvable: true, fileHash: 'ABC', + resolvable: true, + position: { + formatter: diffPosition, + }, + original_position: { + formatter: diffPosition, + }, }; const discussions = reduceDiscussionsToLineCodes([singleDiscussion]); @@ -123,6 +148,17 @@ describe('DiffsStoreActions', () => { payload: { fileHash: 'ABC', discussions: [singleDiscussion], + diffPositionByLineCode: { + ABC_1_1: { + baseSha: 'abc', + headSha: 'def', + startSha: 'ghi', + newLine: null, + newPath: 'file1', + oldLine: 5, + oldPath: 'file2', + }, + }, }, }, ], diff --git a/spec/javascripts/diffs/store/mutations_spec.js b/spec/javascripts/diffs/store/mutations_spec.js index 9a89bc57404..7eeca6712cc 100644 --- a/spec/javascripts/diffs/store/mutations_spec.js +++ b/spec/javascripts/diffs/store/mutations_spec.js @@ -151,6 +151,16 @@ describe('DiffsStoreMutations', () => { describe('SET_LINE_DISCUSSIONS_FOR_FILE', () => { it('should add discussions to the given line', () => { + const diffPosition = { + baseSha: 'ed13df29948c41ba367caa757ab3ec4892509910', + headSha: 'b921914f9a834ac47e6fd9420f78db0f83559130', + newLine: null, + newPath: '500-lines-4.txt', + oldLine: 5, + oldPath: '500-lines-4.txt', + startSha: 'ed13df29948c41ba367caa757ab3ec4892509910', + }; + const state = { diffFiles: [ { @@ -180,14 +190,38 @@ describe('DiffsStoreMutations', () => { { id: 1, line_code: 'ABC_1', + diff_discussion: true, + resolvable: true, + original_position: { + formatter: diffPosition, + }, + position: { + formatter: diffPosition, + }, }, { id: 2, line_code: 'ABC_1', + diff_discussion: true, + resolvable: true, + original_position: { + formatter: diffPosition, + }, + position: { + formatter: diffPosition, + }, }, ]; - mutations[types.SET_LINE_DISCUSSIONS_FOR_FILE](state, { fileHash: 'ABC', discussions }); + const diffPositionByLineCode = { + ABC_1: diffPosition, + }; + + mutations[types.SET_LINE_DISCUSSIONS_FOR_FILE](state, { + fileHash: 'ABC', + discussions, + diffPositionByLineCode, + }); expect(state.diffFiles[0].parallelDiffLines[0].left.discussions.length).toEqual(2); expect(state.diffFiles[0].parallelDiffLines[0].left.discussions[1].id).toEqual(2); diff --git a/spec/javascripts/diffs/store/utils_spec.js b/spec/javascripts/diffs/store/utils_spec.js index bd9d63769a1..1c580580582 100644 --- a/spec/javascripts/diffs/store/utils_spec.js +++ b/spec/javascripts/diffs/store/utils_spec.js @@ -239,4 +239,57 @@ describe('DiffsStoreUtils', () => { expect(preparedDiff.diffFiles[0].collapsed).toBeFalsy(); }); }); + + describe('isDiscussionApplicableToLine', () => { + const diffPosition = { + baseSha: 'ed13df29948c41ba367caa757ab3ec4892509910', + headSha: 'b921914f9a834ac47e6fd9420f78db0f83559130', + newLine: null, + newPath: '500-lines-4.txt', + oldLine: 5, + oldPath: '500-lines-4.txt', + startSha: 'ed13df29948c41ba367caa757ab3ec4892509910', + }; + + const wrongDiffPosition = { + baseSha: 'wrong', + headSha: 'wrong', + newLine: null, + newPath: '500-lines-4.txt', + oldLine: 5, + oldPath: '500-lines-4.txt', + startSha: 'wrong', + }; + + const discussions = { + upToDateDiscussion1: { + original_position: { + formatter: diffPosition, + }, + position: { + formatter: wrongDiffPosition, + }, + }, + outDatedDiscussion1: { + original_position: { + formatter: wrongDiffPosition, + }, + position: { + formatter: wrongDiffPosition, + }, + }, + }; + + it('returns true when the discussion is up to date', () => { + expect( + utils.isDiscussionApplicableToLine(discussions.upToDateDiscussion1, diffPosition), + ).toBe(true); + }); + + it('returns false when the discussion is not up to date', () => { + expect( + utils.isDiscussionApplicableToLine(discussions.outDatedDiscussion1, diffPosition), + ).toBe(false); + }); + }); }); -- cgit v1.2.1 From 12b48e61af4cdcf1caf0355ccc9c7a4b98175d6a Mon Sep 17 00:00:00 2001 From: Tim Zallmann Date: Mon, 10 Sep 2018 08:50:41 +0000 Subject: Resolve "On master, inline diff view contains extra `+` and `-` signs" --- spec/javascripts/diffs/store/utils_spec.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'spec/javascripts/diffs') diff --git a/spec/javascripts/diffs/store/utils_spec.js b/spec/javascripts/diffs/store/utils_spec.js index 1c580580582..4b5cf450c68 100644 --- a/spec/javascripts/diffs/store/utils_spec.js +++ b/spec/javascripts/diffs/store/utils_spec.js @@ -231,9 +231,18 @@ describe('DiffsStoreUtils', () => { expect(firstParallelDiffLine.left).not.toHaveAttr('text'); expect(firstParallelDiffLine.right.discussions.length).toBe(0); expect(firstParallelDiffLine.right).not.toHaveAttr('text'); - - expect(preparedDiff.diffFiles[0].highlightedDiffLines[0].discussions.length).toBe(0); - expect(preparedDiff.diffFiles[0].highlightedDiffLines[0]).not.toHaveAttr('text'); + const firstParallelChar = firstParallelDiffLine.right.richText.charAt(0); + expect(firstParallelChar).not.toBe(' '); + expect(firstParallelChar).not.toBe('+'); + expect(firstParallelChar).not.toBe('-'); + + const checkLine = preparedDiff.diffFiles[0].highlightedDiffLines[0]; + expect(checkLine.discussions.length).toBe(0); + expect(checkLine).not.toHaveAttr('text'); + const firstChar = checkLine.richText.charAt(0); + expect(firstChar).not.toBe(' '); + expect(firstChar).not.toBe('+'); + expect(firstChar).not.toBe('-'); expect(preparedDiff.diffFiles[0].renderIt).toBeTruthy(); expect(preparedDiff.diffFiles[0].collapsed).toBeFalsy(); -- cgit v1.2.1