2020-11-24 15:15:51 +05:30
|
|
|
import { shallowMount, mount, createLocalVue } from '@vue/test-utils';
|
2021-03-11 19:13:27 +05:30
|
|
|
import Vuex from 'vuex';
|
2020-11-24 15:15:51 +05:30
|
|
|
import CollapsedFilesWarning from '~/diffs/components/collapsed_files_warning.vue';
|
2021-01-29 00:20:46 +05:30
|
|
|
import { CENTERED_LIMITED_CONTAINER_CLASSES, EVT_EXPAND_ALL_FILES } from '~/diffs/constants';
|
|
|
|
import eventHub from '~/diffs/event_hub';
|
2021-03-11 19:13:27 +05:30
|
|
|
import createStore from '~/diffs/store/modules';
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
const propsData = {
|
|
|
|
limited: true,
|
|
|
|
mergeable: true,
|
|
|
|
resolutionPath: 'a-path',
|
|
|
|
};
|
|
|
|
const limitedClasses = CENTERED_LIMITED_CONTAINER_CLASSES.split(' ');
|
|
|
|
|
|
|
|
describe('CollapsedFilesWarning', () => {
|
|
|
|
const localVue = createLocalVue();
|
|
|
|
let store;
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
localVue.use(Vuex);
|
|
|
|
|
|
|
|
const getAlertActionButton = () =>
|
|
|
|
wrapper.find(CollapsedFilesWarning).find('button.gl-alert-action:first-child');
|
|
|
|
const getAlertCloseButton = () => wrapper.find(CollapsedFilesWarning).find('button');
|
|
|
|
|
|
|
|
const createComponent = (props = {}, { full } = { full: false }) => {
|
|
|
|
const mounter = full ? mount : shallowMount;
|
|
|
|
store = new Vuex.Store({
|
|
|
|
modules: {
|
|
|
|
diffs: createStore(),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
wrapper = mounter(CollapsedFilesWarning, {
|
|
|
|
propsData: { ...propsData, ...props },
|
|
|
|
localVue,
|
|
|
|
store,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it.each`
|
|
|
|
limited | containerClasses
|
|
|
|
${true} | ${limitedClasses}
|
|
|
|
${false} | ${[]}
|
|
|
|
`(
|
|
|
|
'has the correct container classes when limited is $limited',
|
|
|
|
({ limited, containerClasses }) => {
|
|
|
|
createComponent({ limited });
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
expect(wrapper.classes()).toEqual(['col-12'].concat(containerClasses));
|
2020-11-24 15:15:51 +05:30
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
it.each`
|
|
|
|
present | dismissed
|
|
|
|
${false} | ${true}
|
|
|
|
${true} | ${false}
|
|
|
|
`('toggles the alert when dismissed is $dismissed', ({ present, dismissed }) => {
|
|
|
|
createComponent({ dismissed });
|
|
|
|
|
|
|
|
expect(wrapper.find('[data-testid="root"]').exists()).toBe(present);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('dismisses the component when the alert "x" is clicked', async () => {
|
|
|
|
createComponent({}, { full: true });
|
|
|
|
|
|
|
|
expect(wrapper.find('[data-testid="root"]').exists()).toBe(true);
|
|
|
|
|
|
|
|
getAlertCloseButton().element.click();
|
|
|
|
|
|
|
|
await wrapper.vm.$nextTick();
|
|
|
|
|
|
|
|
expect(wrapper.find('[data-testid="root"]').exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
it(`emits the \`${EVT_EXPAND_ALL_FILES}\` event when the alert action button is clicked`, () => {
|
2020-11-24 15:15:51 +05:30
|
|
|
createComponent({}, { full: true });
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
jest.spyOn(eventHub, '$emit');
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
getAlertActionButton().vm.$emit('click');
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
expect(eventHub.$emit).toHaveBeenCalledWith(EVT_EXPAND_ALL_FILES);
|
2020-11-24 15:15:51 +05:30
|
|
|
});
|
|
|
|
});
|