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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

79 lines
2.2 KiB
JavaScript
Raw Normal View History

2022-08-27 11:52:29 +05:30
import { mount } from '@vue/test-utils';
import NewDropdown from '~/ide/components/new_dropdown/index.vue';
import Button from '~/ide/components/new_dropdown/button.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', () => {
2022-08-27 11:52:29 +05:30
let wrapper;
const findAllButtons = () => wrapper.findAllComponents(Button);
const mountComponent = () => {
const store = createStore();
store.state.currentProjectId = 'abcproject';
store.state.path = '';
store.state.trees['abcproject/mybranch'] = { tree: [] };
wrapper = mount(NewDropdown, {
store,
propsData: {
branch: 'main',
path: '',
mouseOver: false,
type: 'tree',
},
2018-05-09 12:01:36 +05:30
});
2022-08-27 11:52:29 +05:30
};
2018-05-09 12:01:36 +05:30
2022-08-27 11:52:29 +05:30
beforeEach(() => {
mountComponent();
jest.spyOn(wrapper.vm.$refs.newModal, 'open').mockImplementation(() => {});
2018-05-09 12:01:36 +05:30
});
afterEach(() => {
2022-08-27 11:52:29 +05:30
wrapper.destroy();
2018-05-09 12:01:36 +05:30
});
it('renders new file, upload and new directory links', () => {
2022-08-27 11:52:29 +05:30
expect(findAllButtons().at(0).text()).toBe('New file');
expect(findAllButtons().at(1).text()).toBe('Upload file');
expect(findAllButtons().at(2).text()).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', () => {
2022-08-27 11:52:29 +05:30
findAllButtons().at(0).trigger('click');
2018-05-09 12:01:36 +05:30
2022-08-27 11:52:29 +05:30
expect(wrapper.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', () => {
2022-08-27 11:52:29 +05:30
findAllButtons().at(2).trigger('click');
2018-05-09 12:01:36 +05:30
2022-08-27 11:52:29 +05:30
expect(wrapper.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 () => {
2022-08-27 11:52:29 +05:30
jest.spyOn(wrapper.vm.$refs.dropdownMenu, 'scrollIntoView').mockImplementation(() => {});
2018-10-15 14:42:47 +05:30
2022-08-27 11:52:29 +05:30
await wrapper.setProps({ isOpen: true });
2018-10-15 14:42:47 +05:30
2022-08-27 11:52:29 +05:30
expect(wrapper.vm.$refs.dropdownMenu.scrollIntoView).toHaveBeenCalledWith({
2022-04-04 11:22:00 +05:30
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', () => {
2022-08-27 11:52:29 +05:30
jest.spyOn(wrapper.vm, 'deleteEntry').mockImplementation(() => {});
2018-11-18 11:00:15 +05:30
2022-08-27 11:52:29 +05:30
findAllButtons().at(4).trigger('click');
2018-11-18 11:00:15 +05:30
2022-08-27 11:52:29 +05:30
expect(wrapper.vm.deleteEntry).toHaveBeenCalledWith('');
2018-11-18 11:00:15 +05:30
});
});
2018-05-09 12:01:36 +05:30
});