@saooti/octopus-sdk 42.0.0-beta → 42.0.0-beta2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/eslint-config.d.ts +3 -0
- package/eslint-config.mjs +54 -0
- package/package.json +5 -2
- package/tests/api/podcastApi.spec.ts +43 -0
- package/tests/api/transcriptionApi.spec.ts +58 -0
- package/tests/components/composable/player/usePlayerTranscript.spec.ts +238 -0
- package/tests/components/composable/useAdvancedParamInit.spec.ts +91 -0
- package/tests/components/composable/usePresentationItem.spec.ts +164 -0
- package/tests/components/composable/useRights.spec.ts +838 -0
- package/tests/components/composable/useSeasonsManagement.spec.ts +35 -0
- package/tests/components/composable/useTranslation.spec.ts +209 -0
- package/tests/components/display/RightsIndicator.spec.ts +481 -0
- package/tests/components/display/comments/item/CommentMoreActions.spec.ts +75 -0
- package/tests/components/display/comments/modal/RecaptchaModal.spec.ts +43 -0
- package/tests/components/display/emission/EmissionItem.spec.ts +54 -0
- package/tests/components/display/emission/EmissionPresentationItem.spec.ts +46 -0
- package/tests/components/display/filter/AdvancedSearch.spec.ts +187 -0
- package/tests/components/display/podcasts/PodcastFilterList.spec.ts +34 -0
- package/tests/components/display/podcasts/PodcastInlineListTemplate.spec.ts +24 -0
- package/tests/components/display/podcasts/PodcastItemInfo.spec.ts +99 -0
- package/tests/components/display/podcasts/PodcastModuleBox.spec.ts +279 -0
- package/tests/components/display/podcasts/PodcastPresentationList.spec.ts +108 -0
- package/tests/components/display/podcasts/PodcastRawTranscript.spec.ts +254 -0
- package/tests/components/display/sharing/ShareNewsletter.spec.ts +68 -0
- package/tests/components/display/sharing/SharePlayer.spec.ts +59 -0
- package/tests/components/display/sharing/SharePlayerRadio.spec.ts +55 -0
- package/tests/components/form/ClassicButtonGroup.spec.ts +78 -0
- package/tests/components/form/ClassicInputText.spec.ts +24 -0
- package/tests/components/form/OctopusMultiselect.spec.ts +506 -0
- package/tests/components/form/OctopusSelect.spec.ts +240 -0
- package/tests/components/layouts/PresentationItem.spec.ts +37 -0
- package/tests/components/misc/ClassicAvatar.spec.ts +68 -0
- package/tests/components/misc/ClassicPopover.spec.ts +260 -0
- package/tests/components/misc/FooterSection.spec.ts +49 -0
- package/tests/components/misc/HomeDropdown.spec.ts +44 -0
- package/tests/components/misc/modal/ClipboardModal.spec.ts +51 -0
- package/tests/components/misc/player/PlayerLarge.spec.ts +72 -0
- package/tests/components/pages/EmissionPage.spec.ts +253 -0
- package/tests/components/pages/EmissionsPage.spec.ts +18 -0
- package/tests/components/pages/ParticipantPage.spec.ts +65 -0
- package/tests/components/pages/PlaylistPage.spec.ts +60 -0
- package/tests/components/pages/PodcastPage.spec.ts +89 -0
- package/tests/components/pages/PodcastsPage.spec.ts +18 -0
- package/tests/components/pages/RadioPage.spec.ts +65 -0
- package/tests/components/pages/SmartLinkPage.spec.ts +90 -0
- package/tests/helper/language.spec.ts +45 -0
- package/tests/index.ts +9 -0
- package/tests/localisation.ts +10 -0
- package/tests/mocks/i18n.ts +13 -0
- package/tests/mocks/index.ts +11 -0
- package/tests/mocks/rights.ts +17 -0
- package/tests/mocks/useAdvancedParamInit.ts +22 -0
- package/tests/mocks/useRouter.ts +11 -0
- package/tests/stores/CacheStore.spec.ts +110 -0
- package/tests/utils.ts +178 -0
|
@@ -0,0 +1,506 @@
|
|
|
1
|
+
import { mockI18n } from '@tests/mocks';
|
|
2
|
+
vi.mock('vue-i18n', () => mockI18n());
|
|
3
|
+
|
|
4
|
+
import OctopusMultiselect from '@/components/form/OctopusMultiselect.vue';
|
|
5
|
+
import { DOMWrapper, type VueWrapper } from '@vue/test-utils';
|
|
6
|
+
import { mount } from '@tests/utils';
|
|
7
|
+
import { nextTick } from 'vue';
|
|
8
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
9
|
+
|
|
10
|
+
const options = [
|
|
11
|
+
{ id: 1, name: 'Alpha' },
|
|
12
|
+
{ id: 2, name: 'Beta' },
|
|
13
|
+
{ id: 3, name: 'Gamma' },
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
// The dropdown is teleported to .octopus-app — helper to query it from the document.
|
|
17
|
+
function getDropdown(): Element | null {
|
|
18
|
+
return document.body.querySelector('.octopus-multiselect-dropdown');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function getOptionLabels(): (string | undefined)[] {
|
|
22
|
+
return Array.from(document.body.querySelectorAll('.octopus-multiselect-options label'))
|
|
23
|
+
.map((l) => l.textContent?.trim());
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Simulates a click outside the component to trigger onClickOutside's closeDropdown.
|
|
27
|
+
async function clickOutside(): Promise<void> {
|
|
28
|
+
const outsideElement = document.createElement('div');
|
|
29
|
+
document.body.appendChild(outsideElement);
|
|
30
|
+
outsideElement.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true }));
|
|
31
|
+
await nextTick();
|
|
32
|
+
document.body.removeChild(outsideElement);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
describe('OctopusMultiselect', () => {
|
|
36
|
+
// The dropdown teleports to .octopus-app, which is normally the app root (see App.vue).
|
|
37
|
+
// It doesn't exist in the test DOM, so it must be created before mount.
|
|
38
|
+
let appElement: HTMLElement;
|
|
39
|
+
|
|
40
|
+
beforeEach(() => {
|
|
41
|
+
appElement = document.createElement('div');
|
|
42
|
+
appElement.className = 'octopus-app';
|
|
43
|
+
document.body.appendChild(appElement);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Shared wrapper ref so afterEach can properly unmount it.
|
|
47
|
+
// Proper unmount lets Vue clean up the teleport target before the next test starts.
|
|
48
|
+
let wrapper: VueWrapper;
|
|
49
|
+
afterEach(() => {
|
|
50
|
+
wrapper?.unmount();
|
|
51
|
+
appElement.remove();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('renders label when provided', async () => {
|
|
55
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
56
|
+
props: { options, optionLabel: 'name', label: 'My label' },
|
|
57
|
+
});
|
|
58
|
+
expect(wrapper.find('label.form-label').text()).toBe('My label');
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('does not render label when not provided', async () => {
|
|
62
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
63
|
+
props: { options, optionLabel: 'name' },
|
|
64
|
+
});
|
|
65
|
+
expect(wrapper.find('label.form-label').exists()).toBe(false);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('opens dropdown on input focus', async () => {
|
|
69
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
70
|
+
props: { options, optionLabel: 'name' },
|
|
71
|
+
});
|
|
72
|
+
expect(getDropdown()).toBeNull();
|
|
73
|
+
await wrapper.find('input').trigger('focus');
|
|
74
|
+
expect(getDropdown()).not.toBeNull();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('shows "All" checkbox and one checkbox per option when open', async () => {
|
|
78
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
79
|
+
props: { options, optionLabel: 'name' },
|
|
80
|
+
});
|
|
81
|
+
await wrapper.find('input').trigger('focus');
|
|
82
|
+
const checkboxes = document.body.querySelectorAll('input[type="checkbox"]');
|
|
83
|
+
// 1 for "All" + 3 for options
|
|
84
|
+
expect(checkboxes).toHaveLength(4);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('filters options locally by search query', async () => {
|
|
88
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
89
|
+
props: { options, optionLabel: 'name' },
|
|
90
|
+
});
|
|
91
|
+
await wrapper.find('input').trigger('focus');
|
|
92
|
+
await wrapper.find('input').setValue('al');
|
|
93
|
+
await wrapper.find('input').trigger('input');
|
|
94
|
+
const checkboxes = document.body.querySelectorAll('input[type="checkbox"]');
|
|
95
|
+
// 1 for "All" + 1 matching "Alpha"
|
|
96
|
+
expect(checkboxes).toHaveLength(2);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('shows no-results message when filter matches nothing', async () => {
|
|
100
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
101
|
+
props: { options, optionLabel: 'name' },
|
|
102
|
+
});
|
|
103
|
+
await wrapper.find('input').trigger('focus');
|
|
104
|
+
await wrapper.find('input').setValue('zzz');
|
|
105
|
+
await wrapper.find('input').trigger('input');
|
|
106
|
+
expect(document.body.querySelector('.text-indic')).not.toBeNull();
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('calls onSearch with current query and updates displayed options', async () => {
|
|
110
|
+
const searchResult = [{ id: 4, name: 'Delta' }];
|
|
111
|
+
const onSearch = vi.fn().mockResolvedValue(searchResult);
|
|
112
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
113
|
+
props: { options, optionLabel: 'name', onSearch },
|
|
114
|
+
});
|
|
115
|
+
await wrapper.find('input').trigger('focus');
|
|
116
|
+
await wrapper.find('input').setValue('del');
|
|
117
|
+
await wrapper.find('input').trigger('input');
|
|
118
|
+
await vi.dynamicImportSettled();
|
|
119
|
+
expect(onSearch).toHaveBeenCalledWith('del');
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('emits update:selected when toggling a single option', async () => {
|
|
123
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
124
|
+
props: { options, optionLabel: 'name', selected: [] },
|
|
125
|
+
});
|
|
126
|
+
await wrapper.find('input').trigger('focus');
|
|
127
|
+
const optionCheckboxes = document.body.querySelectorAll('.octopus-multiselect-options input[type="checkbox"]');
|
|
128
|
+
await new DOMWrapper(optionCheckboxes[0] as Element).trigger('input');
|
|
129
|
+
expect(wrapper.emitted('update:selected')?.[0]).toEqual([[options[0]]]);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('deselects an already-selected option', async () => {
|
|
133
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
134
|
+
props: { options, optionLabel: 'name', selected: [options[0]] },
|
|
135
|
+
});
|
|
136
|
+
await wrapper.find('input').trigger('focus');
|
|
137
|
+
const optionCheckboxes = document.body.querySelectorAll('.octopus-multiselect-options input[type="checkbox"]');
|
|
138
|
+
await new DOMWrapper(optionCheckboxes[0] as Element).trigger('input');
|
|
139
|
+
expect(wrapper.emitted('update:selected')?.[0]).toEqual([[]]);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('toggleAll selects all displayed options', async () => {
|
|
143
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
144
|
+
props: { options, optionLabel: 'name', selected: [] },
|
|
145
|
+
});
|
|
146
|
+
await wrapper.find('input').trigger('focus');
|
|
147
|
+
const allCheckbox = document.body.querySelector('.octopus-multiselect-dropdown > .octopus-form-item input[type="checkbox"]')!;
|
|
148
|
+
await new DOMWrapper(allCheckbox).trigger('input');
|
|
149
|
+
const emitted = wrapper.emitted('update:selected')?.[0]?.[0] as unknown[];
|
|
150
|
+
expect(emitted).toHaveLength(3);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it('toggleAll deselects all displayed options when all are selected', async () => {
|
|
154
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
155
|
+
props: { options, optionLabel: 'name', selected: [...options] },
|
|
156
|
+
});
|
|
157
|
+
await wrapper.find('input').trigger('focus');
|
|
158
|
+
const allCheckbox = document.body.querySelector('.octopus-multiselect-dropdown > .octopus-form-item input[type="checkbox"]')!;
|
|
159
|
+
await new DOMWrapper(allCheckbox).trigger('input');
|
|
160
|
+
expect(wrapper.emitted('update:selected')?.[0]).toEqual([[]]);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('shows selected items in the selection display', async () => {
|
|
164
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
165
|
+
props: { options, optionLabel: 'name', selected: [options[0], options[1]] },
|
|
166
|
+
});
|
|
167
|
+
expect(wrapper.find('.octopus-multiselect-selection-text').text()).toBe('Alpha, Beta');
|
|
168
|
+
expect(wrapper.find('.octopus-multiselect-selection-count').exists()).toBe(false);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('shows overflow count badge when more than visible items are selected', async () => {
|
|
172
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
173
|
+
props: { options, optionLabel: 'name', selected: [...options] },
|
|
174
|
+
});
|
|
175
|
+
expect(wrapper.find('.octopus-multiselect-selection-count').exists()).toBe(true);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('disables input when isDisabled is true', async () => {
|
|
179
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
180
|
+
props: { options, optionLabel: 'name', isDisabled: true },
|
|
181
|
+
});
|
|
182
|
+
expect(wrapper.find('input').attributes('disabled')).toBeDefined();
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('does not open dropdown when disabled', async () => {
|
|
186
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
187
|
+
props: { options, optionLabel: 'name', isDisabled: true },
|
|
188
|
+
});
|
|
189
|
+
await wrapper.find('input').trigger('focus');
|
|
190
|
+
expect(getDropdown()).toBeNull();
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('uses selectAllText as the "All" checkbox label when provided', async () => {
|
|
194
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
195
|
+
props: { options, optionLabel: 'name', selectAllText: 'Tout' },
|
|
196
|
+
});
|
|
197
|
+
await wrapper.find('input').trigger('focus');
|
|
198
|
+
const allCheckboxLabel = document.body.querySelector('.octopus-multiselect-dropdown > .octopus-form-item label')!;
|
|
199
|
+
expect(allCheckboxLabel.textContent?.trim()).toBe('Tout');
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it('deselects by optionKey even when selected objects are different references', async () => {
|
|
203
|
+
const selected = [{ id: 1, name: 'Alpha' }];
|
|
204
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
205
|
+
props: { options, optionLabel: 'name', optionKey: 'id', selected },
|
|
206
|
+
});
|
|
207
|
+
await wrapper.find('input').trigger('focus');
|
|
208
|
+
const optionCheckboxes = document.body.querySelectorAll('.octopus-multiselect-options input[type="checkbox"]');
|
|
209
|
+
await new DOMWrapper(optionCheckboxes[0] as Element).trigger('input');
|
|
210
|
+
expect(wrapper.emitted('update:selected')?.[0]).toEqual([[]]);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it('toggleAll deselects by optionKey even when selected objects are different references', async () => {
|
|
214
|
+
const selected = options.map((o) => ({ ...o }));
|
|
215
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
216
|
+
props: { options, optionLabel: 'name', optionKey: 'id', selected },
|
|
217
|
+
});
|
|
218
|
+
await wrapper.find('input').trigger('focus');
|
|
219
|
+
const allCheckbox = document.body.querySelector('.octopus-multiselect-dropdown > .octopus-form-item input[type="checkbox"]')!;
|
|
220
|
+
await new DOMWrapper(allCheckbox).trigger('input');
|
|
221
|
+
expect(wrapper.emitted('update:selected')?.[0]).toEqual([[]]);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
describe('pullSelectedToTop', () => {
|
|
225
|
+
it('does not reorder options when pullSelectedToTop is not set', async () => {
|
|
226
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
227
|
+
props: { options, optionLabel: 'name', selected: [options[1]] },
|
|
228
|
+
});
|
|
229
|
+
await wrapper.find('input').trigger('focus');
|
|
230
|
+
expect(getOptionLabels()).toEqual(['Alpha', 'Beta', 'Gamma']);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it('moves the selected option to the top when pullSelectedToTop is true', async () => {
|
|
234
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
235
|
+
props: { options, optionLabel: 'name', selected: [options[1]], pullSelectedToTop: true },
|
|
236
|
+
});
|
|
237
|
+
await wrapper.find('input').trigger('focus');
|
|
238
|
+
expect(getOptionLabels()).toEqual(['Beta', 'Alpha', 'Gamma']);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it('preserves relative order within pinned and unpinned groups', async () => {
|
|
242
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
243
|
+
props: { options, optionLabel: 'name', selected: [options[2], options[0]], pullSelectedToTop: true },
|
|
244
|
+
});
|
|
245
|
+
await wrapper.find('input').trigger('focus');
|
|
246
|
+
expect(getOptionLabels()).toEqual(['Alpha', 'Gamma', 'Beta']);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it('does not reorder while the dropdown stays open as selection changes', async () => {
|
|
250
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
251
|
+
props: { options, optionLabel: 'name', selected: [], pullSelectedToTop: true },
|
|
252
|
+
});
|
|
253
|
+
await wrapper.find('input').trigger('focus');
|
|
254
|
+
const optionCheckboxes = document.body.querySelectorAll('.octopus-multiselect-options input[type="checkbox"]');
|
|
255
|
+
await new DOMWrapper(optionCheckboxes[2] as Element).trigger('input');
|
|
256
|
+
await wrapper.setProps({ selected: [options[2]] });
|
|
257
|
+
expect(getOptionLabels()).toEqual(['Alpha', 'Beta', 'Gamma']);
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it('re-pins using the latest selection after closing and reopening', async () => {
|
|
261
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
262
|
+
props: { options, optionLabel: 'name', selected: [options[2]], pullSelectedToTop: true },
|
|
263
|
+
});
|
|
264
|
+
await wrapper.find('input').trigger('focus');
|
|
265
|
+
await clickOutside();
|
|
266
|
+
await wrapper.find('input').trigger('focus');
|
|
267
|
+
expect(getOptionLabels()).toEqual(['Gamma', 'Alpha', 'Beta']);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it('pins by optionKey even when selected objects are different references', async () => {
|
|
271
|
+
const selected = [{ id: 2, name: 'Beta' }];
|
|
272
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
273
|
+
props: { options, optionLabel: 'name', optionKey: 'id', selected, pullSelectedToTop: true },
|
|
274
|
+
});
|
|
275
|
+
await wrapper.find('input').trigger('focus');
|
|
276
|
+
expect(getOptionLabels()).toEqual(['Beta', 'Alpha', 'Gamma']);
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it('still respects the active search filter when pinning', async () => {
|
|
280
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
281
|
+
props: { options, optionLabel: 'name', selected: [options[2]], pullSelectedToTop: true },
|
|
282
|
+
});
|
|
283
|
+
await wrapper.find('input').trigger('focus');
|
|
284
|
+
await wrapper.find('input').setValue('be');
|
|
285
|
+
await wrapper.find('input').trigger('input');
|
|
286
|
+
expect(getOptionLabels()).toEqual(['Beta']);
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
it('keeps a selected custom value pinned alongside allowCustomValue', async () => {
|
|
290
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
291
|
+
props: {
|
|
292
|
+
options: ['Alpha', 'Beta', 'Gamma'],
|
|
293
|
+
selected: ['Delta'],
|
|
294
|
+
allowCustomValue: true,
|
|
295
|
+
pullSelectedToTop: true,
|
|
296
|
+
},
|
|
297
|
+
});
|
|
298
|
+
await wrapper.find('input').trigger('focus');
|
|
299
|
+
expect(getOptionLabels()).toEqual(['Delta', 'Alpha', 'Beta', 'Gamma']);
|
|
300
|
+
});
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
describe('with string options', () => {
|
|
304
|
+
const stringOptions = ['Alpha', 'Beta', 'Gamma'];
|
|
305
|
+
|
|
306
|
+
it('uses each string as its own label without optionLabel', async () => {
|
|
307
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
308
|
+
props: { options: stringOptions },
|
|
309
|
+
});
|
|
310
|
+
await wrapper.find('input').trigger('focus');
|
|
311
|
+
const labels = document.body.querySelectorAll('.octopus-multiselect-options label');
|
|
312
|
+
expect(Array.from(labels).map((l) => l.textContent?.trim())).toEqual(stringOptions);
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it('emits update:selected when toggling a string option', async () => {
|
|
316
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
317
|
+
props: { options: stringOptions, selected: [] },
|
|
318
|
+
});
|
|
319
|
+
await wrapper.find('input').trigger('focus');
|
|
320
|
+
const optionCheckboxes = document.body.querySelectorAll('.octopus-multiselect-options input[type="checkbox"]');
|
|
321
|
+
await new DOMWrapper(optionCheckboxes[0] as Element).trigger('input');
|
|
322
|
+
expect(wrapper.emitted('update:selected')?.[0]).toEqual([['Alpha']]);
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
it('deselects an already-selected string option', async () => {
|
|
326
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
327
|
+
props: { options: stringOptions, selected: ['Alpha'] },
|
|
328
|
+
});
|
|
329
|
+
await wrapper.find('input').trigger('focus');
|
|
330
|
+
const optionCheckboxes = document.body.querySelectorAll('.octopus-multiselect-options input[type="checkbox"]');
|
|
331
|
+
await new DOMWrapper(optionCheckboxes[0] as Element).trigger('input');
|
|
332
|
+
expect(wrapper.emitted('update:selected')?.[0]).toEqual([[]]);
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
it('filters string options locally by search query', async () => {
|
|
336
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
337
|
+
props: { options: stringOptions },
|
|
338
|
+
});
|
|
339
|
+
await wrapper.find('input').trigger('focus');
|
|
340
|
+
await wrapper.find('input').setValue('al');
|
|
341
|
+
await wrapper.find('input').trigger('input');
|
|
342
|
+
const checkboxes = document.body.querySelectorAll('.octopus-multiselect-options input[type="checkbox"]');
|
|
343
|
+
expect(checkboxes).toHaveLength(1);
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
it('toggleAll selects all displayed string options', async () => {
|
|
347
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
348
|
+
props: { options: stringOptions, selected: [] },
|
|
349
|
+
});
|
|
350
|
+
await wrapper.find('input').trigger('focus');
|
|
351
|
+
const allCheckbox = document.body.querySelector('.octopus-multiselect-dropdown > .octopus-form-item input[type="checkbox"]')!;
|
|
352
|
+
await new DOMWrapper(allCheckbox).trigger('input');
|
|
353
|
+
expect(wrapper.emitted('update:selected')?.[0]).toEqual([stringOptions]);
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
it('shows selected strings in the selection display', async () => {
|
|
357
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
358
|
+
props: { options: stringOptions, selected: ['Alpha', 'Beta'] },
|
|
359
|
+
});
|
|
360
|
+
expect(wrapper.find('.octopus-multiselect-selection-text').text()).toBe('Alpha, Beta');
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
it('adds typed value as a new selection on Enter when allowCustomValue is true', async () => {
|
|
364
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
365
|
+
props: { options: stringOptions, selected: [], allowCustomValue: true },
|
|
366
|
+
});
|
|
367
|
+
await wrapper.find('input').trigger('focus');
|
|
368
|
+
await wrapper.find('input').setValue('Delta');
|
|
369
|
+
await wrapper.find('input').trigger('keydown.enter');
|
|
370
|
+
expect(wrapper.emitted('update:selected')?.[0]).toEqual([['Delta']]);
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
it('does not add typed value on Enter when allowCustomValue is not set', async () => {
|
|
374
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
375
|
+
props: { options: stringOptions, selected: [] },
|
|
376
|
+
});
|
|
377
|
+
await wrapper.find('input').trigger('focus');
|
|
378
|
+
await wrapper.find('input').setValue('Delta');
|
|
379
|
+
await wrapper.find('input').trigger('keydown.enter');
|
|
380
|
+
expect(wrapper.emitted('update:selected')).toBeUndefined();
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
it('does not add an empty or whitespace-only value on Enter', async () => {
|
|
384
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
385
|
+
props: { options: stringOptions, selected: [], allowCustomValue: true },
|
|
386
|
+
});
|
|
387
|
+
await wrapper.find('input').trigger('focus');
|
|
388
|
+
await wrapper.find('input').setValue(' ');
|
|
389
|
+
await wrapper.find('input').trigger('keydown.enter');
|
|
390
|
+
expect(wrapper.emitted('update:selected')).toBeUndefined();
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
it('does not duplicate an already-selected value on Enter', async () => {
|
|
394
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
395
|
+
props: { options: stringOptions, selected: ['Alpha'], allowCustomValue: true },
|
|
396
|
+
});
|
|
397
|
+
await wrapper.find('input').trigger('focus');
|
|
398
|
+
await wrapper.find('input').setValue('Alpha');
|
|
399
|
+
await wrapper.find('input').trigger('keydown.enter');
|
|
400
|
+
expect(wrapper.emitted('update:selected')).toBeUndefined();
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
it('clears the search input after adding a custom value on Enter', async () => {
|
|
404
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
405
|
+
props: { options: stringOptions, selected: [], allowCustomValue: true },
|
|
406
|
+
});
|
|
407
|
+
await wrapper.find('input').trigger('focus');
|
|
408
|
+
await wrapper.find('input').setValue('Delta');
|
|
409
|
+
await wrapper.find('input').trigger('keydown.enter');
|
|
410
|
+
expect((wrapper.find('input').element as HTMLInputElement).value).toBe('');
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
it('shows a previously added custom value as a checked option in the dropdown', async () => {
|
|
414
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
415
|
+
props: { options: stringOptions, selected: ['Delta'], allowCustomValue: true },
|
|
416
|
+
});
|
|
417
|
+
await wrapper.find('input').trigger('focus');
|
|
418
|
+
const labels = Array.from(document.body.querySelectorAll('.octopus-multiselect-options label'))
|
|
419
|
+
.map((l) => l.textContent?.trim());
|
|
420
|
+
expect(labels).toContain('Delta');
|
|
421
|
+
const checkboxes = document.body.querySelectorAll('.octopus-multiselect-options input[type="checkbox"]');
|
|
422
|
+
expect((checkboxes[labels.indexOf('Delta')] as HTMLInputElement).checked).toBe(true);
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
it('shows the checkbox for a value right after it is added via Enter', async () => {
|
|
426
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
427
|
+
props: { options: stringOptions, selected: [], allowCustomValue: true },
|
|
428
|
+
});
|
|
429
|
+
await wrapper.find('input').trigger('focus');
|
|
430
|
+
await wrapper.find('input').setValue('Delta');
|
|
431
|
+
await wrapper.find('input').trigger('keydown.enter');
|
|
432
|
+
const emittedSelected = wrapper.emitted('update:selected')?.[0]?.[0] as string[];
|
|
433
|
+
await wrapper.setProps({ selected: emittedSelected });
|
|
434
|
+
const labels = Array.from(document.body.querySelectorAll('.octopus-multiselect-options label'))
|
|
435
|
+
.map((l) => l.textContent?.trim());
|
|
436
|
+
expect(labels).toContain('Delta');
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
it('does not show out-of-options selected values in the dropdown when allowCustomValue is not set', async () => {
|
|
440
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
441
|
+
props: { options: stringOptions, selected: ['Delta'] },
|
|
442
|
+
});
|
|
443
|
+
await wrapper.find('input').trigger('focus');
|
|
444
|
+
const labels = Array.from(document.body.querySelectorAll('.octopus-multiselect-options label'))
|
|
445
|
+
.map((l) => l.textContent?.trim());
|
|
446
|
+
expect(labels).not.toContain('Delta');
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
it('deselects a custom value when its checkbox in the dropdown is toggled off', async () => {
|
|
450
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
451
|
+
props: { options: stringOptions, selected: ['Alpha', 'Delta'], allowCustomValue: true },
|
|
452
|
+
});
|
|
453
|
+
await wrapper.find('input').trigger('focus');
|
|
454
|
+
const checkboxes = document.body.querySelectorAll('.octopus-multiselect-options input[type="checkbox"]');
|
|
455
|
+
// visibleOptions = [Alpha, Beta, Gamma, Delta] — Delta is the appended custom entry
|
|
456
|
+
await new DOMWrapper(checkboxes[3] as Element).trigger('input');
|
|
457
|
+
expect(wrapper.emitted('update:selected')?.[0]).toEqual([['Alpha']]);
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
it('toggleAll includes an already-selected custom value shown in the dropdown', async () => {
|
|
461
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
462
|
+
props: { options: stringOptions, selected: ['Delta'], allowCustomValue: true },
|
|
463
|
+
});
|
|
464
|
+
await wrapper.find('input').trigger('focus');
|
|
465
|
+
const allCheckbox = document.body.querySelector('.octopus-multiselect-dropdown > .octopus-form-item input[type="checkbox"]')!;
|
|
466
|
+
await new DOMWrapper(allCheckbox).trigger('input');
|
|
467
|
+
const emitted = wrapper.emitted('update:selected')?.[0]?.[0] as string[];
|
|
468
|
+
expect(emitted).toHaveLength(4);
|
|
469
|
+
expect(emitted).toEqual(expect.arrayContaining(['Alpha', 'Beta', 'Gamma', 'Delta']));
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
it('shows a hint to press Enter when allowCustomValue is true and text is typed', async () => {
|
|
473
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
474
|
+
props: { options: stringOptions, allowCustomValue: true },
|
|
475
|
+
});
|
|
476
|
+
await wrapper.find('input').trigger('focus');
|
|
477
|
+
await wrapper.find('input').setValue('Delta');
|
|
478
|
+
await wrapper.find('input').trigger('input');
|
|
479
|
+
const hints = Array.from(document.body.querySelectorAll('.octopus-multiselect-options .text-indic'))
|
|
480
|
+
.map((el) => el.textContent?.trim());
|
|
481
|
+
expect(hints).toContain('Press Enter to add this value');
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
it('does not show the Enter hint when allowCustomValue is not set', async () => {
|
|
485
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
486
|
+
props: { options: stringOptions },
|
|
487
|
+
});
|
|
488
|
+
await wrapper.find('input').trigger('focus');
|
|
489
|
+
await wrapper.find('input').setValue('Delta');
|
|
490
|
+
await wrapper.find('input').trigger('input');
|
|
491
|
+
const hints = Array.from(document.body.querySelectorAll('.octopus-multiselect-options .text-indic'))
|
|
492
|
+
.map((el) => el.textContent?.trim());
|
|
493
|
+
expect(hints).not.toContain('Press Enter to add this value');
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
it('does not show the Enter hint when the search input is empty', async () => {
|
|
497
|
+
wrapper = await mount(OctopusMultiselect, {
|
|
498
|
+
props: { options: stringOptions, allowCustomValue: true },
|
|
499
|
+
});
|
|
500
|
+
await wrapper.find('input').trigger('focus');
|
|
501
|
+
const hints = Array.from(document.body.querySelectorAll('.octopus-multiselect-options .text-indic'))
|
|
502
|
+
.map((el) => el.textContent?.trim());
|
|
503
|
+
expect(hints).not.toContain('Press Enter to add this value');
|
|
504
|
+
});
|
|
505
|
+
});
|
|
506
|
+
});
|