diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /spec/frontend/diffs/store | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/frontend/diffs/store')
-rw-r--r-- | spec/frontend/diffs/store/actions_spec.js | 27 | ||||
-rw-r--r-- | spec/frontend/diffs/store/mutations_spec.js | 2 | ||||
-rw-r--r-- | spec/frontend/diffs/store/utils_spec.js | 55 |
3 files changed, 78 insertions, 6 deletions
diff --git a/spec/frontend/diffs/store/actions_spec.js b/spec/frontend/diffs/store/actions_spec.js index fc5e39357ca..5fef35d6c5b 100644 --- a/spec/frontend/diffs/store/actions_spec.js +++ b/spec/frontend/diffs/store/actions_spec.js @@ -1,6 +1,8 @@ import MockAdapter from 'axios-mock-adapter'; import Cookies from 'js-cookie'; import mockDiffFile from 'jest/diffs/mock_data/diff_file'; +import { useLocalStorageSpy } from 'helpers/local_storage_helper'; +import { TEST_HOST } from 'jest/helpers/test_constants'; import { DIFF_VIEW_COOKIE_NAME, INLINE_DIFF_VIEW_TYPE, @@ -56,12 +58,10 @@ import testAction from '../../helpers/vuex_action_helper'; import * as utils from '~/diffs/store/utils'; import * as commonUtils from '~/lib/utils/common_utils'; import { mergeUrlParams } from '~/lib/utils/url_utility'; -import { useLocalStorageSpy } from 'helpers/local_storage_helper'; import { diffMetadata } from '../mock_data/diff_metadata'; -import createFlash from '~/flash'; -import { TEST_HOST } from 'jest/helpers/test_constants'; +import { deprecatedCreateFlash as createFlash } from '~/flash'; -jest.mock('~/flash', () => jest.fn()); +jest.mock('~/flash'); describe('DiffsStoreActions', () => { useLocalStorageSpy(); @@ -1594,24 +1594,39 @@ describe('DiffsStoreActions', () => { describe('setCurrentDiffFileIdFromNote', () => { it('commits UPDATE_CURRENT_DIFF_FILE_ID', () => { const commit = jest.fn(); + const state = { diffFiles: [{ file_hash: '123' }] }; const rootGetters = { getDiscussion: () => ({ diff_file: { file_hash: '123' } }), notesById: { '1': { discussion_id: '2' } }, }; - setCurrentDiffFileIdFromNote({ commit, rootGetters }, '1'); + setCurrentDiffFileIdFromNote({ commit, state, rootGetters }, '1'); expect(commit).toHaveBeenCalledWith(types.UPDATE_CURRENT_DIFF_FILE_ID, '123'); }); it('does not commit UPDATE_CURRENT_DIFF_FILE_ID when discussion has no diff_file', () => { const commit = jest.fn(); + const state = { diffFiles: [{ file_hash: '123' }] }; const rootGetters = { getDiscussion: () => ({ id: '1' }), notesById: { '1': { discussion_id: '2' } }, }; - setCurrentDiffFileIdFromNote({ commit, rootGetters }, '1'); + setCurrentDiffFileIdFromNote({ commit, state, rootGetters }, '1'); + + expect(commit).not.toHaveBeenCalled(); + }); + + it('does not commit UPDATE_CURRENT_DIFF_FILE_ID when diff file does not exist', () => { + const commit = jest.fn(); + const state = { diffFiles: [{ file_hash: '123' }] }; + const rootGetters = { + getDiscussion: () => ({ diff_file: { file_hash: '124' } }), + notesById: { '1': { discussion_id: '2' } }, + }; + + setCurrentDiffFileIdFromNote({ commit, state, rootGetters }, '1'); expect(commit).not.toHaveBeenCalled(); }); diff --git a/spec/frontend/diffs/store/mutations_spec.js b/spec/frontend/diffs/store/mutations_spec.js index c24d406fef3..70047899612 100644 --- a/spec/frontend/diffs/store/mutations_spec.js +++ b/spec/frontend/diffs/store/mutations_spec.js @@ -830,6 +830,7 @@ describe('DiffsStoreMutations', () => { const state = { treeEntries: {}, tree: [], + isTreeLoaded: false, }; mutations[types.SET_TREE_DATA](state, { @@ -844,6 +845,7 @@ describe('DiffsStoreMutations', () => { }); expect(state.tree).toEqual(['tree']); + expect(state.isTreeLoaded).toEqual(true); }); }); diff --git a/spec/frontend/diffs/store/utils_spec.js b/spec/frontend/diffs/store/utils_spec.js index d87619e1e3c..62c82468ea0 100644 --- a/spec/frontend/diffs/store/utils_spec.js +++ b/spec/frontend/diffs/store/utils_spec.js @@ -20,6 +20,14 @@ import { noteableDataMock } from '../../notes/mock_data'; const getDiffFileMock = () => JSON.parse(JSON.stringify(diffFileMockData)); const getDiffMetadataMock = () => JSON.parse(JSON.stringify(diffMetadata)); +function extractLinesFromFile(file) { + const unpackedParallel = file.parallel_diff_lines + .flatMap(({ left, right }) => [left, right]) + .filter(Boolean); + + return [...file.highlighted_diff_lines, ...unpackedParallel]; +} + describe('DiffsStoreUtils', () => { describe('findDiffFile', () => { const files = [{ file_hash: 1, name: 'one' }]; @@ -429,6 +437,28 @@ describe('DiffsStoreUtils', () => { expect(preppedLine.right).toEqual(correctLine); expect(preppedLine.line_code).toEqual(correctLine.line_code); }); + + it.each` + brokenSymlink + ${false} + ${{}} + ${'anything except `false`'} + `( + "properly assigns each line's `commentsDisabled` as the same value as the parent file's `brokenSymlink` value (`$brokenSymlink`)", + ({ brokenSymlink }) => { + preppedLine = utils.prepareLineForRenamedFile({ + diffViewType: INLINE_DIFF_VIEW_TYPE, + line: sourceLine, + index: lineIndex, + diffFile: { + ...diffFile, + brokenSymlink, + }, + }); + + expect(preppedLine.commentsDisabled).toStrictEqual(brokenSymlink); + }, + ); }); describe('prepareDiffData', () => { @@ -541,6 +571,25 @@ describe('DiffsStoreUtils', () => { }), ]); }); + + it('adds the `.brokenSymlink` property to each diff file', () => { + preparedDiff.diff_files.forEach(file => { + expect(file).toEqual(expect.objectContaining({ brokenSymlink: false })); + }); + }); + + it("copies the diff file's `.brokenSymlink` value to each of that file's child lines", () => { + const lines = [ + ...preparedDiff.diff_files, + ...splitInlineDiff.diff_files, + ...splitParallelDiff.diff_files, + ...completedDiff.diff_files, + ].flatMap(file => extractLinesFromFile(file)); + + lines.forEach(line => { + expect(line.commentsDisabled).toBe(false); + }); + }); }); describe('for diff metadata', () => { @@ -603,6 +652,12 @@ describe('DiffsStoreUtils', () => { }, ]); }); + + it('adds the `.brokenSymlink` property to each meta diff file', () => { + preparedDiffFiles.forEach(file => { + expect(file).toMatchObject({ brokenSymlink: false }); + }); + }); }); }); |