2018-11-08 19:23:39 +05:30
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
|
|
|
import Cookies from 'js-cookie';
|
|
|
|
import {
|
|
|
|
DIFF_VIEW_COOKIE_NAME,
|
|
|
|
INLINE_DIFF_VIEW_TYPE,
|
|
|
|
PARALLEL_DIFF_VIEW_TYPE,
|
|
|
|
} from '~/diffs/constants';
|
2018-11-20 20:47:30 +05:30
|
|
|
import actions, {
|
|
|
|
setBaseConfig,
|
|
|
|
fetchDiffFiles,
|
|
|
|
assignDiscussionsToDiff,
|
|
|
|
removeDiscussionsFromDiff,
|
|
|
|
startRenderDiffsQueue,
|
|
|
|
setInlineDiffViewType,
|
|
|
|
setParallelDiffViewType,
|
|
|
|
showCommentForm,
|
|
|
|
cancelCommentForm,
|
|
|
|
loadMoreLines,
|
|
|
|
scrollToLineIfNeededInline,
|
|
|
|
scrollToLineIfNeededParallel,
|
|
|
|
loadCollapsedDiff,
|
|
|
|
expandAllFiles,
|
|
|
|
toggleFileDiscussions,
|
2018-12-05 23:21:45 +05:30
|
|
|
saveDiffDiscussion,
|
2019-02-15 15:39:39 +05:30
|
|
|
setHighlightedRow,
|
2018-12-05 23:21:45 +05:30
|
|
|
toggleTreeOpen,
|
|
|
|
scrollToFile,
|
|
|
|
toggleShowTreeList,
|
2019-02-15 15:39:39 +05:30
|
|
|
renderFileForDiscussionId,
|
2019-03-02 22:35:43 +05:30
|
|
|
setRenderTreeList,
|
|
|
|
setShowWhitespace,
|
2019-07-07 11:18:12 +05:30
|
|
|
setRenderIt,
|
|
|
|
requestFullDiff,
|
|
|
|
receiveFullDiffSucess,
|
|
|
|
receiveFullDiffError,
|
|
|
|
fetchFullDiff,
|
|
|
|
toggleFullDiff,
|
|
|
|
setFileCollapsed,
|
2019-07-31 22:56:46 +05:30
|
|
|
setExpandedDiffLines,
|
2018-11-20 20:47:30 +05:30
|
|
|
} from '~/diffs/store/actions';
|
2019-02-15 15:39:39 +05:30
|
|
|
import eventHub from '~/notes/event_hub';
|
2018-11-08 19:23:39 +05:30
|
|
|
import * as types from '~/diffs/store/mutation_types';
|
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2019-02-15 15:39:39 +05:30
|
|
|
import mockDiffFile from 'spec/diffs/mock_data/diff_file';
|
2018-11-08 19:23:39 +05:30
|
|
|
import testAction from '../../helpers/vuex_action_helper';
|
|
|
|
|
|
|
|
describe('DiffsStoreActions', () => {
|
2018-11-20 20:47:30 +05:30
|
|
|
const originalMethods = {
|
|
|
|
requestAnimationFrame: global.requestAnimationFrame,
|
|
|
|
requestIdleCallback: global.requestIdleCallback,
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
['requestAnimationFrame', 'requestIdleCallback'].forEach(method => {
|
|
|
|
global[method] = cb => {
|
|
|
|
cb();
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
['requestAnimationFrame', 'requestIdleCallback'].forEach(method => {
|
|
|
|
global[method] = originalMethods[method];
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
describe('setBaseConfig', () => {
|
|
|
|
it('should set given endpoint and project path', done => {
|
|
|
|
const endpoint = '/diffs/set/endpoint';
|
|
|
|
const projectPath = '/root/project';
|
|
|
|
|
|
|
|
testAction(
|
2018-11-20 20:47:30 +05:30
|
|
|
setBaseConfig,
|
2018-11-08 19:23:39 +05:30
|
|
|
{ endpoint, projectPath },
|
|
|
|
{ endpoint: '', projectPath: '' },
|
|
|
|
[{ type: types.SET_BASE_CONFIG, payload: { endpoint, projectPath } }],
|
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('fetchDiffFiles', () => {
|
|
|
|
it('should fetch diff files', done => {
|
|
|
|
const endpoint = '/fetch/diff/files';
|
|
|
|
const mock = new MockAdapter(axios);
|
|
|
|
const res = { diff_files: 1, merge_request_diffs: [] };
|
|
|
|
mock.onGet(endpoint).reply(200, res);
|
|
|
|
|
|
|
|
testAction(
|
2018-11-20 20:47:30 +05:30
|
|
|
fetchDiffFiles,
|
2018-11-08 19:23:39 +05:30
|
|
|
{},
|
|
|
|
{ endpoint },
|
|
|
|
[
|
|
|
|
{ type: types.SET_LOADING, payload: true },
|
|
|
|
{ type: types.SET_LOADING, payload: false },
|
|
|
|
{ type: types.SET_MERGE_REQUEST_DIFFS, payload: res.merge_request_diffs },
|
|
|
|
{ type: types.SET_DIFF_DATA, payload: res },
|
|
|
|
],
|
|
|
|
[],
|
|
|
|
() => {
|
|
|
|
mock.restore();
|
|
|
|
done();
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
describe('setHighlightedRow', () => {
|
2019-07-07 11:18:12 +05:30
|
|
|
it('should mark currently selected diff and set lineHash and fileHash of highlightedRow', () => {
|
2019-02-15 15:39:39 +05:30
|
|
|
testAction(setHighlightedRow, 'ABC_123', {}, [
|
|
|
|
{ type: types.SET_HIGHLIGHTED_ROW, payload: 'ABC_123' },
|
2019-07-07 11:18:12 +05:30
|
|
|
{ type: types.UPDATE_CURRENT_DIFF_FILE_ID, payload: 'ABC' },
|
2019-02-15 15:39:39 +05:30
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
describe('assignDiscussionsToDiff', () => {
|
|
|
|
it('should merge discussions into diffs', done => {
|
|
|
|
const state = {
|
|
|
|
diffFiles: [
|
|
|
|
{
|
2019-02-15 15:39:39 +05:30
|
|
|
file_hash: 'ABC',
|
|
|
|
parallel_diff_lines: [
|
2018-11-20 20:47:30 +05:30
|
|
|
{
|
|
|
|
left: {
|
2019-02-15 15:39:39 +05:30
|
|
|
line_code: 'ABC_1_1',
|
2018-11-20 20:47:30 +05:30
|
|
|
discussions: [],
|
|
|
|
},
|
|
|
|
right: {
|
2019-02-15 15:39:39 +05:30
|
|
|
line_code: 'ABC_1_1',
|
2018-11-20 20:47:30 +05:30
|
|
|
discussions: [],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2019-02-15 15:39:39 +05:30
|
|
|
highlighted_diff_lines: [
|
2018-11-20 20:47:30 +05:30
|
|
|
{
|
2019-02-15 15:39:39 +05:30
|
|
|
line_code: 'ABC_1_1',
|
2018-11-20 20:47:30 +05:30
|
|
|
discussions: [],
|
2019-02-15 15:39:39 +05:30
|
|
|
old_line: 5,
|
|
|
|
new_line: null,
|
2018-11-20 20:47:30 +05:30
|
|
|
},
|
|
|
|
],
|
2019-02-15 15:39:39 +05:30
|
|
|
diff_refs: {
|
|
|
|
base_sha: 'abc',
|
|
|
|
head_sha: 'def',
|
|
|
|
start_sha: 'ghi',
|
2018-11-20 20:47:30 +05:30
|
|
|
},
|
2019-02-15 15:39:39 +05:30
|
|
|
new_path: 'file1',
|
|
|
|
old_path: 'file2',
|
2018-11-20 20:47:30 +05:30
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
const diffPosition = {
|
2019-02-15 15:39:39 +05:30
|
|
|
base_sha: 'abc',
|
|
|
|
head_sha: 'def',
|
|
|
|
start_sha: 'ghi',
|
|
|
|
new_line: null,
|
|
|
|
new_path: 'file1',
|
|
|
|
old_line: 5,
|
|
|
|
old_path: 'file2',
|
2018-11-20 20:47:30 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
const singleDiscussion = {
|
|
|
|
line_code: 'ABC_1_1',
|
|
|
|
diff_discussion: {},
|
|
|
|
diff_file: {
|
|
|
|
file_hash: 'ABC',
|
|
|
|
},
|
2019-02-15 15:39:39 +05:30
|
|
|
file_hash: 'ABC',
|
2018-11-20 20:47:30 +05:30
|
|
|
resolvable: true,
|
|
|
|
position: diffPosition,
|
|
|
|
original_position: diffPosition,
|
|
|
|
};
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
const discussions = [singleDiscussion];
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
testAction(
|
|
|
|
assignDiscussionsToDiff,
|
|
|
|
discussions,
|
|
|
|
state,
|
|
|
|
[
|
|
|
|
{
|
|
|
|
type: types.SET_LINE_DISCUSSIONS_FOR_FILE,
|
|
|
|
payload: {
|
2018-12-13 13:39:08 +05:30
|
|
|
discussion: singleDiscussion,
|
2018-11-20 20:47:30 +05:30
|
|
|
diffPositionByLineCode: {
|
|
|
|
ABC_1_1: {
|
2019-02-15 15:39:39 +05:30
|
|
|
base_sha: 'abc',
|
|
|
|
head_sha: 'def',
|
|
|
|
start_sha: 'ghi',
|
|
|
|
new_line: null,
|
|
|
|
new_path: 'file1',
|
|
|
|
old_line: 5,
|
|
|
|
old_path: 'file2',
|
|
|
|
line_code: 'ABC_1_1',
|
|
|
|
position_type: 'text',
|
2018-11-20 20:47:30 +05:30
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[],
|
2019-02-15 15:39:39 +05:30
|
|
|
done,
|
2018-11-20 20:47:30 +05:30
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('removeDiscussionsFromDiff', () => {
|
|
|
|
it('should remove discussions from diffs', done => {
|
|
|
|
const state = {
|
|
|
|
diffFiles: [
|
|
|
|
{
|
2019-02-15 15:39:39 +05:30
|
|
|
file_hash: 'ABC',
|
|
|
|
parallel_diff_lines: [
|
2018-11-20 20:47:30 +05:30
|
|
|
{
|
|
|
|
left: {
|
2019-02-15 15:39:39 +05:30
|
|
|
line_code: 'ABC_1_1',
|
2018-11-20 20:47:30 +05:30
|
|
|
discussions: [
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
right: {
|
2019-02-15 15:39:39 +05:30
|
|
|
line_code: 'ABC_1_1',
|
2018-11-20 20:47:30 +05:30
|
|
|
discussions: [],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2019-02-15 15:39:39 +05:30
|
|
|
highlighted_diff_lines: [
|
2018-11-20 20:47:30 +05:30
|
|
|
{
|
2019-02-15 15:39:39 +05:30
|
|
|
line_code: 'ABC_1_1',
|
2018-11-20 20:47:30 +05:30
|
|
|
discussions: [],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
const singleDiscussion = {
|
2018-12-13 13:39:08 +05:30
|
|
|
id: '1',
|
2019-02-15 15:39:39 +05:30
|
|
|
file_hash: 'ABC',
|
2018-11-20 20:47:30 +05:30
|
|
|
line_code: 'ABC_1_1',
|
|
|
|
};
|
|
|
|
|
|
|
|
testAction(
|
|
|
|
removeDiscussionsFromDiff,
|
|
|
|
singleDiscussion,
|
|
|
|
state,
|
|
|
|
[
|
|
|
|
{
|
|
|
|
type: types.REMOVE_LINE_DISCUSSIONS_FOR_FILE,
|
|
|
|
payload: {
|
2018-12-13 13:39:08 +05:30
|
|
|
id: '1',
|
2018-11-20 20:47:30 +05:30
|
|
|
fileHash: 'ABC',
|
|
|
|
lineCode: 'ABC_1_1',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[],
|
2019-02-15 15:39:39 +05:30
|
|
|
done,
|
2018-11-20 20:47:30 +05:30
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('startRenderDiffsQueue', () => {
|
2018-12-05 23:21:45 +05:30
|
|
|
it('should set all files to RENDER_FILE', () => {
|
2018-11-20 20:47:30 +05:30
|
|
|
const state = {
|
|
|
|
diffFiles: [
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
renderIt: false,
|
2019-07-07 11:18:12 +05:30
|
|
|
viewer: {
|
|
|
|
collapsed: false,
|
|
|
|
},
|
2018-11-20 20:47:30 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 2,
|
|
|
|
renderIt: false,
|
2019-07-07 11:18:12 +05:30
|
|
|
viewer: {
|
|
|
|
collapsed: false,
|
|
|
|
},
|
2018-11-20 20:47:30 +05:30
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
const pseudoCommit = (commitType, file) => {
|
|
|
|
expect(commitType).toBe(types.RENDER_FILE);
|
|
|
|
Object.assign(file, {
|
|
|
|
renderIt: true,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
startRenderDiffsQueue({ state, commit: pseudoCommit });
|
2018-11-20 20:47:30 +05:30
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
expect(state.diffFiles[0].renderIt).toBe(true);
|
|
|
|
expect(state.diffFiles[1].renderIt).toBe(true);
|
2018-11-20 20:47:30 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
describe('setInlineDiffViewType', () => {
|
|
|
|
it('should set diff view type to inline and also set the cookie properly', done => {
|
|
|
|
testAction(
|
2018-11-20 20:47:30 +05:30
|
|
|
setInlineDiffViewType,
|
2018-11-08 19:23:39 +05:30
|
|
|
null,
|
|
|
|
{},
|
|
|
|
[{ type: types.SET_DIFF_VIEW_TYPE, payload: INLINE_DIFF_VIEW_TYPE }],
|
|
|
|
[],
|
|
|
|
() => {
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(Cookies.get('diff_view')).toEqual(INLINE_DIFF_VIEW_TYPE);
|
|
|
|
done();
|
|
|
|
}, 0);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setParallelDiffViewType', () => {
|
|
|
|
it('should set diff view type to parallel and also set the cookie properly', done => {
|
|
|
|
testAction(
|
2018-11-20 20:47:30 +05:30
|
|
|
setParallelDiffViewType,
|
2018-11-08 19:23:39 +05:30
|
|
|
null,
|
|
|
|
{},
|
|
|
|
[{ type: types.SET_DIFF_VIEW_TYPE, payload: PARALLEL_DIFF_VIEW_TYPE }],
|
|
|
|
[],
|
|
|
|
() => {
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(Cookies.get(DIFF_VIEW_COOKIE_NAME)).toEqual(PARALLEL_DIFF_VIEW_TYPE);
|
|
|
|
done();
|
|
|
|
}, 0);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('showCommentForm', () => {
|
|
|
|
it('should call mutation to show comment form', done => {
|
2019-02-15 15:39:39 +05:30
|
|
|
const payload = { lineCode: 'lineCode', fileHash: 'hash' };
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
testAction(
|
2018-11-20 20:47:30 +05:30
|
|
|
showCommentForm,
|
2018-11-08 19:23:39 +05:30
|
|
|
payload,
|
|
|
|
{},
|
2019-02-15 15:39:39 +05:30
|
|
|
[{ type: types.TOGGLE_LINE_HAS_FORM, payload: { ...payload, hasForm: true } }],
|
2018-11-08 19:23:39 +05:30
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('cancelCommentForm', () => {
|
|
|
|
it('should call mutation to cancel comment form', done => {
|
2019-02-15 15:39:39 +05:30
|
|
|
const payload = { lineCode: 'lineCode', fileHash: 'hash' };
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
testAction(
|
2018-11-20 20:47:30 +05:30
|
|
|
cancelCommentForm,
|
2018-11-08 19:23:39 +05:30
|
|
|
payload,
|
|
|
|
{},
|
2019-02-15 15:39:39 +05:30
|
|
|
[{ type: types.TOGGLE_LINE_HAS_FORM, payload: { ...payload, hasForm: false } }],
|
2018-11-08 19:23:39 +05:30
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('loadMoreLines', () => {
|
|
|
|
it('should call mutation to show comment form', done => {
|
|
|
|
const endpoint = '/diffs/load/more/lines';
|
|
|
|
const params = { since: 6, to: 26 };
|
|
|
|
const lineNumbers = { oldLineNumber: 3, newLineNumber: 5 };
|
|
|
|
const fileHash = 'ff9200';
|
|
|
|
const options = { endpoint, params, lineNumbers, fileHash };
|
|
|
|
const mock = new MockAdapter(axios);
|
|
|
|
const contextLines = { contextLines: [{ lineCode: 6 }] };
|
|
|
|
mock.onGet(endpoint).reply(200, contextLines);
|
|
|
|
|
|
|
|
testAction(
|
2018-11-20 20:47:30 +05:30
|
|
|
loadMoreLines,
|
2018-11-08 19:23:39 +05:30
|
|
|
options,
|
|
|
|
{},
|
|
|
|
[
|
|
|
|
{
|
|
|
|
type: types.ADD_CONTEXT_LINES,
|
|
|
|
payload: { lineNumbers, contextLines, params, fileHash },
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[],
|
|
|
|
() => {
|
|
|
|
mock.restore();
|
|
|
|
done();
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('loadCollapsedDiff', () => {
|
|
|
|
it('should fetch data and call mutation with response and the give parameter', done => {
|
2019-02-15 15:39:39 +05:30
|
|
|
const file = { hash: 123, load_collapsed_diff_url: '/load/collapsed/diff/url' };
|
2018-11-08 19:23:39 +05:30
|
|
|
const data = { hash: 123, parallelDiffLines: [{ lineCode: 1 }] };
|
|
|
|
const mock = new MockAdapter(axios);
|
2019-02-15 15:39:39 +05:30
|
|
|
const commit = jasmine.createSpy('commit');
|
2018-11-08 19:23:39 +05:30
|
|
|
mock.onGet(file.loadCollapsedDiffUrl).reply(200, data);
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
loadCollapsedDiff({ commit, getters: { commitId: null } }, file)
|
|
|
|
.then(() => {
|
|
|
|
expect(commit).toHaveBeenCalledWith(types.ADD_COLLAPSED_DIFFS, { file, data });
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
mock.restore();
|
|
|
|
done();
|
2019-02-15 15:39:39 +05:30
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should fetch data without commit ID', () => {
|
|
|
|
const file = { load_collapsed_diff_url: '/load/collapsed/diff/url' };
|
|
|
|
const getters = {
|
|
|
|
commitId: null,
|
|
|
|
};
|
|
|
|
|
|
|
|
spyOn(axios, 'get').and.returnValue(Promise.resolve({ data: {} }));
|
|
|
|
|
|
|
|
loadCollapsedDiff({ commit() {}, getters }, file);
|
|
|
|
|
|
|
|
expect(axios.get).toHaveBeenCalledWith(file.load_collapsed_diff_url, {
|
|
|
|
params: { commit_id: null },
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should fetch data with commit ID', () => {
|
|
|
|
const file = { load_collapsed_diff_url: '/load/collapsed/diff/url' };
|
|
|
|
const getters = {
|
|
|
|
commitId: '123',
|
|
|
|
};
|
|
|
|
|
|
|
|
spyOn(axios, 'get').and.returnValue(Promise.resolve({ data: {} }));
|
|
|
|
|
|
|
|
loadCollapsedDiff({ commit() {}, getters }, file);
|
|
|
|
|
|
|
|
expect(axios.get).toHaveBeenCalledWith(file.load_collapsed_diff_url, {
|
|
|
|
params: { commit_id: '123' },
|
|
|
|
});
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('expandAllFiles', () => {
|
|
|
|
it('should change the collapsed prop from the diffFiles', done => {
|
|
|
|
testAction(
|
2018-11-20 20:47:30 +05:30
|
|
|
expandAllFiles,
|
2018-11-08 19:23:39 +05:30
|
|
|
null,
|
|
|
|
{},
|
|
|
|
[
|
|
|
|
{
|
|
|
|
type: types.EXPAND_ALL_FILES,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('toggleFileDiscussions', () => {
|
|
|
|
it('should dispatch collapseDiscussion when all discussions are expanded', () => {
|
|
|
|
const getters = {
|
|
|
|
getDiffFileDiscussions: jasmine.createSpy().and.returnValue([{ id: 1 }]),
|
|
|
|
diffHasAllExpandedDiscussions: jasmine.createSpy().and.returnValue(true),
|
2019-02-15 15:39:39 +05:30
|
|
|
diffHasAllCollapsedDiscussions: jasmine.createSpy().and.returnValue(false),
|
2018-11-08 19:23:39 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
const dispatch = jasmine.createSpy('dispatch');
|
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
toggleFileDiscussions({ getters, dispatch });
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
expect(dispatch).toHaveBeenCalledWith(
|
|
|
|
'collapseDiscussion',
|
|
|
|
{ discussionId: 1 },
|
|
|
|
{ root: true },
|
|
|
|
);
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should dispatch expandDiscussion when all discussions are collapsed', () => {
|
|
|
|
const getters = {
|
|
|
|
getDiffFileDiscussions: jasmine.createSpy().and.returnValue([{ id: 1 }]),
|
|
|
|
diffHasAllExpandedDiscussions: jasmine.createSpy().and.returnValue(false),
|
2019-02-15 15:39:39 +05:30
|
|
|
diffHasAllCollapsedDiscussions: jasmine.createSpy().and.returnValue(true),
|
2018-11-08 19:23:39 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
const dispatch = jasmine.createSpy();
|
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
toggleFileDiscussions({ getters, dispatch });
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
expect(dispatch).toHaveBeenCalledWith(
|
|
|
|
'expandDiscussion',
|
|
|
|
{ discussionId: 1 },
|
|
|
|
{ root: true },
|
|
|
|
);
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should dispatch expandDiscussion when some discussions are collapsed and others are expanded for the collapsed discussion', () => {
|
|
|
|
const getters = {
|
|
|
|
getDiffFileDiscussions: jasmine.createSpy().and.returnValue([{ expanded: false, id: 1 }]),
|
|
|
|
diffHasAllExpandedDiscussions: jasmine.createSpy().and.returnValue(false),
|
2019-02-15 15:39:39 +05:30
|
|
|
diffHasAllCollapsedDiscussions: jasmine.createSpy().and.returnValue(false),
|
2018-11-08 19:23:39 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
const dispatch = jasmine.createSpy();
|
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
toggleFileDiscussions({ getters, dispatch });
|
|
|
|
|
|
|
|
expect(dispatch).toHaveBeenCalledWith(
|
|
|
|
'expandDiscussion',
|
|
|
|
{ discussionId: 1 },
|
|
|
|
{ root: true },
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('scrollToLineIfNeededInline', () => {
|
|
|
|
const lineMock = {
|
2019-02-15 15:39:39 +05:30
|
|
|
line_code: 'ABC_123',
|
2018-11-20 20:47:30 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
it('should not call handleLocationHash when there is not hash', () => {
|
|
|
|
window.location.hash = '';
|
|
|
|
|
|
|
|
const handleLocationHashSpy = spyOnDependency(actions, 'handleLocationHash').and.stub();
|
|
|
|
|
|
|
|
scrollToLineIfNeededInline({}, lineMock);
|
|
|
|
|
|
|
|
expect(handleLocationHashSpy).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not call handleLocationHash when the hash does not match any line', () => {
|
|
|
|
window.location.hash = 'XYZ_456';
|
|
|
|
|
|
|
|
const handleLocationHashSpy = spyOnDependency(actions, 'handleLocationHash').and.stub();
|
|
|
|
|
|
|
|
scrollToLineIfNeededInline({}, lineMock);
|
|
|
|
|
|
|
|
expect(handleLocationHashSpy).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should call handleLocationHash only when the hash matches a line', () => {
|
|
|
|
window.location.hash = 'ABC_123';
|
|
|
|
|
|
|
|
const handleLocationHashSpy = spyOnDependency(actions, 'handleLocationHash').and.stub();
|
|
|
|
|
|
|
|
scrollToLineIfNeededInline(
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
lineCode: 'ABC_456',
|
|
|
|
},
|
|
|
|
);
|
|
|
|
scrollToLineIfNeededInline({}, lineMock);
|
|
|
|
scrollToLineIfNeededInline(
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
lineCode: 'XYZ_456',
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(handleLocationHashSpy).toHaveBeenCalled();
|
|
|
|
expect(handleLocationHashSpy).toHaveBeenCalledTimes(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('scrollToLineIfNeededParallel', () => {
|
|
|
|
const lineMock = {
|
|
|
|
left: null,
|
|
|
|
right: {
|
2019-02-15 15:39:39 +05:30
|
|
|
line_code: 'ABC_123',
|
2018-11-20 20:47:30 +05:30
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
it('should not call handleLocationHash when there is not hash', () => {
|
|
|
|
window.location.hash = '';
|
|
|
|
|
|
|
|
const handleLocationHashSpy = spyOnDependency(actions, 'handleLocationHash').and.stub();
|
|
|
|
|
|
|
|
scrollToLineIfNeededParallel({}, lineMock);
|
|
|
|
|
|
|
|
expect(handleLocationHashSpy).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not call handleLocationHash when the hash does not match any line', () => {
|
|
|
|
window.location.hash = 'XYZ_456';
|
|
|
|
|
|
|
|
const handleLocationHashSpy = spyOnDependency(actions, 'handleLocationHash').and.stub();
|
|
|
|
|
|
|
|
scrollToLineIfNeededParallel({}, lineMock);
|
|
|
|
|
|
|
|
expect(handleLocationHashSpy).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should call handleLocationHash only when the hash matches a line', () => {
|
|
|
|
window.location.hash = 'ABC_123';
|
|
|
|
|
|
|
|
const handleLocationHashSpy = spyOnDependency(actions, 'handleLocationHash').and.stub();
|
|
|
|
|
|
|
|
scrollToLineIfNeededParallel(
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
left: null,
|
|
|
|
right: {
|
|
|
|
lineCode: 'ABC_456',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
scrollToLineIfNeededParallel({}, lineMock);
|
|
|
|
scrollToLineIfNeededParallel(
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
left: null,
|
|
|
|
right: {
|
|
|
|
lineCode: 'XYZ_456',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
expect(handleLocationHashSpy).toHaveBeenCalled();
|
|
|
|
expect(handleLocationHashSpy).toHaveBeenCalledTimes(1);
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|
|
|
|
});
|
2018-12-05 23:21:45 +05:30
|
|
|
|
|
|
|
describe('saveDiffDiscussion', () => {
|
|
|
|
it('dispatches actions', done => {
|
2019-02-15 15:39:39 +05:30
|
|
|
const commitId = 'something';
|
|
|
|
const formData = {
|
|
|
|
diffFile: { ...mockDiffFile },
|
|
|
|
noteableData: {},
|
|
|
|
};
|
|
|
|
const note = {};
|
|
|
|
const state = {
|
|
|
|
commit: {
|
|
|
|
id: commitId,
|
|
|
|
},
|
|
|
|
};
|
2018-12-05 23:21:45 +05:30
|
|
|
const dispatch = jasmine.createSpy('dispatch').and.callFake(name => {
|
|
|
|
switch (name) {
|
|
|
|
case 'saveNote':
|
|
|
|
return Promise.resolve({
|
|
|
|
discussion: 'test',
|
|
|
|
});
|
|
|
|
case 'updateDiscussion':
|
|
|
|
return Promise.resolve('discussion');
|
|
|
|
default:
|
|
|
|
return Promise.resolve({});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
saveDiffDiscussion({ state, dispatch }, { note, formData })
|
2018-12-05 23:21:45 +05:30
|
|
|
.then(() => {
|
2019-02-15 15:39:39 +05:30
|
|
|
const { calls } = dispatch;
|
|
|
|
|
|
|
|
expect(calls.count()).toBe(5);
|
|
|
|
expect(calls.argsFor(0)).toEqual(['saveNote', jasmine.any(Object), { root: true }]);
|
|
|
|
|
|
|
|
const postData = calls.argsFor(0)[1];
|
|
|
|
|
|
|
|
expect(postData.data.note.commit_id).toBe(commitId);
|
|
|
|
|
|
|
|
expect(calls.argsFor(1)).toEqual(['updateDiscussion', 'test', { root: true }]);
|
|
|
|
expect(calls.argsFor(2)).toEqual(['assignDiscussionsToDiff', ['discussion']]);
|
2018-12-05 23:21:45 +05:30
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('toggleTreeOpen', () => {
|
|
|
|
it('commits TOGGLE_FOLDER_OPEN', done => {
|
|
|
|
testAction(
|
|
|
|
toggleTreeOpen,
|
|
|
|
'path',
|
|
|
|
{},
|
|
|
|
[{ type: types.TOGGLE_FOLDER_OPEN, payload: 'path' }],
|
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('scrollToFile', () => {
|
|
|
|
let commit;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
commit = jasmine.createSpy();
|
|
|
|
jasmine.clock().install();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
jasmine.clock().uninstall();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('updates location hash', () => {
|
|
|
|
const state = {
|
|
|
|
treeEntries: {
|
|
|
|
path: {
|
|
|
|
fileHash: 'test',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
scrollToFile({ state, commit }, 'path');
|
|
|
|
|
|
|
|
expect(document.location.hash).toBe('#test');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('commits UPDATE_CURRENT_DIFF_FILE_ID', () => {
|
|
|
|
const state = {
|
|
|
|
treeEntries: {
|
|
|
|
path: {
|
|
|
|
fileHash: 'test',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
scrollToFile({ state, commit }, 'path');
|
|
|
|
|
|
|
|
expect(commit).toHaveBeenCalledWith(types.UPDATE_CURRENT_DIFF_FILE_ID, 'test');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('toggleShowTreeList', () => {
|
|
|
|
it('commits toggle', done => {
|
|
|
|
testAction(toggleShowTreeList, null, {}, [{ type: types.TOGGLE_SHOW_TREE_LIST }], [], done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('updates localStorage', () => {
|
|
|
|
spyOn(localStorage, 'setItem');
|
|
|
|
|
|
|
|
toggleShowTreeList({ commit() {}, state: { showTreeList: true } });
|
|
|
|
|
|
|
|
expect(localStorage.setItem).toHaveBeenCalledWith('mr_tree_show', true);
|
|
|
|
});
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
it('does not update localStorage', () => {
|
|
|
|
spyOn(localStorage, 'setItem');
|
|
|
|
|
|
|
|
toggleShowTreeList({ commit() {}, state: { showTreeList: true } }, false);
|
|
|
|
|
|
|
|
expect(localStorage.setItem).not.toHaveBeenCalled();
|
|
|
|
});
|
2018-12-05 23:21:45 +05:30
|
|
|
});
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
describe('renderFileForDiscussionId', () => {
|
|
|
|
const rootState = {
|
|
|
|
notes: {
|
|
|
|
discussions: [
|
|
|
|
{
|
|
|
|
id: '123',
|
|
|
|
diff_file: {
|
|
|
|
file_hash: 'HASH',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: '456',
|
|
|
|
diff_file: {
|
|
|
|
file_hash: 'HASH',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
let commit;
|
|
|
|
let $emit;
|
|
|
|
let scrollToElement;
|
|
|
|
const state = ({ collapsed, renderIt }) => ({
|
|
|
|
diffFiles: [
|
|
|
|
{
|
|
|
|
file_hash: 'HASH',
|
2019-07-07 11:18:12 +05:30
|
|
|
viewer: {
|
|
|
|
collapsed,
|
|
|
|
},
|
2019-02-15 15:39:39 +05:30
|
|
|
renderIt,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
commit = jasmine.createSpy('commit');
|
|
|
|
scrollToElement = spyOnDependency(actions, 'scrollToElement').and.stub();
|
|
|
|
$emit = spyOn(eventHub, '$emit');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders and expands file for the given discussion id', () => {
|
|
|
|
const localState = state({ collapsed: true, renderIt: false });
|
|
|
|
|
|
|
|
renderFileForDiscussionId({ rootState, state: localState, commit }, '123');
|
|
|
|
|
|
|
|
expect(commit).toHaveBeenCalledWith('RENDER_FILE', localState.diffFiles[0]);
|
|
|
|
expect($emit).toHaveBeenCalledTimes(1);
|
|
|
|
expect(scrollToElement).toHaveBeenCalledTimes(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('jumps to discussion on already rendered and expanded file', () => {
|
|
|
|
const localState = state({ collapsed: false, renderIt: true });
|
|
|
|
|
|
|
|
renderFileForDiscussionId({ rootState, state: localState, commit }, '123');
|
|
|
|
|
|
|
|
expect(commit).not.toHaveBeenCalled();
|
|
|
|
expect($emit).toHaveBeenCalledTimes(1);
|
|
|
|
expect(scrollToElement).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
2019-03-02 22:35:43 +05:30
|
|
|
|
|
|
|
describe('setRenderTreeList', () => {
|
|
|
|
it('commits SET_RENDER_TREE_LIST', done => {
|
|
|
|
testAction(
|
|
|
|
setRenderTreeList,
|
|
|
|
true,
|
|
|
|
{},
|
|
|
|
[{ type: types.SET_RENDER_TREE_LIST, payload: true }],
|
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets localStorage', () => {
|
|
|
|
spyOn(localStorage, 'setItem').and.stub();
|
|
|
|
|
|
|
|
setRenderTreeList({ commit() {} }, true);
|
|
|
|
|
|
|
|
expect(localStorage.setItem).toHaveBeenCalledWith('mr_diff_tree_list', true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setShowWhitespace', () => {
|
|
|
|
it('commits SET_SHOW_WHITESPACE', done => {
|
|
|
|
testAction(
|
|
|
|
setShowWhitespace,
|
|
|
|
{ showWhitespace: true },
|
|
|
|
{},
|
|
|
|
[{ type: types.SET_SHOW_WHITESPACE, payload: true }],
|
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets localStorage', () => {
|
|
|
|
spyOn(localStorage, 'setItem').and.stub();
|
|
|
|
|
|
|
|
setShowWhitespace({ commit() {} }, { showWhitespace: true });
|
|
|
|
|
|
|
|
expect(localStorage.setItem).toHaveBeenCalledWith('mr_show_whitespace', true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls history pushState', () => {
|
|
|
|
spyOn(localStorage, 'setItem').and.stub();
|
|
|
|
spyOn(window.history, 'pushState').and.stub();
|
|
|
|
|
|
|
|
setShowWhitespace({ commit() {} }, { showWhitespace: true, pushState: true });
|
|
|
|
|
|
|
|
expect(window.history.pushState).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
describe('setRenderIt', () => {
|
|
|
|
it('commits RENDER_FILE', done => {
|
|
|
|
testAction(setRenderIt, 'file', {}, [{ type: types.RENDER_FILE, payload: 'file' }], [], done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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,
|
2019-07-31 22:56:46 +05:30
|
|
|
{ filePath: 'test' },
|
2019-07-07 11:18:12 +05:30
|
|
|
{},
|
2019-07-31 22:56:46 +05:30
|
|
|
[{ type: types.RECEIVE_FULL_DIFF_SUCCESS, payload: { filePath: 'test' } }],
|
2019-07-07 11:18:12 +05:30
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('receiveFullDiffError', () => {
|
|
|
|
it('commits REQUEST_FULL_DIFF', done => {
|
|
|
|
testAction(
|
|
|
|
receiveFullDiffError,
|
|
|
|
'file',
|
|
|
|
{},
|
|
|
|
[{ type: types.RECEIVE_FULL_DIFF_ERROR, payload: 'file' }],
|
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('fetchFullDiff', () => {
|
|
|
|
let mock;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('success', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
mock.onGet(`${gl.TEST_HOST}/context`).replyOnce(200, ['test']);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('dispatches receiveFullDiffSucess', done => {
|
2019-07-31 22:56:46 +05:30
|
|
|
const file = {
|
|
|
|
context_lines_path: `${gl.TEST_HOST}/context`,
|
|
|
|
file_path: 'test',
|
|
|
|
file_hash: 'test',
|
|
|
|
};
|
2019-07-07 11:18:12 +05:30
|
|
|
testAction(
|
|
|
|
fetchFullDiff,
|
2019-07-31 22:56:46 +05:30
|
|
|
file,
|
2019-07-07 11:18:12 +05:30
|
|
|
null,
|
|
|
|
[],
|
2019-07-31 22:56:46 +05:30
|
|
|
[
|
|
|
|
{ type: 'receiveFullDiffSucess', payload: { filePath: 'test' } },
|
|
|
|
{ type: 'setExpandedDiffLines', payload: { file, data: ['test'] } },
|
|
|
|
],
|
2019-07-07 11:18:12 +05:30
|
|
|
done,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('error', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
mock.onGet(`${gl.TEST_HOST}/context`).replyOnce(500);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('dispatches receiveFullDiffError', done => {
|
|
|
|
testAction(
|
|
|
|
fetchFullDiff,
|
|
|
|
{ context_lines_path: `${gl.TEST_HOST}/context`, file_path: 'test', file_hash: 'test' },
|
|
|
|
null,
|
|
|
|
[],
|
|
|
|
[{ type: 'receiveFullDiffError', payload: 'test' }],
|
|
|
|
done,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('toggleFullDiff', () => {
|
|
|
|
let state;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
state = {
|
|
|
|
diffFiles: [{ file_path: 'test', isShowingFullFile: false }],
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
it('dispatches fetchFullDiff when file is not expanded', done => {
|
|
|
|
testAction(
|
|
|
|
toggleFullDiff,
|
|
|
|
'test',
|
|
|
|
state,
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
{ type: 'requestFullDiff', payload: 'test' },
|
|
|
|
{ type: 'fetchFullDiff', payload: state.diffFiles[0] },
|
|
|
|
],
|
|
|
|
done,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setFileCollapsed', () => {
|
|
|
|
it('commits SET_FILE_COLLAPSED', done => {
|
|
|
|
testAction(
|
|
|
|
setFileCollapsed,
|
|
|
|
{ filePath: 'test', collapsed: true },
|
|
|
|
null,
|
|
|
|
[{ type: types.SET_FILE_COLLAPSED, payload: { filePath: 'test', collapsed: true } }],
|
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2019-07-31 22:56:46 +05:30
|
|
|
|
|
|
|
describe('setExpandedDiffLines', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
spyOnDependency(actions, 'idleCallback').and.callFake(cb => {
|
|
|
|
cb({ timeRemaining: () => 50 });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('commits SET_CURRENT_VIEW_DIFF_FILE_LINES when lines less than MAX_RENDERING_DIFF_LINES', done => {
|
|
|
|
spyOnDependency(actions, 'convertExpandLines').and.callFake(() => ['test']);
|
|
|
|
|
|
|
|
testAction(
|
|
|
|
setExpandedDiffLines,
|
|
|
|
{ file: { file_path: 'path' }, data: [] },
|
|
|
|
{ diffViewType: 'inline' },
|
|
|
|
[
|
|
|
|
{
|
|
|
|
type: 'SET_HIDDEN_VIEW_DIFF_FILE_LINES',
|
|
|
|
payload: { filePath: 'path', lines: ['test'] },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'SET_CURRENT_VIEW_DIFF_FILE_LINES',
|
|
|
|
payload: { filePath: 'path', lines: ['test'] },
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('commits ADD_CURRENT_VIEW_DIFF_FILE_LINES when lines more than MAX_RENDERING_DIFF_LINES', done => {
|
|
|
|
const lines = new Array(501).fill().map((_, i) => `line-${i}`);
|
|
|
|
spyOnDependency(actions, 'convertExpandLines').and.callFake(() => lines);
|
|
|
|
|
|
|
|
testAction(
|
|
|
|
setExpandedDiffLines,
|
|
|
|
{ file: { file_path: 'path' }, data: [] },
|
|
|
|
{ diffViewType: 'inline' },
|
|
|
|
[
|
|
|
|
{
|
|
|
|
type: 'SET_HIDDEN_VIEW_DIFF_FILE_LINES',
|
|
|
|
payload: { filePath: 'path', lines },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'SET_CURRENT_VIEW_DIFF_FILE_LINES',
|
|
|
|
payload: { filePath: 'path', lines: lines.slice(0, 200) },
|
|
|
|
},
|
|
|
|
{ type: 'TOGGLE_DIFF_FILE_RENDERING_MORE', payload: 'path' },
|
|
|
|
...new Array(301).fill().map((_, i) => ({
|
|
|
|
type: 'ADD_CURRENT_VIEW_DIFF_FILE_LINES',
|
|
|
|
payload: { filePath: 'path', line: `line-${i + 200}` },
|
|
|
|
})),
|
|
|
|
{ type: 'TOGGLE_DIFF_FILE_RENDERING_MORE', payload: 'path' },
|
|
|
|
],
|
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|