Commit 64c7f99a authored by Thomas Randolph's avatar Thomas Randolph

Respond to diffs app hub requests to change the fileByFile setting

parent 66e502c6
...@@ -12,6 +12,8 @@ import { isSingleViewStyle } from '~/helpers/diffs_helper'; ...@@ -12,6 +12,8 @@ import { isSingleViewStyle } from '~/helpers/diffs_helper';
import { updateHistory } from '~/lib/utils/url_utility'; import { updateHistory } from '~/lib/utils/url_utility';
import notesEventHub from '../../notes/event_hub'; import notesEventHub from '../../notes/event_hub';
import eventHub from '../event_hub';
import CompareVersions from './compare_versions.vue'; import CompareVersions from './compare_versions.vue';
import DiffFile from './diff_file.vue'; import DiffFile from './diff_file.vue';
import NoChanges from './no_changes.vue'; import NoChanges from './no_changes.vue';
...@@ -36,6 +38,7 @@ import { ...@@ -36,6 +38,7 @@ import {
ALERT_OVERFLOW_HIDDEN, ALERT_OVERFLOW_HIDDEN,
ALERT_MERGE_CONFLICT, ALERT_MERGE_CONFLICT,
ALERT_COLLAPSED_FILES, ALERT_COLLAPSED_FILES,
EVT_VIEW_FILE_BY_FILE,
} from '../constants'; } from '../constants';
export default { export default {
...@@ -283,6 +286,8 @@ export default { ...@@ -283,6 +286,8 @@ export default {
notesEventHub.$once('fetchDiffData', this.fetchData); notesEventHub.$once('fetchDiffData', this.fetchData);
notesEventHub.$on('refetchDiffData', this.refetchDiffData); notesEventHub.$on('refetchDiffData', this.refetchDiffData);
eventHub.$on(EVT_VIEW_FILE_BY_FILE, this.fileByFileListener);
this.CENTERED_LIMITED_CONTAINER_CLASSES = CENTERED_LIMITED_CONTAINER_CLASSES; this.CENTERED_LIMITED_CONTAINER_CLASSES = CENTERED_LIMITED_CONTAINER_CLASSES;
this.unwatchDiscussions = this.$watch( this.unwatchDiscussions = this.$watch(
...@@ -303,6 +308,7 @@ export default { ...@@ -303,6 +308,7 @@ export default {
beforeDestroy() { beforeDestroy() {
diffsApp.deinstrument(); diffsApp.deinstrument();
eventHub.$off(EVT_VIEW_FILE_BY_FILE, this.fileByFileListener);
notesEventHub.$off('refetchDiffData', this.refetchDiffData); notesEventHub.$off('refetchDiffData', this.refetchDiffData);
notesEventHub.$off('fetchDiffData', this.fetchData); notesEventHub.$off('fetchDiffData', this.fetchData);
...@@ -323,7 +329,11 @@ export default { ...@@ -323,7 +329,11 @@ export default {
'scrollToFile', 'scrollToFile',
'setShowTreeList', 'setShowTreeList',
'navigateToDiffFileIndex', 'navigateToDiffFileIndex',
'setFileByFile',
]), ]),
fileByFileListener({ setting } = {}) {
this.setFileByFile({ fileByFile: setting });
},
navigateToDiffFileNumber(number) { navigateToDiffFileNumber(number) {
this.navigateToDiffFileIndex(number - 1); this.navigateToDiffFileIndex(number - 1);
}, },
......
...@@ -103,6 +103,7 @@ export const RENAMED_DIFF_TRANSITIONS = { ...@@ -103,6 +103,7 @@ export const RENAMED_DIFF_TRANSITIONS = {
// MR Diffs known events // MR Diffs known events
export const EVT_EXPAND_ALL_FILES = 'mr:diffs:expandAllFiles'; export const EVT_EXPAND_ALL_FILES = 'mr:diffs:expandAllFiles';
export const EVT_VIEW_FILE_BY_FILE = 'mr:diffs:preference:fileByFile';
export const EVT_PERF_MARK_FILE_TREE_START = 'mr:diffs:perf:fileTreeStart'; export const EVT_PERF_MARK_FILE_TREE_START = 'mr:diffs:perf:fileTreeStart';
export const EVT_PERF_MARK_FILE_TREE_END = 'mr:diffs:perf:fileTreeEnd'; export const EVT_PERF_MARK_FILE_TREE_END = 'mr:diffs:perf:fileTreeEnd';
export const EVT_PERF_MARK_DIFF_FILES_START = 'mr:diffs:perf:filesStart'; export const EVT_PERF_MARK_DIFF_FILES_START = 'mr:diffs:perf:filesStart';
......
...@@ -17,6 +17,10 @@ import axios from '~/lib/utils/axios_utils'; ...@@ -17,6 +17,10 @@ import axios from '~/lib/utils/axios_utils';
import * as urlUtils from '~/lib/utils/url_utility'; import * as urlUtils from '~/lib/utils/url_utility';
import diffsMockData from '../mock_data/merge_request_diffs'; import diffsMockData from '../mock_data/merge_request_diffs';
import { EVT_VIEW_FILE_BY_FILE } from '~/diffs/constants';
import eventHub from '~/diffs/event_hub';
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 = `${TEST_HOST}/COMMIT/OLD`; const COMMIT_URL = `${TEST_HOST}/COMMIT/OLD`;
...@@ -773,5 +777,24 @@ describe('diffs/components/app', () => { ...@@ -773,5 +777,24 @@ describe('diffs/components/app', () => {
}, },
); );
}); });
describe('control via event stream', () => {
it.each`
setting
${true}
${false}
`(
'triggers the action with the new fileByFile setting - $setting - when the event with that setting is received',
async ({ setting }) => {
createComponent();
await wrapper.vm.$nextTick();
eventHub.$emit(EVT_VIEW_FILE_BY_FILE, { setting });
await wrapper.vm.$nextTick();
expect(store.state.diffs.viewDiffsFileByFile).toBe(setting);
},
);
});
}); });
}); });
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