Commit f17d1cc4 authored by Andrew Fontaine's avatar Andrew Fontaine

Merge branch 'maintenance/diff-events-constant' into 'master'

Extract a re-used event name to the constants file

See merge request gitlab-org/gitlab!46599
parents 14c064c2 bf3f3c69
<script>
import { GlAlert, GlButton } from '@gitlab/ui';
import { CENTERED_LIMITED_CONTAINER_CLASSES } from '../constants';
import { CENTERED_LIMITED_CONTAINER_CLASSES, EVT_EXPAND_ALL_FILES } from '../constants';
import eventHub from '../event_hub';
export default {
......@@ -40,7 +40,7 @@ export default {
this.$emit('dismiss');
},
expand() {
eventHub.$emit('mr:diffs:expandAllFiles');
eventHub.$emit(EVT_EXPAND_ALL_FILES);
this.dismiss();
},
},
......
......@@ -6,7 +6,7 @@ import { polyfillSticky } from '~/lib/utils/sticky';
import CompareDropdownLayout from './compare_dropdown_layout.vue';
import SettingsDropdown from './settings_dropdown.vue';
import DiffStats from './diff_stats.vue';
import { CENTERED_LIMITED_CONTAINER_CLASSES } from '../constants';
import { CENTERED_LIMITED_CONTAINER_CLASSES, EVT_EXPAND_ALL_FILES } from '../constants';
import eventHub from '../event_hub';
export default {
......@@ -71,7 +71,7 @@ export default {
'toggleShowTreeList',
]),
expandAllFiles() {
eventHub.$emit('mr:diffs:expandAllFiles');
eventHub.$emit(EVT_EXPAND_ALL_FILES);
},
},
};
......
......@@ -11,7 +11,11 @@ import DiffFileHeader from './diff_file_header.vue';
import DiffContent from './diff_content.vue';
import { diffViewerErrors } from '~/ide/constants';
import { collapsedType, isCollapsed } from '../diff_file';
import { DIFF_FILE_AUTOMATIC_COLLAPSE, DIFF_FILE_MANUAL_COLLAPSE } from '../constants';
import {
DIFF_FILE_AUTOMATIC_COLLAPSE,
DIFF_FILE_MANUAL_COLLAPSE,
EVT_EXPAND_ALL_FILES,
} from '../constants';
import { DIFF_FILE, GENERIC_ERROR } from '../i18n';
import eventHub from '../event_hub';
......@@ -154,10 +158,10 @@ export default {
},
created() {
notesEventHub.$on(`loadCollapsedDiff/${this.file.file_hash}`, this.requestDiff);
eventHub.$on('mr:diffs:expandAllFiles', this.expandAllListener);
eventHub.$on(EVT_EXPAND_ALL_FILES, this.expandAllListener);
},
beforeDestroy() {
eventHub.$off('mr:diffs:expandAllFiles', this.expandAllListener);
eventHub.$off(EVT_EXPAND_ALL_FILES, this.expandAllListener);
},
methods: {
...mapActions('diffs', [
......
......@@ -95,3 +95,6 @@ export const RENAMED_DIFF_TRANSITIONS = {
[`${STATE_ERRORED}:${TRANSITION_LOAD_START}`]: STATE_LOADING,
[`${STATE_ERRORED}:${TRANSITION_ACKNOWLEDGE_ERROR}`]: STATE_IDLING,
};
// MR Diffs known events
export const EVT_EXPAND_ALL_FILES = 'mr:diffs:expandAllFiles';
......@@ -2,7 +2,7 @@ import Vuex from 'vuex';
import { shallowMount, mount, createLocalVue } from '@vue/test-utils';
import createStore from '~/diffs/store/modules';
import CollapsedFilesWarning from '~/diffs/components/collapsed_files_warning.vue';
import { CENTERED_LIMITED_CONTAINER_CLASSES } from '~/diffs/constants';
import { CENTERED_LIMITED_CONTAINER_CLASSES, EVT_EXPAND_ALL_FILES } from '~/diffs/constants';
import eventHub from '~/diffs/event_hub';
const propsData = {
......@@ -77,13 +77,13 @@ describe('CollapsedFilesWarning', () => {
expect(wrapper.find('[data-testid="root"]').exists()).toBe(false);
});
it('emits the `mr:diffs:expandAllFiles` event when the alert action button is clicked', () => {
it(`emits the \`${EVT_EXPAND_ALL_FILES}\` event when the alert action button is clicked`, () => {
createComponent({}, { full: true });
jest.spyOn(eventHub, '$emit');
getAlertActionButton().vm.$emit('click');
expect(eventHub.$emit).toHaveBeenCalledWith('mr:diffs:expandAllFiles');
expect(eventHub.$emit).toHaveBeenCalledWith(EVT_EXPAND_ALL_FILES);
});
});
......@@ -12,6 +12,7 @@ import DiffContentComponent from '~/diffs/components/diff_content.vue';
import eventHub from '~/diffs/event_hub';
import { diffViewerModes, diffViewerErrors } from '~/ide/constants';
import { EVT_EXPAND_ALL_FILES } from '~/diffs/constants';
function changeViewer(store, index, { automaticallyCollapsed, manuallyCollapsed, name }) {
const file = store.state.diffs.diffFiles[index];
......@@ -140,7 +141,7 @@ describe('DiffFile', () => {
});
describe('collapsing', () => {
describe('`mr:diffs:expandAllFiles` event', () => {
describe(`\`${EVT_EXPAND_ALL_FILES}\` event`, () => {
beforeEach(() => {
jest.spyOn(wrapper.vm, 'handleToggle').mockImplementation(() => {});
});
......@@ -150,13 +151,13 @@ describe('DiffFile', () => {
await wrapper.vm.$nextTick();
eventHub.$emit('mr:diffs:expandAllFiles');
eventHub.$emit(EVT_EXPAND_ALL_FILES);
expect(wrapper.vm.handleToggle).toHaveBeenCalledTimes(1);
});
it('does nothing when the file is not collapsed', async () => {
eventHub.$emit('mr:diffs:expandAllFiles');
eventHub.$emit(EVT_EXPAND_ALL_FILES);
await wrapper.vm.$nextTick();
......
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