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
79
80
81
82
83
84
85
86
87
88
89
|
import { mount } from '@vue/test-utils';
import $ from 'jquery';
import { nextTick } from 'vue';
import NavDropdown from '~/ide/components/nav_dropdown.vue';
import { PERMISSION_READ_MR } from '~/ide/constants';
import { createStore } from '~/ide/stores';
const TEST_PROJECT_ID = 'lorem-ipsum';
describe('IDE NavDropdown', () => {
let store;
let wrapper;
beforeEach(() => {
store = createStore();
Object.assign(store.state, {
currentProjectId: TEST_PROJECT_ID,
currentBranchId: 'main',
projects: {
[TEST_PROJECT_ID]: {
userPermissions: {
[PERMISSION_READ_MR]: true,
},
branches: {
main: { id: 'main' },
},
},
},
});
jest.spyOn(store, 'dispatch').mockImplementation(() => {});
});
const createComponent = () => {
wrapper = mount(NavDropdown, {
store,
});
};
const findIcon = (name) => wrapper.find(`[data-testid="${name}-icon"]`);
const findMRIcon = () => findIcon('merge-request');
const findNavForm = () => wrapper.find('.ide-nav-form');
const showDropdown = () => {
$(wrapper.vm.$el).trigger('show.bs.dropdown');
};
const hideDropdown = () => {
$(wrapper.vm.$el).trigger('hide.bs.dropdown');
};
describe('default', () => {
beforeEach(() => {
createComponent();
});
it('renders nothing initially', () => {
expect(findNavForm().exists()).toBe(false);
});
it('renders nav form when show.bs.dropdown', async () => {
showDropdown();
await nextTick();
expect(findNavForm().exists()).toBe(true);
});
it('destroys nav form when closed', async () => {
showDropdown();
hideDropdown();
await nextTick();
expect(findNavForm().exists()).toBe(false);
});
it('renders merge request icon', () => {
expect(findMRIcon().exists()).toBe(true);
});
});
describe('when user cannot read merge requests', () => {
beforeEach(() => {
store.state.projects[TEST_PROJECT_ID].userPermissions = {};
createComponent();
});
it('does not render merge requests', () => {
expect(findMRIcon().exists()).toBe(false);
});
});
});
|