diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-04-12 15:08:27 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-04-12 15:08:27 +0300 |
commit | e0d7577e29dcab90623e1f38cf11b351c665ee23 (patch) | |
tree | 5a34f26be66301f1af9e36b10a67dfca01fed8ec /spec/frontend/diffs | |
parent | 60e7627c998b74d48df10b9a7759d6038a1f139c (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/diffs')
-rw-r--r-- | spec/frontend/diffs/components/app_spec.js | 35 | ||||
-rw-r--r-- | spec/frontend/diffs/store/actions_spec.js | 91 |
2 files changed, 82 insertions, 44 deletions
diff --git a/spec/frontend/diffs/components/app_spec.js b/spec/frontend/diffs/components/app_spec.js index 545ba4a0e04..ab01c3e528e 100644 --- a/spec/frontend/diffs/components/app_spec.js +++ b/spec/frontend/diffs/components/app_spec.js @@ -715,19 +715,27 @@ describe('diffs/components/app', () => { }); it.each` - currentDiffFileId | targetFile - ${'123'} | ${2} - ${'312'} | ${1} + currentDiffFileId | targetFile | newFileByFile + ${'123'} | ${2} | ${false} + ${'312'} | ${1} | ${true} `( 'calls navigateToDiffFileIndex with $index when $link is clicked', - async ({ currentDiffFileId, targetFile }) => { - createComponent({ fileByFileUserPreference: true }, ({ state }) => { - state.diffs.treeEntries = { - 123: { type: 'blob', fileHash: '123' }, - 312: { type: 'blob', fileHash: '312' }, - }; - state.diffs.currentDiffFileId = currentDiffFileId; - }); + async ({ currentDiffFileId, targetFile, newFileByFile }) => { + createComponent( + { fileByFileUserPreference: true }, + ({ state }) => { + state.diffs.treeEntries = { + 123: { type: 'blob', fileHash: '123', filePaths: { old: '1234', new: '123' } }, + 312: { type: 'blob', fileHash: '312', filePaths: { old: '3124', new: '312' } }, + }; + state.diffs.currentDiffFileId = currentDiffFileId; + }, + { + glFeatures: { + singleFileFileByFile: newFileByFile, + }, + }, + ); await nextTick(); @@ -737,7 +745,10 @@ describe('diffs/components/app', () => { await nextTick(); - expect(wrapper.vm.navigateToDiffFileIndex).toHaveBeenCalledWith(targetFile - 1); + expect(wrapper.vm.navigateToDiffFileIndex).toHaveBeenCalledWith({ + index: targetFile - 1, + singleFile: newFileByFile, + }); }, ); }); diff --git a/spec/frontend/diffs/store/actions_spec.js b/spec/frontend/diffs/store/actions_spec.js index b988472f947..f3581c3dd74 100644 --- a/spec/frontend/diffs/store/actions_spec.js +++ b/spec/frontend/diffs/store/actions_spec.js @@ -1026,50 +1026,67 @@ describe('DiffsStoreActions', () => { }); describe('when the app is in fileByFile mode', () => { - it('commits SET_CURRENT_DIFF_FILE', () => { - diffActions.goToFile({ state, commit, dispatch, getters }, file); + describe('when the singleFileFileByFile feature flag is enabled', () => { + it('commits SET_CURRENT_DIFF_FILE', () => { + diffActions.goToFile( + { state, commit, dispatch, getters }, + { path: file.path, singleFile: true }, + ); - expect(commit).toHaveBeenCalledWith(types.SET_CURRENT_DIFF_FILE, fileHash); - }); + expect(commit).toHaveBeenCalledWith(types.SET_CURRENT_DIFF_FILE, fileHash); + }); - it('does nothing more if the path has already been loaded', () => { - getters.isTreePathLoaded = () => true; + it('does nothing more if the path has already been loaded', () => { + getters.isTreePathLoaded = () => true; - diffActions.goToFile({ state, dispatch, getters, commit }, file); + diffActions.goToFile( + { state, dispatch, getters, commit }, + { path: file.path, singleFile: true }, + ); - expect(commit).toHaveBeenCalledWith(types.SET_CURRENT_DIFF_FILE, fileHash); - expect(dispatch).toHaveBeenCalledTimes(0); - }); + expect(commit).toHaveBeenCalledWith(types.SET_CURRENT_DIFF_FILE, fileHash); + expect(dispatch).toHaveBeenCalledTimes(0); + }); - describe('when the tree entry has not been loaded', () => { - it('updates location hash', () => { - diffActions.goToFile({ state, commit, getters, dispatch }, file); + describe('when the tree entry has not been loaded', () => { + it('updates location hash', () => { + diffActions.goToFile( + { state, commit, getters, dispatch }, + { path: file.path, singleFile: true }, + ); - expect(document.location.hash).toBe('#test'); - }); + expect(document.location.hash).toBe('#test'); + }); - it('loads the file and then scrolls to it', async () => { - diffActions.goToFile({ state, commit, getters, dispatch }, file); + it('loads the file and then scrolls to it', async () => { + diffActions.goToFile( + { state, commit, getters, dispatch }, + { path: file.path, singleFile: true }, + ); - // Wait for the fetchFileByFile dispatch to return, to trigger scrollToFile - await waitForPromises(); + // Wait for the fetchFileByFile dispatch to return, to trigger scrollToFile + await waitForPromises(); - expect(dispatch).toHaveBeenCalledWith('fetchFileByFile'); - expect(dispatch).toHaveBeenCalledWith('scrollToFile', file); - expect(dispatch).toHaveBeenCalledTimes(2); - }); + expect(dispatch).toHaveBeenCalledWith('fetchFileByFile'); + expect(dispatch).toHaveBeenCalledWith('scrollToFile', file); + expect(dispatch).toHaveBeenCalledTimes(2); + }); - it('shows an alert when there was an error fetching the file', async () => { - dispatch = jest.fn().mockRejectedValue(); + it('shows an alert when there was an error fetching the file', async () => { + dispatch = jest.fn().mockRejectedValue(); - diffActions.goToFile({ state, commit, getters, dispatch }, file); + diffActions.goToFile( + { state, commit, getters, dispatch }, + { path: file.path, singleFile: true }, + ); - // Wait for the fetchFileByFile dispatch to return, to trigger the catch - await waitForPromises(); + // Wait for the fetchFileByFile dispatch to return, to trigger the catch + await waitForPromises(); - expect(createAlert).toHaveBeenCalledTimes(1); - expect(createAlert).toHaveBeenCalledWith({ - message: expect.stringMatching(LOAD_SINGLE_DIFF_FAILED), + expect(createAlert).toHaveBeenCalledTimes(1); + expect(createAlert).toHaveBeenCalledWith({ + message: expect.stringMatching(LOAD_SINGLE_DIFF_FAILED), + }); }); }); }); @@ -1690,12 +1707,22 @@ describe('DiffsStoreActions', () => { it('commits SET_CURRENT_DIFF_FILE', () => { return testAction( diffActions.navigateToDiffFileIndex, - 0, + { index: 0, singleFile: false }, { flatBlobsList: [{ fileHash: '123' }] }, [{ type: types.SET_CURRENT_DIFF_FILE, payload: '123' }], [], ); }); + + it('dispatches the fetchFileByFile action when the state value viewDiffsFileByFile is true and the single-file file-by-file feature flag is enabled', () => { + return testAction( + diffActions.navigateToDiffFileIndex, + { index: 0, singleFile: true }, + { viewDiffsFileByFile: true, flatBlobsList: [{ fileHash: '123' }] }, + [{ type: types.SET_CURRENT_DIFF_FILE, payload: '123' }], + [{ type: 'fetchFileByFile' }], + ); + }); }); describe('setFileByFile', () => { |