2020-03-13 15:44:24 +05:30
|
|
|
import { mount, createLocalVue } from '@vue/test-utils';
|
2021-03-11 19:13:27 +05:30
|
|
|
import Vuex from 'vuex';
|
2020-03-13 15:44:24 +05:30
|
|
|
import EditorHeader from '~/ide/components/commit_sidebar/editor_header.vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { createStore } from '~/ide/stores';
|
2020-03-13 15:44:24 +05:30
|
|
|
import { file } from '../../helpers';
|
|
|
|
|
|
|
|
const localVue = createLocalVue();
|
|
|
|
localVue.use(Vuex);
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
const TEST_FILE_PATH = 'test/file/path';
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
describe('IDE commit editor header', () => {
|
|
|
|
let wrapper;
|
|
|
|
let store;
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
const createComponent = (fileProps = {}) => {
|
2020-03-13 15:44:24 +05:30
|
|
|
wrapper = mount(EditorHeader, {
|
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
propsData: {
|
2020-05-24 23:13:21 +05:30
|
|
|
activeFile: {
|
|
|
|
...file(TEST_FILE_PATH),
|
|
|
|
staged: true,
|
|
|
|
...fileProps,
|
|
|
|
},
|
2020-03-13 15:44:24 +05:30
|
|
|
},
|
|
|
|
});
|
2020-05-24 23:13:21 +05:30
|
|
|
};
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
const findDiscardModal = () => wrapper.find({ ref: 'discardModal' });
|
|
|
|
const findDiscardButton = () => wrapper.find({ ref: 'discardButton' });
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
store = createStore();
|
|
|
|
jest.spyOn(store, 'dispatch').mockImplementation();
|
2020-03-13 15:44:24 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
});
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
it.each`
|
|
|
|
fileProps | shouldExist
|
|
|
|
${{ staged: false, changed: false }} | ${false}
|
|
|
|
${{ staged: true, changed: false }} | ${true}
|
|
|
|
${{ staged: false, changed: true }} | ${true}
|
|
|
|
${{ staged: true, changed: true }} | ${true}
|
|
|
|
`('with $fileProps, show discard button is $shouldExist', ({ fileProps, shouldExist }) => {
|
|
|
|
createComponent(fileProps);
|
|
|
|
|
|
|
|
expect(findDiscardButton().exists()).toBe(shouldExist);
|
2020-03-13 15:44:24 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('discard button', () => {
|
|
|
|
beforeEach(() => {
|
2020-05-24 23:13:21 +05:30
|
|
|
createComponent();
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
const modal = findDiscardModal();
|
2020-03-13 15:44:24 +05:30
|
|
|
jest.spyOn(modal.vm, 'show');
|
|
|
|
|
|
|
|
findDiscardButton().trigger('click');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('opens a dialog confirming discard', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(findDiscardModal().vm.show).toHaveBeenCalled();
|
2020-03-13 15:44:24 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('calls discardFileChanges if dialog result is confirmed', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(store.dispatch).not.toHaveBeenCalled();
|
|
|
|
|
|
|
|
findDiscardModal().vm.$emit('ok');
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(store.dispatch).toHaveBeenCalledWith('discardFileChanges', TEST_FILE_PATH);
|
2020-03-13 15:44:24 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|