@warp-ds/elements 2.5.0 → 2.5.1-next.1
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/dist/custom-elements.json +8 -0
- package/dist/packages/combobox/combobox.d.ts +5 -0
- package/dist/packages/combobox/combobox.js +12 -12
- package/dist/packages/combobox/combobox.js.map +3 -3
- package/dist/packages/combobox/combobox.stories.js +7 -7
- package/dist/packages/combobox/combobox.test.js +90 -0
- package/dist/web-types.json +1 -1
- package/package.json +1 -1
|
@@ -26,13 +26,13 @@ const meta = {
|
|
|
26
26
|
};
|
|
27
27
|
export default meta;
|
|
28
28
|
const sampleOptions = [
|
|
29
|
-
{ value: '
|
|
30
|
-
{ value: '
|
|
31
|
-
{ value: '
|
|
32
|
-
{ value: '
|
|
33
|
-
{ value: '
|
|
34
|
-
{ value: '
|
|
35
|
-
{ value: '
|
|
29
|
+
{ value: 'apple', label: 'Apple' },
|
|
30
|
+
{ value: 'banana', label: 'Banana' },
|
|
31
|
+
{ value: 'orange', label: 'Orange' },
|
|
32
|
+
{ value: 'grape', label: 'Grape' },
|
|
33
|
+
{ value: 'strawberry', label: 'Strawberry' },
|
|
34
|
+
{ value: 'pineapple', label: 'Pineapple' },
|
|
35
|
+
{ value: 'mango', label: 'Mango' },
|
|
36
36
|
];
|
|
37
37
|
export const Default = {
|
|
38
38
|
args: {},
|
|
@@ -19,3 +19,93 @@ test('renders with autocomplete attribute when provided', async () => {
|
|
|
19
19
|
const el = (await locator.element());
|
|
20
20
|
expect(el.getAttribute('autocomplete')).toBe('on');
|
|
21
21
|
});
|
|
22
|
+
test('displays initial value correctly when value prop is set', async () => {
|
|
23
|
+
const options = [
|
|
24
|
+
{ value: 'apple', label: 'Apple' },
|
|
25
|
+
{ value: 'banana', label: 'Banana' },
|
|
26
|
+
];
|
|
27
|
+
const component = html `<w-combobox
|
|
28
|
+
data-testid="combobox"
|
|
29
|
+
value="apple"
|
|
30
|
+
.options="${options}"
|
|
31
|
+
></w-combobox>`;
|
|
32
|
+
const page = render(component);
|
|
33
|
+
const locator = page.getByTestId('combobox');
|
|
34
|
+
await expect.element(locator).toBeVisible();
|
|
35
|
+
const el = (await locator.element());
|
|
36
|
+
// Get the textfield's input element
|
|
37
|
+
const textfield = el.shadowRoot?.querySelector('w-textfield');
|
|
38
|
+
const input = textfield?.shadowRoot?.querySelector('input');
|
|
39
|
+
// Verify the displayed text shows the label "Apple", not the value "apple"
|
|
40
|
+
expect(input?.value).toBe('Apple');
|
|
41
|
+
// Verify the combobox value is "apple"
|
|
42
|
+
expect(el.value).toBe('apple');
|
|
43
|
+
});
|
|
44
|
+
test('filters options by label, not value', async () => {
|
|
45
|
+
const options = [
|
|
46
|
+
{ value: 'us', label: 'United States' },
|
|
47
|
+
{ value: 'uk', label: 'United Kingdom' },
|
|
48
|
+
{ value: 'no', label: 'Norway' },
|
|
49
|
+
];
|
|
50
|
+
const component = html `<w-combobox
|
|
51
|
+
data-testid="combobox"
|
|
52
|
+
open-on-focus
|
|
53
|
+
.options="${options}"
|
|
54
|
+
></w-combobox>`;
|
|
55
|
+
const page = render(component);
|
|
56
|
+
const locator = page.getByTestId('combobox');
|
|
57
|
+
await expect.element(locator).toBeVisible();
|
|
58
|
+
const el = (await locator.element());
|
|
59
|
+
// Get the textfield's input element
|
|
60
|
+
const textfield = el.shadowRoot?.querySelector('w-textfield');
|
|
61
|
+
const input = textfield?.shadowRoot?.querySelector('input');
|
|
62
|
+
// Type "United" which should match labels "United States" and "United Kingdom"
|
|
63
|
+
// but NOT match any values (us, uk, no)
|
|
64
|
+
input?.focus();
|
|
65
|
+
input.value = 'United';
|
|
66
|
+
input.dispatchEvent(new InputEvent('input', { bubbles: true, composed: true }));
|
|
67
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
68
|
+
// Check that the dropdown shows the matching options
|
|
69
|
+
const listbox = el.shadowRoot?.querySelector('[role="listbox"]');
|
|
70
|
+
const visibleOptions = listbox?.querySelectorAll('[role="option"]');
|
|
71
|
+
// Should show 2 options: "United States" and "United Kingdom"
|
|
72
|
+
expect(visibleOptions?.length).toBe(2);
|
|
73
|
+
const optionTexts = Array.from(visibleOptions || []).map((opt) => opt.textContent?.trim());
|
|
74
|
+
expect(optionTexts).toContain('United States');
|
|
75
|
+
expect(optionTexts).toContain('United Kingdom');
|
|
76
|
+
expect(optionTexts).not.toContain('Norway');
|
|
77
|
+
});
|
|
78
|
+
test('displays option label in textfield but stores option value', async () => {
|
|
79
|
+
const optionsWithDifferentLabelAndValue = [
|
|
80
|
+
{ value: 'us', label: 'United States' },
|
|
81
|
+
{ value: 'uk', label: 'United Kingdom' },
|
|
82
|
+
{ value: 'no', label: 'Norway' },
|
|
83
|
+
];
|
|
84
|
+
const component = html `<w-combobox
|
|
85
|
+
data-testid="combobox"
|
|
86
|
+
open-on-focus
|
|
87
|
+
.options="${optionsWithDifferentLabelAndValue}"
|
|
88
|
+
></w-combobox>`;
|
|
89
|
+
const page = render(component);
|
|
90
|
+
const locator = page.getByTestId('combobox');
|
|
91
|
+
await expect.element(locator).toBeVisible();
|
|
92
|
+
const el = (await locator.element());
|
|
93
|
+
// Get the textfield's input element
|
|
94
|
+
const textfield = el.shadowRoot?.querySelector('w-textfield');
|
|
95
|
+
const input = textfield?.shadowRoot?.querySelector('input');
|
|
96
|
+
// Focus to open the dropdown
|
|
97
|
+
input?.focus();
|
|
98
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
99
|
+
// Find and click the "Norway" option (which has value "no")
|
|
100
|
+
const listbox = el.shadowRoot?.querySelector('[role="listbox"]');
|
|
101
|
+
const options = listbox?.querySelectorAll('[role="option"]');
|
|
102
|
+
const norwayOption = Array.from(options || []).find((opt) => opt.textContent?.trim() === 'Norway');
|
|
103
|
+
expect(norwayOption).toBeDefined();
|
|
104
|
+
// Simulate mousedown on the option
|
|
105
|
+
norwayOption?.dispatchEvent(new MouseEvent('mousedown', { bubbles: true }));
|
|
106
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
107
|
+
// Verify the displayed text is the label "Norway", not the value "no"
|
|
108
|
+
expect(input?.value).toBe('Norway');
|
|
109
|
+
// Verify the combobox value is "no", not "Norway"
|
|
110
|
+
expect(el.value).toBe('no');
|
|
111
|
+
});
|
package/dist/web-types.json
CHANGED