vueless 1.3.7-beta.1 → 1.3.7-beta.3
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/components.d.ts +1 -0
- package/components.ts +1 -0
- package/constants.d.ts +2 -0
- package/constants.js +2 -0
- package/package.json +2 -2
- package/ui.container-col/UCol.vue +0 -1
- package/ui.container-collapsible/UCollapsible.vue +190 -0
- package/ui.container-collapsible/config.ts +45 -0
- package/ui.container-collapsible/constants.ts +1 -0
- package/ui.container-collapsible/storybook/docs.mdx +17 -0
- package/ui.container-collapsible/storybook/stories.ts +261 -0
- package/ui.container-collapsible/tests/UCollapsible.test.ts +571 -0
- package/ui.container-collapsible/types.ts +57 -0
- package/ui.dropdown/UDropdown.vue +324 -0
- package/ui.dropdown/config.ts +27 -0
- package/ui.dropdown/constants.ts +1 -0
- package/ui.dropdown/storybook/docs.mdx +17 -0
- package/ui.dropdown/storybook/stories.ts +286 -0
- package/ui.dropdown/tests/UDropdown.test.ts +631 -0
- package/ui.dropdown/types.ts +127 -0
- package/ui.dropdown-badge/UDropdownBadge.vue +119 -227
- package/ui.dropdown-badge/config.ts +18 -15
- package/ui.dropdown-badge/tests/UDropdownBadge.test.ts +201 -67
- package/ui.dropdown-button/UDropdownButton.vue +121 -226
- package/ui.dropdown-button/config.ts +32 -28
- package/ui.dropdown-button/tests/UDropdownButton.test.ts +189 -73
- package/ui.dropdown-link/UDropdownLink.vue +123 -233
- package/ui.dropdown-link/config.ts +15 -18
- package/ui.dropdown-link/tests/UDropdownLink.test.ts +190 -71
- package/ui.form-listbox/UListbox.vue +2 -3
- package/ui.form-listbox/config.ts +2 -2
- package/ui.form-select/config.ts +1 -1
- package/utils/node/helper.js +6 -5
|
@@ -0,0 +1,631 @@
|
|
|
1
|
+
import { mount } from "@vue/test-utils";
|
|
2
|
+
import { describe, it, expect } from "vitest";
|
|
3
|
+
import { nextTick } from "vue";
|
|
4
|
+
|
|
5
|
+
import UDropdown from "../UDropdown.vue";
|
|
6
|
+
import UListbox from "../../ui.form-listbox/UListbox.vue";
|
|
7
|
+
|
|
8
|
+
describe("UDropdown.vue", () => {
|
|
9
|
+
const defaultOptions = [
|
|
10
|
+
{ value: 1, label: "Option 1" },
|
|
11
|
+
{ value: 2, label: "Option 2" },
|
|
12
|
+
{ value: 3, label: "Option 3" },
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
describe("Props", () => {
|
|
16
|
+
it("ModelValue – selects the correct option based on modelValue", async () => {
|
|
17
|
+
const modelValue = 2;
|
|
18
|
+
|
|
19
|
+
const component = mount(UDropdown, {
|
|
20
|
+
props: {
|
|
21
|
+
modelValue,
|
|
22
|
+
options: defaultOptions,
|
|
23
|
+
},
|
|
24
|
+
slots: {
|
|
25
|
+
default: `<button>Trigger</button>`,
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
expect(component.vm.selectedOptions[0]?.value).toBe(modelValue);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("Multiple – handles multiple selections correctly", async () => {
|
|
33
|
+
const modelValue = [1, 3];
|
|
34
|
+
|
|
35
|
+
const component = mount(UDropdown, {
|
|
36
|
+
props: {
|
|
37
|
+
modelValue,
|
|
38
|
+
multiple: true,
|
|
39
|
+
options: defaultOptions,
|
|
40
|
+
},
|
|
41
|
+
slots: {
|
|
42
|
+
default: `<button>Trigger</button>`,
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
expect(component.vm.selectedOptions.length).toBe(2);
|
|
47
|
+
expect(component.vm.selectedOptions[0]?.value).toBe(1);
|
|
48
|
+
expect(component.vm.selectedOptions[1]?.value).toBe(3);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("Disabled – applies disabled state correctly", async () => {
|
|
52
|
+
const component = mount(UDropdown, {
|
|
53
|
+
props: {
|
|
54
|
+
disabled: true,
|
|
55
|
+
options: defaultOptions,
|
|
56
|
+
dataTest: "dropdown",
|
|
57
|
+
},
|
|
58
|
+
slots: {
|
|
59
|
+
default: `<button>Click me</button>`,
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const collapsible = component.findComponent({ name: "UCollapsible" });
|
|
64
|
+
|
|
65
|
+
expect(collapsible.props("disabled")).toBe(true);
|
|
66
|
+
|
|
67
|
+
await component.find("button").trigger("click");
|
|
68
|
+
await nextTick();
|
|
69
|
+
|
|
70
|
+
expect(component.findComponent(UListbox).exists()).toBe(false);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("Searchable – renders searchable dropdown", async () => {
|
|
74
|
+
const component = mount(UDropdown, {
|
|
75
|
+
props: {
|
|
76
|
+
searchable: true,
|
|
77
|
+
options: defaultOptions,
|
|
78
|
+
},
|
|
79
|
+
slots: {
|
|
80
|
+
default: `<button>Trigger</button>`,
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
await component.find("button").trigger("click");
|
|
85
|
+
await nextTick();
|
|
86
|
+
|
|
87
|
+
expect(component.findComponent(UListbox).props("searchable")).toBe(true);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("Size – applies the correct size to listbox", async () => {
|
|
91
|
+
const sizes = ["sm", "md", "lg"] as const;
|
|
92
|
+
|
|
93
|
+
for (const size of sizes) {
|
|
94
|
+
const component = mount(UDropdown, {
|
|
95
|
+
props: {
|
|
96
|
+
size,
|
|
97
|
+
options: defaultOptions,
|
|
98
|
+
},
|
|
99
|
+
slots: {
|
|
100
|
+
default: `<button>Trigger</button>`,
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
await component.find("button").trigger("click");
|
|
105
|
+
await nextTick();
|
|
106
|
+
|
|
107
|
+
expect(component.findComponent(UListbox).props("size")).toBe(size);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("Color – applies the correct color to listbox", async () => {
|
|
112
|
+
const colors = [
|
|
113
|
+
"primary",
|
|
114
|
+
"secondary",
|
|
115
|
+
"error",
|
|
116
|
+
"warning",
|
|
117
|
+
"success",
|
|
118
|
+
"info",
|
|
119
|
+
"notice",
|
|
120
|
+
"neutral",
|
|
121
|
+
"grayscale",
|
|
122
|
+
] as const;
|
|
123
|
+
|
|
124
|
+
for (const color of colors) {
|
|
125
|
+
const component = mount(UDropdown, {
|
|
126
|
+
props: {
|
|
127
|
+
color,
|
|
128
|
+
options: defaultOptions,
|
|
129
|
+
},
|
|
130
|
+
slots: {
|
|
131
|
+
default: `<button>Trigger</button>`,
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
await component.find("button").trigger("click");
|
|
136
|
+
await nextTick();
|
|
137
|
+
|
|
138
|
+
expect(component.findComponent(UListbox).props("color")).toBe(color);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("XPosition – passes xPosition prop to collapsible", () => {
|
|
143
|
+
const component = mount(UDropdown, {
|
|
144
|
+
props: {
|
|
145
|
+
xPosition: "right",
|
|
146
|
+
options: defaultOptions,
|
|
147
|
+
},
|
|
148
|
+
slots: {
|
|
149
|
+
default: `<button>Trigger</button>`,
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
const collapsible = component.findComponent({ name: "UCollapsible" });
|
|
154
|
+
|
|
155
|
+
expect(collapsible.props("xPosition")).toBe("right");
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("YPosition – passes yPosition prop to collapsible", () => {
|
|
159
|
+
const component = mount(UDropdown, {
|
|
160
|
+
props: {
|
|
161
|
+
yPosition: "top",
|
|
162
|
+
options: defaultOptions,
|
|
163
|
+
},
|
|
164
|
+
slots: {
|
|
165
|
+
default: `<button>Trigger</button>`,
|
|
166
|
+
},
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
const collapsible = component.findComponent({ name: "UCollapsible" });
|
|
170
|
+
|
|
171
|
+
expect(collapsible.props("yPosition")).toBe("top");
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it("LabelKey – uses custom label key for options", async () => {
|
|
175
|
+
const customOptions = [
|
|
176
|
+
{ id: 1, name: "First" },
|
|
177
|
+
{ id: 2, name: "Second" },
|
|
178
|
+
];
|
|
179
|
+
|
|
180
|
+
const component = mount(UDropdown, {
|
|
181
|
+
props: {
|
|
182
|
+
options: customOptions,
|
|
183
|
+
labelKey: "name",
|
|
184
|
+
valueKey: "id",
|
|
185
|
+
modelValue: 1,
|
|
186
|
+
},
|
|
187
|
+
slots: {
|
|
188
|
+
default: `<button>Trigger</button>`,
|
|
189
|
+
},
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
await component.find("button").trigger("click");
|
|
193
|
+
await nextTick();
|
|
194
|
+
|
|
195
|
+
expect(component.findComponent(UListbox).props("labelKey")).toBe("name");
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it("ValueKey – uses custom value key for options", async () => {
|
|
199
|
+
const customOptions = [
|
|
200
|
+
{ id: 1, name: "First" },
|
|
201
|
+
{ id: 2, name: "Second" },
|
|
202
|
+
];
|
|
203
|
+
|
|
204
|
+
const component = mount(UDropdown, {
|
|
205
|
+
props: {
|
|
206
|
+
options: customOptions,
|
|
207
|
+
labelKey: "name",
|
|
208
|
+
valueKey: "id",
|
|
209
|
+
modelValue: 1,
|
|
210
|
+
},
|
|
211
|
+
slots: {
|
|
212
|
+
default: `<button>Trigger</button>`,
|
|
213
|
+
},
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
await component.find("button").trigger("click");
|
|
217
|
+
await nextTick();
|
|
218
|
+
|
|
219
|
+
expect(component.findComponent(UListbox).props("valueKey")).toBe("id");
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it("GroupValueKey – passes groupValueKey prop to listbox", async () => {
|
|
223
|
+
const component = mount(UDropdown, {
|
|
224
|
+
props: {
|
|
225
|
+
groupValueKey: "items",
|
|
226
|
+
options: defaultOptions,
|
|
227
|
+
},
|
|
228
|
+
slots: {
|
|
229
|
+
default: `<button>Trigger</button>`,
|
|
230
|
+
},
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
await component.find("button").trigger("click");
|
|
234
|
+
await nextTick();
|
|
235
|
+
|
|
236
|
+
expect(component.findComponent(UListbox).props("groupValueKey")).toBe("items");
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it("CloseOnSelect – closes dropdown when option is selected and closeOnSelect is true", async () => {
|
|
240
|
+
const component = mount(UDropdown, {
|
|
241
|
+
props: {
|
|
242
|
+
closeOnSelect: true,
|
|
243
|
+
options: defaultOptions,
|
|
244
|
+
},
|
|
245
|
+
slots: {
|
|
246
|
+
default: `<button>Trigger</button>`,
|
|
247
|
+
},
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
await component.find("button").trigger("click");
|
|
251
|
+
await nextTick();
|
|
252
|
+
|
|
253
|
+
expect(component.findComponent(UListbox).exists()).toBe(true);
|
|
254
|
+
|
|
255
|
+
const listbox = component.findComponent(UListbox);
|
|
256
|
+
|
|
257
|
+
await listbox.vm.$emit("click-option", defaultOptions[0]);
|
|
258
|
+
await nextTick();
|
|
259
|
+
|
|
260
|
+
// Give time for the hide function to execute
|
|
261
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
262
|
+
await nextTick();
|
|
263
|
+
|
|
264
|
+
expect(component.findComponent(UListbox).exists()).toBe(false);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
it("CloseOnSelect – keeps dropdown open when option is selected and closeOnSelect is false", async () => {
|
|
268
|
+
const component = mount(UDropdown, {
|
|
269
|
+
props: {
|
|
270
|
+
closeOnSelect: false,
|
|
271
|
+
options: defaultOptions,
|
|
272
|
+
},
|
|
273
|
+
slots: {
|
|
274
|
+
default: `<button>Trigger</button>`,
|
|
275
|
+
},
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
await component.find("button").trigger("click");
|
|
279
|
+
await nextTick();
|
|
280
|
+
|
|
281
|
+
expect(component.findComponent(UListbox).exists()).toBe(true);
|
|
282
|
+
|
|
283
|
+
const listbox = component.findComponent(UListbox);
|
|
284
|
+
|
|
285
|
+
await listbox.vm.$emit("click-option", defaultOptions[0]);
|
|
286
|
+
await nextTick();
|
|
287
|
+
|
|
288
|
+
expect(component.findComponent(UListbox).exists()).toBe(true);
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
describe("Slots", () => {
|
|
293
|
+
it("Default – renders default slot with correct bindings", () => {
|
|
294
|
+
const component = mount(UDropdown, {
|
|
295
|
+
props: {
|
|
296
|
+
options: defaultOptions,
|
|
297
|
+
},
|
|
298
|
+
slots: {
|
|
299
|
+
default: `
|
|
300
|
+
<template #default="{ opened }">
|
|
301
|
+
<button>{{ opened ? 'Opened' : 'Closed' }}</button>
|
|
302
|
+
</template>
|
|
303
|
+
`,
|
|
304
|
+
},
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
expect(component.find("button").exists()).toBe(true);
|
|
308
|
+
expect(component.text()).toContain("Closed");
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
it("Empty – renders empty slot when no options are provided", async () => {
|
|
312
|
+
const component = mount(UDropdown, {
|
|
313
|
+
props: {
|
|
314
|
+
options: [],
|
|
315
|
+
},
|
|
316
|
+
slots: {
|
|
317
|
+
default: `<button>Open</button>`,
|
|
318
|
+
empty: `<div class="empty-state">No options available</div>`,
|
|
319
|
+
},
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
await component.find("button").trigger("click");
|
|
323
|
+
await nextTick();
|
|
324
|
+
|
|
325
|
+
expect(component.find(".empty-state").exists()).toBe(true);
|
|
326
|
+
expect(component.text()).toContain("No options available");
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
it("Before-option – renders before-option slot", async () => {
|
|
330
|
+
const component = mount(UDropdown, {
|
|
331
|
+
props: {
|
|
332
|
+
options: defaultOptions,
|
|
333
|
+
},
|
|
334
|
+
slots: {
|
|
335
|
+
default: `<button>Open</button>`,
|
|
336
|
+
"before-option": `<span class="before-icon">→</span>`,
|
|
337
|
+
},
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
await component.find("button").trigger("click");
|
|
341
|
+
await nextTick();
|
|
342
|
+
|
|
343
|
+
expect(component.findAll(".before-icon").length).toBeGreaterThan(0);
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
it("Option – renders option slot with custom content", async () => {
|
|
347
|
+
const component = mount(UDropdown, {
|
|
348
|
+
props: {
|
|
349
|
+
options: defaultOptions,
|
|
350
|
+
},
|
|
351
|
+
slots: {
|
|
352
|
+
default: `<button>Open</button>`,
|
|
353
|
+
option: `<template #option="{ option }"><div class="custom-option">{{ option.label }}</div></template>`,
|
|
354
|
+
},
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
await component.find("button").trigger("click");
|
|
358
|
+
await nextTick();
|
|
359
|
+
|
|
360
|
+
expect(component.findAll(".custom-option").length).toBeGreaterThan(0);
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
it("After-option – renders after-option slot", async () => {
|
|
364
|
+
const component = mount(UDropdown, {
|
|
365
|
+
props: {
|
|
366
|
+
options: defaultOptions,
|
|
367
|
+
},
|
|
368
|
+
slots: {
|
|
369
|
+
default: `<button>Open</button>`,
|
|
370
|
+
"after-option": `<span class="after-icon">✓</span>`,
|
|
371
|
+
},
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
await component.find("button").trigger("click");
|
|
375
|
+
await nextTick();
|
|
376
|
+
|
|
377
|
+
expect(component.findAll(".after-icon").length).toBeGreaterThan(0);
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
it("Dropdown – renders custom dropdown content slot", async () => {
|
|
381
|
+
const component = mount(UDropdown, {
|
|
382
|
+
props: {
|
|
383
|
+
options: defaultOptions,
|
|
384
|
+
},
|
|
385
|
+
slots: {
|
|
386
|
+
default: `<button>Open</button>`,
|
|
387
|
+
dropdown: `<div class="custom-dropdown">Custom dropdown content</div>`,
|
|
388
|
+
},
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
await component.find("button").trigger("click");
|
|
392
|
+
await nextTick();
|
|
393
|
+
|
|
394
|
+
expect(component.find(".custom-dropdown").exists()).toBe(true);
|
|
395
|
+
expect(component.text()).toContain("Custom dropdown content");
|
|
396
|
+
});
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
describe("Events", () => {
|
|
400
|
+
it("Update:modelValue – emits update:modelValue when an option is selected", async () => {
|
|
401
|
+
const component = mount(UDropdown, {
|
|
402
|
+
props: {
|
|
403
|
+
options: defaultOptions,
|
|
404
|
+
},
|
|
405
|
+
slots: {
|
|
406
|
+
default: `<button>Open</button>`,
|
|
407
|
+
},
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
await component.find("button").trigger("click");
|
|
411
|
+
await nextTick();
|
|
412
|
+
|
|
413
|
+
const listbox = component.findComponent(UListbox);
|
|
414
|
+
|
|
415
|
+
await listbox.vm.$emit("update:modelValue", defaultOptions[0].value);
|
|
416
|
+
|
|
417
|
+
expect(component.emitted("update:modelValue")).toBeTruthy();
|
|
418
|
+
expect(component.emitted("update:modelValue")![0][0]).toBe(defaultOptions[0].value);
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
it("Open – emits open event when dropdown is opened", async () => {
|
|
422
|
+
const component = mount(UDropdown, {
|
|
423
|
+
props: {
|
|
424
|
+
options: defaultOptions,
|
|
425
|
+
},
|
|
426
|
+
slots: {
|
|
427
|
+
default: `<button>Open</button>`,
|
|
428
|
+
},
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
await component.find("button").trigger("click");
|
|
432
|
+
await nextTick();
|
|
433
|
+
|
|
434
|
+
expect(component.emitted("open")).toBeTruthy();
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
it("Close – emits close event when dropdown is closed", async () => {
|
|
438
|
+
const component = mount(UDropdown, {
|
|
439
|
+
props: {
|
|
440
|
+
options: defaultOptions,
|
|
441
|
+
},
|
|
442
|
+
slots: {
|
|
443
|
+
default: `<button>Open</button>`,
|
|
444
|
+
},
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
await component.find("button").trigger("click");
|
|
448
|
+
await nextTick();
|
|
449
|
+
|
|
450
|
+
const hide = component.vm.hide as () => void;
|
|
451
|
+
|
|
452
|
+
hide();
|
|
453
|
+
await nextTick();
|
|
454
|
+
|
|
455
|
+
expect(component.emitted("close")).toBeTruthy();
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
it("ClickOption – emits clickOption event when an option is clicked", async () => {
|
|
459
|
+
const component = mount(UDropdown, {
|
|
460
|
+
props: {
|
|
461
|
+
options: defaultOptions,
|
|
462
|
+
},
|
|
463
|
+
slots: {
|
|
464
|
+
default: `<button>Open</button>`,
|
|
465
|
+
},
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
await component.find("button").trigger("click");
|
|
469
|
+
await nextTick();
|
|
470
|
+
|
|
471
|
+
const listbox = component.findComponent(UListbox);
|
|
472
|
+
|
|
473
|
+
await listbox.vm.$emit("click-option", defaultOptions[0]);
|
|
474
|
+
|
|
475
|
+
expect(component.emitted("clickOption")).toBeTruthy();
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
it("SearchChange – emits searchChange event when search value changes", async () => {
|
|
479
|
+
const component = mount(UDropdown, {
|
|
480
|
+
props: {
|
|
481
|
+
searchable: true,
|
|
482
|
+
options: defaultOptions,
|
|
483
|
+
},
|
|
484
|
+
slots: {
|
|
485
|
+
default: `<button>Open</button>`,
|
|
486
|
+
},
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
await component.find("button").trigger("click");
|
|
490
|
+
await nextTick();
|
|
491
|
+
|
|
492
|
+
const listbox = component.findComponent(UListbox);
|
|
493
|
+
|
|
494
|
+
await listbox.vm.$emit("search-change", "test query");
|
|
495
|
+
|
|
496
|
+
expect(component.emitted("searchChange")).toBeTruthy();
|
|
497
|
+
expect(component.emitted("searchChange")![0][0]).toBe("test query");
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
it("Update:search – emits update:search event when search value updates", async () => {
|
|
501
|
+
const component = mount(UDropdown, {
|
|
502
|
+
props: {
|
|
503
|
+
searchable: true,
|
|
504
|
+
options: defaultOptions,
|
|
505
|
+
},
|
|
506
|
+
slots: {
|
|
507
|
+
default: `<button>Open</button>`,
|
|
508
|
+
},
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
await component.find("button").trigger("click");
|
|
512
|
+
await nextTick();
|
|
513
|
+
|
|
514
|
+
const listbox = component.findComponent(UListbox);
|
|
515
|
+
|
|
516
|
+
await listbox.vm.$emit("update:search", "new search");
|
|
517
|
+
|
|
518
|
+
expect(component.emitted("update:search")).toBeTruthy();
|
|
519
|
+
expect(component.emitted("update:search")![0][0]).toBe("new search");
|
|
520
|
+
});
|
|
521
|
+
});
|
|
522
|
+
|
|
523
|
+
describe("Exposed methods", () => {
|
|
524
|
+
it("Toggle – exposes toggle method", () => {
|
|
525
|
+
const component = mount(UDropdown, {
|
|
526
|
+
props: {
|
|
527
|
+
options: defaultOptions,
|
|
528
|
+
},
|
|
529
|
+
slots: {
|
|
530
|
+
default: `<button>Open</button>`,
|
|
531
|
+
},
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
expect(component.vm.toggle).toBeDefined();
|
|
535
|
+
expect(typeof component.vm.toggle).toBe("function");
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
it("Hide – exposes hide method", () => {
|
|
539
|
+
const component = mount(UDropdown, {
|
|
540
|
+
props: {
|
|
541
|
+
options: defaultOptions,
|
|
542
|
+
},
|
|
543
|
+
slots: {
|
|
544
|
+
default: `<button>Open</button>`,
|
|
545
|
+
},
|
|
546
|
+
});
|
|
547
|
+
|
|
548
|
+
expect(component.vm.hide).toBeDefined();
|
|
549
|
+
expect(typeof component.vm.hide).toBe("function");
|
|
550
|
+
});
|
|
551
|
+
|
|
552
|
+
it("WrapperRef – exposes wrapperRef", () => {
|
|
553
|
+
const component = mount(UDropdown, {
|
|
554
|
+
props: {
|
|
555
|
+
options: defaultOptions,
|
|
556
|
+
},
|
|
557
|
+
slots: {
|
|
558
|
+
default: `<button>Open</button>`,
|
|
559
|
+
},
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
expect(component.vm.wrapperRef).toBeDefined();
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
it("IsOpened – exposes isOpened property", async () => {
|
|
566
|
+
const component = mount(UDropdown, {
|
|
567
|
+
props: {
|
|
568
|
+
options: defaultOptions,
|
|
569
|
+
},
|
|
570
|
+
slots: {
|
|
571
|
+
default: `<button>Open</button>`,
|
|
572
|
+
},
|
|
573
|
+
});
|
|
574
|
+
|
|
575
|
+
expect(component.vm.isOpened).toBe(false);
|
|
576
|
+
|
|
577
|
+
await component.find("button").trigger("click");
|
|
578
|
+
await nextTick();
|
|
579
|
+
|
|
580
|
+
expect(component.vm.isOpened).toBe(true);
|
|
581
|
+
});
|
|
582
|
+
|
|
583
|
+
it("SelectedOptions – exposes selectedOptions property", () => {
|
|
584
|
+
const component = mount(UDropdown, {
|
|
585
|
+
props: {
|
|
586
|
+
options: defaultOptions,
|
|
587
|
+
modelValue: 2,
|
|
588
|
+
},
|
|
589
|
+
slots: {
|
|
590
|
+
default: `<button>Open</button>`,
|
|
591
|
+
},
|
|
592
|
+
});
|
|
593
|
+
|
|
594
|
+
expect(component.vm.selectedOptions).toBeDefined();
|
|
595
|
+
expect(component.vm.selectedOptions.length).toBe(1);
|
|
596
|
+
expect(component.vm.selectedOptions[0].value).toBe(2);
|
|
597
|
+
});
|
|
598
|
+
|
|
599
|
+
it("DisplayLabel – exposes displayLabel property", () => {
|
|
600
|
+
const component = mount(UDropdown, {
|
|
601
|
+
props: {
|
|
602
|
+
options: defaultOptions,
|
|
603
|
+
modelValue: 2,
|
|
604
|
+
labelDisplayCount: 1,
|
|
605
|
+
},
|
|
606
|
+
slots: {
|
|
607
|
+
default: `<button>Open</button>`,
|
|
608
|
+
},
|
|
609
|
+
});
|
|
610
|
+
|
|
611
|
+
expect(component.vm.displayLabel).toBeDefined();
|
|
612
|
+
expect(component.vm.displayLabel).toBe("Option 2");
|
|
613
|
+
});
|
|
614
|
+
|
|
615
|
+
it("FullLabel – exposes fullLabel property", () => {
|
|
616
|
+
const component = mount(UDropdown, {
|
|
617
|
+
props: {
|
|
618
|
+
options: defaultOptions,
|
|
619
|
+
modelValue: [1, 2],
|
|
620
|
+
multiple: true,
|
|
621
|
+
},
|
|
622
|
+
slots: {
|
|
623
|
+
default: `<button>Open</button>`,
|
|
624
|
+
},
|
|
625
|
+
});
|
|
626
|
+
|
|
627
|
+
expect(component.vm.fullLabel).toBeDefined();
|
|
628
|
+
expect(component.vm.fullLabel).toBe("Option 1, Option 2");
|
|
629
|
+
});
|
|
630
|
+
});
|
|
631
|
+
});
|