Commit 775f9093 authored by Thomas Randolph's avatar Thomas Randolph

Set the fileByFile state based on user preference

... when the app loads and the pref is available
parent 37c2c4a2
...@@ -22,6 +22,7 @@ import MergeConflictWarning from './merge_conflict_warning.vue'; ...@@ -22,6 +22,7 @@ import MergeConflictWarning from './merge_conflict_warning.vue';
import CollapsedFilesWarning from './collapsed_files_warning.vue'; import CollapsedFilesWarning from './collapsed_files_warning.vue';
import { diffsApp } from '../utils/performance'; import { diffsApp } from '../utils/performance';
import { fileByFile } from '../utils/preferences';
import { import {
TREE_LIST_WIDTH_STORAGE_KEY, TREE_LIST_WIDTH_STORAGE_KEY,
...@@ -114,7 +115,7 @@ export default { ...@@ -114,7 +115,7 @@ export default {
required: false, required: false,
default: false, default: false,
}, },
viewDiffsFileByFile: { fileByFileUserPreference: {
type: Boolean, type: Boolean,
required: false, required: false,
default: false, default: false,
...@@ -154,6 +155,7 @@ export default { ...@@ -154,6 +155,7 @@ export default {
'conflictResolutionPath', 'conflictResolutionPath',
'canMerge', 'canMerge',
'hasConflicts', 'hasConflicts',
'viewDiffsFileByFile',
]), ]),
...mapGetters('diffs', ['whichCollapsedTypes', 'isParallelView', 'currentDiffIndex']), ...mapGetters('diffs', ['whichCollapsedTypes', 'isParallelView', 'currentDiffIndex']),
...mapGetters(['isNotesFetched', 'getNoteableData']), ...mapGetters(['isNotesFetched', 'getNoteableData']),
...@@ -254,7 +256,7 @@ export default { ...@@ -254,7 +256,7 @@ export default {
projectPath: this.projectPath, projectPath: this.projectPath,
dismissEndpoint: this.dismissEndpoint, dismissEndpoint: this.dismissEndpoint,
showSuggestPopover: this.showSuggestPopover, showSuggestPopover: this.showSuggestPopover,
viewDiffsFileByFile: this.viewDiffsFileByFile, viewDiffsFileByFile: fileByFile(this.fileByFileUserPreference),
}); });
if (this.shouldShow) { if (this.shouldShow) {
......
...@@ -116,7 +116,7 @@ export default function initDiffsApp(store) { ...@@ -116,7 +116,7 @@ export default function initDiffsApp(store) {
isFluidLayout: this.isFluidLayout, isFluidLayout: this.isFluidLayout,
dismissEndpoint: this.dismissEndpoint, dismissEndpoint: this.dismissEndpoint,
showSuggestPopover: this.showSuggestPopover, showSuggestPopover: this.showSuggestPopover,
viewDiffsFileByFile: this.viewDiffsFileByFile, fileByFileUserPreference: this.viewDiffsFileByFile,
}, },
}); });
}, },
......
...@@ -19,8 +19,8 @@ import diffsMockData from '../mock_data/merge_request_diffs'; ...@@ -19,8 +19,8 @@ import diffsMockData from '../mock_data/merge_request_diffs';
const mergeRequestDiff = { version_index: 1 }; const mergeRequestDiff = { version_index: 1 };
const TEST_ENDPOINT = `${TEST_HOST}/diff/endpoint`; const TEST_ENDPOINT = `${TEST_HOST}/diff/endpoint`;
const COMMIT_URL = '[BASE URL]/OLD'; const COMMIT_URL = `${TEST_HOST}/COMMIT/OLD`;
const UPDATED_COMMIT_URL = '[BASE URL]/NEW'; const UPDATED_COMMIT_URL = `${TEST_HOST}/COMMIT/NEW`;
function getCollapsedFilesWarning(wrapper) { function getCollapsedFilesWarning(wrapper) {
return wrapper.find(CollapsedFilesWarning); return wrapper.find(CollapsedFilesWarning);
...@@ -61,7 +61,7 @@ describe('diffs/components/app', () => { ...@@ -61,7 +61,7 @@ describe('diffs/components/app', () => {
changesEmptyStateIllustration: '', changesEmptyStateIllustration: '',
dismissEndpoint: '', dismissEndpoint: '',
showSuggestPopover: true, showSuggestPopover: true,
viewDiffsFileByFile: false, fileByFileUserPreference: false,
...props, ...props,
}, },
provide, provide,
...@@ -700,12 +700,14 @@ describe('diffs/components/app', () => { ...@@ -700,12 +700,14 @@ describe('diffs/components/app', () => {
}); });
describe('file-by-file', () => { describe('file-by-file', () => {
it('renders a single diff', () => { it('renders a single diff', async () => {
createComponent({ viewDiffsFileByFile: true }, ({ state }) => { createComponent({ fileByFileUserPreference: true }, ({ state }) => {
state.diffs.diffFiles.push({ file_hash: '123' }); state.diffs.diffFiles.push({ file_hash: '123' });
state.diffs.diffFiles.push({ file_hash: '312' }); state.diffs.diffFiles.push({ file_hash: '312' });
}); });
await wrapper.vm.$nextTick();
expect(wrapper.findAll(DiffFile).length).toBe(1); expect(wrapper.findAll(DiffFile).length).toBe(1);
}); });
...@@ -713,31 +715,37 @@ describe('diffs/components/app', () => { ...@@ -713,31 +715,37 @@ describe('diffs/components/app', () => {
const fileByFileNav = () => wrapper.find('[data-testid="file-by-file-navigation"]'); const fileByFileNav = () => wrapper.find('[data-testid="file-by-file-navigation"]');
const paginator = () => fileByFileNav().find(GlPagination); const paginator = () => fileByFileNav().find(GlPagination);
it('sets previous button as disabled', () => { it('sets previous button as disabled', async () => {
createComponent({ viewDiffsFileByFile: true }, ({ state }) => { createComponent({ fileByFileUserPreference: true }, ({ state }) => {
state.diffs.diffFiles.push({ file_hash: '123' }, { file_hash: '312' }); state.diffs.diffFiles.push({ file_hash: '123' }, { file_hash: '312' });
}); });
await wrapper.vm.$nextTick();
expect(paginator().attributes('prevpage')).toBe(undefined); expect(paginator().attributes('prevpage')).toBe(undefined);
expect(paginator().attributes('nextpage')).toBe('2'); expect(paginator().attributes('nextpage')).toBe('2');
}); });
it('sets next button as disabled', () => { it('sets next button as disabled', async () => {
createComponent({ viewDiffsFileByFile: true }, ({ state }) => { createComponent({ fileByFileUserPreference: true }, ({ state }) => {
state.diffs.diffFiles.push({ file_hash: '123' }, { file_hash: '312' }); state.diffs.diffFiles.push({ file_hash: '123' }, { file_hash: '312' });
state.diffs.currentDiffFileId = '312'; state.diffs.currentDiffFileId = '312';
}); });
await wrapper.vm.$nextTick();
expect(paginator().attributes('prevpage')).toBe('1'); expect(paginator().attributes('prevpage')).toBe('1');
expect(paginator().attributes('nextpage')).toBe(undefined); expect(paginator().attributes('nextpage')).toBe(undefined);
}); });
it("doesn't display when there's fewer than 2 files", () => { it("doesn't display when there's fewer than 2 files", async () => {
createComponent({ viewDiffsFileByFile: true }, ({ state }) => { createComponent({ fileByFileUserPreference: true }, ({ state }) => {
state.diffs.diffFiles.push({ file_hash: '123' }); state.diffs.diffFiles.push({ file_hash: '123' });
state.diffs.currentDiffFileId = '123'; state.diffs.currentDiffFileId = '123';
}); });
await wrapper.vm.$nextTick();
expect(fileByFileNav().exists()).toBe(false); expect(fileByFileNav().exists()).toBe(false);
}); });
...@@ -748,11 +756,13 @@ describe('diffs/components/app', () => { ...@@ -748,11 +756,13 @@ describe('diffs/components/app', () => {
`( `(
'it calls navigateToDiffFileIndex with $index when $link is clicked', 'it calls navigateToDiffFileIndex with $index when $link is clicked',
async ({ currentDiffFileId, targetFile }) => { async ({ currentDiffFileId, targetFile }) => {
createComponent({ viewDiffsFileByFile: true }, ({ state }) => { createComponent({ fileByFileUserPreference: true }, ({ state }) => {
state.diffs.diffFiles.push({ file_hash: '123' }, { file_hash: '312' }); state.diffs.diffFiles.push({ file_hash: '123' }, { file_hash: '312' });
state.diffs.currentDiffFileId = currentDiffFileId; state.diffs.currentDiffFileId = currentDiffFileId;
}); });
await wrapper.vm.$nextTick();
jest.spyOn(wrapper.vm, 'navigateToDiffFileIndex'); jest.spyOn(wrapper.vm, 'navigateToDiffFileIndex');
paginator().vm.$emit('input', targetFile); paginator().vm.$emit('input', targetFile);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment