diff options
author | Tim Zallmann <tzallmann@gitlab.com> | 2018-09-07 01:27:21 +0200 |
---|---|---|
committer | Tim Zallmann <tzallmann@gitlab.com> | 2018-09-07 12:25:50 +0200 |
commit | b8ecb2c7eb5eeb488e4532b9011d681b398f165d (patch) | |
tree | c6b71bd189bad8e5c106bbb502f9adf43ffb0349 /spec/javascripts | |
parent | 89c796db5c67d1d6698c46f75670f197e2647a8f (diff) | |
download | gitlab-ce-b8ecb2c7eb5eeb488e4532b9011d681b398f165d.tar.gz |
Added new tests for newly added mutations, actions, utils
Diffstat (limited to 'spec/javascripts')
-rw-r--r-- | spec/javascripts/diffs/store/actions_spec.js | 165 | ||||
-rw-r--r-- | spec/javascripts/diffs/store/mutations_spec.js | 37 | ||||
-rw-r--r-- | spec/javascripts/diffs/store/utils_spec.js | 19 |
3 files changed, 218 insertions, 3 deletions
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: '+<span id="LC2" class="line" lang="plaintext"></span>\n', + richText: '<span id="LC2" class="line" lang="plaintext"></span>\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: '+<span id="LC2" class="line" lang="plaintext"></span>\n', + richText: '+<span id="LC2" class="line" lang="plaintext"></span>\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: '+<span id="LC2" class="line" lang="plaintext"></span>\n', + richText: '<span id="LC2" class="line" lang="plaintext"></span>\n', + metaData: null, + }, + }, + { + type: types.REMOVE_LINE_DISCUSSIONS, + payload: { + lineCode: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_2', + type: 'new', + oldLine: null, + newLine: 2, + discussions: [], + text: '+<span id="LC2" class="line" lang="plaintext"></span>\n', + richText: '+<span id="LC2" class="line" lang="plaintext"></span>\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(); + }); + }); }); |