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

83 lines
2.2 KiB
JavaScript
Raw Normal View History

2022-04-04 11:22:00 +05:30
import Vue, { nextTick } from 'vue';
2020-05-24 23:13:21 +05:30
import { createComponentWithStore } from 'helpers/vue_mount_component_helper';
2018-05-09 12:01:36 +05:30
import newDropdown from '~/ide/components/new_dropdown/index.vue';
2021-03-11 19:13:27 +05:30
import { createStore } from '~/ide/stores';
2018-05-09 12:01:36 +05:30
describe('new dropdown component', () => {
2020-10-24 23:57:45 +05:30
let store;
2018-05-09 12:01:36 +05:30
let vm;
beforeEach(() => {
2020-10-24 23:57:45 +05:30
store = createStore();
2018-05-09 12:01:36 +05:30
const component = Vue.extend(newDropdown);
vm = createComponentWithStore(component, store, {
2021-09-04 01:27:46 +05:30
branch: 'main',
2018-05-09 12:01:36 +05:30
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: [],
};
vm.$mount();
2020-05-24 23:13:21 +05:30
jest.spyOn(vm.$refs.newModal, 'open').mockImplementation(() => {});
2018-05-09 12:01:36 +05:30
});
afterEach(() => {
vm.$destroy();
});
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', () => {
2020-05-24 23:13:21 +05:30
it('opens modal for a 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
2020-05-24 23:13:21 +05:30
expect(vm.$refs.newModal.open).toHaveBeenCalledWith('blob', '');
2018-05-09 12:01:36 +05:30
});
2020-05-24 23:13:21 +05:30
it('opens modal for a 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
2020-05-24 23:13:21 +05:30
expect(vm.$refs.newModal.open).toHaveBeenCalledWith('tree', '');
2018-05-09 12:01:36 +05:30
});
});
2018-10-15 14:42:47 +05:30
2019-07-07 11:18:12 +05:30
describe('isOpen', () => {
2022-04-04 11:22:00 +05:30
it('scrolls dropdown into view', async () => {
2020-05-24 23:13:21 +05:30
jest.spyOn(vm.$refs.dropdownMenu, 'scrollIntoView').mockImplementation(() => {});
2018-10-15 14:42:47 +05:30
2019-07-07 11:18:12 +05:30
vm.isOpen = true;
2018-10-15 14:42:47 +05:30
2022-04-04 11:22:00 +05:30
await nextTick();
2018-10-15 14:42:47 +05:30
2022-04-04 11:22:00 +05:30
expect(vm.$refs.dropdownMenu.scrollIntoView).toHaveBeenCalledWith({
block: 'nearest',
2018-10-15 14:42:47 +05:30
});
});
});
2018-11-18 11:00:15 +05:30
describe('delete entry', () => {
it('calls delete action', () => {
2020-05-24 23:13:21 +05:30
jest.spyOn(vm, 'deleteEntry').mockImplementation(() => {});
2018-11-18 11:00:15 +05:30
vm.$el.querySelectorAll('.dropdown-menu button')[4].click();
expect(vm.deleteEntry).toHaveBeenCalledWith('');
});
});
2018-05-09 12:01:36 +05:30
});