summaryrefslogtreecommitdiff
path: root/spec/javascripts/diffs/store/mutations_spec.js
diff options
context:
space:
mode:
Diffstat (limited to 'spec/javascripts/diffs/store/mutations_spec.js')
-rw-r--r--spec/javascripts/diffs/store/mutations_spec.js58
1 files changed, 52 insertions, 6 deletions
diff --git a/spec/javascripts/diffs/store/mutations_spec.js b/spec/javascripts/diffs/store/mutations_spec.js
index 93dbf03e1ed..24405dcc796 100644
--- a/spec/javascripts/diffs/store/mutations_spec.js
+++ b/spec/javascripts/diffs/store/mutations_spec.js
@@ -52,7 +52,14 @@ describe('DiffsStoreMutations', () => {
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],
};
@@ -62,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', () => {
@@ -168,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' },
+ },
],
};
@@ -208,7 +253,7 @@ describe('DiffsStoreMutations', () => {
discussions: [],
},
right: {
- line_code: 'ABC_1',
+ line_code: 'ABC_2',
discussions: [],
},
},
@@ -274,7 +319,7 @@ describe('DiffsStoreMutations', () => {
discussions: [],
},
right: {
- line_code: 'ABC_1',
+ line_code: 'ABC_2',
discussions: [],
},
},
@@ -352,7 +397,7 @@ describe('DiffsStoreMutations', () => {
discussions: [],
},
right: {
- line_code: 'ABC_1',
+ line_code: 'ABC_2',
discussions: [],
},
},
@@ -448,6 +493,7 @@ describe('DiffsStoreMutations', () => {
discussions: [],
},
],
+ parallel_diff_lines: [],
},
],
};