1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
import { mount } from '@vue/test-utils';
import NewDropdown from '~/ide/components/new_dropdown/index.vue';
import Button from '~/ide/components/new_dropdown/button.vue';
import { createStore } from '~/ide/stores';
describe('new dropdown component', () => {
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',
},
});
};
beforeEach(() => {
mountComponent();
jest.spyOn(wrapper.vm.$refs.newModal, 'open').mockImplementation(() => {});
});
afterEach(() => {
wrapper.destroy();
});
it('renders new file, upload and new directory links', () => {
expect(findAllButtons().at(0).text()).toBe('New file');
expect(findAllButtons().at(1).text()).toBe('Upload file');
expect(findAllButtons().at(2).text()).toBe('New directory');
});
describe('createNewItem', () => {
it('opens modal for a blob when new file is clicked', () => {
findAllButtons().at(0).trigger('click');
expect(wrapper.vm.$refs.newModal.open).toHaveBeenCalledWith('blob', '');
});
it('opens modal for a tree when new directory is clicked', () => {
findAllButtons().at(2).trigger('click');
expect(wrapper.vm.$refs.newModal.open).toHaveBeenCalledWith('tree', '');
});
});
describe('isOpen', () => {
it('scrolls dropdown into view', async () => {
jest.spyOn(wrapper.vm.$refs.dropdownMenu, 'scrollIntoView').mockImplementation(() => {});
await wrapper.setProps({ isOpen: true });
expect(wrapper.vm.$refs.dropdownMenu.scrollIntoView).toHaveBeenCalledWith({
block: 'nearest',
});
});
});
describe('delete entry', () => {
it('calls delete action', () => {
jest.spyOn(wrapper.vm, 'deleteEntry').mockImplementation(() => {});
findAllButtons().at(4).trigger('click');
expect(wrapper.vm.deleteEntry).toHaveBeenCalledWith('');
});
});
});
|