debian-mirror-gitlab/spec/javascripts/ide/components/new_dropdown/index_spec.js

85 lines
2.2 KiB
JavaScript
Raw Normal View History

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');
2018-12-13 13:39:08 +05:30
2018-11-18 11:00:15 +05:30
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
2019-05-18 00:54:41 +05:30
describe('isOpen', () => {
2018-10-15 14:42:47 +05:30
it('scrolls dropdown into view', done => {
spyOn(vm.$refs.dropdownMenu, 'scrollIntoView');
2019-05-18 00:54:41 +05:30
vm.isOpen = true;
2018-10-15 14:42:47 +05:30
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
});