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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
import { GlDropdownDivider, GlDropdownSectionHeader } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import CommitOptionsDropdown from '~/projects/commit/components/commit_options_dropdown.vue';
import { OPEN_REVERT_MODAL, OPEN_CHERRY_PICK_MODAL } from '~/projects/commit/constants';
import eventHub from '~/projects/commit/event_hub';
describe('BranchesDropdown', () => {
let wrapper;
const provide = {
newProjectTagPath: '_new_project_tag_path_',
emailPatchesPath: '_email_patches_path_',
plainDiffPath: '_plain_diff_path_',
};
const createComponent = (props = {}) => {
wrapper = extendedWrapper(
shallowMount(CommitOptionsDropdown, {
provide,
propsData: {
canRevert: true,
canCherryPick: true,
canTag: true,
canEmailPatches: true,
...props,
},
}),
);
};
const findRevertLink = () => wrapper.findByTestId('revert-link');
const findCherryPickLink = () => wrapper.findByTestId('cherry-pick-link');
const findTagItem = () => wrapper.findByTestId('tag-link');
const findEmailPatchesItem = () => wrapper.findByTestId('email-patches-link');
const findPlainDiffItem = () => wrapper.findByTestId('plain-diff-link');
const findDivider = () => wrapper.findComponent(GlDropdownDivider);
const findSectionHeader = () => wrapper.findComponent(GlDropdownSectionHeader);
describe('Everything enabled', () => {
beforeEach(() => {
createComponent();
});
it('has expected dropdown button text', () => {
expect(wrapper.attributes('text')).toBe('Options');
});
it('has expected items', () => {
expect(
[
findRevertLink().exists(),
findCherryPickLink().exists(),
findTagItem().exists(),
findDivider().exists(),
findSectionHeader().exists(),
findEmailPatchesItem().exists(),
findPlainDiffItem().exists(),
].every((exists) => exists),
).toBe(true);
});
it('has expected href links', () => {
expect(findTagItem().attributes('href')).toBe(provide.newProjectTagPath);
expect(findEmailPatchesItem().attributes('href')).toBe(provide.emailPatchesPath);
expect(findPlainDiffItem().attributes('href')).toBe(provide.plainDiffPath);
});
});
describe('Different dropdown item permutations', () => {
it('does not have a revert option', () => {
createComponent({ canRevert: false });
expect(findRevertLink().exists()).toBe(false);
});
it('does not have a cherry-pick option', () => {
createComponent({ canCherryPick: false });
expect(findCherryPickLink().exists()).toBe(false);
});
it('does not have a tag option', () => {
createComponent({ canTag: false });
expect(findTagItem().exists()).toBe(false);
});
it('does not have a email patches options', () => {
createComponent({ canEmailPatches: false });
expect(findEmailPatchesItem().exists()).toBe(false);
});
it('only has the download items', () => {
createComponent({ canRevert: false, canCherryPick: false, canTag: false });
expect(findDivider().exists()).toBe(false);
expect(findEmailPatchesItem().exists()).toBe(true);
expect(findPlainDiffItem().exists()).toBe(true);
});
});
describe('Modal triggering', () => {
let spy;
beforeEach(() => {
spy = jest.spyOn(eventHub, '$emit');
createComponent();
});
it('emits openModal for revert', () => {
findRevertLink().vm.$emit('click');
expect(spy).toHaveBeenCalledWith(OPEN_REVERT_MODAL);
});
it('emits openModal for cherry-pick', () => {
findCherryPickLink().vm.$emit('click');
expect(spy).toHaveBeenCalledWith(OPEN_CHERRY_PICK_MODAL);
});
});
});
|