vueless 1.3.7-beta.2 → 1.3.7-beta.4
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/icons/storybook/help.svg +1 -0
- package/icons/storybook/logout.svg +1 -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 +238 -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/storybook/stories.ts +13 -40
- 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/storybook/stories.ts +15 -42
- 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/storybook/stories.ts +31 -58
- 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
|
@@ -0,0 +1,571 @@
|
|
|
1
|
+
import { mount, flushPromises } from "@vue/test-utils";
|
|
2
|
+
import { describe, it, expect } from "vitest";
|
|
3
|
+
import { nextTick, ref } from "vue";
|
|
4
|
+
|
|
5
|
+
import UCollapsible from "../UCollapsible.vue";
|
|
6
|
+
|
|
7
|
+
import type { Props } from "../types";
|
|
8
|
+
import type { UnknownObject } from "../../types";
|
|
9
|
+
|
|
10
|
+
function mountCollapsible(options: UnknownObject = {}) {
|
|
11
|
+
return mount(UCollapsible, options);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
describe("UCollapsible.vue", () => {
|
|
15
|
+
describe("Props", () => {
|
|
16
|
+
it("Model Value – controls opened state when provided", async () => {
|
|
17
|
+
const open = ref(false);
|
|
18
|
+
|
|
19
|
+
const component = mountCollapsible({
|
|
20
|
+
props: {
|
|
21
|
+
open: open.value,
|
|
22
|
+
dataTest: "test",
|
|
23
|
+
"onUpdate:open": (value: boolean) => {
|
|
24
|
+
open.value = value;
|
|
25
|
+
component.setProps({ open: value });
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
slots: {
|
|
29
|
+
default: "Trigger",
|
|
30
|
+
content: "Content",
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
expect(component.find('[data-test="test-content"]').exists()).toBe(false);
|
|
35
|
+
|
|
36
|
+
await component.find('[data-test="test"]').trigger("click");
|
|
37
|
+
await nextTick();
|
|
38
|
+
|
|
39
|
+
expect(component.emitted("update:open")).toBeTruthy();
|
|
40
|
+
expect(component.emitted("update:open")![0][0]).toBe(true);
|
|
41
|
+
|
|
42
|
+
await component.setProps({ open: true });
|
|
43
|
+
await nextTick();
|
|
44
|
+
|
|
45
|
+
expect(component.find('[data-test="test-content"]').exists()).toBe(true);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("Model Value – works independently when not provided", async () => {
|
|
49
|
+
const component = mountCollapsible({
|
|
50
|
+
props: {
|
|
51
|
+
dataTest: "test",
|
|
52
|
+
},
|
|
53
|
+
slots: {
|
|
54
|
+
default: "Trigger",
|
|
55
|
+
content: "Content",
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
expect(component.find('[data-test="test-content"]').exists()).toBe(false);
|
|
60
|
+
|
|
61
|
+
await component.find('[data-test="test"]').trigger("click");
|
|
62
|
+
await nextTick();
|
|
63
|
+
await flushPromises();
|
|
64
|
+
|
|
65
|
+
expect(component.find('[data-test="test-content"]').exists()).toBe(true);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("YPosition – applies correct position class for top", () => {
|
|
69
|
+
const component = mountCollapsible({
|
|
70
|
+
props: {
|
|
71
|
+
yPosition: "top" as Props["yPosition"],
|
|
72
|
+
open: true,
|
|
73
|
+
dataTest: "test",
|
|
74
|
+
},
|
|
75
|
+
slots: {
|
|
76
|
+
default: "Trigger",
|
|
77
|
+
content: "Content",
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const content = component.find('[data-test="test-content"]');
|
|
82
|
+
|
|
83
|
+
expect(content.attributes("class")).toContain("bottom-full");
|
|
84
|
+
expect(content.attributes("class")).toContain("mb-1");
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("YPosition – applies correct position class for bottom", () => {
|
|
88
|
+
const component = mountCollapsible({
|
|
89
|
+
props: {
|
|
90
|
+
yPosition: "bottom" as Props["yPosition"],
|
|
91
|
+
open: true,
|
|
92
|
+
dataTest: "test",
|
|
93
|
+
},
|
|
94
|
+
slots: {
|
|
95
|
+
default: "Trigger",
|
|
96
|
+
content: "Content",
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const content = component.find('[data-test="test-content"]');
|
|
101
|
+
|
|
102
|
+
expect(content.attributes("class")).toContain("top-full");
|
|
103
|
+
expect(content.attributes("class")).toContain("mt-1");
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("XPosition – applies correct position class for left", () => {
|
|
107
|
+
const component = mountCollapsible({
|
|
108
|
+
props: {
|
|
109
|
+
xPosition: "left" as Props["xPosition"],
|
|
110
|
+
open: true,
|
|
111
|
+
dataTest: "test",
|
|
112
|
+
},
|
|
113
|
+
slots: {
|
|
114
|
+
default: "Trigger",
|
|
115
|
+
content: "Content",
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const content = component.find('[data-test="test-content"]');
|
|
120
|
+
|
|
121
|
+
expect(content.attributes("class")).toContain("left-0");
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("XPosition – applies correct position class for right", () => {
|
|
125
|
+
const component = mountCollapsible({
|
|
126
|
+
props: {
|
|
127
|
+
xPosition: "right" as Props["xPosition"],
|
|
128
|
+
open: true,
|
|
129
|
+
dataTest: "test",
|
|
130
|
+
},
|
|
131
|
+
slots: {
|
|
132
|
+
default: "Trigger",
|
|
133
|
+
content: "Content",
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
const content = component.find('[data-test="test-content"]');
|
|
138
|
+
|
|
139
|
+
expect(content.attributes("class")).toContain("right-0");
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("Absolute – applies absolute positioning when true", () => {
|
|
143
|
+
const component = mountCollapsible({
|
|
144
|
+
props: {
|
|
145
|
+
absolute: true,
|
|
146
|
+
open: true,
|
|
147
|
+
dataTest: "test",
|
|
148
|
+
},
|
|
149
|
+
slots: {
|
|
150
|
+
default: "Trigger",
|
|
151
|
+
content: "Content",
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
const content = component.find('[data-test="test-content"]');
|
|
156
|
+
|
|
157
|
+
expect(content.attributes("class")).toContain("absolute");
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("Absolute – does not apply absolute positioning when false", () => {
|
|
161
|
+
const component = mountCollapsible({
|
|
162
|
+
props: {
|
|
163
|
+
absolute: false,
|
|
164
|
+
open: true,
|
|
165
|
+
dataTest: "test",
|
|
166
|
+
},
|
|
167
|
+
slots: {
|
|
168
|
+
default: "Trigger",
|
|
169
|
+
content: "Content",
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
const content = component.find('[data-test="test-content"]');
|
|
174
|
+
|
|
175
|
+
expect(content.attributes("class")).not.toContain("absolute");
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it("Disabled – prevents opening when disabled", async () => {
|
|
179
|
+
const component = mountCollapsible({
|
|
180
|
+
props: {
|
|
181
|
+
disabled: true,
|
|
182
|
+
dataTest: "test",
|
|
183
|
+
},
|
|
184
|
+
slots: {
|
|
185
|
+
default: "Trigger",
|
|
186
|
+
content: "Content",
|
|
187
|
+
},
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
await component.find('[data-test="test"]').trigger("click");
|
|
191
|
+
await nextTick();
|
|
192
|
+
|
|
193
|
+
expect(component.find('[data-test="test-content"]').exists()).toBe(false);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it("Disabled – applies cursor-not-allowed class", () => {
|
|
197
|
+
const component = mountCollapsible({
|
|
198
|
+
props: {
|
|
199
|
+
disabled: true,
|
|
200
|
+
dataTest: "test",
|
|
201
|
+
},
|
|
202
|
+
slots: {
|
|
203
|
+
default: "Trigger",
|
|
204
|
+
content: "Content",
|
|
205
|
+
},
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
const wrapper = component.find('[data-test="test"]');
|
|
209
|
+
|
|
210
|
+
expect(wrapper.attributes("class")).toContain("cursor-not-allowed");
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it("CloseOnOutside – closes when clicking outside", async () => {
|
|
214
|
+
const component = mountCollapsible({
|
|
215
|
+
props: {
|
|
216
|
+
closeOnOutside: true,
|
|
217
|
+
open: true,
|
|
218
|
+
dataTest: "test",
|
|
219
|
+
},
|
|
220
|
+
slots: {
|
|
221
|
+
default: "Trigger",
|
|
222
|
+
content: "Content",
|
|
223
|
+
},
|
|
224
|
+
attachTo: document.body,
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
expect(component.find('[data-test="test-content"]').exists()).toBe(true);
|
|
228
|
+
|
|
229
|
+
document.body.click();
|
|
230
|
+
await nextTick();
|
|
231
|
+
|
|
232
|
+
expect(component.emitted("close")).toBeTruthy();
|
|
233
|
+
|
|
234
|
+
component.unmount();
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it("CloseOnContent – closes when clicking content", async () => {
|
|
238
|
+
const component = mountCollapsible({
|
|
239
|
+
props: {
|
|
240
|
+
closeOnContent: true,
|
|
241
|
+
open: true,
|
|
242
|
+
dataTest: "test",
|
|
243
|
+
},
|
|
244
|
+
slots: {
|
|
245
|
+
default: "Trigger",
|
|
246
|
+
content: "Content",
|
|
247
|
+
},
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
await component.find('[data-test="test-content"]').trigger("click");
|
|
251
|
+
await nextTick();
|
|
252
|
+
|
|
253
|
+
expect(component.emitted("close")).toBeTruthy();
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
it("CloseOnContent – does not close when false", async () => {
|
|
257
|
+
const component = mountCollapsible({
|
|
258
|
+
props: {
|
|
259
|
+
closeOnContent: false,
|
|
260
|
+
open: true,
|
|
261
|
+
dataTest: "test",
|
|
262
|
+
},
|
|
263
|
+
slots: {
|
|
264
|
+
default: "Trigger",
|
|
265
|
+
content: "Content",
|
|
266
|
+
},
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
await component.find('[data-test="test-content"]').trigger("click");
|
|
270
|
+
await nextTick();
|
|
271
|
+
|
|
272
|
+
expect(component.find('[data-test="test-content"]').exists()).toBe(true);
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it("Id – applies custom id when provided", () => {
|
|
276
|
+
const customId = "custom-collapsible-id";
|
|
277
|
+
|
|
278
|
+
const component = mountCollapsible({
|
|
279
|
+
props: {
|
|
280
|
+
id: customId,
|
|
281
|
+
dataTest: "test",
|
|
282
|
+
},
|
|
283
|
+
slots: {
|
|
284
|
+
default: "Trigger",
|
|
285
|
+
content: "Content",
|
|
286
|
+
},
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
const wrapper = component.find('[data-test="test"]');
|
|
290
|
+
|
|
291
|
+
expect(wrapper.attributes("id")).toBe(customId);
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
it("DataTest – applies custom data-test attribute", () => {
|
|
295
|
+
const dataTest = "custom-test";
|
|
296
|
+
|
|
297
|
+
const component = mountCollapsible({
|
|
298
|
+
props: {
|
|
299
|
+
dataTest,
|
|
300
|
+
},
|
|
301
|
+
slots: {
|
|
302
|
+
default: "Trigger",
|
|
303
|
+
content: "Content",
|
|
304
|
+
},
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
expect(component.find(`[data-test="${dataTest}"]`).exists()).toBe(true);
|
|
308
|
+
});
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
describe("Slots", () => {
|
|
312
|
+
it("Default – renders trigger content", () => {
|
|
313
|
+
const triggerContent = "Click Me";
|
|
314
|
+
|
|
315
|
+
const component = mountCollapsible({
|
|
316
|
+
slots: {
|
|
317
|
+
default: triggerContent,
|
|
318
|
+
},
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
expect(component.text()).toContain(triggerContent);
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
it("Default – exposes opened state to slot", async () => {
|
|
325
|
+
const component = mountCollapsible({
|
|
326
|
+
props: {
|
|
327
|
+
dataTest: "test",
|
|
328
|
+
},
|
|
329
|
+
slots: {
|
|
330
|
+
default: `<template #default="{ opened }">
|
|
331
|
+
<div class="trigger">{{ opened ? 'Opened' : 'Closed' }}</div>
|
|
332
|
+
</template>`,
|
|
333
|
+
},
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
expect(component.find(".trigger").text()).toBe("Closed");
|
|
337
|
+
|
|
338
|
+
await component.find('[data-test="test"]').trigger("click");
|
|
339
|
+
await nextTick();
|
|
340
|
+
await flushPromises();
|
|
341
|
+
|
|
342
|
+
expect(component.find(".trigger").text()).toBe("Opened");
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
it("Content – renders collapsible content when opened", () => {
|
|
346
|
+
const contentText = "Collapsible Content";
|
|
347
|
+
|
|
348
|
+
const component = mountCollapsible({
|
|
349
|
+
props: {
|
|
350
|
+
open: true,
|
|
351
|
+
},
|
|
352
|
+
slots: {
|
|
353
|
+
default: "Trigger",
|
|
354
|
+
content: contentText,
|
|
355
|
+
},
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
expect(component.text()).toContain(contentText);
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
it("Content – exposes opened state to slot", () => {
|
|
362
|
+
const component = mountCollapsible({
|
|
363
|
+
props: {
|
|
364
|
+
open: true,
|
|
365
|
+
},
|
|
366
|
+
slots: {
|
|
367
|
+
default: "Trigger",
|
|
368
|
+
content: `<template #content="{ opened }">
|
|
369
|
+
<div class="content-state">{{ opened ? 'Open' : 'Closed' }}</div>
|
|
370
|
+
</template>`,
|
|
371
|
+
},
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
expect(component.find(".content-state").text()).toBe("Open");
|
|
375
|
+
});
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
describe("Events", () => {
|
|
379
|
+
it("Update:open – emits when toggling", async () => {
|
|
380
|
+
const component = mountCollapsible({
|
|
381
|
+
props: {
|
|
382
|
+
open: false,
|
|
383
|
+
dataTest: "test",
|
|
384
|
+
},
|
|
385
|
+
slots: {
|
|
386
|
+
default: "Trigger",
|
|
387
|
+
content: "Content",
|
|
388
|
+
},
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
await component.find('[data-test="test"]').trigger("click");
|
|
392
|
+
await nextTick();
|
|
393
|
+
|
|
394
|
+
expect(component.emitted("update:open")).toBeTruthy();
|
|
395
|
+
expect(component.emitted("update:open")![0][0]).toBe(true);
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
it("Open – emits when collapsible opens", async () => {
|
|
399
|
+
const component = mountCollapsible({
|
|
400
|
+
props: {
|
|
401
|
+
dataTest: "test",
|
|
402
|
+
},
|
|
403
|
+
slots: {
|
|
404
|
+
default: "Trigger",
|
|
405
|
+
content: "Content",
|
|
406
|
+
},
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
await component.find('[data-test="test"]').trigger("click");
|
|
410
|
+
await nextTick();
|
|
411
|
+
await flushPromises();
|
|
412
|
+
|
|
413
|
+
expect(component.emitted("open")).toBeTruthy();
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
it("Close – emits when collapsible closes", async () => {
|
|
417
|
+
const component = mountCollapsible({
|
|
418
|
+
props: {
|
|
419
|
+
open: true,
|
|
420
|
+
dataTest: "test",
|
|
421
|
+
},
|
|
422
|
+
slots: {
|
|
423
|
+
default: "Trigger",
|
|
424
|
+
content: "Content",
|
|
425
|
+
},
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
await component.find('[data-test="test"]').trigger("click");
|
|
429
|
+
await nextTick();
|
|
430
|
+
await flushPromises();
|
|
431
|
+
|
|
432
|
+
expect(component.emitted("close")).toBeTruthy();
|
|
433
|
+
});
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
describe("Exposed Methods", () => {
|
|
437
|
+
it("wrapperRef – exposes wrapper element reference", () => {
|
|
438
|
+
const component = mountCollapsible({
|
|
439
|
+
slots: {
|
|
440
|
+
default: "Trigger",
|
|
441
|
+
content: "Content",
|
|
442
|
+
},
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
expect(component.vm.wrapperRef).toBeDefined();
|
|
446
|
+
expect(component.vm.wrapperRef).toBeInstanceOf(HTMLDivElement);
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
it("show – opens the collapsible", async () => {
|
|
450
|
+
const component = mountCollapsible({
|
|
451
|
+
props: {
|
|
452
|
+
dataTest: "test",
|
|
453
|
+
},
|
|
454
|
+
slots: {
|
|
455
|
+
default: "Trigger",
|
|
456
|
+
content: "Content",
|
|
457
|
+
},
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
component.vm.show();
|
|
461
|
+
await nextTick();
|
|
462
|
+
await flushPromises();
|
|
463
|
+
|
|
464
|
+
expect(component.find('[data-test="test-content"]').exists()).toBe(true);
|
|
465
|
+
expect(component.emitted("open")).toBeTruthy();
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
it("show – does not open when disabled", async () => {
|
|
469
|
+
const component = mountCollapsible({
|
|
470
|
+
props: {
|
|
471
|
+
disabled: true,
|
|
472
|
+
dataTest: "test",
|
|
473
|
+
},
|
|
474
|
+
slots: {
|
|
475
|
+
default: "Trigger",
|
|
476
|
+
content: "Content",
|
|
477
|
+
},
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
component.vm.show();
|
|
481
|
+
await nextTick();
|
|
482
|
+
|
|
483
|
+
expect(component.find('[data-test="test-content"]').exists()).toBe(false);
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
it("hide – closes the collapsible", async () => {
|
|
487
|
+
const component = mountCollapsible({
|
|
488
|
+
props: {
|
|
489
|
+
open: true,
|
|
490
|
+
dataTest: "test",
|
|
491
|
+
},
|
|
492
|
+
slots: {
|
|
493
|
+
default: "Trigger",
|
|
494
|
+
content: "Content",
|
|
495
|
+
},
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
expect(component.find('[data-test="test-content"]').exists()).toBe(true);
|
|
499
|
+
|
|
500
|
+
component.vm.hide();
|
|
501
|
+
await nextTick();
|
|
502
|
+
|
|
503
|
+
expect(component.emitted("close")).toBeTruthy();
|
|
504
|
+
});
|
|
505
|
+
|
|
506
|
+
it("toggle – toggles the collapsible state", async () => {
|
|
507
|
+
const component = mountCollapsible({
|
|
508
|
+
props: {
|
|
509
|
+
dataTest: "test",
|
|
510
|
+
},
|
|
511
|
+
slots: {
|
|
512
|
+
default: "Trigger",
|
|
513
|
+
content: "Content",
|
|
514
|
+
},
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
component.vm.toggle();
|
|
518
|
+
await nextTick();
|
|
519
|
+
await flushPromises();
|
|
520
|
+
|
|
521
|
+
expect(component.find('[data-test="test-content"]').exists()).toBe(true);
|
|
522
|
+
|
|
523
|
+
component.vm.toggle();
|
|
524
|
+
await nextTick();
|
|
525
|
+
await flushPromises();
|
|
526
|
+
|
|
527
|
+
expect(component.find('[data-test="test-content"]').exists()).toBe(false);
|
|
528
|
+
});
|
|
529
|
+
|
|
530
|
+
it("toggle – does not toggle when disabled", async () => {
|
|
531
|
+
const component = mountCollapsible({
|
|
532
|
+
props: {
|
|
533
|
+
disabled: true,
|
|
534
|
+
dataTest: "test",
|
|
535
|
+
},
|
|
536
|
+
slots: {
|
|
537
|
+
default: "Trigger",
|
|
538
|
+
content: "Content",
|
|
539
|
+
},
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
component.vm.toggle();
|
|
543
|
+
await nextTick();
|
|
544
|
+
|
|
545
|
+
expect(component.find('[data-test="test-content"]').exists()).toBe(false);
|
|
546
|
+
});
|
|
547
|
+
|
|
548
|
+
it("isOpened – reflects the current opened state", async () => {
|
|
549
|
+
const component = mountCollapsible({
|
|
550
|
+
slots: {
|
|
551
|
+
default: "Trigger",
|
|
552
|
+
content: "Content",
|
|
553
|
+
},
|
|
554
|
+
});
|
|
555
|
+
|
|
556
|
+
expect(component.vm.isOpened).toBe(false);
|
|
557
|
+
|
|
558
|
+
component.vm.show();
|
|
559
|
+
await nextTick();
|
|
560
|
+
await flushPromises();
|
|
561
|
+
|
|
562
|
+
expect(component.vm.isOpened).toBe(true);
|
|
563
|
+
|
|
564
|
+
component.vm.hide();
|
|
565
|
+
await nextTick();
|
|
566
|
+
await flushPromises();
|
|
567
|
+
|
|
568
|
+
expect(component.vm.isOpened).toBe(false);
|
|
569
|
+
});
|
|
570
|
+
});
|
|
571
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import defaultConfig from "./config";
|
|
2
|
+
|
|
3
|
+
import type { ComponentConfig } from "../types";
|
|
4
|
+
|
|
5
|
+
export type Config = typeof defaultConfig;
|
|
6
|
+
|
|
7
|
+
export interface Props {
|
|
8
|
+
/**
|
|
9
|
+
* Controls the opened state of the collapsible.
|
|
10
|
+
*/
|
|
11
|
+
open?: boolean;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The position of collapsible content on the y-axis.
|
|
15
|
+
*/
|
|
16
|
+
yPosition?: "top" | "bottom";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The position of collapsible content on the x-axis.
|
|
20
|
+
*/
|
|
21
|
+
xPosition?: "left" | "right";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Position the content absolutely.
|
|
25
|
+
*/
|
|
26
|
+
absolute?: boolean;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Close collapsible when clicking outside.
|
|
30
|
+
*/
|
|
31
|
+
closeOnOutside?: boolean;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Close collapsible when clicking on content.
|
|
35
|
+
*/
|
|
36
|
+
closeOnContent?: boolean;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Disable the collapsible.
|
|
40
|
+
*/
|
|
41
|
+
disabled?: boolean;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Unique element id.
|
|
45
|
+
*/
|
|
46
|
+
id?: string;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Component config object.
|
|
50
|
+
*/
|
|
51
|
+
config?: ComponentConfig<Config>;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Data-test attribute for automated testing.
|
|
55
|
+
*/
|
|
56
|
+
dataTest?: string | null;
|
|
57
|
+
}
|