2018-05-09 12:01:36 +05:30
|
|
|
import Vue from 'vue';
|
|
|
|
import store from '~/ide/stores';
|
|
|
|
import newDropdown from '~/ide/components/new_dropdown/index.vue';
|
|
|
|
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
|
|
|
|
import { resetStore } from '../../helpers';
|
|
|
|
|
|
|
|
describe('new dropdown component', () => {
|
|
|
|
let vm;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
const component = Vue.extend(newDropdown);
|
|
|
|
|
|
|
|
vm = createComponentWithStore(component, store, {
|
|
|
|
branch: 'master',
|
|
|
|
path: '',
|
2018-11-18 11:00:15 +05:30
|
|
|
mouseOver: false,
|
|
|
|
type: 'tree',
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
vm.$store.state.currentProjectId = 'abcproject';
|
|
|
|
vm.$store.state.path = '';
|
|
|
|
vm.$store.state.trees['abcproject/mybranch'] = {
|
|
|
|
tree: [],
|
|
|
|
};
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
spyOn(vm, 'openNewEntryModal');
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
vm.$mount();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
|
|
|
|
|
|
|
resetStore(vm.$store);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders new file, upload and new directory links', () => {
|
2018-11-18 11:00:15 +05:30
|
|
|
const buttons = vm.$el.querySelectorAll('.dropdown-menu button');
|
|
|
|
expect(buttons[0].textContent.trim()).toBe('New file');
|
|
|
|
expect(buttons[1].textContent.trim()).toBe('Upload file');
|
|
|
|
expect(buttons[2].textContent.trim()).toBe('New directory');
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('createNewItem', () => {
|
|
|
|
it('sets modalType to blob when new file is clicked', () => {
|
2018-11-18 11:00:15 +05:30
|
|
|
vm.$el.querySelectorAll('.dropdown-menu button')[0].click();
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
expect(vm.openNewEntryModal).toHaveBeenCalledWith({ type: 'blob', path: '' });
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('sets modalType to tree when new directory is clicked', () => {
|
2018-11-18 11:00:15 +05:30
|
|
|
vm.$el.querySelectorAll('.dropdown-menu button')[2].click();
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
expect(vm.openNewEntryModal).toHaveBeenCalledWith({ type: 'tree', path: '' });
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
});
|
2018-10-15 14:42:47 +05:30
|
|
|
|
|
|
|
describe('dropdownOpen', () => {
|
|
|
|
it('scrolls dropdown into view', done => {
|
|
|
|
spyOn(vm.$refs.dropdownMenu, 'scrollIntoView');
|
|
|
|
|
|
|
|
vm.dropdownOpen = true;
|
|
|
|
|
|
|
|
setTimeout(() => {
|
2018-11-18 11:00:15 +05:30
|
|
|
expect(vm.$refs.dropdownMenu.scrollIntoView).toHaveBeenCalledWith({
|
|
|
|
block: 'nearest',
|
|
|
|
});
|
2018-10-15 14:42:47 +05:30
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-11-18 11:00:15 +05:30
|
|
|
|
|
|
|
describe('delete entry', () => {
|
|
|
|
it('calls delete action', () => {
|
|
|
|
spyOn(vm, 'deleteEntry');
|
|
|
|
|
|
|
|
vm.$el.querySelectorAll('.dropdown-menu button')[4].click();
|
|
|
|
|
|
|
|
expect(vm.deleteEntry).toHaveBeenCalledWith('');
|
|
|
|
});
|
|
|
|
});
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|