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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
import { GlButton, GlDropdown } from '@gitlab/ui';
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
import { mountExtended } from 'helpers/vue_test_utils_helper';
import CsvExportModal from '~/issuable/components/csv_export_modal.vue';
import CsvImportExportButtons from '~/issuable/components/csv_import_export_buttons.vue';
import CsvImportModal from '~/issuable/components/csv_import_modal.vue';
describe('CsvImportExportButtons', () => {
let wrapper;
let glModalDirective;
const exportCsvPath = '/gitlab-org/gitlab-test/-/issues/export_csv';
const issuableCount = 10;
function createComponent(injectedProperties = {}) {
glModalDirective = jest.fn();
return mountExtended(CsvImportExportButtons, {
directives: {
GlTooltip: createMockDirective('gl-tooltip'),
glModal: {
bind(_, { value }) {
glModalDirective(value);
},
},
},
provide: {
...injectedProperties,
},
propsData: {
exportCsvPath,
issuableCount,
},
});
}
afterEach(() => {
wrapper.destroy();
});
const findExportCsvButton = () => wrapper.findComponent(GlButton);
const findImportDropdown = () => wrapper.findComponent(GlDropdown);
const findImportCsvButton = () => wrapper.findByRole('menuitem', { name: 'Import CSV' });
const findImportFromJiraLink = () => wrapper.findByRole('menuitem', { name: 'Import from Jira' });
const findExportCsvModal = () => wrapper.findComponent(CsvExportModal);
const findImportCsvModal = () => wrapper.findComponent(CsvImportModal);
describe('template', () => {
describe('when the showExportButton=true', () => {
beforeEach(() => {
wrapper = createComponent({ showExportButton: true });
});
it('displays the export button', () => {
expect(findExportCsvButton().exists()).toBe(true);
});
it('export button has a tooltip', () => {
const tooltip = getBinding(findExportCsvButton().element, 'gl-tooltip');
expect(tooltip).toBeDefined();
expect(tooltip.value).toBe('Export as CSV');
});
it('renders the export modal', () => {
expect(findExportCsvModal().props()).toMatchObject({ exportCsvPath, issuableCount });
});
it('opens the export modal', () => {
findExportCsvButton().trigger('click');
expect(glModalDirective).toHaveBeenCalledWith(wrapper.vm.exportModalId);
});
});
describe('when the showExportButton=false', () => {
beforeEach(() => {
wrapper = createComponent({ showExportButton: false });
});
it('does not display the export button', () => {
expect(findExportCsvButton().exists()).toBe(false);
});
it('does not render the export modal', () => {
expect(findExportCsvModal().exists()).toBe(false);
});
});
describe('when the showImportButton=true', () => {
beforeEach(() => {
wrapper = createComponent({ showImportButton: true });
});
it('displays the import dropdown', () => {
expect(findImportDropdown().exists()).toBe(true);
});
it('renders the import csv menu item', () => {
expect(findImportCsvButton().exists()).toBe(true);
});
describe('when showLabel=false', () => {
beforeEach(() => {
wrapper = createComponent({ showImportButton: true, showLabel: false });
});
it('hides button text', () => {
expect(findImportDropdown().props()).toMatchObject({
text: 'Import issues',
textSrOnly: true,
});
});
it('import button has a tooltip', () => {
const tooltip = getBinding(findImportDropdown().element, 'gl-tooltip');
expect(tooltip).toBeDefined();
expect(tooltip.value).toBe('Import issues');
});
});
describe('when showLabel=true', () => {
beforeEach(() => {
wrapper = createComponent({ showImportButton: true, showLabel: true });
});
it('displays a button text', () => {
expect(findImportDropdown().props()).toMatchObject({
text: 'Import issues',
textSrOnly: false,
});
});
it('import button has no tooltip', () => {
const tooltip = getBinding(findImportDropdown().element, 'gl-tooltip');
expect(tooltip.value).toBe(null);
});
});
it('renders the import modal', () => {
expect(findImportCsvModal().exists()).toBe(true);
});
it('opens the import modal', () => {
findImportCsvButton().trigger('click');
expect(glModalDirective).toHaveBeenCalledWith(wrapper.vm.importModalId);
});
describe('import from jira link', () => {
const projectImportJiraPath = 'gitlab-org/gitlab-test/-/import/jira';
beforeEach(() => {
wrapper = createComponent({
showImportButton: true,
canEdit: true,
projectImportJiraPath,
});
});
describe('when canEdit=true', () => {
it('renders the import dropdown item', () => {
expect(findImportFromJiraLink().exists()).toBe(true);
});
it('passes the proper path to the link', () => {
expect(findImportFromJiraLink().attributes('href')).toBe(projectImportJiraPath);
});
});
describe('when canEdit=false', () => {
beforeEach(() => {
wrapper = createComponent({ showImportButton: true, canEdit: false });
});
it('does not render the import dropdown item', () => {
expect(findImportFromJiraLink().exists()).toBe(false);
});
});
});
});
describe('when the showImportButton=false', () => {
beforeEach(() => {
wrapper = createComponent({ showImportButton: false });
});
it('does not display the import dropdown', () => {
expect(findImportDropdown().exists()).toBe(false);
});
it('does not render the import modal', () => {
expect(findImportCsvModal().exists()).toBe(false);
});
});
});
});
|