2022-04-04 11:22:00 +05:30
|
|
|
import { shallowMount, mount } from '@vue/test-utils';
|
|
|
|
import Vue, { nextTick } from 'vue';
|
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';
|
2022-04-04 11:22:00 +05:30
|
|
|
import { EVT_EXPAND_ALL_FILES } from '~/diffs/constants';
|
2021-01-29 00:20:46 +05:30
|
|
|
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
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
import file from '../mock_data/diff_file';
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
const propsData = {
|
|
|
|
limited: true,
|
|
|
|
mergeable: true,
|
|
|
|
resolutionPath: 'a-path',
|
|
|
|
};
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
async function files(store, count) {
|
|
|
|
const copies = Array(count).fill(file);
|
|
|
|
store.state.diffs.diffFiles.push(...copies);
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2021-09-30 23:02:18 +05:30
|
|
|
}
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
describe('CollapsedFilesWarning', () => {
|
|
|
|
let store;
|
|
|
|
let wrapper;
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
Vue.use(Vuex);
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
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 },
|
|
|
|
store,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
describe('when there is more than one file', () => {
|
|
|
|
it.each`
|
|
|
|
present | dismissed
|
|
|
|
${false} | ${true}
|
|
|
|
${true} | ${false}
|
|
|
|
`('toggles the alert when dismissed is $dismissed', async ({ present, dismissed }) => {
|
|
|
|
createComponent({ dismissed });
|
|
|
|
await files(store, 2);
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
expect(wrapper.find('[data-testid="root"]').exists()).toBe(present);
|
|
|
|
});
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
it('dismisses the component when the alert "x" is clicked', async () => {
|
|
|
|
createComponent({}, { full: true });
|
|
|
|
await files(store, 2);
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
expect(wrapper.find('[data-testid="root"]').exists()).toBe(true);
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
getAlertCloseButton().element.click();
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
expect(wrapper.find('[data-testid="root"]').exists()).toBe(false);
|
|
|
|
});
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
it(`emits the \`${EVT_EXPAND_ALL_FILES}\` event when the alert action button is clicked`, async () => {
|
|
|
|
createComponent({}, { full: true });
|
|
|
|
await files(store, 2);
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
jest.spyOn(eventHub, '$emit');
|
|
|
|
|
|
|
|
getAlertActionButton().vm.$emit('click');
|
|
|
|
|
|
|
|
expect(eventHub.$emit).toHaveBeenCalledWith(EVT_EXPAND_ALL_FILES);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when there is a single file', () => {
|
|
|
|
it('should not display', async () => {
|
|
|
|
createComponent();
|
|
|
|
await files(store, 1);
|
|
|
|
|
|
|
|
expect(wrapper.find('[data-testid="root"]').exists()).toBe(false);
|
|
|
|
});
|
2020-11-24 15:15:51 +05:30
|
|
|
});
|
|
|
|
});
|