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

188 lines
4.2 KiB
JavaScript
Raw Normal View History

2018-05-09 12:01:36 +05:30
import Vue from 'vue';
2020-06-23 00:09:42 +05:30
import { createStore } from '~/ide/stores';
2018-05-09 12:01:36 +05:30
import repoTab from '~/ide/components/repo_tab.vue';
2020-06-23 00:09:42 +05:30
import { createRouter } from '~/ide/ide_router';
import { file } from '../helpers';
2018-05-09 12:01:36 +05:30
describe('RepoTab', () => {
let vm;
2020-06-23 00:09:42 +05:30
let store;
let router;
2018-05-09 12:01:36 +05:30
function createComponent(propsData) {
const RepoTab = Vue.extend(repoTab);
return new RepoTab({
store,
propsData,
}).$mount();
}
beforeEach(() => {
2020-06-23 00:09:42 +05:30
store = createStore();
router = createRouter(store);
2020-05-24 23:13:21 +05:30
jest.spyOn(router, 'push').mockImplementation(() => {});
2018-05-09 12:01:36 +05:30
});
afterEach(() => {
vm.$destroy();
});
it('renders a close link and a name link', () => {
vm = createComponent({
tab: file(),
});
vm.$store.state.openFiles.push(vm.tab);
const close = vm.$el.querySelector('.multi-file-tab-close');
const name = vm.$el.querySelector(`[title="${vm.tab.url}"]`);
expect(close.innerHTML).toContain('#close');
expect(name.textContent.trim()).toEqual(vm.tab.name);
});
2018-11-08 19:23:39 +05:30
it('does not call openPendingTab when tab is active', done => {
vm = createComponent({
tab: {
...file(),
pending: true,
active: true,
},
});
2020-05-24 23:13:21 +05:30
jest.spyOn(vm, 'openPendingTab').mockImplementation(() => {});
2018-11-08 19:23:39 +05:30
vm.$el.click();
vm.$nextTick(() => {
expect(vm.openPendingTab).not.toHaveBeenCalled();
done();
});
});
2018-05-09 12:01:36 +05:30
it('fires clickFile when the link is clicked', () => {
vm = createComponent({
tab: file(),
});
2020-05-24 23:13:21 +05:30
jest.spyOn(vm, 'clickFile').mockImplementation(() => {});
2018-05-09 12:01:36 +05:30
vm.$el.click();
expect(vm.clickFile).toHaveBeenCalledWith(vm.tab);
});
it('calls closeFile when clicking close button', () => {
vm = createComponent({
tab: file(),
});
2020-05-24 23:13:21 +05:30
jest.spyOn(vm, 'closeFile').mockImplementation(() => {});
2018-05-09 12:01:36 +05:30
vm.$el.querySelector('.multi-file-tab-close').click();
expect(vm.closeFile).toHaveBeenCalledWith(vm.tab);
});
it('changes icon on hover', done => {
const tab = file();
tab.changed = true;
vm = createComponent({
tab,
});
vm.$el.dispatchEvent(new Event('mouseover'));
Vue.nextTick()
.then(() => {
2018-12-05 23:21:45 +05:30
expect(vm.$el.querySelector('.file-modified')).toBeNull();
2018-05-09 12:01:36 +05:30
vm.$el.dispatchEvent(new Event('mouseout'));
})
.then(Vue.nextTick)
.then(() => {
2018-12-05 23:21:45 +05:30
expect(vm.$el.querySelector('.file-modified')).not.toBeNull();
2018-05-09 12:01:36 +05:30
done();
})
.catch(done.fail);
});
describe('locked file', () => {
let f;
beforeEach(() => {
f = file('locked file');
f.file_lock = {
user: {
name: 'testuser',
updated_at: new Date(),
},
};
vm = createComponent({
tab: f,
});
});
afterEach(() => {
vm.$destroy();
});
it('renders lock icon', () => {
expect(vm.$el.querySelector('.file-status-icon')).not.toBeNull();
});
it('renders a tooltip', () => {
2018-11-08 19:23:39 +05:30
expect(vm.$el.querySelector('span:nth-child(2)').dataset.originalTitle).toContain(
'Locked by testuser',
);
2018-05-09 12:01:36 +05:30
});
});
describe('methods', () => {
describe('closeTab', () => {
it('closes tab if file has changed', done => {
const tab = file();
tab.changed = true;
tab.opened = true;
vm = createComponent({
tab,
});
vm.$store.state.openFiles.push(tab);
vm.$store.state.changedFiles.push(tab);
vm.$store.state.entries[tab.path] = tab;
vm.$store.dispatch('setFileActive', tab.path);
vm.$el.querySelector('.multi-file-tab-close').click();
vm.$nextTick(() => {
expect(tab.opened).toBeFalsy();
expect(vm.$store.state.changedFiles.length).toBe(1);
done();
});
});
it('closes tab when clicking close btn', done => {
const tab = file('lose');
tab.opened = true;
vm = createComponent({
tab,
});
vm.$store.state.openFiles.push(tab);
vm.$store.state.entries[tab.path] = tab;
vm.$store.dispatch('setFileActive', tab.path);
vm.$el.querySelector('.multi-file-tab-close').click();
vm.$nextTick(() => {
expect(tab.opened).toBeFalsy();
done();
});
});
});
});
});