summaryrefslogtreecommitdiff
path: root/spec/javascripts/diffs
diff options
context:
space:
mode:
Diffstat (limited to 'spec/javascripts/diffs')
-rw-r--r--spec/javascripts/diffs/components/app_spec.js184
-rw-r--r--spec/javascripts/diffs/components/compare_versions_dropdown_spec.js1
-rw-r--r--spec/javascripts/diffs/components/diff_discussions_spec.js1
-rw-r--r--spec/javascripts/diffs/components/settings_dropdown_spec.js167
-rw-r--r--spec/javascripts/diffs/store/actions_spec.js15
-rw-r--r--spec/javascripts/diffs/store/getters_spec.js8
-rw-r--r--spec/javascripts/diffs/store/mutations_spec.js68
-rw-r--r--spec/javascripts/diffs/store/utils_spec.js33
8 files changed, 282 insertions, 195 deletions
diff --git a/spec/javascripts/diffs/components/app_spec.js b/spec/javascripts/diffs/components/app_spec.js
index 48e1ed18a2f..5f97182489e 100644
--- a/spec/javascripts/diffs/components/app_spec.js
+++ b/spec/javascripts/diffs/components/app_spec.js
@@ -10,6 +10,7 @@ import CompareVersions from '~/diffs/components/compare_versions.vue';
import HiddenFilesWarning from '~/diffs/components/hidden_files_warning.vue';
import CommitWidget from '~/diffs/components/commit_widget.vue';
import TreeList from '~/diffs/components/tree_list.vue';
+import { INLINE_DIFF_VIEW_TYPE, PARALLEL_DIFF_VIEW_TYPE } from '~/diffs/constants';
import createDiffsStore from '../create_diffs_store';
import diffsMockData from '../mock_data/merge_request_diffs';
@@ -41,7 +42,6 @@ describe('diffs/components/app', () => {
changesEmptyStateIllustration: '',
dismissEndpoint: '',
showSuggestPopover: true,
- useSingleDiffStyle: false,
...props,
},
store,
@@ -53,6 +53,12 @@ describe('diffs/components/app', () => {
});
}
+ function getOppositeViewType(currentViewType) {
+ return currentViewType === INLINE_DIFF_VIEW_TYPE
+ ? PARALLEL_DIFF_VIEW_TYPE
+ : INLINE_DIFF_VIEW_TYPE;
+ }
+
beforeEach(() => {
// setup globals (needed for component to mount :/)
window.mrTabs = jasmine.createSpyObj('mrTabs', ['resetViewContainer']);
@@ -68,17 +74,164 @@ describe('diffs/components/app', () => {
});
describe('fetch diff methods', () => {
- beforeEach(() => {
+ beforeEach(done => {
+ const fetchResolver = () => {
+ store.state.diffs.retrievingBatches = false;
+ store.state.notes.discussions = 'test';
+ return Promise.resolve({ real_size: 100 });
+ };
spyOn(window, 'requestIdleCallback').and.callFake(fn => fn());
createComponent();
- spyOn(wrapper.vm, 'fetchDiffFiles').and.callFake(() => Promise.resolve());
- spyOn(wrapper.vm, 'fetchDiffFilesMeta').and.callFake(() => Promise.resolve());
- spyOn(wrapper.vm, 'fetchDiffFilesBatch').and.callFake(() => Promise.resolve());
+ spyOn(wrapper.vm, 'fetchDiffFiles').and.callFake(fetchResolver);
+ spyOn(wrapper.vm, 'fetchDiffFilesMeta').and.callFake(fetchResolver);
+ spyOn(wrapper.vm, 'fetchDiffFilesBatch').and.callFake(fetchResolver);
spyOn(wrapper.vm, 'setDiscussions');
spyOn(wrapper.vm, 'startRenderDiffsQueue');
+ spyOn(wrapper.vm, 'unwatchDiscussions');
+ spyOn(wrapper.vm, 'unwatchRetrievingBatches');
+ store.state.diffs.retrievingBatches = true;
+ store.state.diffs.diffFiles = [];
+ wrapper.vm.$nextTick(done);
+ });
+
+ describe('when the diff view type changes and it should load a single diff view style', () => {
+ const noLinesDiff = {
+ highlighted_diff_lines: [],
+ parallel_diff_lines: [],
+ };
+ const parallelLinesDiff = {
+ highlighted_diff_lines: [],
+ parallel_diff_lines: ['line'],
+ };
+ const inlineLinesDiff = {
+ highlighted_diff_lines: ['line'],
+ parallel_diff_lines: [],
+ };
+ const fullDiff = {
+ highlighted_diff_lines: ['line'],
+ parallel_diff_lines: ['line'],
+ };
+
+ function expectFetchToOccur({
+ vueInstance,
+ done = () => {},
+ batch = false,
+ existingFiles = 1,
+ } = {}) {
+ vueInstance.$nextTick(() => {
+ expect(vueInstance.diffFiles.length).toEqual(existingFiles);
+
+ if (!batch) {
+ expect(vueInstance.fetchDiffFiles).toHaveBeenCalled();
+ expect(vueInstance.fetchDiffFilesBatch).not.toHaveBeenCalled();
+ } else {
+ expect(vueInstance.fetchDiffFiles).not.toHaveBeenCalled();
+ expect(vueInstance.fetchDiffFilesBatch).toHaveBeenCalled();
+ }
+
+ done();
+ });
+ }
+
+ beforeEach(() => {
+ wrapper.vm.glFeatures.singleMrDiffView = true;
+ });
+
+ it('fetches diffs if it has none', done => {
+ wrapper.vm.isLatestVersion = () => false;
+
+ store.state.diffs.diffViewType = getOppositeViewType(wrapper.vm.diffViewType);
+
+ expectFetchToOccur({ vueInstance: wrapper.vm, batch: false, existingFiles: 0, done });
+ });
+
+ it('fetches diffs if it has both view styles, but no lines in either', done => {
+ wrapper.vm.isLatestVersion = () => false;
+
+ store.state.diffs.diffFiles.push(noLinesDiff);
+ store.state.diffs.diffViewType = getOppositeViewType(wrapper.vm.diffViewType);
+
+ expectFetchToOccur({ vueInstance: wrapper.vm, done });
+ });
+
+ it('fetches diffs if it only has inline view style', done => {
+ wrapper.vm.isLatestVersion = () => false;
+
+ store.state.diffs.diffFiles.push(inlineLinesDiff);
+ store.state.diffs.diffViewType = getOppositeViewType(wrapper.vm.diffViewType);
+
+ expectFetchToOccur({ vueInstance: wrapper.vm, done });
+ });
+
+ it('fetches diffs if it only has parallel view style', done => {
+ wrapper.vm.isLatestVersion = () => false;
+
+ store.state.diffs.diffFiles.push(parallelLinesDiff);
+ store.state.diffs.diffViewType = getOppositeViewType(wrapper.vm.diffViewType);
+
+ expectFetchToOccur({ vueInstance: wrapper.vm, done });
+ });
+
+ it('fetches batch diffs if it has none', done => {
+ wrapper.vm.glFeatures.diffsBatchLoad = true;
+
+ store.state.diffs.diffViewType = getOppositeViewType(wrapper.vm.diffViewType);
+
+ expectFetchToOccur({ vueInstance: wrapper.vm, batch: true, existingFiles: 0, done });
+ });
+
+ it('fetches batch diffs if it has both view styles, but no lines in either', done => {
+ wrapper.vm.glFeatures.diffsBatchLoad = true;
+
+ store.state.diffs.diffFiles.push(noLinesDiff);
+ store.state.diffs.diffViewType = getOppositeViewType(wrapper.vm.diffViewType);
+
+ expectFetchToOccur({ vueInstance: wrapper.vm, batch: true, done });
+ });
+
+ it('fetches batch diffs if it only has inline view style', done => {
+ wrapper.vm.glFeatures.diffsBatchLoad = true;
+
+ store.state.diffs.diffFiles.push(inlineLinesDiff);
+ store.state.diffs.diffViewType = getOppositeViewType(wrapper.vm.diffViewType);
+
+ expectFetchToOccur({ vueInstance: wrapper.vm, batch: true, done });
+ });
+
+ it('fetches batch diffs if it only has parallel view style', done => {
+ wrapper.vm.glFeatures.diffsBatchLoad = true;
+
+ store.state.diffs.diffFiles.push(parallelLinesDiff);
+ store.state.diffs.diffViewType = getOppositeViewType(wrapper.vm.diffViewType);
+
+ expectFetchToOccur({ vueInstance: wrapper.vm, batch: true, done });
+ });
+
+ it('does not fetch diffs if it has already fetched both styles of diff', () => {
+ wrapper.vm.glFeatures.diffsBatchLoad = false;
+
+ store.state.diffs.diffFiles.push(fullDiff);
+ store.state.diffs.diffViewType = getOppositeViewType(wrapper.vm.diffViewType);
+
+ expect(wrapper.vm.diffFiles.length).toEqual(1);
+ expect(wrapper.vm.fetchDiffFiles).not.toHaveBeenCalled();
+ expect(wrapper.vm.fetchDiffFilesBatch).not.toHaveBeenCalled();
+ });
+
+ it('does not fetch batch diffs if it has already fetched both styles of diff', () => {
+ wrapper.vm.glFeatures.diffsBatchLoad = true;
+
+ store.state.diffs.diffFiles.push(fullDiff);
+ store.state.diffs.diffViewType = getOppositeViewType(wrapper.vm.diffViewType);
+
+ expect(wrapper.vm.diffFiles.length).toEqual(1);
+ expect(wrapper.vm.fetchDiffFiles).not.toHaveBeenCalled();
+ expect(wrapper.vm.fetchDiffFilesBatch).not.toHaveBeenCalled();
+ });
});
it('calls fetchDiffFiles if diffsBatchLoad is not enabled', done => {
+ expect(wrapper.vm.diffFilesLength).toEqual(0);
wrapper.vm.glFeatures.diffsBatchLoad = false;
wrapper.vm.fetchData(false);
@@ -87,33 +240,46 @@ describe('diffs/components/app', () => {
expect(wrapper.vm.startRenderDiffsQueue).toHaveBeenCalled();
expect(wrapper.vm.fetchDiffFilesMeta).not.toHaveBeenCalled();
expect(wrapper.vm.fetchDiffFilesBatch).not.toHaveBeenCalled();
+ expect(wrapper.vm.unwatchDiscussions).toHaveBeenCalled();
+ expect(wrapper.vm.diffFilesLength).toEqual(100);
+ expect(wrapper.vm.unwatchRetrievingBatches).toHaveBeenCalled();
done();
});
});
- it('calls batch methods if diffsBatchLoad is enabled, and not latest version', () => {
+ it('calls batch methods if diffsBatchLoad is enabled, and not latest version', done => {
+ expect(wrapper.vm.diffFilesLength).toEqual(0);
wrapper.vm.glFeatures.diffsBatchLoad = true;
wrapper.vm.isLatestVersion = () => false;
wrapper.vm.fetchData(false);
expect(wrapper.vm.fetchDiffFiles).not.toHaveBeenCalled();
- wrapper.vm.$nextTick(() => {
+ setTimeout(() => {
expect(wrapper.vm.startRenderDiffsQueue).toHaveBeenCalled();
expect(wrapper.vm.fetchDiffFilesMeta).toHaveBeenCalled();
expect(wrapper.vm.fetchDiffFilesBatch).toHaveBeenCalled();
+ expect(wrapper.vm.unwatchDiscussions).toHaveBeenCalled();
+ expect(wrapper.vm.diffFilesLength).toEqual(100);
+ expect(wrapper.vm.unwatchRetrievingBatches).toHaveBeenCalled();
+ done();
});
});
- it('calls batch methods if diffsBatchLoad is enabled, and latest version', () => {
+ it('calls batch methods if diffsBatchLoad is enabled, and latest version', done => {
+ expect(wrapper.vm.diffFilesLength).toEqual(0);
wrapper.vm.glFeatures.diffsBatchLoad = true;
wrapper.vm.fetchData(false);
expect(wrapper.vm.fetchDiffFiles).not.toHaveBeenCalled();
- wrapper.vm.$nextTick(() => {
+ setTimeout(() => {
expect(wrapper.vm.startRenderDiffsQueue).toHaveBeenCalled();
expect(wrapper.vm.fetchDiffFilesMeta).toHaveBeenCalled();
expect(wrapper.vm.fetchDiffFilesBatch).toHaveBeenCalled();
+ expect(wrapper.vm.unwatchDiscussions).toHaveBeenCalled();
+ expect(wrapper.vm.diffFilesLength).toEqual(100);
+ expect(wrapper.vm.unwatchRetrievingBatches).toHaveBeenCalled();
+ done();
});
});
});
diff --git a/spec/javascripts/diffs/components/compare_versions_dropdown_spec.js b/spec/javascripts/diffs/components/compare_versions_dropdown_spec.js
index 8a3834d542f..df160d7a363 100644
--- a/spec/javascripts/diffs/components/compare_versions_dropdown_spec.js
+++ b/spec/javascripts/diffs/components/compare_versions_dropdown_spec.js
@@ -25,7 +25,6 @@ describe('CompareVersionsDropdown', () => {
const createComponent = (props = {}) => {
wrapper = shallowMount(localVue.extend(CompareVersionsDropdown), {
localVue,
- sync: false,
propsData: { ...props },
});
};
diff --git a/spec/javascripts/diffs/components/diff_discussions_spec.js b/spec/javascripts/diffs/components/diff_discussions_spec.js
index f7f0ab83c21..1b924bb947d 100644
--- a/spec/javascripts/diffs/components/diff_discussions_spec.js
+++ b/spec/javascripts/diffs/components/diff_discussions_spec.js
@@ -24,7 +24,6 @@ describe('DiffDiscussions', () => {
...props,
},
localVue,
- sync: false,
});
};
diff --git a/spec/javascripts/diffs/components/settings_dropdown_spec.js b/spec/javascripts/diffs/components/settings_dropdown_spec.js
deleted file mode 100644
index 6c08474ffd2..00000000000
--- a/spec/javascripts/diffs/components/settings_dropdown_spec.js
+++ /dev/null
@@ -1,167 +0,0 @@
-import { mount, createLocalVue } from '@vue/test-utils';
-import Vuex from 'vuex';
-import diffModule from '~/diffs/store/modules';
-import SettingsDropdown from '~/diffs/components/settings_dropdown.vue';
-import { PARALLEL_DIFF_VIEW_TYPE, INLINE_DIFF_VIEW_TYPE } from '~/diffs/constants';
-
-const localVue = createLocalVue();
-localVue.use(Vuex);
-
-describe('Diff settiings dropdown component', () => {
- let vm;
- let actions;
-
- function createComponent(extendStore = () => {}) {
- const store = new Vuex.Store({
- modules: {
- diffs: {
- namespaced: true,
- actions,
- state: diffModule().state,
- getters: diffModule().getters,
- },
- },
- });
-
- extendStore(store);
-
- vm = mount(localVue.extend(SettingsDropdown), {
- localVue,
- store,
- sync: false,
- });
- }
-
- beforeEach(() => {
- actions = {
- setInlineDiffViewType: jasmine.createSpy('setInlineDiffViewType'),
- setParallelDiffViewType: jasmine.createSpy('setParallelDiffViewType'),
- setRenderTreeList: jasmine.createSpy('setRenderTreeList'),
- setShowWhitespace: jasmine.createSpy('setShowWhitespace'),
- };
- });
-
- afterEach(() => {
- vm.destroy();
- });
-
- describe('tree view buttons', () => {
- it('list view button dispatches setRenderTreeList with false', () => {
- createComponent();
-
- vm.find('.js-list-view').trigger('click');
-
- expect(actions.setRenderTreeList).toHaveBeenCalledWith(jasmine.anything(), false, undefined);
- });
-
- it('tree view button dispatches setRenderTreeList with true', () => {
- createComponent();
-
- vm.find('.js-tree-view').trigger('click');
-
- expect(actions.setRenderTreeList).toHaveBeenCalledWith(jasmine.anything(), true, undefined);
- });
-
- it('sets list button as active when renderTreeList is false', () => {
- createComponent(store => {
- Object.assign(store.state.diffs, {
- renderTreeList: false,
- });
- });
-
- expect(vm.find('.js-list-view').classes('active')).toBe(true);
- expect(vm.find('.js-tree-view').classes('active')).toBe(false);
- });
-
- it('sets tree button as active when renderTreeList is true', () => {
- createComponent(store => {
- Object.assign(store.state.diffs, {
- renderTreeList: true,
- });
- });
-
- expect(vm.find('.js-list-view').classes('active')).toBe(false);
- expect(vm.find('.js-tree-view').classes('active')).toBe(true);
- });
- });
-
- describe('compare changes', () => {
- it('sets inline button as active', () => {
- createComponent(store => {
- Object.assign(store.state.diffs, {
- diffViewType: INLINE_DIFF_VIEW_TYPE,
- });
- });
-
- expect(vm.find('.js-inline-diff-button').classes('active')).toBe(true);
- expect(vm.find('.js-parallel-diff-button').classes('active')).toBe(false);
- });
-
- it('sets parallel button as active', () => {
- createComponent(store => {
- Object.assign(store.state.diffs, {
- diffViewType: PARALLEL_DIFF_VIEW_TYPE,
- });
- });
-
- expect(vm.find('.js-inline-diff-button').classes('active')).toBe(false);
- expect(vm.find('.js-parallel-diff-button').classes('active')).toBe(true);
- });
-
- it('calls setInlineDiffViewType when clicking inline button', () => {
- createComponent();
-
- vm.find('.js-inline-diff-button').trigger('click');
-
- expect(actions.setInlineDiffViewType).toHaveBeenCalled();
- });
-
- it('calls setParallelDiffViewType when clicking parallel button', () => {
- createComponent();
-
- vm.find('.js-parallel-diff-button').trigger('click');
-
- expect(actions.setParallelDiffViewType).toHaveBeenCalled();
- });
- });
-
- describe('whitespace toggle', () => {
- it('does not set as checked when showWhitespace is false', () => {
- createComponent(store => {
- Object.assign(store.state.diffs, {
- showWhitespace: false,
- });
- });
-
- expect(vm.find('#show-whitespace').element.checked).toBe(false);
- });
-
- it('sets as checked when showWhitespace is true', () => {
- createComponent(store => {
- Object.assign(store.state.diffs, {
- showWhitespace: true,
- });
- });
-
- expect(vm.find('#show-whitespace').element.checked).toBe(true);
- });
-
- it('calls setShowWhitespace on change', () => {
- createComponent();
-
- const checkbox = vm.find('#show-whitespace');
-
- checkbox.element.checked = true;
- checkbox.trigger('change');
-
- expect(actions.setShowWhitespace).toHaveBeenCalledWith(
- jasmine.anything(),
- {
- showWhitespace: true,
- pushState: true,
- },
- undefined,
- );
- });
- });
-});
diff --git a/spec/javascripts/diffs/store/actions_spec.js b/spec/javascripts/diffs/store/actions_spec.js
index b23334d38dc..af2dd7b4f93 100644
--- a/spec/javascripts/diffs/store/actions_spec.js
+++ b/spec/javascripts/diffs/store/actions_spec.js
@@ -120,7 +120,7 @@ describe('DiffsStoreActions', () => {
describe('fetchDiffFiles', () => {
it('should fetch diff files', done => {
- const endpoint = '/fetch/diff/files?w=1';
+ const endpoint = '/fetch/diff/files?view=inline&w=1';
const mock = new MockAdapter(axios);
const res = { diff_files: 1, merge_request_diffs: [] };
mock.onGet(endpoint).reply(200, res);
@@ -128,7 +128,7 @@ describe('DiffsStoreActions', () => {
testAction(
fetchDiffFiles,
{},
- { endpoint },
+ { endpoint, diffFiles: [], showWhitespace: false, diffViewType: 'inline' },
[
{ type: types.SET_LOADING, payload: true },
{ type: types.SET_LOADING, payload: false },
@@ -141,6 +141,13 @@ describe('DiffsStoreActions', () => {
done();
},
);
+
+ fetchDiffFiles({ state: { endpoint }, commit: () => null })
+ .then(data => {
+ expect(data).toEqual(res);
+ done();
+ })
+ .catch(done.fail);
});
});
@@ -163,10 +170,12 @@ describe('DiffsStoreActions', () => {
{ endpointBatch },
[
{ type: types.SET_BATCH_LOADING, payload: true },
+ { type: types.SET_RETRIEVING_BATCHES, payload: true },
{ type: types.SET_DIFF_DATA_BATCH, payload: { diff_files: res1.diff_files } },
{ type: types.SET_BATCH_LOADING, payload: false },
{ type: types.SET_DIFF_DATA_BATCH, payload: { diff_files: [] } },
{ type: types.SET_BATCH_LOADING, payload: false },
+ { type: types.SET_RETRIEVING_BATCHES, payload: false },
],
[],
() => {
@@ -215,6 +224,8 @@ describe('DiffsStoreActions', () => {
describe('assignDiscussionsToDiff', () => {
it('should merge discussions into diffs', done => {
+ window.location.hash = 'ABC_123';
+
const state = {
diffFiles: [
{
diff --git a/spec/javascripts/diffs/store/getters_spec.js b/spec/javascripts/diffs/store/getters_spec.js
index eab5703dfb2..9e628fdd540 100644
--- a/spec/javascripts/diffs/store/getters_spec.js
+++ b/spec/javascripts/diffs/store/getters_spec.js
@@ -263,14 +263,6 @@ describe('Diffs Module Getters', () => {
});
});
- describe('diffFilesLength', () => {
- it('returns length of diff files', () => {
- localState.diffFiles.push('test', 'test 2');
-
- expect(getters.diffFilesLength(localState)).toBe(2);
- });
- });
-
describe('currentDiffIndex', () => {
it('returns index of currently selected diff in diffList', () => {
localState.diffFiles = [{ file_hash: '111' }, { file_hash: '222' }, { file_hash: '333' }];
diff --git a/spec/javascripts/diffs/store/mutations_spec.js b/spec/javascripts/diffs/store/mutations_spec.js
index 13f16e4f9a6..24405dcc796 100644
--- a/spec/javascripts/diffs/store/mutations_spec.js
+++ b/spec/javascripts/diffs/store/mutations_spec.js
@@ -40,9 +40,26 @@ describe('DiffsStoreMutations', () => {
});
});
+ describe('SET_RETRIEVING_BATCHES', () => {
+ it('should set retrievingBatches state', () => {
+ const state = {};
+
+ mutations[types.SET_RETRIEVING_BATCHES](state, false);
+
+ expect(state.retrievingBatches).toEqual(false);
+ });
+ });
+
describe('SET_DIFF_DATA', () => {
it('should set diff data type properly', () => {
- const state = {};
+ const state = {
+ diffFiles: [
+ {
+ content_sha: diffFileMockData.content_sha,
+ file_hash: diffFileMockData.file_hash,
+ },
+ ],
+ };
const diffMock = {
diff_files: [diffFileMockData],
};
@@ -52,9 +69,41 @@ describe('DiffsStoreMutations', () => {
const firstLine = state.diffFiles[0].parallel_diff_lines[0];
expect(firstLine.right.text).toBeUndefined();
+ expect(state.diffFiles.length).toEqual(1);
expect(state.diffFiles[0].renderIt).toEqual(true);
expect(state.diffFiles[0].collapsed).toEqual(false);
});
+
+ describe('given diffsBatchLoad feature flag is enabled', () => {
+ beforeEach(() => {
+ gon.features = { diffsBatchLoad: true };
+ });
+
+ afterEach(() => {
+ delete gon.features;
+ });
+
+ it('should not modify the existing state', () => {
+ const state = {
+ diffFiles: [
+ {
+ content_sha: diffFileMockData.content_sha,
+ file_hash: diffFileMockData.file_hash,
+ highlighted_diff_lines: [],
+ },
+ ],
+ };
+ const diffMock = {
+ diff_files: [diffFileMockData],
+ };
+
+ mutations[types.SET_DIFF_DATA](state, diffMock);
+
+ // If the batch load is enabled, there shouldn't be any processing
+ // done on the existing state object, so we shouldn't have this.
+ expect(state.diffFiles[0].parallel_diff_lines).toBeUndefined();
+ });
+ });
});
describe('SET_DIFFSET_DIFF_DATA_BATCH_DATA', () => {
@@ -158,11 +207,17 @@ describe('DiffsStoreMutations', () => {
it('should update the state with the given data for the given file hash', () => {
const fileHash = 123;
const state = {
- diffFiles: [{}, { file_hash: fileHash, existing_field: 0 }],
+ diffFiles: [{}, { content_sha: 'abc', file_hash: fileHash, existing_field: 0 }],
};
const data = {
diff_files: [
- { file_hash: fileHash, extra_field: 1, existing_field: 1, viewer: { name: 'text' } },
+ {
+ content_sha: 'abc',
+ file_hash: fileHash,
+ extra_field: 1,
+ existing_field: 1,
+ viewer: { name: 'text' },
+ },
],
};
@@ -198,7 +253,7 @@ describe('DiffsStoreMutations', () => {
discussions: [],
},
right: {
- line_code: 'ABC_1',
+ line_code: 'ABC_2',
discussions: [],
},
},
@@ -264,7 +319,7 @@ describe('DiffsStoreMutations', () => {
discussions: [],
},
right: {
- line_code: 'ABC_1',
+ line_code: 'ABC_2',
discussions: [],
},
},
@@ -342,7 +397,7 @@ describe('DiffsStoreMutations', () => {
discussions: [],
},
right: {
- line_code: 'ABC_1',
+ line_code: 'ABC_2',
discussions: [],
},
},
@@ -438,6 +493,7 @@ describe('DiffsStoreMutations', () => {
discussions: [],
},
],
+ parallel_diff_lines: [],
},
],
};
diff --git a/spec/javascripts/diffs/store/utils_spec.js b/spec/javascripts/diffs/store/utils_spec.js
index 65eb4c9d2a3..638b4510221 100644
--- a/spec/javascripts/diffs/store/utils_spec.js
+++ b/spec/javascripts/diffs/store/utils_spec.js
@@ -314,11 +314,29 @@ describe('DiffsStoreUtils', () => {
});
describe('prepareDiffData', () => {
+ let mock;
let preparedDiff;
+ let splitInlineDiff;
+ let splitParallelDiff;
+ let completedDiff;
beforeEach(() => {
- preparedDiff = { diff_files: [getDiffFileMock()] };
+ mock = getDiffFileMock();
+ preparedDiff = { diff_files: [mock] };
+ splitInlineDiff = {
+ diff_files: [Object.assign({}, mock, { parallel_diff_lines: undefined })],
+ };
+ splitParallelDiff = {
+ diff_files: [Object.assign({}, mock, { highlighted_diff_lines: undefined })],
+ };
+ completedDiff = {
+ diff_files: [Object.assign({}, mock, { highlighted_diff_lines: undefined })],
+ };
+
utils.prepareDiffData(preparedDiff);
+ utils.prepareDiffData(splitInlineDiff);
+ utils.prepareDiffData(splitParallelDiff);
+ utils.prepareDiffData(completedDiff, [mock]);
});
it('sets the renderIt and collapsed attribute on files', () => {
@@ -359,6 +377,19 @@ describe('DiffsStoreUtils', () => {
expect(firstLine.line_code).toEqual(firstLine.right.line_code);
});
+
+ it('guarantees an empty array for both diff styles', () => {
+ expect(splitInlineDiff.diff_files[0].parallel_diff_lines.length).toEqual(0);
+ expect(splitInlineDiff.diff_files[0].highlighted_diff_lines.length).toBeGreaterThan(0);
+ expect(splitParallelDiff.diff_files[0].parallel_diff_lines.length).toBeGreaterThan(0);
+ expect(splitParallelDiff.diff_files[0].highlighted_diff_lines.length).toEqual(0);
+ });
+
+ it('merges existing diff files with newly loaded diff files to ensure split diffs are eventually completed', () => {
+ expect(completedDiff.diff_files.length).toEqual(1);
+ expect(completedDiff.diff_files[0].parallel_diff_lines.length).toBeGreaterThan(0);
+ expect(completedDiff.diff_files[0].highlighted_diff_lines.length).toBeGreaterThan(0);
+ });
});
describe('isDiscussionApplicableToLine', () => {