@aleph-alpha/ui-library 5.4.0 → 5.6.0
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/config.d.ts +9 -0
- package/config.js +12 -3
- package/dist/system/components/UiAutocomplete/UiAutocomplete.vue.d.ts +2 -0
- package/dist/system/components/UiButtonGroup/UiButtonGroup.vue.d.ts +20 -0
- package/dist/system/components/UiButtonGroup/index.d.ts +2 -0
- package/dist/system/components/UiButtonGroup/types.d.ts +20 -0
- package/dist/system/components/core/button-group/ButtonGroup.vue.d.ts +23 -0
- package/dist/system/components/core/button-group/ButtonGroupSeparator.vue.d.ts +9 -0
- package/dist/system/components/core/button-group/ButtonGroupText.vue.d.ts +26 -0
- package/dist/system/components/core/button-group/index.d.ts +8 -0
- package/dist/system/components/index.d.ts +1 -0
- package/dist/system/lib.js +8878 -8692
- package/dist/system/patterns/UiFloatActions/UiFloatActionItems.vue.d.ts +173 -2
- package/dist/system/patterns/UiFloatActions/floatActionItemContext.d.ts +15 -1
- package/dist/system/patterns/UiFloatActions/types.d.ts +25 -1
- package/dist/system/story-sidebar-icons.json +8 -1
- package/package.json +5 -3
- package/src/components/UiAutocomplete/UiAutocomplete.stories.ts +620 -0
- package/src/components/UiAutocomplete/UiAutocomplete.vue +28 -3
- package/src/components/UiAutocomplete/__tests__/UiAutocomplete.test.ts +14 -69
- package/src/components/UiButton/UiButton.stories.ts +9 -9
- package/src/components/UiButtonGroup/UiButtonGroup.stories.ts +690 -0
- package/src/components/UiButtonGroup/UiButtonGroup.vue +18 -0
- package/src/components/UiButtonGroup/__tests__/UiButtonGroup.test.ts +68 -0
- package/src/components/UiButtonGroup/index.ts +2 -0
- package/src/components/UiButtonGroup/types.ts +21 -0
- package/src/components/UiCheckbox/UiCheckbox.stories.ts +253 -0
- package/src/components/UiCheckbox/__tests__/UiCheckbox.test.ts +3 -18
- package/src/components/UiField/UiField.stories.ts +608 -1
- package/src/components/UiField/UiFieldDescription.vue +7 -2
- package/src/components/UiInput/UiInput.stories.ts +336 -2
- package/src/components/UiInput/__tests__/UiInput.test.ts +20 -28
- package/src/components/UiItem/UiItem.stories.ts +236 -1
- package/src/components/UiItem/__tests__/UiItem.test.ts +11 -72
- package/src/components/UiSelect/UiSelect.stories.ts +769 -0
- package/src/components/UiSelect/__tests__/UiSelect.test.ts +4 -73
- package/src/components/UiSelect/__tests__/UiSelectItem.test.ts +3 -31
- package/src/components/UiSelect/__tests__/UiSelectTrigger.test.ts +14 -5
- package/src/components/UiSnackbar/UiSnackbar.stories.ts +6 -6
- package/src/components/UiSnackbar/UiSnackbar.vue +4 -4
- package/src/components/UiSnackbar/UiSnackbarContent.vue +4 -4
- package/src/components/core/button-group/ButtonGroup.vue +24 -0
- package/src/components/core/button-group/ButtonGroupSeparator.vue +29 -0
- package/src/components/core/button-group/ButtonGroupText.vue +33 -0
- package/src/components/core/button-group/index.ts +25 -0
- package/src/components/core/checkbox/Checkbox.vue +0 -1
- package/src/components/core/select/SelectTrigger.vue +1 -1
- package/src/components/core/tabs/TabsTrigger.vue +1 -1
- package/src/components/index.ts +1 -0
- package/src/patterns/UiDataTable/UiDataTable.stories.ts +495 -8
- package/src/patterns/UiDataTable/UiDataTableFilterMenu.vue +1 -1
- package/src/patterns/UiDataTable/__tests__/UiDataTable.test.ts +7 -184
- package/src/patterns/UiFloatActions/UiFloatActionItems.vue +138 -11
- package/src/patterns/UiFloatActions/UiFloatActions.stories.ts +890 -3
- package/src/patterns/UiFloatActions/__tests__/UiFloatActionItems.test.ts +46 -24
- package/src/patterns/UiFloatActions/floatActionItemContext.ts +16 -1
- package/src/patterns/UiFloatActions/types.ts +28 -1
- package/src/components/UiField/__tests__/UiFieldError.test.ts +0 -39
- package/src/patterns/UiFloatActions/__tests__/UiFloatActions.a11y.test.ts +0 -152
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/vue3-vite';
|
|
2
|
+
import { expect, fn, userEvent, within } from 'storybook/test';
|
|
2
3
|
import UiInput from './UiInput.vue';
|
|
3
4
|
import { UiButton } from '../UiButton';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
|
-
*
|
|
7
|
-
* Pair it with `UiField` and `UiLabel` for accessible form layouts; for multi-line content, use `UiTextarea`.
|
|
7
|
+
* Text input is an interactive field that allows users to enter text and data. It’s commonly used in form patterns.
|
|
8
8
|
*/
|
|
9
9
|
const meta: Meta<typeof UiInput> = {
|
|
10
10
|
title: 'Components/UiInput',
|
|
@@ -35,6 +35,12 @@ export default meta;
|
|
|
35
35
|
|
|
36
36
|
type Story = StoryObj<typeof UiInput>;
|
|
37
37
|
|
|
38
|
+
// `UiInput` wires `defineModel` (`update:modelValue`) and emits `update:files`
|
|
39
|
+
// in file mode. Play functions bind these module-level spies via
|
|
40
|
+
// `@update:model-value` / `@update:files` and `mockClear()` them first.
|
|
41
|
+
const onUpdate = fn();
|
|
42
|
+
const onFiles = fn();
|
|
43
|
+
|
|
38
44
|
const defaultTemplateSource = `<script setup lang="ts">
|
|
39
45
|
import { UiInput } from '@aleph-alpha/ui-library'
|
|
40
46
|
</script>
|
|
@@ -61,6 +67,20 @@ export const Default: Story = {
|
|
|
61
67
|
},
|
|
62
68
|
},
|
|
63
69
|
},
|
|
70
|
+
play: async ({ canvasElement, step }) => {
|
|
71
|
+
// Scenario (UiInput): assistive tech sees an editable textbox that is enabled by
|
|
72
|
+
// default. These checks don't mutate state, so the snapshot stays stable.
|
|
73
|
+
const canvas = within(canvasElement);
|
|
74
|
+
const input = canvas.getByRole('textbox');
|
|
75
|
+
|
|
76
|
+
await step(
|
|
77
|
+
'screen-reader: exposes an editable, enabled textbox (WCAG 4.1.2)',
|
|
78
|
+
async () => {
|
|
79
|
+
await expect(input).toBeEnabled();
|
|
80
|
+
await expect(input).toHaveAttribute('placeholder', 'Email');
|
|
81
|
+
},
|
|
82
|
+
);
|
|
83
|
+
},
|
|
64
84
|
};
|
|
65
85
|
|
|
66
86
|
const withLabelTemplateSource = `<script setup lang="ts">
|
|
@@ -95,6 +115,19 @@ export const WithLabel: Story = {
|
|
|
95
115
|
},
|
|
96
116
|
},
|
|
97
117
|
},
|
|
118
|
+
play: async ({ canvasElement, step }) => {
|
|
119
|
+
// Scenario (UiInput): a visible label is programmatically associated with the input,
|
|
120
|
+
// so screen readers announce it as the accessible name.
|
|
121
|
+
const canvas = within(canvasElement);
|
|
122
|
+
|
|
123
|
+
await step(
|
|
124
|
+
'screen-reader: the label names its associated input (WCAG 1.3.1 / 4.1.2)',
|
|
125
|
+
async () => {
|
|
126
|
+
const input = canvas.getByRole('textbox', { name: 'Email' });
|
|
127
|
+
await expect(input).toHaveAccessibleName('Email');
|
|
128
|
+
},
|
|
129
|
+
);
|
|
130
|
+
},
|
|
98
131
|
};
|
|
99
132
|
|
|
100
133
|
const disabledTemplateSource = `<script setup lang="ts">
|
|
@@ -126,6 +159,24 @@ export const Disabled: Story = {
|
|
|
126
159
|
},
|
|
127
160
|
},
|
|
128
161
|
},
|
|
162
|
+
play: async ({ canvasElement, step }) => {
|
|
163
|
+
// Scenario (UiInput): a disabled input reports its disabled state to assistive tech
|
|
164
|
+
// and is removed from the tab order.
|
|
165
|
+
const canvas = within(canvasElement);
|
|
166
|
+
const input = canvas.getByRole('textbox');
|
|
167
|
+
|
|
168
|
+
await step(
|
|
169
|
+
'interaction: exposes the disabled state (WCAG 4.1.2)',
|
|
170
|
+
async () => {
|
|
171
|
+
await expect(input).toBeDisabled();
|
|
172
|
+
},
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
await step('keyboard: disabled input is skipped by Tab', async () => {
|
|
176
|
+
await userEvent.tab();
|
|
177
|
+
await expect(input).not.toHaveFocus();
|
|
178
|
+
});
|
|
179
|
+
},
|
|
129
180
|
};
|
|
130
181
|
|
|
131
182
|
const withButtonTemplateSource = `<script setup lang="ts">
|
|
@@ -195,3 +246,286 @@ export const File: Story = {
|
|
|
195
246
|
},
|
|
196
247
|
},
|
|
197
248
|
};
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* `UiInput` is keyboard operable and emits `update:modelValue` as the user
|
|
252
|
+
* types. Hidden test-only story.
|
|
253
|
+
*/
|
|
254
|
+
export const TextEntry: Story = {
|
|
255
|
+
name: 'test - Text Entry',
|
|
256
|
+
tags: ['!dev', '!autodocs'],
|
|
257
|
+
render: () => ({
|
|
258
|
+
components: { UiInput },
|
|
259
|
+
setup() {
|
|
260
|
+
return { onUpdate };
|
|
261
|
+
},
|
|
262
|
+
template: `<div class="grid w-full max-w-sm items-center gap-1.5">
|
|
263
|
+
<label for="full-name" class="body-14-medium">Full name</label>
|
|
264
|
+
<UiInput id="full-name" name="full-name" placeholder="Ada Lovelace" @update:model-value="onUpdate" />
|
|
265
|
+
</div>`,
|
|
266
|
+
}),
|
|
267
|
+
parameters: {
|
|
268
|
+
// The play function focuses the input and types; skip the visual snapshot.
|
|
269
|
+
chromatic: { disableSnapshot: true },
|
|
270
|
+
docs: {
|
|
271
|
+
description: {
|
|
272
|
+
story:
|
|
273
|
+
'Tab to focus the input, then type — each keystroke emits `update:modelValue`.',
|
|
274
|
+
},
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
play: async ({ canvasElement, step }) => {
|
|
278
|
+
// Scenario (UiInput): a keyboard user tabs to the input and types, which updates the
|
|
279
|
+
// value and emits update:modelValue.
|
|
280
|
+
onUpdate.mockClear();
|
|
281
|
+
const canvas = within(canvasElement);
|
|
282
|
+
const input = canvas.getByRole('textbox', { name: 'Full name' });
|
|
283
|
+
|
|
284
|
+
await step(
|
|
285
|
+
'keyboard: input is reachable via Tab (WCAG 2.1.1)',
|
|
286
|
+
async () => {
|
|
287
|
+
await userEvent.tab();
|
|
288
|
+
await expect(input).toHaveFocus();
|
|
289
|
+
},
|
|
290
|
+
);
|
|
291
|
+
|
|
292
|
+
await step(
|
|
293
|
+
'interaction: typing updates the value and emits update:modelValue',
|
|
294
|
+
async () => {
|
|
295
|
+
await userEvent.keyboard('Ada Lovelace');
|
|
296
|
+
await expect(input).toHaveValue('Ada Lovelace');
|
|
297
|
+
await expect(onUpdate).toHaveBeenLastCalledWith('Ada Lovelace');
|
|
298
|
+
},
|
|
299
|
+
);
|
|
300
|
+
},
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* File mode exposes an accessible upload control and emits `update:files` with
|
|
305
|
+
* the selected files. Hidden test-only story.
|
|
306
|
+
*/
|
|
307
|
+
export const FileUpload: Story = {
|
|
308
|
+
name: 'test - File Upload',
|
|
309
|
+
tags: ['!dev', '!autodocs'],
|
|
310
|
+
render: () => ({
|
|
311
|
+
components: { UiInput },
|
|
312
|
+
setup() {
|
|
313
|
+
return { onFiles };
|
|
314
|
+
},
|
|
315
|
+
template: `<div class="grid w-full max-w-sm items-center gap-1.5">
|
|
316
|
+
<label for="attachment" class="body-14-medium">Attachment</label>
|
|
317
|
+
<UiInput id="attachment" name="attachment" type="file" @update:files="onFiles" />
|
|
318
|
+
</div>`,
|
|
319
|
+
}),
|
|
320
|
+
parameters: {
|
|
321
|
+
chromatic: { disableSnapshot: true },
|
|
322
|
+
docs: {
|
|
323
|
+
description: {
|
|
324
|
+
story:
|
|
325
|
+
'Selecting a file emits `update:files` and shows the file name. The upload control is labelled for assistive tech.',
|
|
326
|
+
},
|
|
327
|
+
},
|
|
328
|
+
},
|
|
329
|
+
play: async ({ canvasElement, step }) => {
|
|
330
|
+
// Scenario (UiInput): the hidden file input is labelled and, once a file is picked,
|
|
331
|
+
// the component emits update:files and shows the file name.
|
|
332
|
+
onFiles.mockClear();
|
|
333
|
+
const canvas = within(canvasElement);
|
|
334
|
+
const fileInput = canvas.getByLabelText('Upload') as HTMLInputElement;
|
|
335
|
+
|
|
336
|
+
await step(
|
|
337
|
+
'screen-reader: the upload control exposes an accessible name (WCAG 4.1.2)',
|
|
338
|
+
async () => {
|
|
339
|
+
await expect(fileInput).toHaveAccessibleName('Upload');
|
|
340
|
+
},
|
|
341
|
+
);
|
|
342
|
+
|
|
343
|
+
await step(
|
|
344
|
+
'interaction: selecting a file emits update:files and shows the file name',
|
|
345
|
+
async () => {
|
|
346
|
+
// Use globalThis.File because this module exports a `File` story that
|
|
347
|
+
// shadows the global File constructor.
|
|
348
|
+
const file = new globalThis.File(['hello'], 'hello.png', {
|
|
349
|
+
type: 'image/png',
|
|
350
|
+
});
|
|
351
|
+
await userEvent.upload(fileInput, file);
|
|
352
|
+
await expect(onFiles).toHaveBeenCalledWith([file]);
|
|
353
|
+
await expect(canvas.getByText('hello.png')).toBeInTheDocument();
|
|
354
|
+
},
|
|
355
|
+
);
|
|
356
|
+
},
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Design guidance for when to use the raw input vs. the field component.
|
|
361
|
+
*/
|
|
362
|
+
export const DesignNotes: Story = {
|
|
363
|
+
render: () => ({
|
|
364
|
+
template: `
|
|
365
|
+
<section class="flex flex-col gap-8 p-4 bg-surface-secondary">
|
|
366
|
+
<div>
|
|
367
|
+
<h2 class="heading-m font-bold text-content-on-surface-primary">Usage</h2>
|
|
368
|
+
<p class="body-16-regular mt-2 text-content-on-surface-primary">
|
|
369
|
+
The input field is a base component for form fields. It should not be
|
|
370
|
+
used on its own unless there is a specific need for text input without
|
|
371
|
+
labels. Please use the <strong class="font-semibold">field component</strong> and the
|
|
372
|
+
documentation there.
|
|
373
|
+
</p>
|
|
374
|
+
</div>
|
|
375
|
+
</section>
|
|
376
|
+
`,
|
|
377
|
+
}),
|
|
378
|
+
tags: ['!autodocs'],
|
|
379
|
+
parameters: {
|
|
380
|
+
a11y: { test: 'off' },
|
|
381
|
+
chromatic: {
|
|
382
|
+
disableSnapshot: true,
|
|
383
|
+
},
|
|
384
|
+
docs: {
|
|
385
|
+
canvas: {
|
|
386
|
+
sourceState: 'none',
|
|
387
|
+
},
|
|
388
|
+
},
|
|
389
|
+
},
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Accessibility guidance for input labelling, keyboard operability, and contrast.
|
|
394
|
+
*/
|
|
395
|
+
export const Accessibility: Story = {
|
|
396
|
+
render: () => ({
|
|
397
|
+
components: { UiInput },
|
|
398
|
+
template: `
|
|
399
|
+
<section class="flex flex-col gap-6 p-4">
|
|
400
|
+
<div>
|
|
401
|
+
<h2 class="heading-m font-bold text-content-on-surface-primary">
|
|
402
|
+
Accessibility
|
|
403
|
+
</h2>
|
|
404
|
+
</div>
|
|
405
|
+
|
|
406
|
+
<div class="flex flex-col gap-6">
|
|
407
|
+
<div class="flex flex-col gap-2">
|
|
408
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
409
|
+
Enable accessibility theme
|
|
410
|
+
</h3>
|
|
411
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
412
|
+
When accessibility is required, enable our accessibility theme. This
|
|
413
|
+
increases contrast and ensures there are no color contrast issues.
|
|
414
|
+
</p>
|
|
415
|
+
</div>
|
|
416
|
+
</div>
|
|
417
|
+
|
|
418
|
+
<div class="grid gap-4 md:grid-cols-2">
|
|
419
|
+
<div class="flex flex-col gap-3">
|
|
420
|
+
<h3 class="label-16-medium text-center text-content-on-surface-primary">
|
|
421
|
+
Default
|
|
422
|
+
</h3>
|
|
423
|
+
<div class="flex min-h-20 items-center justify-center border border-border-surface-default p-6">
|
|
424
|
+
<UiInput name="a11y-default" placeholder="Placeholder" class="max-w-xs" />
|
|
425
|
+
</div>
|
|
426
|
+
</div>
|
|
427
|
+
|
|
428
|
+
<div class="accessible-theme flex flex-col gap-3">
|
|
429
|
+
<h3 class="label-16-medium text-center text-content-on-surface-primary">
|
|
430
|
+
Accessible
|
|
431
|
+
</h3>
|
|
432
|
+
<div class="flex min-h-20 items-center justify-center border border-border-surface-default p-6">
|
|
433
|
+
<UiInput name="a11y-accessible" placeholder="Placeholder" class="max-w-xs" />
|
|
434
|
+
</div>
|
|
435
|
+
</div>
|
|
436
|
+
</div>
|
|
437
|
+
</section>
|
|
438
|
+
`,
|
|
439
|
+
}),
|
|
440
|
+
tags: ['!autodocs'],
|
|
441
|
+
parameters: {
|
|
442
|
+
a11y: { test: 'off' },
|
|
443
|
+
chromatic: {
|
|
444
|
+
disableSnapshot: true,
|
|
445
|
+
},
|
|
446
|
+
docs: {
|
|
447
|
+
canvas: {
|
|
448
|
+
sourceState: 'none',
|
|
449
|
+
},
|
|
450
|
+
},
|
|
451
|
+
},
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
const mobileBreakpointTemplateSource = `<script setup lang="ts">
|
|
455
|
+
import { UiInput } from '@aleph-alpha/ui-library'
|
|
456
|
+
</script>
|
|
457
|
+
|
|
458
|
+
<template>
|
|
459
|
+
<div class="grid w-full max-w-sm items-center gap-1.5">
|
|
460
|
+
<label for="mobile-email" class="body-14-medium">Email</label>
|
|
461
|
+
<UiInput id="mobile-email" name="email" type="email" placeholder="Email" />
|
|
462
|
+
</div>
|
|
463
|
+
</template>`;
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* Rendered at the mobile (320px reflow) breakpoint via the Media breakpoint
|
|
467
|
+
* toolbar. Stays operable, keyboard navigable, and meets the minimum
|
|
468
|
+
* touch-target size (WCAG 2.5.8). Hidden test-only story.
|
|
469
|
+
*/
|
|
470
|
+
export const MobileBreakpoint: Story = {
|
|
471
|
+
name: 'test - Mobile Breakpoint',
|
|
472
|
+
tags: ['!dev', '!autodocs'],
|
|
473
|
+
globals: { mediaBreakpoint: 'reflow' },
|
|
474
|
+
render: () => ({
|
|
475
|
+
components: { UiInput },
|
|
476
|
+
setup() {
|
|
477
|
+
return { onUpdate };
|
|
478
|
+
},
|
|
479
|
+
template: `<div class="grid w-full max-w-sm items-center gap-1.5">
|
|
480
|
+
<label for="mobile-email" class="body-14-medium">Email</label>
|
|
481
|
+
<UiInput id="mobile-email" name="email" type="email" placeholder="Email" @update:model-value="onUpdate" />
|
|
482
|
+
</div>`,
|
|
483
|
+
}),
|
|
484
|
+
parameters: {
|
|
485
|
+
// The play function focuses the input and types; skip the visual snapshot.
|
|
486
|
+
chromatic: { disableSnapshot: true },
|
|
487
|
+
docs: {
|
|
488
|
+
description: {
|
|
489
|
+
story:
|
|
490
|
+
'Switch the Media breakpoint toolbar to Mobile to preview the 320px layout.',
|
|
491
|
+
},
|
|
492
|
+
source: { code: mobileBreakpointTemplateSource },
|
|
493
|
+
},
|
|
494
|
+
},
|
|
495
|
+
play: async ({ canvasElement, step }) => {
|
|
496
|
+
// Scenario (UiInput): at the 320px mobile breakpoint the input stays labelled,
|
|
497
|
+
// keyboard operable, and large enough to touch.
|
|
498
|
+
onUpdate.mockClear();
|
|
499
|
+
const canvas = within(canvasElement);
|
|
500
|
+
const input = canvas.getByRole('textbox', { name: 'Email' });
|
|
501
|
+
|
|
502
|
+
await step(
|
|
503
|
+
'mobile: exposes an enabled, labelled textbox at the 320px breakpoint (WCAG 4.1.2)',
|
|
504
|
+
async () => {
|
|
505
|
+
await expect(input).toBeVisible();
|
|
506
|
+
await expect(input).toBeEnabled();
|
|
507
|
+
await expect(input).toHaveAccessibleName('Email');
|
|
508
|
+
},
|
|
509
|
+
);
|
|
510
|
+
|
|
511
|
+
await step(
|
|
512
|
+
'mobile: stays keyboard operable — Tab focuses and typing emits update:modelValue (WCAG 2.1.1)',
|
|
513
|
+
async () => {
|
|
514
|
+
await userEvent.tab();
|
|
515
|
+
await expect(input).toHaveFocus();
|
|
516
|
+
await userEvent.keyboard('ada@company.com');
|
|
517
|
+
await expect(input).toHaveValue('ada@company.com');
|
|
518
|
+
await expect(onUpdate).toHaveBeenLastCalledWith('ada@company.com');
|
|
519
|
+
},
|
|
520
|
+
);
|
|
521
|
+
|
|
522
|
+
await step(
|
|
523
|
+
'mobile: meets the minimum touch-target size (WCAG 2.5.8)',
|
|
524
|
+
async () => {
|
|
525
|
+
const { width, height } = input.getBoundingClientRect();
|
|
526
|
+
await expect(width).toBeGreaterThanOrEqual(24);
|
|
527
|
+
await expect(height).toBeGreaterThanOrEqual(24);
|
|
528
|
+
},
|
|
529
|
+
);
|
|
530
|
+
},
|
|
531
|
+
};
|
|
@@ -4,37 +4,29 @@ import { describe, expect, test } from 'vitest';
|
|
|
4
4
|
import UiInput from '../UiInput.vue';
|
|
5
5
|
|
|
6
6
|
describe('UiInput', () => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
// Text-input accessibility (textbox role, label association, disabled state),
|
|
8
|
+
// keyboard entry, and the `update:modelValue` / `update:files` events are
|
|
9
|
+
// covered by the Storybook play tests in `UiInput.stories.ts`. These unit
|
|
10
|
+
// tests cover the file-mode display logic that is unique to this wrapper.
|
|
11
|
+
test('file mode shows the selected file name', async () => {
|
|
12
|
+
const { getByLabelText, getByText } = render(UiInput, {
|
|
13
|
+
props: { name: 'attachment', type: 'file' },
|
|
13
14
|
});
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
expect(getByRole('textbox')).toBeEnabled();
|
|
15
|
+
await userEvent.upload(
|
|
16
|
+
getByLabelText('Upload'),
|
|
17
|
+
new File(['hello'], 'hello.png', { type: 'image/png' }),
|
|
18
|
+
);
|
|
19
|
+
expect(getByText('hello.png')).toBeInTheDocument();
|
|
20
20
|
});
|
|
21
21
|
|
|
22
|
-
test('
|
|
23
|
-
const {
|
|
24
|
-
props: {
|
|
25
|
-
disabled: true,
|
|
26
|
-
},
|
|
22
|
+
test('file mode shows a count when multiple files are selected', async () => {
|
|
23
|
+
const { getByLabelText, getByText } = render(UiInput, {
|
|
24
|
+
props: { name: 'attachments', type: 'file', multiple: true },
|
|
27
25
|
});
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const { getByRole, emitted } = render(UiInput);
|
|
34
|
-
await userEvent.type(getByRole('textbox'), testValue);
|
|
35
|
-
const emittedModelValue = emitted('update:modelValue') as string[][];
|
|
36
|
-
expect(emittedModelValue[emittedModelValue.length - 1][0]).toMatch(
|
|
37
|
-
testValue,
|
|
38
|
-
);
|
|
26
|
+
await userEvent.upload(getByLabelText('Upload'), [
|
|
27
|
+
new File(['a'], 'a.png', { type: 'image/png' }),
|
|
28
|
+
new File(['b'], 'b.png', { type: 'image/png' }),
|
|
29
|
+
]);
|
|
30
|
+
expect(getByText('2 files selected')).toBeInTheDocument();
|
|
39
31
|
});
|
|
40
32
|
});
|