diff options
author | Tim Zallmann <tzallmann@gitlab.com> | 2018-09-07 18:13:11 +0300 |
---|---|---|
committer | Tim Zallmann <tzallmann@gitlab.com> | 2018-09-07 18:13:11 +0300 |
commit | d2cbe07398c3f824ffecbd78ff5749daca678d3e (patch) | |
tree | 80db47a1f53e1333b6252d14e314bb6a758f158e /spec/javascripts | |
parent | d4d5ed59f98eb3218418c385327224d2512e518e (diff) |
Adapted so utils + actions don't include any mutations and mutations are always against state
Diffstat (limited to 'spec/javascripts')
-rw-r--r-- | spec/javascripts/diffs/store/actions_spec.js | 34 | ||||
-rw-r--r-- | spec/javascripts/diffs/store/mutations_spec.js | 94 |
2 files changed, 86 insertions, 42 deletions
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); }); }); }); |