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
|
import { GlSearchBoxByType } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import DropdownHeader from '~/vue_shared/components/sidebar/labels_select_widget/dropdown_header.vue';
describe('DropdownHeader', () => {
let wrapper;
const createComponent = ({
showDropdownContentsCreateView = false,
labelsFetchInProgress = false,
isStandalone = false,
} = {}) => {
wrapper = extendedWrapper(
shallowMount(DropdownHeader, {
propsData: {
showDropdownContentsCreateView,
labelsFetchInProgress,
labelsCreateTitle: 'Create label',
labelsListTitle: 'Select label',
searchKey: '',
isStandalone,
},
stubs: {
GlSearchBoxByType,
},
}),
);
};
afterEach(() => {
wrapper.destroy();
});
const findSearchInput = () => wrapper.findComponent(GlSearchBoxByType);
const findGoBackButton = () => wrapper.findByTestId('go-back-button');
const findDropdownTitle = () => wrapper.findByTestId('dropdown-header-title');
beforeEach(() => {
createComponent();
});
describe('Create view', () => {
beforeEach(() => {
createComponent({ showDropdownContentsCreateView: true });
});
it('renders go back button', () => {
expect(findGoBackButton().exists()).toBe(true);
});
it('does not render search input field', async () => {
expect(findSearchInput().exists()).toBe(false);
});
});
describe('Labels view', () => {
beforeEach(() => {
createComponent();
});
it('does not render go back button', () => {
expect(findGoBackButton().exists()).toBe(false);
});
it.each`
labelsFetchInProgress | disabled
${true} | ${true}
${false} | ${false}
`(
'when labelsFetchInProgress is $labelsFetchInProgress, renders search input with disabled prop to $disabled',
({ labelsFetchInProgress, disabled }) => {
createComponent({ labelsFetchInProgress });
expect(findSearchInput().props('disabled')).toBe(disabled);
},
);
});
describe('Standalone variant', () => {
beforeEach(() => {
createComponent({ isStandalone: true });
});
it('renders search input', () => {
expect(findSearchInput().exists()).toBe(true);
});
it('does not render title', async () => {
expect(findDropdownTitle().exists()).toBe(false);
});
});
});
|