2021-01-29 00:20:46 +05:30
|
|
|
import Vuex from 'vuex';
|
|
|
|
import { createLocalVue, shallowMount } from '@vue/test-utils';
|
2021-02-22 17:27:13 +05:30
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
2020-06-23 00:09:42 +05:30
|
|
|
import { createStore } from '~/ide/stores';
|
2021-01-29 00:20:46 +05:30
|
|
|
import ErrorMessage from '~/ide/components/error_message.vue';
|
2018-05-09 12:01:36 +05:30
|
|
|
import ide from '~/ide/components/ide.vue';
|
2020-10-24 23:57:45 +05:30
|
|
|
import { file } from '../helpers';
|
2018-10-15 14:42:47 +05:30
|
|
|
import { projectData } from '../mock_data';
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
const localVue = createLocalVue();
|
|
|
|
localVue.use(Vuex);
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
describe('WebIDE', () => {
|
|
|
|
const emptyProjData = { ...projectData, empty_repo: true, branches: {} };
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
let wrapper;
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
function createComponent({ projData = emptyProjData, state = {} } = {}) {
|
|
|
|
const store = createStore();
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
store.state.currentProjectId = 'abcproject';
|
|
|
|
store.state.currentBranchId = 'master';
|
|
|
|
store.state.projects.abcproject = { ...projData };
|
|
|
|
store.state.trees['abcproject/master'] = {
|
|
|
|
tree: [],
|
|
|
|
loading: false,
|
|
|
|
};
|
2021-03-08 18:12:59 +05:30
|
|
|
Object.keys(state).forEach((key) => {
|
2021-01-29 00:20:46 +05:30
|
|
|
store.state[key] = state[key];
|
|
|
|
});
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
return shallowMount(ide, {
|
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
}
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
afterEach(() => {
|
2021-01-29 00:20:46 +05:30
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
2019-09-04 21:01:54 +05:30
|
|
|
});
|
2018-10-15 14:42:47 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
describe('ide component, empty repo', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = createComponent({
|
|
|
|
projData: {
|
|
|
|
empty_repo: true,
|
|
|
|
},
|
|
|
|
});
|
2019-09-04 21:01:54 +05:30
|
|
|
});
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
it('renders "New file" button in empty repo', async () => {
|
|
|
|
expect(wrapper.find('[title="New file"]').exists()).toBe(true);
|
|
|
|
});
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
describe('ide component, non-empty repo', () => {
|
|
|
|
describe('error message', () => {
|
2021-02-22 17:27:13 +05:30
|
|
|
it.each`
|
|
|
|
errorMessage | exists
|
|
|
|
${null} | ${false}
|
|
|
|
${{ text: 'error' }} | ${true}
|
|
|
|
`(
|
|
|
|
'should error message exists=$exists when errorMessage=$errorMessage',
|
|
|
|
async ({ errorMessage, exists }) => {
|
|
|
|
wrapper = createComponent({
|
|
|
|
state: {
|
|
|
|
errorMessage,
|
2021-01-29 00:20:46 +05:30
|
|
|
},
|
2021-02-22 17:27:13 +05:30
|
|
|
});
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(wrapper.find(ErrorMessage).exists()).toBe(exists);
|
|
|
|
},
|
|
|
|
);
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
2018-10-15 14:42:47 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
describe('onBeforeUnload', () => {
|
|
|
|
it('returns undefined when no staged files or changed files', () => {
|
|
|
|
wrapper = createComponent();
|
|
|
|
expect(wrapper.vm.onBeforeUnload()).toBe(undefined);
|
|
|
|
});
|
2018-11-18 11:00:15 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
it('returns warning text when their are changed files', () => {
|
|
|
|
wrapper = createComponent({
|
|
|
|
state: {
|
|
|
|
changedFiles: [file()],
|
|
|
|
},
|
|
|
|
});
|
2018-11-18 11:00:15 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
expect(wrapper.vm.onBeforeUnload()).toBe('Are you sure you want to lose unsaved changes?');
|
|
|
|
});
|
2018-11-18 11:00:15 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
it('returns warning text when their are staged files', () => {
|
|
|
|
wrapper = createComponent({
|
|
|
|
state: {
|
|
|
|
stagedFiles: [file()],
|
|
|
|
},
|
|
|
|
});
|
2018-11-18 11:00:15 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
expect(wrapper.vm.onBeforeUnload()).toBe('Are you sure you want to lose unsaved changes?');
|
|
|
|
});
|
2018-11-18 11:00:15 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
it('updates event object', () => {
|
|
|
|
const event = {};
|
|
|
|
wrapper = createComponent({
|
|
|
|
state: {
|
|
|
|
stagedFiles: [file()],
|
|
|
|
},
|
|
|
|
});
|
2018-11-18 11:00:15 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
wrapper.vm.onBeforeUnload(event);
|
2018-11-18 11:00:15 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
expect(event.returnValue).toBe('Are you sure you want to lose unsaved changes?');
|
|
|
|
});
|
2018-11-18 11:00:15 +05:30
|
|
|
});
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
describe('non-existent branch', () => {
|
|
|
|
it('does not render "New file" button for non-existent branch when repo is not empty', () => {
|
|
|
|
wrapper = createComponent({
|
|
|
|
state: {
|
|
|
|
projects: {},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.find('[title="New file"]').exists()).toBe(false);
|
2019-09-04 21:01:54 +05:30
|
|
|
});
|
|
|
|
});
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
describe('branch with files', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = createComponent({
|
|
|
|
projData: {
|
|
|
|
empty_repo: false,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
it('does not render "New file" button', () => {
|
|
|
|
expect(wrapper.find('[title="New file"]').exists()).toBe(false);
|
2019-09-04 21:01:54 +05:30
|
|
|
});
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|
|
|
|
});
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|