2018-03-20 10:12:48 -04:00
|
|
|
import Vue from 'vue';
|
2018-03-20 10:16:38 -04:00
|
|
|
import store from '~/ide/stores';
|
|
|
|
import repoTab from '~/ide/components/repo_tab.vue';
|
|
|
|
import router from '~/ide/ide_router';
|
2018-03-20 10:12:48 -04:00
|
|
|
import { file, resetStore } from '../helpers';
|
|
|
|
|
|
|
|
describe('RepoTab', () => {
|
|
|
|
let vm;
|
|
|
|
|
|
|
|
function createComponent(propsData) {
|
|
|
|
const RepoTab = Vue.extend(repoTab);
|
|
|
|
|
|
|
|
return new RepoTab({
|
|
|
|
store,
|
|
|
|
propsData,
|
|
|
|
}).$mount();
|
|
|
|
}
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
spyOn(router, 'push');
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
|
|
|
|
|
|
|
resetStore(vm.$store);
|
|
|
|
});
|
|
|
|
|
|
|
|
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-06-25 06:58:24 -04:00
|
|
|
it('does not call openPendingTab when tab is active', done => {
|
|
|
|
vm = createComponent({
|
|
|
|
tab: {
|
|
|
|
...file(),
|
|
|
|
pending: true,
|
|
|
|
active: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
spyOn(vm, 'openPendingTab');
|
|
|
|
|
|
|
|
vm.$el.click();
|
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.openPendingTab).not.toHaveBeenCalled();
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-20 10:12:48 -04:00
|
|
|
it('fires clickFile when the link is clicked', () => {
|
|
|
|
vm = createComponent({
|
|
|
|
tab: file(),
|
|
|
|
});
|
|
|
|
|
|
|
|
spyOn(vm, 'clickFile');
|
|
|
|
|
|
|
|
vm.$el.click();
|
|
|
|
|
|
|
|
expect(vm.clickFile).toHaveBeenCalledWith(vm.tab);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls closeFile when clicking close button', () => {
|
|
|
|
vm = createComponent({
|
|
|
|
tab: file(),
|
|
|
|
});
|
|
|
|
|
|
|
|
spyOn(vm, 'closeFile');
|
|
|
|
|
|
|
|
vm.$el.querySelector('.multi-file-tab-close').click();
|
|
|
|
|
2018-03-23 11:59:09 -04:00
|
|
|
expect(vm.closeFile).toHaveBeenCalledWith(vm.tab);
|
2018-03-20 10:12:48 -04:00
|
|
|
});
|
|
|
|
|
2018-03-20 10:16:38 -04:00
|
|
|
it('changes icon on hover', done => {
|
2018-03-20 10:12:48 -04:00
|
|
|
const tab = file();
|
|
|
|
tab.changed = true;
|
|
|
|
vm = createComponent({
|
|
|
|
tab,
|
|
|
|
});
|
|
|
|
|
|
|
|
vm.$el.dispatchEvent(new Event('mouseover'));
|
|
|
|
|
|
|
|
Vue.nextTick()
|
|
|
|
.then(() => {
|
2018-10-03 05:05:43 -04:00
|
|
|
expect(vm.$el.querySelector('.file-modified')).toBeNull();
|
2018-03-20 10:12:48 -04:00
|
|
|
|
|
|
|
vm.$el.dispatchEvent(new Event('mouseout'));
|
|
|
|
})
|
|
|
|
.then(Vue.nextTick)
|
|
|
|
.then(() => {
|
2018-10-03 05:05:43 -04:00
|
|
|
expect(vm.$el.querySelector('.file-modified')).not.toBeNull();
|
2018-03-20 10:12:48 -04:00
|
|
|
|
|
|
|
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-06-25 06:58:24 -04:00
|
|
|
expect(vm.$el.querySelector('span:nth-child(2)').dataset.originalTitle).toContain(
|
|
|
|
'Locked by testuser',
|
|
|
|
);
|
2018-03-20 10:12:48 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('methods', () => {
|
|
|
|
describe('closeTab', () => {
|
2018-03-20 10:16:38 -04:00
|
|
|
it('closes tab if file has changed', done => {
|
2018-03-20 10:12:48 -04:00
|
|
|
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();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-20 10:16:38 -04:00
|
|
|
it('closes tab when clicking close btn', done => {
|
2018-03-20 10:12:48 -04:00
|
|
|
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();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|