2017-09-10 17:25:29 +05:30
|
|
|
import Vue from 'vue';
|
2018-03-17 18:26:18 +05:30
|
|
|
import store from '~/ide/stores';
|
|
|
|
import repoTab from '~/ide/components/repo_tab.vue';
|
|
|
|
import { file, resetStore } from '../helpers';
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
describe('RepoTab', () => {
|
2018-03-17 18:26:18 +05:30
|
|
|
let vm;
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
function createComponent(propsData) {
|
|
|
|
const RepoTab = Vue.extend(repoTab);
|
|
|
|
|
|
|
|
return new RepoTab({
|
2018-03-17 18:26:18 +05:30
|
|
|
store,
|
2017-09-10 17:25:29 +05:30
|
|
|
propsData,
|
|
|
|
}).$mount();
|
|
|
|
}
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
afterEach(() => {
|
|
|
|
resetStore(vm.$store);
|
|
|
|
});
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
it('renders a close link and a name link', () => {
|
2018-03-17 18:26:18 +05:30
|
|
|
vm = createComponent({
|
|
|
|
tab: file(),
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
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}"]`);
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
expect(close.querySelector('.fa-times')).toBeTruthy();
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(name.textContent.trim()).toEqual(vm.tab.name);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('fires clickFile when the link is clicked', () => {
|
|
|
|
vm = createComponent({
|
|
|
|
tab: file(),
|
|
|
|
});
|
|
|
|
|
|
|
|
spyOn(vm, 'clickFile');
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
vm.$el.click();
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
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();
|
|
|
|
|
|
|
|
expect(vm.closeFile).toHaveBeenCalledWith({ file: vm.tab });
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders an fa-circle icon if tab is changed', () => {
|
2018-03-17 18:26:18 +05:30
|
|
|
const tab = file('changedFile');
|
|
|
|
tab.changed = true;
|
|
|
|
vm = createComponent({
|
2017-09-10 17:25:29 +05:30
|
|
|
tab,
|
|
|
|
});
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(vm.$el.querySelector('.multi-file-tab-close .fa-circle')).not.toBeNull();
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('methods', () => {
|
|
|
|
describe('closeTab', () => {
|
2018-03-17 18:26:18 +05:30
|
|
|
it('does not close tab if is changed', (done) => {
|
|
|
|
const tab = file('closeFile');
|
|
|
|
tab.changed = true;
|
|
|
|
tab.opened = true;
|
|
|
|
vm = createComponent({
|
|
|
|
tab,
|
|
|
|
});
|
|
|
|
vm.$store.state.openFiles.push(tab);
|
|
|
|
vm.$store.dispatch('setFileActive', tab);
|
|
|
|
|
|
|
|
vm.$el.querySelector('.multi-file-tab-close').click();
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(tab.opened).toBeTruthy();
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
done();
|
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
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.dispatch('setFileActive', tab);
|
|
|
|
|
|
|
|
vm.$el.querySelector('.multi-file-tab-close').click();
|
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(tab.opened).toBeFalsy();
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
done();
|
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|