Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/diffs/store/actions_spec.js')
-rw-r--r--spec/frontend/diffs/store/actions_spec.js228
1 files changed, 131 insertions, 97 deletions
diff --git a/spec/frontend/diffs/store/actions_spec.js b/spec/frontend/diffs/store/actions_spec.js
index 3fba661da44..7d79dcfbfe3 100644
--- a/spec/frontend/diffs/store/actions_spec.js
+++ b/spec/frontend/diffs/store/actions_spec.js
@@ -35,8 +35,6 @@ import {
setRenderTreeList,
setShowWhitespace,
setRenderIt,
- requestFullDiff,
- receiveFullDiffSucess,
receiveFullDiffError,
fetchFullDiff,
toggleFullDiff,
@@ -53,7 +51,9 @@ import axios from '~/lib/utils/axios_utils';
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';
jest.mock('~/flash', () => jest.fn());
@@ -175,19 +175,44 @@ describe('DiffsStoreActions', () => {
});
describe('fetchDiffFilesBatch', () => {
+ let mock;
+
+ beforeEach(() => {
+ mock = new MockAdapter(axios);
+ });
+
+ afterEach(() => {
+ mock.restore();
+ });
+
it('should fetch batch diff files', done => {
const endpointBatch = '/fetch/diffs_batch';
- const mock = new MockAdapter(axios);
const res1 = { diff_files: [], pagination: { next_page: 2 } };
const res2 = { diff_files: [], pagination: {} };
mock
- .onGet(endpointBatch, {
- params: { page: 1, per_page: DIFFS_PER_PAGE, w: '1', view: 'inline' },
- })
+ .onGet(
+ mergeUrlParams(
+ {
+ per_page: DIFFS_PER_PAGE,
+ w: '1',
+ view: 'inline',
+ page: 1,
+ },
+ endpointBatch,
+ ),
+ )
.reply(200, res1)
- .onGet(endpointBatch, {
- params: { page: 2, per_page: DIFFS_PER_PAGE, w: '1', view: 'inline' },
- })
+ .onGet(
+ mergeUrlParams(
+ {
+ per_page: DIFFS_PER_PAGE,
+ w: '1',
+ view: 'inline',
+ page: 2,
+ },
+ endpointBatch,
+ ),
+ )
.reply(200, res2);
testAction(
@@ -204,22 +229,50 @@ describe('DiffsStoreActions', () => {
{ type: types.SET_RETRIEVING_BATCHES, payload: false },
],
[],
- () => {
- mock.restore();
- done();
- },
+ done,
);
});
+
+ it.each`
+ viewStyle | otherView
+ ${'inline'} | ${'parallel'}
+ ${'parallel'} | ${'inline'}
+ `(
+ 'should make a request with the view parameter "$viewStyle" when the batchEndpoint already contains "$otherView"',
+ ({ viewStyle, otherView }) => {
+ const endpointBatch = '/fetch/diffs_batch';
+
+ fetchDiffFilesBatch({
+ commit: () => {},
+ state: {
+ endpointBatch: `${endpointBatch}?view=${otherView}`,
+ useSingleDiffStyle: true,
+ diffViewType: viewStyle,
+ },
+ })
+ .then(() => {
+ expect(mock.history.get[0].url).toContain(`view=${viewStyle}`);
+ expect(mock.history.get[0].url).not.toContain(`view=${otherView}`);
+ })
+ .catch(() => {});
+ },
+ );
});
describe('fetchDiffFilesMeta', () => {
- it('should fetch diff meta information', done => {
- const endpointMetadata = '/fetch/diffs_meta?view=inline';
- const mock = new MockAdapter(axios);
- const data = { diff_files: [] };
- const res = { data };
- mock.onGet(endpointMetadata).reply(200, res);
+ const endpointMetadata = '/fetch/diffs_metadata.json?view=inline';
+ const noFilesData = { ...diffMetadata };
+ let mock;
+
+ beforeEach(() => {
+ mock = new MockAdapter(axios);
+
+ delete noFilesData.diff_files;
+
+ mock.onGet(endpointMetadata).reply(200, diffMetadata);
+ });
+ it('should fetch diff meta information', done => {
testAction(
fetchDiffFilesMeta,
{},
@@ -227,8 +280,8 @@ describe('DiffsStoreActions', () => {
[
{ type: types.SET_LOADING, payload: true },
{ type: types.SET_LOADING, payload: false },
- { type: types.SET_MERGE_REQUEST_DIFFS, payload: [] },
- { type: types.SET_DIFF_DATA, payload: { data } },
+ { type: types.SET_MERGE_REQUEST_DIFFS, payload: diffMetadata.merge_request_diffs },
+ { type: types.SET_DIFF_DATA, payload: noFilesData },
],
[],
() => {
@@ -280,15 +333,24 @@ describe('DiffsStoreActions', () => {
});
describe('fetchDiffFilesBatch', () => {
+ let mock;
+
+ beforeEach(() => {
+ mock = new MockAdapter(axios);
+ });
+
+ afterEach(() => {
+ mock.restore();
+ });
+
it('should fetch batch diff files', done => {
const endpointBatch = '/fetch/diffs_batch';
- const mock = new MockAdapter(axios);
const res1 = { diff_files: [], pagination: { next_page: 2 } };
const res2 = { diff_files: [], pagination: {} };
mock
- .onGet(endpointBatch, { params: { page: 1, per_page: DIFFS_PER_PAGE, w: '1' } })
+ .onGet(mergeUrlParams({ per_page: DIFFS_PER_PAGE, w: '1', page: 1 }, endpointBatch))
.reply(200, res1)
- .onGet(endpointBatch, { params: { page: 2, per_page: DIFFS_PER_PAGE, w: '1' } })
+ .onGet(mergeUrlParams({ per_page: DIFFS_PER_PAGE, w: '1', page: 2 }, endpointBatch))
.reply(200, res2);
testAction(
@@ -305,22 +367,48 @@ describe('DiffsStoreActions', () => {
{ type: types.SET_RETRIEVING_BATCHES, payload: false },
],
[],
- () => {
- mock.restore();
- done();
- },
+ done,
);
});
+
+ it.each`
+ querystrings | requestUrl
+ ${'?view=parallel'} | ${'/fetch/diffs_batch?view=parallel'}
+ ${'?view=inline'} | ${'/fetch/diffs_batch?view=inline'}
+ ${''} | ${'/fetch/diffs_batch'}
+ `(
+ 'should use the endpoint $requestUrl if the endpointBatch in state includes `$querystrings` as a querystring',
+ ({ querystrings, requestUrl }) => {
+ const endpointBatch = '/fetch/diffs_batch';
+
+ fetchDiffFilesBatch({
+ commit: () => {},
+ state: {
+ endpointBatch: `${endpointBatch}${querystrings}`,
+ diffViewType: 'inline',
+ },
+ })
+ .then(() => {
+ expect(mock.history.get[0].url).toEqual(requestUrl);
+ })
+ .catch(() => {});
+ },
+ );
});
describe('fetchDiffFilesMeta', () => {
- it('should fetch diff meta information', done => {
- const endpointMetadata = '/fetch/diffs_meta';
- const mock = new MockAdapter(axios);
- const data = { diff_files: [] };
- const res = { data };
- mock.onGet(endpointMetadata).reply(200, res);
+ const endpointMetadata = '/fetch/diffs_metadata.json';
+ const noFilesData = { ...diffMetadata };
+ let mock;
+
+ beforeEach(() => {
+ mock = new MockAdapter(axios);
+
+ delete noFilesData.diff_files;
+ mock.onGet(endpointMetadata).reply(200, diffMetadata);
+ });
+ it('should fetch diff meta information', done => {
testAction(
fetchDiffFilesMeta,
{},
@@ -328,8 +416,8 @@ describe('DiffsStoreActions', () => {
[
{ type: types.SET_LOADING, payload: true },
{ type: types.SET_LOADING, payload: false },
- { type: types.SET_MERGE_REQUEST_DIFFS, payload: [] },
- { type: types.SET_DIFF_DATA, payload: { data } },
+ { type: types.SET_MERGE_REQUEST_DIFFS, payload: diffMetadata.merge_request_diffs },
+ { type: types.SET_DIFF_DATA, payload: noFilesData },
],
[],
() => {
@@ -467,9 +555,9 @@ describe('DiffsStoreActions', () => {
new_path: 'file1',
old_line: 5,
old_path: 'file2',
+ line_range: null,
line_code: 'ABC_1_1',
position_type: 'text',
- line_range: null,
},
},
hash: 'ABC_123',
@@ -1136,34 +1224,8 @@ describe('DiffsStoreActions', () => {
});
});
- describe('requestFullDiff', () => {
- it('commits REQUEST_FULL_DIFF', done => {
- testAction(
- requestFullDiff,
- 'file',
- {},
- [{ type: types.REQUEST_FULL_DIFF, payload: 'file' }],
- [],
- done,
- );
- });
- });
-
- describe('receiveFullDiffSucess', () => {
- it('commits REQUEST_FULL_DIFF', done => {
- testAction(
- receiveFullDiffSucess,
- { filePath: 'test' },
- {},
- [{ type: types.RECEIVE_FULL_DIFF_SUCCESS, payload: { filePath: 'test' } }],
- [],
- done,
- );
- });
- });
-
describe('receiveFullDiffError', () => {
- it('commits REQUEST_FULL_DIFF', done => {
+ it('updates state with the file that did not load', done => {
testAction(
receiveFullDiffError,
'file',
@@ -1191,7 +1253,7 @@ describe('DiffsStoreActions', () => {
mock.onGet(`${gl.TEST_HOST}/context`).replyOnce(200, ['test']);
});
- it('dispatches receiveFullDiffSucess', done => {
+ it('commits the success and dispatches an action to expand the new lines', done => {
const file = {
context_lines_path: `${gl.TEST_HOST}/context`,
file_path: 'test',
@@ -1201,11 +1263,8 @@ describe('DiffsStoreActions', () => {
fetchFullDiff,
file,
null,
- [],
- [
- { type: 'receiveFullDiffSucess', payload: { filePath: 'test' } },
- { type: 'setExpandedDiffLines', payload: { file, data: ['test'] } },
- ],
+ [{ type: types.RECEIVE_FULL_DIFF_SUCCESS, payload: { filePath: 'test' } }],
+ [{ type: 'setExpandedDiffLines', payload: { file, data: ['test'] } }],
done,
);
});
@@ -1243,11 +1302,8 @@ describe('DiffsStoreActions', () => {
toggleFullDiff,
'test',
state,
- [],
- [
- { type: 'requestFullDiff', payload: 'test' },
- { type: 'fetchFullDiff', payload: state.diffFiles[0] },
- ],
+ [{ type: types.REQUEST_FULL_DIFF, payload: 'test' }],
+ [{ type: 'fetchFullDiff', payload: state.diffFiles[0] }],
done,
);
});
@@ -1255,7 +1311,6 @@ describe('DiffsStoreActions', () => {
describe('switchToFullDiffFromRenamedFile', () => {
const SUCCESS_URL = 'fakehost/context.success';
- const ERROR_URL = 'fakehost/context.error';
const testFilePath = 'testpath';
const updatedViewerName = 'testviewer';
const preparedLine = { prepared: 'in-a-test' };
@@ -1311,27 +1366,6 @@ describe('DiffsStoreActions', () => {
},
);
});
-
- describe('error', () => {
- beforeEach(() => {
- renamedFile = { ...testFile, context_lines_path: ERROR_URL };
- mock.onGet(ERROR_URL).reply(500);
- });
-
- it('dispatches the error handling action', () => {
- const rejected = testAction(
- switchToFullDiffFromRenamedFile,
- { diffFile: renamedFile },
- null,
- [],
- [{ type: 'receiveFullDiffError', payload: testFilePath }],
- );
-
- return rejected.catch(error =>
- expect(error).toEqual(new Error('Request failed with status code 500')),
- );
- });
- });
});
describe('setFileCollapsed', () => {