diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-21 02:50:22 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-21 02:50:22 +0300 |
commit | 9dc93a4519d9d5d7be48ff274127136236a3adb3 (patch) | |
tree | 70467ae3692a0e35e5ea56bcb803eb512a10bedb /spec/frontend/diffs/store | |
parent | 4b0f34b6d759d6299322b3a54453e930c6121ff0 (diff) |
Add latest changes from gitlab-org/gitlab@13-11-stable-eev13.11.0-rc43
Diffstat (limited to 'spec/frontend/diffs/store')
-rw-r--r-- | spec/frontend/diffs/store/actions_spec.js | 47 | ||||
-rw-r--r-- | spec/frontend/diffs/store/getters_spec.js | 44 | ||||
-rw-r--r-- | spec/frontend/diffs/store/mutations_spec.js | 14 |
3 files changed, 72 insertions, 33 deletions
diff --git a/spec/frontend/diffs/store/actions_spec.js b/spec/frontend/diffs/store/actions_spec.js index ed3210ecfaf..f46a42fae7a 100644 --- a/spec/frontend/diffs/store/actions_spec.js +++ b/spec/frontend/diffs/store/actions_spec.js @@ -80,7 +80,7 @@ describe('DiffsStoreActions', () => { jest.spyOn(utils, 'idleCallback').mockImplementation(() => null); ['requestAnimationFrame', 'requestIdleCallback'].forEach((method) => { global[method] = (cb) => { - cb(); + cb({ timeRemaining: () => 10 }); }; }); }); @@ -198,7 +198,7 @@ describe('DiffsStoreActions', () => { { type: types.VIEW_DIFF_FILE, payload: 'test2' }, { type: types.SET_RETRIEVING_BATCHES, payload: false }, ], - [], + [{ type: 'startRenderDiffsQueue' }, { type: 'startRenderDiffsQueue' }], done, ); }); @@ -251,6 +251,8 @@ describe('DiffsStoreActions', () => { { type: types.SET_LOADING, payload: false }, { type: types.SET_MERGE_REQUEST_DIFFS, payload: diffMetadata.merge_request_diffs }, { type: types.SET_DIFF_METADATA, payload: noFilesData }, + // Workers are synchronous in Jest environment (see https://gitlab.com/gitlab-org/gitlab/-/merge_requests/58805) + { type: types.SET_TREE_DATA, payload: utils.generateTreeList(diffMetadata.diff_files) }, ], [], () => { @@ -1459,19 +1461,42 @@ describe('DiffsStoreActions', () => { }); describe('setFileByFile', () => { + const updateUserEndpoint = 'user/prefs'; + let putSpy; + let mock; + + beforeEach(() => { + mock = new MockAdapter(axios); + putSpy = jest.spyOn(axios, 'put'); + + mock.onPut(updateUserEndpoint).reply(200, {}); + }); + + afterEach(() => { + mock.restore(); + }); + it.each` value ${true} ${false} - `('commits SET_FILE_BY_FILE with the new value $value', ({ value }) => { - return testAction( - setFileByFile, - { fileByFile: value }, - { viewDiffsFileByFile: null }, - [{ type: types.SET_FILE_BY_FILE, payload: value }], - [], - ); - }); + `( + 'commits SET_FILE_BY_FILE and persists the File-by-File user preference with the new value $value', + async ({ value }) => { + await testAction( + setFileByFile, + { fileByFile: value }, + { + viewDiffsFileByFile: null, + endpointUpdateUser: updateUserEndpoint, + }, + [{ type: types.SET_FILE_BY_FILE, payload: value }], + [], + ); + + expect(putSpy).toHaveBeenCalledWith(updateUserEndpoint, { view_diffs_file_by_file: value }); + }, + ); }); describe('reviewFile', () => { diff --git a/spec/frontend/diffs/store/getters_spec.js b/spec/frontend/diffs/store/getters_spec.js index 04606b48662..2e3a66d5b01 100644 --- a/spec/frontend/diffs/store/getters_spec.js +++ b/spec/frontend/diffs/store/getters_spec.js @@ -377,32 +377,40 @@ describe('Diffs Module Getters', () => { }); describe('suggestionCommitMessage', () => { + let rootState; + beforeEach(() => { Object.assign(localState, { defaultSuggestionCommitMessage: '%{branch_name}%{project_path}%{project_name}%{username}%{user_full_name}%{file_paths}%{suggestions_count}%{files_count}', - branchName: 'branch', - projectPath: '/path', - projectName: 'name', - username: 'user', - userFullName: 'user userton', }); + rootState = { + page: { + mrMetadata: { + branch_name: 'branch', + project_path: '/path', + project_name: 'name', + username: 'user', + user_full_name: 'user userton', + }, + }, + }; }); it.each` - specialState | output - ${{}} | ${'branch/pathnameuseruser userton%{file_paths}%{suggestions_count}%{files_count}'} - ${{ userFullName: null }} | ${'branch/pathnameuser%{user_full_name}%{file_paths}%{suggestions_count}%{files_count}'} - ${{ username: null }} | ${'branch/pathname%{username}user userton%{file_paths}%{suggestions_count}%{files_count}'} - ${{ projectName: null }} | ${'branch/path%{project_name}useruser userton%{file_paths}%{suggestions_count}%{files_count}'} - ${{ projectPath: null }} | ${'branch%{project_path}nameuseruser userton%{file_paths}%{suggestions_count}%{files_count}'} - ${{ branchName: null }} | ${'%{branch_name}/pathnameuseruser userton%{file_paths}%{suggestions_count}%{files_count}'} + specialState | output + ${{}} | ${'branch/pathnameuseruser userton%{file_paths}%{suggestions_count}%{files_count}'} + ${{ user_full_name: null }} | ${'branch/pathnameuser%{user_full_name}%{file_paths}%{suggestions_count}%{files_count}'} + ${{ username: null }} | ${'branch/pathname%{username}user userton%{file_paths}%{suggestions_count}%{files_count}'} + ${{ project_name: null }} | ${'branch/path%{project_name}useruser userton%{file_paths}%{suggestions_count}%{files_count}'} + ${{ project_path: null }} | ${'branch%{project_path}nameuseruser userton%{file_paths}%{suggestions_count}%{files_count}'} + ${{ branch_name: null }} | ${'%{branch_name}/pathnameuseruser userton%{file_paths}%{suggestions_count}%{files_count}'} `( 'provides the correct "base" default commit message based on state ($specialState)', ({ specialState, output }) => { - Object.assign(localState, specialState); + Object.assign(rootState.page.mrMetadata, specialState); - expect(getters.suggestionCommitMessage(localState)()).toBe(output); + expect(getters.suggestionCommitMessage(localState, null, rootState)()).toBe(output); }, ); @@ -417,7 +425,9 @@ describe('Diffs Module Getters', () => { `( "properly overrides state values ($stateOverrides) if they're provided", ({ stateOverrides, output }) => { - expect(getters.suggestionCommitMessage(localState)(stateOverrides)).toBe(output); + expect(getters.suggestionCommitMessage(localState, null, rootState)(stateOverrides)).toBe( + output, + ); }, ); @@ -431,7 +441,9 @@ describe('Diffs Module Getters', () => { `( "fills in any missing interpolations ($providedValues) when they're provided at the getter callsite", ({ providedValues, output }) => { - expect(getters.suggestionCommitMessage(localState)(providedValues)).toBe(output); + expect(getters.suggestionCommitMessage(localState, null, rootState)(providedValues)).toBe( + output, + ); }, ); }); diff --git a/spec/frontend/diffs/store/mutations_spec.js b/spec/frontend/diffs/store/mutations_spec.js index a8ae759e693..b549ca42634 100644 --- a/spec/frontend/diffs/store/mutations_spec.js +++ b/spec/frontend/diffs/store/mutations_spec.js @@ -7,15 +7,17 @@ import diffFileMockData from '../mock_data/diff_file'; describe('DiffsStoreMutations', () => { describe('SET_BASE_CONFIG', () => { - it('should set endpoint and project path', () => { + it.each` + prop | value + ${'endpoint'} | ${'/diffs/endpoint'} + ${'projectPath'} | ${'/root/project'} + ${'endpointUpdateUser'} | ${'/user/preferences'} + `('should set the $prop property into state', ({ prop, value }) => { const state = {}; - const endpoint = '/diffs/endpoint'; - const projectPath = '/root/project'; - mutations[types.SET_BASE_CONFIG](state, { endpoint, projectPath }); + mutations[types.SET_BASE_CONFIG](state, { [prop]: value }); - expect(state.endpoint).toEqual(endpoint); - expect(state.projectPath).toEqual(projectPath); + expect(state[prop]).toEqual(value); }); }); |