debian-mirror-gitlab/spec/frontend/ide/components/ide_spec.js

129 lines
3.3 KiB
JavaScript
Raw Normal View History

2018-05-09 12:01:36 +05:30
import Vue from 'vue';
2020-05-24 23:13:21 +05:30
import { createComponentWithStore } from 'helpers/vue_mount_component_helper';
2020-06-23 00:09:42 +05:30
import { createStore } from '~/ide/stores';
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';
2020-06-23 00:09:42 +05:30
import extendStore from '~/ide/stores/extend';
let store;
2018-05-09 12:01:36 +05:30
2019-09-04 21:01:54 +05:30
function bootstrap(projData) {
2020-06-23 00:09:42 +05:30
store = createStore();
extendStore(store, document.createElement('div'));
2019-09-04 21:01:54 +05:30
const Component = Vue.extend(ide);
store.state.currentProjectId = 'abcproject';
store.state.currentBranchId = 'master';
2020-05-24 23:13:21 +05:30
store.state.projects.abcproject = { ...projData };
2019-09-04 21:01:54 +05:30
Vue.set(store.state.trees, 'abcproject/master', {
tree: [],
loading: false,
});
return createComponentWithStore(Component, store, {
emptyStateSvgPath: 'svg',
noChangesStateSvgPath: 'svg',
committedStateSvgPath: 'svg',
});
}
describe('ide component, empty repo', () => {
2018-05-09 12:01:36 +05:30
let vm;
beforeEach(() => {
2020-05-24 23:13:21 +05:30
const emptyProjData = { ...projectData, empty_repo: true, branches: {} };
2019-09-04 21:01:54 +05:30
vm = bootstrap(emptyProjData);
vm.$mount();
});
2018-05-09 12:01:36 +05:30
2019-09-04 21:01:54 +05:30
afterEach(() => {
vm.$destroy();
});
2018-10-15 14:42:47 +05:30
2019-09-04 21:01:54 +05:30
it('renders "New file" button in empty repo', done => {
vm.$nextTick(() => {
expect(vm.$el.querySelector('.ide-empty-state button[title="New file"]')).not.toBeNull();
done();
});
});
});
describe('ide component, non-empty repo', () => {
let vm;
beforeEach(() => {
vm = bootstrap(projectData);
vm.$mount();
2018-05-09 12:01:36 +05:30
});
afterEach(() => {
vm.$destroy();
});
2019-09-04 21:01:54 +05:30
it('shows error message when set', done => {
2020-03-13 15:44:24 +05:30
expect(vm.$el.querySelector('.gl-alert')).toBe(null);
2018-05-09 12:01:36 +05:30
2019-09-04 21:01:54 +05:30
vm.$store.state.errorMessage = {
text: 'error',
2018-05-09 12:01:36 +05:30
};
2019-09-04 21:01:54 +05:30
vm.$nextTick(() => {
2020-03-13 15:44:24 +05:30
expect(vm.$el.querySelector('.gl-alert')).not.toBe(null);
2018-05-09 12:01:36 +05:30
done();
});
});
2018-10-15 14:42:47 +05:30
2018-11-18 11:00:15 +05:30
describe('onBeforeUnload', () => {
it('returns undefined when no staged files or changed files', () => {
expect(vm.onBeforeUnload()).toBe(undefined);
});
it('returns warning text when their are changed files', () => {
vm.$store.state.changedFiles.push(file());
expect(vm.onBeforeUnload()).toBe('Are you sure you want to lose unsaved changes?');
});
it('returns warning text when their are staged files', () => {
vm.$store.state.stagedFiles.push(file());
expect(vm.onBeforeUnload()).toBe('Are you sure you want to lose unsaved changes?');
});
it('updates event object', () => {
const event = {};
vm.$store.state.stagedFiles.push(file());
vm.onBeforeUnload(event);
expect(event.returnValue).toBe('Are you sure you want to lose unsaved changes?');
});
});
2019-09-04 21:01:54 +05:30
describe('non-existent branch', () => {
it('does not render "New file" button for non-existent branch when repo is not empty', done => {
vm.$nextTick(() => {
expect(vm.$el.querySelector('.ide-empty-state button[title="New file"]')).toBeNull();
done();
});
});
});
2018-11-08 19:23:39 +05:30
2019-09-04 21:01:54 +05:30
describe('branch with files', () => {
beforeEach(() => {
store.state.trees['abcproject/master'].tree = [file()];
});
2018-11-08 19:23:39 +05:30
2019-09-04 21:01:54 +05:30
it('does not render "New file" button', done => {
vm.$nextTick(() => {
expect(vm.$el.querySelector('.ide-empty-state button[title="New file"]')).toBeNull();
done();
});
2018-11-08 19:23:39 +05:30
});
});
2018-05-09 12:01:36 +05:30
});