@olenbetong/appframe-ds 1.6.0 → 1.6.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/CHANGELOG.md +6 -0
- package/package.json +2 -2
- package/scripts/copyAssets.mjs +27 -27
- package/src/AfLookup/Lookup.css +147 -147
- package/src/AfLookup/Lookup.tsx +186 -186
- package/src/AfLookup/LookupCombobox.css +69 -69
- package/src/AfLookup/LookupCombobox.tsx +273 -273
- package/src/AfLookup/LookupEdit.tsx +130 -130
- package/src/AfLookup/LookupGrid.css +145 -145
- package/src/AfLookup/LookupGrid.test.tsx +142 -142
- package/src/AfLookup/LookupGrid.tsx +324 -324
- package/src/AfLookup/index.ts +5 -5
- package/src/autocomplete/Autocomplete.css +253 -253
- package/src/autocomplete/Autocomplete.tsx +320 -320
- package/src/autocomplete/AutocompleteFrame.tsx +168 -168
- package/src/autocomplete/Combobox.tsx +286 -286
- package/src/autocomplete/index.ts +4 -4
- package/src/autocomplete/types.ts +204 -204
- package/src/autocomplete/utils.ts +183 -183
- package/src/binding/BoundNumberInput.tsx +42 -42
- package/src/binding/BoundNumericTextField.tsx +102 -102
- package/src/binding/BoundTextField.tsx +49 -49
- package/src/binding/CancelButton.tsx +30 -30
- package/src/binding/CancelIconButton.tsx +30 -30
- package/src/binding/DataEditToolbar.css +23 -23
- package/src/binding/DataEditToolbar.tsx +84 -84
- package/src/binding/DeleteButton.tsx +35 -35
- package/src/binding/DeleteIconButton.tsx +35 -35
- package/src/binding/RefreshButton.tsx +31 -31
- package/src/binding/RefreshIconButton.tsx +33 -33
- package/src/binding/RefreshRowIconButton.tsx +33 -33
- package/src/binding/SaveButton.tsx +37 -37
- package/src/binding/SaveIconButton.tsx +38 -38
- package/src/binding/index.ts +20 -20
- package/src/container/Container.tsx +50 -50
- package/src/container/index.ts +1 -1
- package/src/cutoff/CutOffPicker.css +12 -12
- package/src/cutoff/CutOffPicker.tsx +165 -165
- package/src/cutoff/context.tsx +194 -194
- package/src/cutoff/dsCutOffDates.ts +21 -21
- package/src/cutoff/index.ts +4 -4
- package/src/cutoff/utils.test.ts +59 -59
- package/src/cutoff/utils.ts +276 -276
- package/src/filter/ChipListInput.tsx +79 -79
- package/src/filter/FieldFilterPanel.css +150 -150
- package/src/filter/FieldFilterPanel.tsx +309 -309
- package/src/filter/FilterBuilder.css +152 -152
- package/src/filter/FilterBuilder.test.tsx +153 -153
- package/src/filter/FilterBuilder.tsx +435 -435
- package/src/filter/FilterEditor.css +231 -231
- package/src/filter/FilterEditor.test.tsx +285 -285
- package/src/filter/FilterEditor.tsx +75 -75
- package/src/filter/FilterGroupEditor.tsx +160 -160
- package/src/filter/FilterNameDialog.css +22 -22
- package/src/filter/FilterNameDialog.tsx +81 -81
- package/src/filter/FilterRow.tsx +117 -117
- package/src/filter/FilterShareDialog.css +28 -28
- package/src/filter/FilterShareDialog.tsx +201 -201
- package/src/filter/FilterStringField.tsx +78 -78
- package/src/filter/FilterValueEditor.tsx +239 -239
- package/src/filter/SavedFilterTree.css +107 -107
- package/src/filter/SavedFilterTree.test.tsx +94 -94
- package/src/filter/SavedFilterTree.tsx +218 -218
- package/src/filter/fieldFilter.test.ts +158 -158
- package/src/filter/fieldFilter.ts +139 -139
- package/src/filter/index.ts +27 -27
- package/src/filter/types.ts +38 -38
- package/src/filter/useDistinctValues.test.ts +102 -102
- package/src/filter/useDistinctValues.ts +230 -230
- package/src/global.d.ts +11 -11
- package/src/grid/formatters.ts +23 -0
- package/src/grid/useAfColumns.tsx +28 -4
- package/src/grid/utcDate.test.ts +25 -0
- package/src/grid/utcDate.ts +28 -0
- package/src/grid/utcDateEditing.tsx +11 -0
- package/src/i18n.ts +13 -13
- package/src/index.ts +14 -14
- package/src/input/InputAdornments.css +80 -80
- package/src/input/InputAdornments.tsx +102 -102
- package/src/input/NumberInput.css +9 -9
- package/src/input/NumberInput.test.tsx +212 -212
- package/src/input/NumberInput.tsx +268 -268
- package/src/input/index.ts +3 -3
- package/src/input/numberFormat.test.ts +79 -79
- package/src/input/numberFormat.ts +94 -94
- package/src/layout/AppMenu.tsx +74 -74
- package/src/layout/AppMenuDrawer.css +71 -71
- package/src/layout/AppMenuDrawer.tsx +122 -122
- package/src/layout/DialogMotion.css +79 -79
- package/src/layout/ErrorBoundary.tsx +162 -162
- package/src/layout/PageContainer.css +48 -48
- package/src/layout/PageContainer.tsx +41 -41
- package/src/layout/ResponsiveDialog.css +86 -86
- package/src/layout/ResponsiveDialog.tsx +55 -55
- package/src/layout/index.tsx +70 -70
- package/src/link/Link.tsx +23 -23
- package/src/link/index.ts +1 -1
- package/src/mdi/Mdi.css +138 -138
- package/src/mdi/Mdi.test.tsx +91 -91
- package/src/mdi/Mdi.tsx +141 -141
- package/src/mdi/MdiConfirmCloseDialog.tsx +47 -47
- package/src/mdi/MdiContext.tsx +59 -59
- package/src/mdi/MdiDocumentContext.tsx +60 -60
- package/src/mdi/MdiPanel.tsx +61 -61
- package/src/mdi/MdiRestore.test.tsx +86 -86
- package/src/mdi/MdiTab.tsx +30 -30
- package/src/mdi/controller.test.ts +382 -382
- package/src/mdi/controller.ts +656 -656
- package/src/mdi/dockviewHost.ts +132 -132
- package/src/mdi/fakeHost.ts +200 -200
- package/src/mdi/host.ts +44 -44
- package/src/mdi/ids.test.ts +20 -20
- package/src/mdi/ids.ts +18 -18
- package/src/mdi/index.ts +31 -31
- package/src/mdi/layoutRestore.test.ts +156 -156
- package/src/mdi/layoutRestore.ts +311 -311
- package/src/mdi/layoutSpec.test.ts +143 -143
- package/src/mdi/layoutSpec.ts +214 -214
- package/src/mdi/layoutStore.test.ts +93 -93
- package/src/mdi/layoutStore.ts +99 -99
- package/src/mdi/memorySettingsStore.ts +21 -21
- package/src/mdi/registry.ts +34 -34
- package/src/mdi/testTypes.ts +37 -37
- package/src/mdi/theme.ts +22 -22
- package/src/mdi/types.ts +214 -214
- package/src/page/Page.css +57 -57
- package/src/page/PageBlock.css +64 -64
- package/src/page/PageBlock.tsx +93 -93
- package/src/page/PageHeader.css +88 -88
- package/src/page/PageHeader.tsx +115 -115
- package/src/page/PageTitle.css +5 -5
- package/src/page/PageTitle.tsx +21 -21
- package/src/page/index.ts +4 -4
- package/src/paper/Paper.tsx +52 -52
- package/src/progress/LinearProgress.css +121 -121
- package/src/progress/LinearProgress.tsx +106 -106
- package/src/progress/index.ts +1 -1
- package/src/report-downloader/ReportDownloader.css +67 -67
- package/src/report-downloader/components/StatusItem.tsx +87 -87
- package/src/report-downloader/components/StatusList.tsx +28 -28
- package/src/report-downloader/index.ts +41 -41
- package/src/report-downloader/status.tsx +92 -92
- package/src/sortable/DropIndicator.css +51 -51
- package/src/sortable/DropIndicator.tsx +27 -27
- package/src/sortable/SortableItemList.css +21 -21
- package/src/sortable/SortableItemList.tsx +264 -264
- package/src/sortable/index.ts +8 -8
- package/src/sortable/reorderSortOrder.ts +126 -126
- package/src/sortable/sortOrder.ts +101 -101
- package/src/sortable/types.ts +9 -9
- package/src/sortable/useSortableContainer.ts +53 -53
- package/src/sortable/useSortableItem.ts +95 -95
- package/src/sortable/useSortableList.ts +117 -117
- package/src/test/happy-dom-document-class.ts +24 -24
- package/src/test/setup.ts +27 -27
- package/src/theme/useDsColorScheme.ts +53 -53
- package/tsconfig.build.json +9 -9
- package/tsconfig.json +8 -8
- package/vitest.config.ts +10 -10
|
@@ -1,212 +1,212 @@
|
|
|
1
|
-
import { fireEvent, render, screen } from "@testing-library/react";
|
|
2
|
-
import userEvent from "@testing-library/user-event";
|
|
3
|
-
import { useState } from "react";
|
|
4
|
-
import { describe, expect, it, vi } from "vitest";
|
|
5
|
-
|
|
6
|
-
import { NumberInput, type NumberInputProps } from "./NumberInput.js";
|
|
7
|
-
|
|
8
|
-
function Controlled({
|
|
9
|
-
initial = null,
|
|
10
|
-
onChange,
|
|
11
|
-
...props
|
|
12
|
-
}: Partial<Omit<NumberInputProps, "value" | "onChange">> & {
|
|
13
|
-
initial?: number | null;
|
|
14
|
-
onChange?: (value: number | null) => void;
|
|
15
|
-
}) {
|
|
16
|
-
let [value, setValue] = useState<number | null>(initial);
|
|
17
|
-
|
|
18
|
-
return (
|
|
19
|
-
<NumberInput
|
|
20
|
-
label="Hours"
|
|
21
|
-
{...props}
|
|
22
|
-
value={value}
|
|
23
|
-
onChange={(next) => {
|
|
24
|
-
setValue(next);
|
|
25
|
-
onChange?.(next);
|
|
26
|
-
}}
|
|
27
|
-
/>
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
describe("NumberInput", () => {
|
|
32
|
-
it("shows the value formatted with the fraction digits, in nb-NO without a session", () => {
|
|
33
|
-
render(<Controlled initial={8} />);
|
|
34
|
-
|
|
35
|
-
expect(screen.getByLabelText("Hours")).toHaveValue("8,00");
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it("formats in the culture given", () => {
|
|
39
|
-
render(<Controlled initial={1234.5} culture="en-GB" />);
|
|
40
|
-
|
|
41
|
-
expect(screen.getByLabelText("Hours")).toHaveValue("1,234.50");
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("reads a period as the decimal separator for a Norwegian user too", async () => {
|
|
45
|
-
let onChange = vi.fn();
|
|
46
|
-
let user = userEvent.setup();
|
|
47
|
-
render(<Controlled initial={null} culture="nb-NO" onChange={onChange} />);
|
|
48
|
-
|
|
49
|
-
let input = screen.getByLabelText("Hours");
|
|
50
|
-
await user.type(input, "1.5");
|
|
51
|
-
expect(onChange).toHaveBeenLastCalledWith(1.5);
|
|
52
|
-
|
|
53
|
-
await user.tab();
|
|
54
|
-
expect(input).toHaveValue("1,50");
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it("shows an empty input for null", () => {
|
|
58
|
-
render(<Controlled initial={null} />);
|
|
59
|
-
|
|
60
|
-
expect(screen.getByLabelText("Hours")).toHaveValue("");
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it("parses typed text with either decimal separator", async () => {
|
|
64
|
-
let onChange = vi.fn();
|
|
65
|
-
let user = userEvent.setup();
|
|
66
|
-
render(<Controlled initial={null} onChange={onChange} />);
|
|
67
|
-
|
|
68
|
-
let input = screen.getByLabelText("Hours");
|
|
69
|
-
await user.type(input, "1,5");
|
|
70
|
-
expect(onChange).toHaveBeenLastCalledWith(1.5);
|
|
71
|
-
expect(input).toHaveValue("1,5");
|
|
72
|
-
|
|
73
|
-
await user.clear(input);
|
|
74
|
-
await user.type(input, "2.25");
|
|
75
|
-
expect(onChange).toHaveBeenLastCalledWith(2.25);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it("reports null when cleared and nothing while the text is incomplete", async () => {
|
|
79
|
-
let onChange = vi.fn();
|
|
80
|
-
let user = userEvent.setup();
|
|
81
|
-
render(<Controlled initial={3} onChange={onChange} />);
|
|
82
|
-
|
|
83
|
-
let input = screen.getByLabelText("Hours");
|
|
84
|
-
await user.clear(input);
|
|
85
|
-
expect(onChange).toHaveBeenLastCalledWith(null);
|
|
86
|
-
|
|
87
|
-
onChange.mockClear();
|
|
88
|
-
await user.type(input, "-");
|
|
89
|
-
expect(onChange).not.toHaveBeenCalled();
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it("formats the value again on blur", async () => {
|
|
93
|
-
let user = userEvent.setup();
|
|
94
|
-
render(<Controlled initial={null} />);
|
|
95
|
-
|
|
96
|
-
let input = screen.getByLabelText("Hours");
|
|
97
|
-
await user.type(input, "1,5");
|
|
98
|
-
await user.tab();
|
|
99
|
-
|
|
100
|
-
expect(input).toHaveValue("1,50");
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it("steps with the buttons, rounding to the fraction digits", async () => {
|
|
104
|
-
let onChange = vi.fn();
|
|
105
|
-
let user = userEvent.setup();
|
|
106
|
-
render(<Controlled initial={0.1} step={0.2} onChange={onChange} />);
|
|
107
|
-
|
|
108
|
-
await user.click(screen.getByRole("button", { name: "Increase value" }));
|
|
109
|
-
expect(onChange).toHaveBeenLastCalledWith(0.3);
|
|
110
|
-
|
|
111
|
-
await user.click(screen.getByRole("button", { name: "Decrease value" }));
|
|
112
|
-
await user.click(screen.getByRole("button", { name: "Decrease value" }));
|
|
113
|
-
expect(onChange).toHaveBeenLastCalledWith(-0.1);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it("steps from zero when empty", async () => {
|
|
117
|
-
let onChange = vi.fn();
|
|
118
|
-
let user = userEvent.setup();
|
|
119
|
-
render(<Controlled initial={null} step={0.25} onChange={onChange} />);
|
|
120
|
-
|
|
121
|
-
await user.click(screen.getByRole("button", { name: "Increase value" }));
|
|
122
|
-
expect(onChange).toHaveBeenLastCalledWith(0.25);
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it("steps with the arrow keys and keeps the text selected", async () => {
|
|
126
|
-
let onChange = vi.fn();
|
|
127
|
-
let user = userEvent.setup();
|
|
128
|
-
render(<Controlled initial={1} onChange={onChange} />);
|
|
129
|
-
|
|
130
|
-
let input = screen.getByLabelText("Hours") as HTMLInputElement;
|
|
131
|
-
await user.click(input);
|
|
132
|
-
await user.keyboard("{ArrowUp}{ArrowUp}{ArrowDown}");
|
|
133
|
-
|
|
134
|
-
expect(onChange).toHaveBeenLastCalledWith(2);
|
|
135
|
-
expect(input).toHaveValue("2,00");
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it("clamps typed and stepped values to min and max", async () => {
|
|
139
|
-
let onChange = vi.fn();
|
|
140
|
-
let user = userEvent.setup();
|
|
141
|
-
render(<Controlled initial={23} min={0} max={24} onChange={onChange} />);
|
|
142
|
-
|
|
143
|
-
let input = screen.getByLabelText("Hours");
|
|
144
|
-
await user.click(screen.getByRole("button", { name: "Increase value" }));
|
|
145
|
-
expect(onChange).toHaveBeenLastCalledWith(24);
|
|
146
|
-
expect(screen.getByRole("button", { name: "Increase value" })).toBeDisabled();
|
|
147
|
-
|
|
148
|
-
await user.clear(input);
|
|
149
|
-
await user.type(input, "30");
|
|
150
|
-
expect(onChange).toHaveBeenLastCalledWith(24);
|
|
151
|
-
expect(input).toHaveValue("24,00");
|
|
152
|
-
|
|
153
|
-
await user.clear(input);
|
|
154
|
-
await user.type(input, "-5");
|
|
155
|
-
expect(onChange).toHaveBeenLastCalledWith(0);
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it("hides the steppers when read only, disabled or asked to", () => {
|
|
159
|
-
let { rerender } = render(<Controlled initial={1} readOnly />);
|
|
160
|
-
expect(screen.queryByRole("button")).toBeNull();
|
|
161
|
-
|
|
162
|
-
rerender(<Controlled initial={1} disabled />);
|
|
163
|
-
expect(screen.queryByRole("button")).toBeNull();
|
|
164
|
-
|
|
165
|
-
rerender(<Controlled initial={1} hideSteppers />);
|
|
166
|
-
expect(screen.queryByRole("button")).toBeNull();
|
|
167
|
-
|
|
168
|
-
rerender(<Controlled initial={1} />);
|
|
169
|
-
expect(screen.getAllByRole("button")).toHaveLength(2);
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
it("does not step a read only input from the keyboard", () => {
|
|
173
|
-
let onChange = vi.fn();
|
|
174
|
-
render(<Controlled initial={1} readOnly onChange={onChange} />);
|
|
175
|
-
|
|
176
|
-
fireEvent.keyDown(screen.getByLabelText("Hours"), { key: "ArrowUp" });
|
|
177
|
-
expect(onChange).not.toHaveBeenCalled();
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
it("shows the description and the error, and marks the input invalid", () => {
|
|
181
|
-
render(<Controlled initial={1} description="Including overtime" error="Too many hours" />);
|
|
182
|
-
|
|
183
|
-
expect(screen.getByText("Including overtime")).toBeInTheDocument();
|
|
184
|
-
expect(screen.getByText("Too many hours")).toBeInTheDocument();
|
|
185
|
-
expect(screen.getByLabelText("Hours")).toHaveAttribute("aria-invalid", "true");
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
it("shows a value changed from the outside while focused", async () => {
|
|
189
|
-
function Resettable() {
|
|
190
|
-
let [value, setValue] = useState<number | null>(5);
|
|
191
|
-
return (
|
|
192
|
-
<>
|
|
193
|
-
<NumberInput label="Hours" value={value} onChange={setValue} />
|
|
194
|
-
<button type="button" onClick={() => setValue(0)}>
|
|
195
|
-
Reset
|
|
196
|
-
</button>
|
|
197
|
-
</>
|
|
198
|
-
);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
let user = userEvent.setup();
|
|
202
|
-
render(<Resettable />);
|
|
203
|
-
|
|
204
|
-
let input = screen.getByLabelText("Hours");
|
|
205
|
-
await user.click(input);
|
|
206
|
-
await user.keyboard("7");
|
|
207
|
-
expect(input).toHaveValue("7");
|
|
208
|
-
|
|
209
|
-
fireEvent.click(screen.getByRole("button", { name: "Reset" }));
|
|
210
|
-
expect(input).toHaveValue("0,00");
|
|
211
|
-
});
|
|
212
|
-
});
|
|
1
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
2
|
+
import userEvent from "@testing-library/user-event";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { describe, expect, it, vi } from "vitest";
|
|
5
|
+
|
|
6
|
+
import { NumberInput, type NumberInputProps } from "./NumberInput.js";
|
|
7
|
+
|
|
8
|
+
function Controlled({
|
|
9
|
+
initial = null,
|
|
10
|
+
onChange,
|
|
11
|
+
...props
|
|
12
|
+
}: Partial<Omit<NumberInputProps, "value" | "onChange">> & {
|
|
13
|
+
initial?: number | null;
|
|
14
|
+
onChange?: (value: number | null) => void;
|
|
15
|
+
}) {
|
|
16
|
+
let [value, setValue] = useState<number | null>(initial);
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<NumberInput
|
|
20
|
+
label="Hours"
|
|
21
|
+
{...props}
|
|
22
|
+
value={value}
|
|
23
|
+
onChange={(next) => {
|
|
24
|
+
setValue(next);
|
|
25
|
+
onChange?.(next);
|
|
26
|
+
}}
|
|
27
|
+
/>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
describe("NumberInput", () => {
|
|
32
|
+
it("shows the value formatted with the fraction digits, in nb-NO without a session", () => {
|
|
33
|
+
render(<Controlled initial={8} />);
|
|
34
|
+
|
|
35
|
+
expect(screen.getByLabelText("Hours")).toHaveValue("8,00");
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("formats in the culture given", () => {
|
|
39
|
+
render(<Controlled initial={1234.5} culture="en-GB" />);
|
|
40
|
+
|
|
41
|
+
expect(screen.getByLabelText("Hours")).toHaveValue("1,234.50");
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("reads a period as the decimal separator for a Norwegian user too", async () => {
|
|
45
|
+
let onChange = vi.fn();
|
|
46
|
+
let user = userEvent.setup();
|
|
47
|
+
render(<Controlled initial={null} culture="nb-NO" onChange={onChange} />);
|
|
48
|
+
|
|
49
|
+
let input = screen.getByLabelText("Hours");
|
|
50
|
+
await user.type(input, "1.5");
|
|
51
|
+
expect(onChange).toHaveBeenLastCalledWith(1.5);
|
|
52
|
+
|
|
53
|
+
await user.tab();
|
|
54
|
+
expect(input).toHaveValue("1,50");
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("shows an empty input for null", () => {
|
|
58
|
+
render(<Controlled initial={null} />);
|
|
59
|
+
|
|
60
|
+
expect(screen.getByLabelText("Hours")).toHaveValue("");
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("parses typed text with either decimal separator", async () => {
|
|
64
|
+
let onChange = vi.fn();
|
|
65
|
+
let user = userEvent.setup();
|
|
66
|
+
render(<Controlled initial={null} onChange={onChange} />);
|
|
67
|
+
|
|
68
|
+
let input = screen.getByLabelText("Hours");
|
|
69
|
+
await user.type(input, "1,5");
|
|
70
|
+
expect(onChange).toHaveBeenLastCalledWith(1.5);
|
|
71
|
+
expect(input).toHaveValue("1,5");
|
|
72
|
+
|
|
73
|
+
await user.clear(input);
|
|
74
|
+
await user.type(input, "2.25");
|
|
75
|
+
expect(onChange).toHaveBeenLastCalledWith(2.25);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("reports null when cleared and nothing while the text is incomplete", async () => {
|
|
79
|
+
let onChange = vi.fn();
|
|
80
|
+
let user = userEvent.setup();
|
|
81
|
+
render(<Controlled initial={3} onChange={onChange} />);
|
|
82
|
+
|
|
83
|
+
let input = screen.getByLabelText("Hours");
|
|
84
|
+
await user.clear(input);
|
|
85
|
+
expect(onChange).toHaveBeenLastCalledWith(null);
|
|
86
|
+
|
|
87
|
+
onChange.mockClear();
|
|
88
|
+
await user.type(input, "-");
|
|
89
|
+
expect(onChange).not.toHaveBeenCalled();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("formats the value again on blur", async () => {
|
|
93
|
+
let user = userEvent.setup();
|
|
94
|
+
render(<Controlled initial={null} />);
|
|
95
|
+
|
|
96
|
+
let input = screen.getByLabelText("Hours");
|
|
97
|
+
await user.type(input, "1,5");
|
|
98
|
+
await user.tab();
|
|
99
|
+
|
|
100
|
+
expect(input).toHaveValue("1,50");
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("steps with the buttons, rounding to the fraction digits", async () => {
|
|
104
|
+
let onChange = vi.fn();
|
|
105
|
+
let user = userEvent.setup();
|
|
106
|
+
render(<Controlled initial={0.1} step={0.2} onChange={onChange} />);
|
|
107
|
+
|
|
108
|
+
await user.click(screen.getByRole("button", { name: "Increase value" }));
|
|
109
|
+
expect(onChange).toHaveBeenLastCalledWith(0.3);
|
|
110
|
+
|
|
111
|
+
await user.click(screen.getByRole("button", { name: "Decrease value" }));
|
|
112
|
+
await user.click(screen.getByRole("button", { name: "Decrease value" }));
|
|
113
|
+
expect(onChange).toHaveBeenLastCalledWith(-0.1);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("steps from zero when empty", async () => {
|
|
117
|
+
let onChange = vi.fn();
|
|
118
|
+
let user = userEvent.setup();
|
|
119
|
+
render(<Controlled initial={null} step={0.25} onChange={onChange} />);
|
|
120
|
+
|
|
121
|
+
await user.click(screen.getByRole("button", { name: "Increase value" }));
|
|
122
|
+
expect(onChange).toHaveBeenLastCalledWith(0.25);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("steps with the arrow keys and keeps the text selected", async () => {
|
|
126
|
+
let onChange = vi.fn();
|
|
127
|
+
let user = userEvent.setup();
|
|
128
|
+
render(<Controlled initial={1} onChange={onChange} />);
|
|
129
|
+
|
|
130
|
+
let input = screen.getByLabelText("Hours") as HTMLInputElement;
|
|
131
|
+
await user.click(input);
|
|
132
|
+
await user.keyboard("{ArrowUp}{ArrowUp}{ArrowDown}");
|
|
133
|
+
|
|
134
|
+
expect(onChange).toHaveBeenLastCalledWith(2);
|
|
135
|
+
expect(input).toHaveValue("2,00");
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("clamps typed and stepped values to min and max", async () => {
|
|
139
|
+
let onChange = vi.fn();
|
|
140
|
+
let user = userEvent.setup();
|
|
141
|
+
render(<Controlled initial={23} min={0} max={24} onChange={onChange} />);
|
|
142
|
+
|
|
143
|
+
let input = screen.getByLabelText("Hours");
|
|
144
|
+
await user.click(screen.getByRole("button", { name: "Increase value" }));
|
|
145
|
+
expect(onChange).toHaveBeenLastCalledWith(24);
|
|
146
|
+
expect(screen.getByRole("button", { name: "Increase value" })).toBeDisabled();
|
|
147
|
+
|
|
148
|
+
await user.clear(input);
|
|
149
|
+
await user.type(input, "30");
|
|
150
|
+
expect(onChange).toHaveBeenLastCalledWith(24);
|
|
151
|
+
expect(input).toHaveValue("24,00");
|
|
152
|
+
|
|
153
|
+
await user.clear(input);
|
|
154
|
+
await user.type(input, "-5");
|
|
155
|
+
expect(onChange).toHaveBeenLastCalledWith(0);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("hides the steppers when read only, disabled or asked to", () => {
|
|
159
|
+
let { rerender } = render(<Controlled initial={1} readOnly />);
|
|
160
|
+
expect(screen.queryByRole("button")).toBeNull();
|
|
161
|
+
|
|
162
|
+
rerender(<Controlled initial={1} disabled />);
|
|
163
|
+
expect(screen.queryByRole("button")).toBeNull();
|
|
164
|
+
|
|
165
|
+
rerender(<Controlled initial={1} hideSteppers />);
|
|
166
|
+
expect(screen.queryByRole("button")).toBeNull();
|
|
167
|
+
|
|
168
|
+
rerender(<Controlled initial={1} />);
|
|
169
|
+
expect(screen.getAllByRole("button")).toHaveLength(2);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("does not step a read only input from the keyboard", () => {
|
|
173
|
+
let onChange = vi.fn();
|
|
174
|
+
render(<Controlled initial={1} readOnly onChange={onChange} />);
|
|
175
|
+
|
|
176
|
+
fireEvent.keyDown(screen.getByLabelText("Hours"), { key: "ArrowUp" });
|
|
177
|
+
expect(onChange).not.toHaveBeenCalled();
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it("shows the description and the error, and marks the input invalid", () => {
|
|
181
|
+
render(<Controlled initial={1} description="Including overtime" error="Too many hours" />);
|
|
182
|
+
|
|
183
|
+
expect(screen.getByText("Including overtime")).toBeInTheDocument();
|
|
184
|
+
expect(screen.getByText("Too many hours")).toBeInTheDocument();
|
|
185
|
+
expect(screen.getByLabelText("Hours")).toHaveAttribute("aria-invalid", "true");
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it("shows a value changed from the outside while focused", async () => {
|
|
189
|
+
function Resettable() {
|
|
190
|
+
let [value, setValue] = useState<number | null>(5);
|
|
191
|
+
return (
|
|
192
|
+
<>
|
|
193
|
+
<NumberInput label="Hours" value={value} onChange={setValue} />
|
|
194
|
+
<button type="button" onClick={() => setValue(0)}>
|
|
195
|
+
Reset
|
|
196
|
+
</button>
|
|
197
|
+
</>
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
let user = userEvent.setup();
|
|
202
|
+
render(<Resettable />);
|
|
203
|
+
|
|
204
|
+
let input = screen.getByLabelText("Hours");
|
|
205
|
+
await user.click(input);
|
|
206
|
+
await user.keyboard("7");
|
|
207
|
+
expect(input).toHaveValue("7");
|
|
208
|
+
|
|
209
|
+
fireEvent.click(screen.getByRole("button", { name: "Reset" }));
|
|
210
|
+
expect(input).toHaveValue("0,00");
|
|
211
|
+
});
|
|
212
|
+
});
|