@saooti/octopus-sdk 41.12.0-beta → 41.12.0-beta3

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