@delacour/react-native-ui 0.6.0-alpha.20261103164139 → 0.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/package.json +13 -7
- package/src/components/accordion/AGENTS.md +1 -0
- package/src/components/accordion/accordion.render.test.tsx +330 -0
- package/src/components/alert/AGENTS.md +1 -0
- package/src/components/alert/alert.render.test.tsx +162 -0
- package/src/components/animated-badge/AGENTS.md +1 -0
- package/src/components/animated-badge/animated-badge.render.test.tsx +136 -0
- package/src/components/attachment/AGENTS.md +1 -0
- package/src/components/attachment/attachment.render.test.tsx +422 -0
- package/src/components/avatar/AGENTS.md +1 -0
- package/src/components/avatar/avatar.render.test.tsx +353 -0
- package/src/components/badge/AGENTS.md +1 -0
- package/src/components/badge/badge.render.test.tsx +216 -0
- package/src/components/bottom-sheet/AGENTS.md +1 -0
- package/src/components/bottom-sheet/bottom-sheet.render.test.tsx +190 -0
- package/src/components/breadcrumb/AGENTS.md +1 -0
- package/src/components/breadcrumb/breadcrumb.render.test.tsx +324 -0
- package/src/components/button/AGENTS.md +1 -0
- package/src/components/button/button.render.test.tsx +67 -0
- package/src/components/calendar/AGENTS.md +1 -0
- package/src/components/calendar/calendar.render.test.tsx +388 -0
- package/src/components/card/AGENTS.md +1 -0
- package/src/components/card/card.render.test.tsx +287 -0
- package/src/components/carousel/AGENTS.md +3 -0
- package/src/components/carousel/carousel-content.tsx +3 -1
- package/src/components/carousel/carousel.render.test.tsx +356 -0
- package/src/components/chart/AGENTS.md +1 -0
- package/src/components/chart/chart.render.test.tsx +443 -0
- package/src/components/checkbox/AGENTS.md +2 -0
- package/src/components/checkbox/checkbox.render.test.tsx +250 -0
- package/src/components/checkbox/checkbox.tsx +2 -1
- package/src/components/chip/chip.render.test.tsx +277 -0
- package/src/components/circular-text/AGENTS.md +1 -0
- package/src/components/circular-text/circular-text.render.test.tsx +154 -0
- package/src/components/collapsible/AGENTS.md +1 -0
- package/src/components/collapsible/collapsible.render.test.tsx +243 -0
- package/src/components/color-picker/AGENTS.md +1 -0
- package/src/components/color-picker/color-picker.render.test.tsx +347 -0
- package/src/components/combobox/AGENTS.md +1 -0
- package/src/components/combobox/combobox.render.test.tsx +464 -0
- package/src/components/compare/AGENTS.md +1 -0
- package/src/components/compare/compare.render.test.tsx +265 -0
- package/src/components/context-menu/AGENTS.md +1 -0
- package/src/components/context-menu/context-menu.render.test.tsx +183 -0
- package/src/components/countdown/AGENTS.md +1 -0
- package/src/components/countdown/countdown.render.test.tsx +194 -0
- package/src/components/date-picker/AGENTS.md +1 -0
- package/src/components/date-picker/date-picker.render.test.tsx +378 -0
- package/src/components/date-time-picker/AGENTS.md +1 -0
- package/src/components/date-time-picker/date-time-picker.render.test.tsx +356 -0
- package/src/components/dialog/AGENTS.md +1 -0
- package/src/components/dialog/dialog.render.test.tsx +67 -0
- package/src/components/direction/AGENTS.md +1 -0
- package/src/components/direction/direction.render.test.tsx +150 -0
- package/src/components/drawer/AGENTS.md +1 -0
- package/src/components/drawer/drawer.render.test.tsx +340 -0
- package/src/components/empty-state/AGENTS.md +1 -0
- package/src/components/empty-state/empty-state.render.test.tsx +134 -0
- package/src/components/fab/AGENTS.md +1 -0
- package/src/components/fab/fab.render.test.tsx +278 -0
- package/src/components/feedback/AGENTS.md +1 -0
- package/src/components/feedback/feedback.render.test.tsx +257 -0
- package/src/components/field/AGENTS.md +1 -0
- package/src/components/field/field.render.test.tsx +361 -0
- package/src/components/flip-card/AGENTS.md +1 -0
- package/src/components/flip-card/flip-card.render.test.tsx +259 -0
- package/src/components/flow/AGENTS.md +1 -0
- package/src/components/flow/flow.render.test.tsx +354 -0
- package/src/components/frame/AGENTS.md +1 -0
- package/src/components/frame/frame.render.test.tsx +273 -0
- package/src/components/grid-item/AGENTS.md +1 -0
- package/src/components/grid-item/grid-item.render.test.tsx +326 -0
- package/src/components/icon/AGENTS.md +1 -0
- package/src/components/icon/icon.render.test.tsx +110 -0
- package/src/components/image-viewer/AGENTS.md +5 -0
- package/src/components/image-viewer/image-viewer.render.test.tsx +244 -0
- package/src/components/image-viewer/image-viewer.tsx +6 -3
- package/src/components/input/AGENTS.md +1 -0
- package/src/components/input/input.render.test.tsx +246 -0
- package/src/components/item/AGENTS.md +1 -0
- package/src/components/item/item.render.test.tsx +276 -0
- package/src/components/kpi/AGENTS.md +1 -0
- package/src/components/kpi/kpi.render.test.tsx +232 -0
- package/src/components/label/AGENTS.md +1 -0
- package/src/components/label/label.render.test.tsx +81 -0
- package/src/components/leaderboard/AGENTS.md +1 -0
- package/src/components/leaderboard/leaderboard.render.test.tsx +198 -0
- package/src/components/list-group/AGENTS.md +1 -0
- package/src/components/list-group/list-group.render.test.tsx +279 -0
- package/src/components/map/AGENTS.md +1 -0
- package/src/components/map/map.render.test.tsx +460 -0
- package/src/components/markdown-editor/AGENTS.md +1 -0
- package/src/components/markdown-editor/markdown-editor.render.test.tsx +461 -0
- package/src/components/marker/AGENTS.md +1 -0
- package/src/components/marker/marker.render.test.tsx +232 -0
- package/src/components/marquee/AGENTS.md +1 -0
- package/src/components/marquee/marquee.render.test.tsx +145 -0
- package/src/components/menu/AGENTS.md +2 -0
- package/src/components/menu/menu-item.tsx +40 -1
- package/src/components/menu/menu.render.test.tsx +449 -0
- package/src/components/message/AGENTS.md +1 -0
- package/src/components/message/message.render.test.tsx +401 -0
- package/src/components/message-scroller/AGENTS.md +1 -0
- package/src/components/message-scroller/message-scroller.render.test.tsx +295 -0
- package/src/components/meter/AGENTS.md +1 -0
- package/src/components/meter/meter.render.test.tsx +249 -0
- package/src/components/number-input/AGENTS.md +2 -0
- package/src/components/number-input/number-input-field.tsx +3 -2
- package/src/components/number-input/number-input.render.test.tsx +426 -0
- package/src/components/otp-input/AGENTS.md +3 -0
- package/src/components/otp-input/otp-input.render.test.tsx +405 -0
- package/src/components/otp-input/otp-input.tsx +9 -2
- package/src/components/overlay/AGENTS.md +7 -1
- package/src/components/overlay/overlay-teleport.ts +21 -0
- package/src/components/overlay/overlay.render.test.tsx +367 -0
- package/src/components/overlay/overlay.tsx +5 -2
- package/src/components/page-header/AGENTS.md +1 -0
- package/src/components/page-header/page-header.render.test.tsx +217 -0
- package/src/components/pagination/AGENTS.md +1 -0
- package/src/components/pagination/pagination.render.test.tsx +293 -0
- package/src/components/planner/AGENTS.md +1 -0
- package/src/components/planner/planner.render.test.tsx +429 -0
- package/src/components/popover/AGENTS.md +1 -0
- package/src/components/popover/popover.render.test.tsx +206 -0
- package/src/components/post/AGENTS.md +4 -0
- package/src/components/post/post-author.tsx +8 -1
- package/src/components/post/post-community.tsx +7 -1
- package/src/components/post/post.render.test.tsx +456 -0
- package/src/components/pressable/AGENTS.md +7 -0
- package/src/components/pressable/pressable.render.test.tsx +183 -0
- package/src/components/pressable/pressable.tsx +1 -1
- package/src/components/progress/AGENTS.md +1 -0
- package/src/components/progress/progress.render.test.tsx +192 -0
- package/src/components/progress-button/AGENTS.md +1 -0
- package/src/components/progress-button/progress-button.render.test.tsx +251 -0
- package/src/components/provider/AGENTS.md +1 -0
- package/src/components/provider/provider.render.test.tsx +101 -0
- package/src/components/qr-code/AGENTS.md +1 -0
- package/src/components/qr-code/qr-code.render.test.tsx +117 -0
- package/src/components/questionnaire/AGENTS.md +1 -0
- package/src/components/questionnaire/questionnaire.render.test.tsx +549 -0
- package/src/components/radio/AGENTS.md +1 -0
- package/src/components/radio/radio.render.test.tsx +334 -0
- package/src/components/rating/AGENTS.md +5 -0
- package/src/components/rating/rating-stars.tsx +4 -0
- package/src/components/rating/rating.render.test.tsx +402 -0
- package/src/components/screen/AGENTS.md +9 -0
- package/src/components/screen/screen-error.tsx +3 -1
- package/src/components/screen/screen-navbar-title.tsx +6 -1
- package/src/components/screen/screen.render.test.tsx +309 -0
- package/src/components/scroll-blur/AGENTS.md +1 -0
- package/src/components/scroll-blur/scroll-blur.render.test.tsx +197 -0
- package/src/components/scroll-canvas/AGENTS.md +1 -0
- package/src/components/scroll-canvas/scroll-canvas.render.test.tsx +184 -0
- package/src/components/scroll-fade/AGENTS.md +1 -0
- package/src/components/scroll-fade/scroll-fade-edge.tsx +1 -0
- package/src/components/scroll-fade/scroll-fade.render.test.tsx +122 -0
- package/src/components/scroll-header/AGENTS.md +1 -0
- package/src/components/scroll-header/scroll-header.render.test.tsx +168 -0
- package/src/components/scroll-text/AGENTS.md +1 -0
- package/src/components/scroll-text/scroll-text.render.test.tsx +191 -0
- package/src/components/search-bar/AGENTS.md +1 -0
- package/src/components/search-bar/search-bar.render.test.tsx +377 -0
- package/src/components/section-progress/AGENTS.md +1 -0
- package/src/components/section-progress/section-progress.render.test.tsx +186 -0
- package/src/components/section-rail/AGENTS.md +1 -0
- package/src/components/section-rail/section-rail.render.test.tsx +341 -0
- package/src/components/select/AGENTS.md +1 -0
- package/src/components/select/select.render.test.tsx +466 -0
- package/src/components/selection-mode/AGENTS.md +1 -0
- package/src/components/selection-mode/selection-mode.render.test.tsx +487 -0
- package/src/components/separator/AGENTS.md +1 -0
- package/src/components/separator/separator.render.test.tsx +43 -0
- package/src/components/signature/AGENTS.md +4 -0
- package/src/components/signature/signature-pad.tsx +4 -0
- package/src/components/signature/signature.render.test.tsx +257 -0
- package/src/components/skeleton/AGENTS.md +2 -1
- package/src/components/skeleton/skeleton.render.test.tsx +222 -0
- package/src/components/sketch/AGENTS.md +2 -0
- package/src/components/sketch/sketch-canvas.tsx +4 -0
- package/src/components/sketch/sketch.render.test.tsx +527 -0
- package/src/components/slide-button/AGENTS.md +2 -0
- package/src/components/slide-button/slide-button.render.test.tsx +354 -0
- package/src/components/slide-button/slide-button.tsx +4 -0
- package/src/components/slider/AGENTS.md +12 -0
- package/src/components/slider/slider-thumb.tsx +2 -1
- package/src/components/slider/slider-track.tsx +4 -1
- package/src/components/slider/slider.render.test.tsx +254 -0
- package/src/components/slider/slider.tsx +11 -0
- package/src/components/sortable/AGENTS.md +2 -0
- package/src/components/sortable/sortable-item.tsx +2 -1
- package/src/components/sortable/sortable.render.test.tsx +204 -0
- package/src/components/spinner/AGENTS.md +3 -0
- package/src/components/spinner/spinner.render.test.tsx +88 -0
- package/src/components/spinner/spinner.tsx +1 -0
- package/src/components/split-view/AGENTS.md +1 -0
- package/src/components/split-view/split-view-drag-area.tsx +2 -0
- package/src/components/split-view/split-view.render.test.tsx +423 -0
- package/src/components/splitter/AGENTS.md +7 -0
- package/src/components/splitter/splitter-handle.tsx +2 -0
- package/src/components/splitter/splitter.render.test.tsx +307 -0
- package/src/components/stack-card/AGENTS.md +3 -0
- package/src/components/stack-card/stack-card.render.test.tsx +309 -0
- package/src/components/stack-card/stack-card.tsx +1 -1
- package/src/components/steps/AGENTS.md +1 -0
- package/src/components/steps/steps.render.test.tsx +318 -0
- package/src/components/support/AGENTS.md +1 -0
- package/src/components/support/support.render.test.tsx +331 -0
- package/src/components/surface/AGENTS.md +1 -0
- package/src/components/surface/surface.render.test.tsx +129 -0
- package/src/components/swipe/AGENTS.md +3 -0
- package/src/components/swipe/swipe.render.test.tsx +280 -0
- package/src/components/swipe/swipe.tsx +7 -4
- package/src/components/switch/AGENTS.md +5 -0
- package/src/components/switch/switch.render.test.tsx +46 -0
- package/src/components/switch/switch.tsx +5 -1
- package/src/components/table/AGENTS.md +1 -0
- package/src/components/table/table.render.test.tsx +294 -0
- package/src/components/tabs/AGENTS.md +6 -0
- package/src/components/tabs/tabs.render.test.tsx +325 -0
- package/src/components/tabs/tabs.tsx +12 -1
- package/src/components/tag-input/AGENTS.md +1 -0
- package/src/components/tag-input/tag-input.render.test.tsx +655 -0
- package/src/components/text/AGENTS.md +1 -0
- package/src/components/text/text.render.test.tsx +197 -0
- package/src/components/text-animation/AGENTS.md +1 -0
- package/src/components/text-animation/text-animation.render.test.tsx +283 -0
- package/src/components/textarea/AGENTS.md +1 -0
- package/src/components/textarea/textarea.render.test.tsx +192 -0
- package/src/components/theme-selector/AGENTS.md +1 -0
- package/src/components/theme-selector/theme-selector.render.test.tsx +196 -0
- package/src/components/time-picker/AGENTS.md +1 -0
- package/src/components/time-picker/time-picker.render.test.tsx +466 -0
- package/src/components/timeline/AGENTS.md +1 -0
- package/src/components/timeline/timeline.render.test.tsx +316 -0
- package/src/components/toast/AGENTS.md +1 -0
- package/src/components/toast/toast.render.test.tsx +245 -0
- package/src/components/toggle-button/AGENTS.md +1 -0
- package/src/components/toggle-button/toggle-button.render.test.tsx +392 -0
- package/src/components/tooltip/AGENTS.md +1 -0
- package/src/components/tooltip/tooltip.render.test.tsx +231 -0
- package/src/components/tour/AGENTS.md +1 -0
- package/src/components/tour/tour.render.test.tsx +217 -0
- package/src/components/tree/AGENTS.md +1 -0
- package/src/components/tree/tree.render.test.tsx +395 -0
- package/src/display-name.test.ts +9 -3
- package/src/render-tests.test.ts +27 -0
- package/src/test/AGENTS.md +121 -0
- package/src/test/render.tsx +22 -0
- package/src/test/setup.ts +142 -0
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, jest, test } from "@jest/globals";
|
|
2
|
+
import { fireEvent, renderWithProviders, screen } from "../../test/render";
|
|
3
|
+
import { Field } from "../field";
|
|
4
|
+
import { Checkbox } from "./checkbox";
|
|
5
|
+
import { useCheckbox, useCheckboxGroup } from "./checkbox.context";
|
|
6
|
+
|
|
7
|
+
const tap = (element: Parameters<typeof fireEvent>[0]) => fireEvent(element, "accessibilityTap");
|
|
8
|
+
|
|
9
|
+
describe("Checkbox", () => {
|
|
10
|
+
test("is a checkbox named by its label, unchecked by default", async () => {
|
|
11
|
+
await renderWithProviders(<Checkbox>Remember me</Checkbox>);
|
|
12
|
+
const control = screen.getByRole("checkbox", { name: "Remember me" });
|
|
13
|
+
expect(control).toBeOnTheScreen();
|
|
14
|
+
expect(control).not.toBeChecked();
|
|
15
|
+
expect(screen.getByText("Remember me")).toBeOnTheScreen();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test("Checkbox.Label inside the root names it", async () => {
|
|
19
|
+
await renderWithProviders(
|
|
20
|
+
<Checkbox>
|
|
21
|
+
<Checkbox.Label>Accept terms</Checkbox.Label>
|
|
22
|
+
</Checkbox>
|
|
23
|
+
);
|
|
24
|
+
expect(screen.getByRole("checkbox", { name: "Accept terms" })).toBeOnTheScreen();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test("uncontrolled: defaultChecked seeds it and an activation flips it", async () => {
|
|
28
|
+
const onCheckedChange = jest.fn();
|
|
29
|
+
await renderWithProviders(
|
|
30
|
+
<Checkbox defaultChecked onCheckedChange={onCheckedChange}>
|
|
31
|
+
Remember me
|
|
32
|
+
</Checkbox>
|
|
33
|
+
);
|
|
34
|
+
const control = screen.getByRole("checkbox");
|
|
35
|
+
expect(control).toBeChecked();
|
|
36
|
+
|
|
37
|
+
await tap(control);
|
|
38
|
+
expect(control).not.toBeChecked();
|
|
39
|
+
expect(onCheckedChange).toHaveBeenLastCalledWith(false);
|
|
40
|
+
|
|
41
|
+
await tap(control);
|
|
42
|
+
expect(control).toBeChecked();
|
|
43
|
+
expect(onCheckedChange).toHaveBeenLastCalledWith(true);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test("controlled: reports the change and waits for the prop", async () => {
|
|
47
|
+
const onCheckedChange = jest.fn();
|
|
48
|
+
const view = await renderWithProviders(
|
|
49
|
+
<Checkbox isChecked={false} onCheckedChange={onCheckedChange}>
|
|
50
|
+
Remember me
|
|
51
|
+
</Checkbox>
|
|
52
|
+
);
|
|
53
|
+
await tap(screen.getByRole("checkbox"));
|
|
54
|
+
expect(onCheckedChange).toHaveBeenCalledWith(true);
|
|
55
|
+
expect(screen.getByRole("checkbox")).not.toBeChecked();
|
|
56
|
+
|
|
57
|
+
await view.rerender(
|
|
58
|
+
<Checkbox isChecked onCheckedChange={onCheckedChange}>
|
|
59
|
+
Remember me
|
|
60
|
+
</Checkbox>
|
|
61
|
+
);
|
|
62
|
+
expect(screen.getByRole("checkbox")).toBeChecked();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test("isIndeterminate is announced as mixed and a press still reports a toggle", async () => {
|
|
66
|
+
const onCheckedChange = jest.fn();
|
|
67
|
+
await renderWithProviders(
|
|
68
|
+
<Checkbox isChecked={false} isIndeterminate onCheckedChange={onCheckedChange}>
|
|
69
|
+
Select all
|
|
70
|
+
</Checkbox>
|
|
71
|
+
);
|
|
72
|
+
const control = screen.getByRole("checkbox");
|
|
73
|
+
expect(control).toBePartiallyChecked();
|
|
74
|
+
await tap(control);
|
|
75
|
+
expect(onCheckedChange).toHaveBeenCalledWith(true);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test("isDisabled is announced and ignores every activation", async () => {
|
|
79
|
+
const onCheckedChange = jest.fn();
|
|
80
|
+
await renderWithProviders(
|
|
81
|
+
<Checkbox isDisabled onCheckedChange={onCheckedChange}>
|
|
82
|
+
Remember me
|
|
83
|
+
</Checkbox>
|
|
84
|
+
);
|
|
85
|
+
const control = screen.getByRole("checkbox");
|
|
86
|
+
expect(control).toBeDisabled();
|
|
87
|
+
await tap(control);
|
|
88
|
+
expect(onCheckedChange).not.toHaveBeenCalled();
|
|
89
|
+
expect(control).not.toBeChecked();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test("a press on an enclosing Field's row toggles the box", async () => {
|
|
93
|
+
const onCheckedChange = jest.fn();
|
|
94
|
+
await renderWithProviders(
|
|
95
|
+
<Field testID="row">
|
|
96
|
+
<Field.Label>Newsletter</Field.Label>
|
|
97
|
+
<Checkbox onCheckedChange={onCheckedChange} />
|
|
98
|
+
</Field>
|
|
99
|
+
);
|
|
100
|
+
await tap(screen.getByTestId("row"));
|
|
101
|
+
expect(onCheckedChange).toHaveBeenCalledWith(true);
|
|
102
|
+
expect(screen.getByRole("checkbox")).toBeChecked();
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test("a disabled box ignores a press on its Field's row", async () => {
|
|
106
|
+
const onCheckedChange = jest.fn();
|
|
107
|
+
await renderWithProviders(
|
|
108
|
+
<Field testID="row">
|
|
109
|
+
<Field.Label>Newsletter</Field.Label>
|
|
110
|
+
<Checkbox isDisabled onCheckedChange={onCheckedChange} />
|
|
111
|
+
</Field>
|
|
112
|
+
);
|
|
113
|
+
await tap(screen.getByTestId("row"));
|
|
114
|
+
expect(onCheckedChange).not.toHaveBeenCalled();
|
|
115
|
+
expect(screen.getByRole("checkbox")).not.toBeChecked();
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test("a disabled Field disables the box it holds", async () => {
|
|
119
|
+
await renderWithProviders(
|
|
120
|
+
<Field isDisabled>
|
|
121
|
+
<Checkbox>Newsletter</Checkbox>
|
|
122
|
+
</Field>
|
|
123
|
+
);
|
|
124
|
+
expect(screen.getByRole("checkbox")).toBeDisabled();
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test("an explicit isDisabled={false} wins over a disabled Field", async () => {
|
|
128
|
+
const onCheckedChange = jest.fn();
|
|
129
|
+
await renderWithProviders(
|
|
130
|
+
<Field isDisabled>
|
|
131
|
+
<Checkbox isDisabled={false} onCheckedChange={onCheckedChange}>
|
|
132
|
+
Newsletter
|
|
133
|
+
</Checkbox>
|
|
134
|
+
</Field>
|
|
135
|
+
);
|
|
136
|
+
await tap(screen.getByRole("checkbox"));
|
|
137
|
+
expect(onCheckedChange).toHaveBeenCalledWith(true);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
describe("Checkbox.Group", () => {
|
|
142
|
+
test("uncontrolled: defaultChecked ticks matching children and toggling reports the whole list", async () => {
|
|
143
|
+
const onChecked = jest.fn();
|
|
144
|
+
await renderWithProviders(
|
|
145
|
+
<Checkbox.Group defaultChecked={["email"]} onChecked={onChecked}>
|
|
146
|
+
<Checkbox value="email">Email</Checkbox>
|
|
147
|
+
<Checkbox value="sms">SMS</Checkbox>
|
|
148
|
+
</Checkbox.Group>
|
|
149
|
+
);
|
|
150
|
+
expect(screen.getByRole("checkbox", { name: "Email" })).toBeChecked();
|
|
151
|
+
expect(screen.getByRole("checkbox", { name: "SMS" })).not.toBeChecked();
|
|
152
|
+
|
|
153
|
+
await tap(screen.getByRole("checkbox", { name: "SMS" }));
|
|
154
|
+
expect(onChecked).toHaveBeenLastCalledWith(["email", "sms"]);
|
|
155
|
+
expect(screen.getByRole("checkbox", { name: "SMS" })).toBeChecked();
|
|
156
|
+
|
|
157
|
+
await tap(screen.getByRole("checkbox", { name: "Email" }));
|
|
158
|
+
expect(onChecked).toHaveBeenLastCalledWith(["sms"]);
|
|
159
|
+
expect(screen.getByRole("checkbox", { name: "Email" })).not.toBeChecked();
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
test("controlled: reports the list and waits for the prop", async () => {
|
|
163
|
+
const onChecked = jest.fn();
|
|
164
|
+
const view = await renderWithProviders(
|
|
165
|
+
<Checkbox.Group checked={[]} onChecked={onChecked}>
|
|
166
|
+
<Checkbox value="email">Email</Checkbox>
|
|
167
|
+
</Checkbox.Group>
|
|
168
|
+
);
|
|
169
|
+
await tap(screen.getByRole("checkbox"));
|
|
170
|
+
expect(onChecked).toHaveBeenCalledWith(["email"]);
|
|
171
|
+
expect(screen.getByRole("checkbox")).not.toBeChecked();
|
|
172
|
+
|
|
173
|
+
await view.rerender(
|
|
174
|
+
<Checkbox.Group checked={["email"]} onChecked={onChecked}>
|
|
175
|
+
<Checkbox value="email">Email</Checkbox>
|
|
176
|
+
</Checkbox.Group>
|
|
177
|
+
);
|
|
178
|
+
expect(screen.getByRole("checkbox")).toBeChecked();
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
test("isDisabled cascades to children and blocks toggling", async () => {
|
|
182
|
+
const onChecked = jest.fn();
|
|
183
|
+
await renderWithProviders(
|
|
184
|
+
<Checkbox.Group isDisabled onChecked={onChecked}>
|
|
185
|
+
<Checkbox value="email">Email</Checkbox>
|
|
186
|
+
</Checkbox.Group>
|
|
187
|
+
);
|
|
188
|
+
const control = screen.getByRole("checkbox");
|
|
189
|
+
expect(control).toBeDisabled();
|
|
190
|
+
await tap(control);
|
|
191
|
+
expect(onChecked).not.toHaveBeenCalled();
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
test("a child's own isDisabled={false} overrides a disabled group", async () => {
|
|
195
|
+
const onChecked = jest.fn();
|
|
196
|
+
await renderWithProviders(
|
|
197
|
+
<Checkbox.Group isDisabled onChecked={onChecked}>
|
|
198
|
+
<Checkbox isDisabled={false} value="email">
|
|
199
|
+
Email
|
|
200
|
+
</Checkbox>
|
|
201
|
+
</Checkbox.Group>
|
|
202
|
+
);
|
|
203
|
+
await tap(screen.getByRole("checkbox"));
|
|
204
|
+
expect(onChecked).toHaveBeenCalledWith(["email"]);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
describe("errors", () => {
|
|
208
|
+
const original = console.error;
|
|
209
|
+
beforeEach(() => {
|
|
210
|
+
console.error = () => undefined;
|
|
211
|
+
});
|
|
212
|
+
afterEach(() => {
|
|
213
|
+
console.error = original;
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
test("a grouped Checkbox without a value throws by name", async () => {
|
|
217
|
+
await expect(
|
|
218
|
+
renderWithProviders(
|
|
219
|
+
<Checkbox.Group>
|
|
220
|
+
<Checkbox>Email</Checkbox>
|
|
221
|
+
</Checkbox.Group>
|
|
222
|
+
)
|
|
223
|
+
).rejects.toThrow("needs a `value`");
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
test("Checkbox.Label outside a Checkbox throws its documented error", async () => {
|
|
227
|
+
await expect(renderWithProviders(<Checkbox.Label>Orphan</Checkbox.Label>)).rejects.toThrow(
|
|
228
|
+
"Checkbox.Label must be rendered inside a <Checkbox>."
|
|
229
|
+
);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
test("useCheckbox outside a Checkbox throws", async () => {
|
|
233
|
+
function Probe() {
|
|
234
|
+
useCheckbox();
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
await expect(renderWithProviders(<Probe />)).rejects.toThrow("useCheckbox must be called inside a <Checkbox>.");
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
test("useCheckboxGroup outside a group throws", async () => {
|
|
241
|
+
function Probe() {
|
|
242
|
+
useCheckboxGroup();
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
await expect(renderWithProviders(<Probe />)).rejects.toThrow(
|
|
246
|
+
"useCheckboxGroup must be called inside a <Checkbox.Group>."
|
|
247
|
+
);
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
});
|
|
@@ -84,12 +84,13 @@ function CheckboxRoot({
|
|
|
84
84
|
const checked = group && groupValue !== undefined ? group.checked.includes(groupValue) : ownChecked;
|
|
85
85
|
|
|
86
86
|
const toggle = useCallback(() => {
|
|
87
|
+
if (axes.isDisabled) return;
|
|
87
88
|
if (group && groupValue !== undefined) {
|
|
88
89
|
group.toggle(groupValue);
|
|
89
90
|
return;
|
|
90
91
|
}
|
|
91
92
|
setOwnChecked(!checked);
|
|
92
|
-
}, [checked, group, groupValue, setOwnChecked]);
|
|
93
|
+
}, [axes.isDisabled, checked, group, groupValue, setOwnChecked]);
|
|
93
94
|
|
|
94
95
|
// Offered to an enclosing `Field` so tapping the label or the description
|
|
95
96
|
// beside the box ticks it. A checkbox in a form is a small square next to a
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import { describe, expect, jest, test } from "@jest/globals";
|
|
2
|
+
import { fireEvent, renderWithProviders, screen } from "../../test/render";
|
|
3
|
+
import { Chip } from "./chip";
|
|
4
|
+
|
|
5
|
+
const REMOVE = { nativeEvent: { actionName: "remove" } };
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
* A pressable chip with `onClose` is queried by a name prefix: RNTL derives the name from every
|
|
9
|
+
* descendant, the hidden close control's "Remove" included, where iOS
|
|
10
|
+
* (`RCTRecursiveAccessibilityLabel` skips `accessibilityElementsHidden`) and Android (`isSpeakingNode`
|
|
11
|
+
* skips `no-hide-descendants`) leave it out.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
describe("Chip", () => {
|
|
15
|
+
describe("what the props make it", () => {
|
|
16
|
+
test("with no handler it is a tag, not announced as a control", async () => {
|
|
17
|
+
await renderWithProviders(<Chip>Shipped</Chip>);
|
|
18
|
+
expect(screen.getByText("Shipped")).toBeOnTheScreen();
|
|
19
|
+
expect(screen.queryByRole("button")).not.toBeOnTheScreen();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test("onPress makes it a button that is not announced as selected", async () => {
|
|
23
|
+
const onPress = jest.fn();
|
|
24
|
+
await renderWithProviders(<Chip onPress={onPress}>Design</Chip>);
|
|
25
|
+
const chip = screen.getByRole("button", { name: "Design" });
|
|
26
|
+
expect(chip).not.toBeSelected();
|
|
27
|
+
await fireEvent(chip, "accessibilityTap");
|
|
28
|
+
expect(onPress).toHaveBeenCalledTimes(1);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("onLongPress alone makes it a button", async () => {
|
|
32
|
+
await renderWithProviders(<Chip onLongPress={() => {}}>Design</Chip>);
|
|
33
|
+
expect(screen.getByRole("button", { name: "Design" })).toBeOnTheScreen();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test.each([
|
|
37
|
+
["isSelected={false}", () => <Chip isSelected={false}>Open</Chip>],
|
|
38
|
+
["defaultSelected={false}", () => <Chip defaultSelected={false}>Open</Chip>],
|
|
39
|
+
["onSelectedChange", () => <Chip onSelectedChange={() => {}}>Open</Chip>],
|
|
40
|
+
])("%s makes it a toggle announced with its state", async (_name, element) => {
|
|
41
|
+
await renderWithProviders(element());
|
|
42
|
+
expect(screen.getByRole("button", { name: "Open" })).not.toBeSelected();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test("string and number children collapse into one label", async () => {
|
|
46
|
+
await renderWithProviders(<Chip>{3} open</Chip>);
|
|
47
|
+
expect(screen.getByText("3 open")).toBeOnTheScreen();
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe("selection", () => {
|
|
52
|
+
test("uncontrolled: defaultSelected seeds it and an activation flips it", async () => {
|
|
53
|
+
const onSelectedChange = jest.fn();
|
|
54
|
+
await renderWithProviders(
|
|
55
|
+
<Chip defaultSelected onSelectedChange={onSelectedChange}>
|
|
56
|
+
Open
|
|
57
|
+
</Chip>
|
|
58
|
+
);
|
|
59
|
+
const chip = screen.getByRole("button", { name: "Open" });
|
|
60
|
+
expect(chip).toBeSelected();
|
|
61
|
+
|
|
62
|
+
await fireEvent(chip, "accessibilityTap");
|
|
63
|
+
expect(chip).not.toBeSelected();
|
|
64
|
+
expect(onSelectedChange).toHaveBeenLastCalledWith(false);
|
|
65
|
+
|
|
66
|
+
await fireEvent(chip, "accessibilityTap");
|
|
67
|
+
expect(chip).toBeSelected();
|
|
68
|
+
expect(onSelectedChange).toHaveBeenLastCalledWith(true);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test("controlled: reports the flip and waits for the prop", async () => {
|
|
72
|
+
const onSelectedChange = jest.fn();
|
|
73
|
+
const view = await renderWithProviders(
|
|
74
|
+
<Chip isSelected={false} onSelectedChange={onSelectedChange}>
|
|
75
|
+
Open
|
|
76
|
+
</Chip>
|
|
77
|
+
);
|
|
78
|
+
await fireEvent(screen.getByRole("button"), "accessibilityTap");
|
|
79
|
+
expect(onSelectedChange).toHaveBeenCalledWith(true);
|
|
80
|
+
expect(screen.getByRole("button")).not.toBeSelected();
|
|
81
|
+
|
|
82
|
+
await view.rerender(
|
|
83
|
+
<Chip isSelected onSelectedChange={onSelectedChange}>
|
|
84
|
+
Open
|
|
85
|
+
</Chip>
|
|
86
|
+
);
|
|
87
|
+
expect(screen.getByRole("button")).toBeSelected();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test("a toggle still calls onPress after flipping", async () => {
|
|
91
|
+
const onPress = jest.fn();
|
|
92
|
+
const onSelectedChange = jest.fn();
|
|
93
|
+
await renderWithProviders(
|
|
94
|
+
<Chip onPress={onPress} onSelectedChange={onSelectedChange}>
|
|
95
|
+
Open
|
|
96
|
+
</Chip>
|
|
97
|
+
);
|
|
98
|
+
await fireEvent(screen.getByRole("button"), "accessibilityTap");
|
|
99
|
+
expect(onSelectedChange).toHaveBeenCalledWith(true);
|
|
100
|
+
expect(onPress).toHaveBeenCalledTimes(1);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test("a chip that is not a toggle is never selected", async () => {
|
|
104
|
+
await renderWithProviders(<Chip onPress={() => {}}>Design</Chip>);
|
|
105
|
+
expect(screen.getByRole("button")).not.toBeSelected();
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
describe("disabled", () => {
|
|
110
|
+
test("is announced and ignores activation", async () => {
|
|
111
|
+
const onPress = jest.fn();
|
|
112
|
+
const onSelectedChange = jest.fn();
|
|
113
|
+
await renderWithProviders(
|
|
114
|
+
<Chip isDisabled onClose={() => {}} onPress={onPress} onSelectedChange={onSelectedChange}>
|
|
115
|
+
Open
|
|
116
|
+
</Chip>
|
|
117
|
+
);
|
|
118
|
+
const chip = screen.getByRole("button", { name: /^Open/ });
|
|
119
|
+
expect(chip).toBeDisabled();
|
|
120
|
+
await fireEvent(chip, "accessibilityTap");
|
|
121
|
+
expect(onPress).not.toHaveBeenCalled();
|
|
122
|
+
expect(onSelectedChange).not.toHaveBeenCalled();
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test("does not remove through the remove action", async () => {
|
|
126
|
+
const onClose = jest.fn();
|
|
127
|
+
await renderWithProviders(
|
|
128
|
+
<Chip isDisabled onClose={onClose} onPress={() => {}}>
|
|
129
|
+
Open
|
|
130
|
+
</Chip>
|
|
131
|
+
);
|
|
132
|
+
await fireEvent(screen.getByRole("button"), "accessibilityAction", REMOVE);
|
|
133
|
+
expect(onClose).not.toHaveBeenCalled();
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test("disables a static chip's close control", async () => {
|
|
137
|
+
const onClose = jest.fn();
|
|
138
|
+
await renderWithProviders(
|
|
139
|
+
<Chip closeTestID="close" isDisabled onClose={onClose}>
|
|
140
|
+
Tag
|
|
141
|
+
</Chip>
|
|
142
|
+
);
|
|
143
|
+
const close = screen.getByTestId("close");
|
|
144
|
+
expect(close).toBeDisabled();
|
|
145
|
+
await fireEvent(close, "accessibilityTap");
|
|
146
|
+
expect(onClose).not.toHaveBeenCalled();
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
describe("onClose", () => {
|
|
151
|
+
test("a static chip keeps the remove control as its own element, named Remove", async () => {
|
|
152
|
+
const onClose = jest.fn();
|
|
153
|
+
await renderWithProviders(<Chip onClose={onClose}>Tag</Chip>);
|
|
154
|
+
await fireEvent(screen.getByRole("button", { name: "Remove" }), "accessibilityTap");
|
|
155
|
+
expect(onClose).toHaveBeenCalledTimes(1);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
test("closeAccessibilityLabel names the remove control", async () => {
|
|
159
|
+
await renderWithProviders(
|
|
160
|
+
<Chip closeAccessibilityLabel="Remove Tag" onClose={() => {}}>
|
|
161
|
+
Tag
|
|
162
|
+
</Chip>
|
|
163
|
+
);
|
|
164
|
+
expect(screen.getByRole("button", { name: "Remove Tag" })).toBeOnTheScreen();
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test("closeTestID reaches the remove control", async () => {
|
|
168
|
+
const onClose = jest.fn();
|
|
169
|
+
await renderWithProviders(
|
|
170
|
+
<Chip closeTestID="close" onClose={onClose}>
|
|
171
|
+
Tag
|
|
172
|
+
</Chip>
|
|
173
|
+
);
|
|
174
|
+
await fireEvent(screen.getByTestId("close"), "accessibilityTap");
|
|
175
|
+
expect(onClose).toHaveBeenCalledTimes(1);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
test("a pressable chip hides the control and offers a remove action instead", async () => {
|
|
179
|
+
const onClose = jest.fn();
|
|
180
|
+
const onPress = jest.fn();
|
|
181
|
+
const onSelectedChange = jest.fn();
|
|
182
|
+
await renderWithProviders(
|
|
183
|
+
<Chip
|
|
184
|
+
closeAccessibilityLabel="Remove React"
|
|
185
|
+
onClose={onClose}
|
|
186
|
+
onPress={onPress}
|
|
187
|
+
onSelectedChange={onSelectedChange}
|
|
188
|
+
>
|
|
189
|
+
React
|
|
190
|
+
</Chip>
|
|
191
|
+
);
|
|
192
|
+
expect(screen.queryByRole("button", { name: "Remove React" })).not.toBeOnTheScreen();
|
|
193
|
+
const chip = screen.getByRole("button", { name: /^React/ });
|
|
194
|
+
expect(chip.props.accessibilityActions).toEqual(
|
|
195
|
+
expect.arrayContaining([expect.objectContaining({ label: "Remove React", name: "remove" })])
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
await fireEvent(chip, "accessibilityAction", REMOVE);
|
|
199
|
+
expect(onClose).toHaveBeenCalledTimes(1);
|
|
200
|
+
expect(onPress).not.toHaveBeenCalled();
|
|
201
|
+
expect(onSelectedChange).not.toHaveBeenCalled();
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
test("the remove action defaults its label to Remove and keeps the caller's actions", async () => {
|
|
205
|
+
const onAccessibilityAction = jest.fn();
|
|
206
|
+
await renderWithProviders(
|
|
207
|
+
<Chip
|
|
208
|
+
accessibilityActions={[{ label: "Edit", name: "edit" }]}
|
|
209
|
+
onAccessibilityAction={onAccessibilityAction}
|
|
210
|
+
onClose={() => {}}
|
|
211
|
+
onPress={() => {}}
|
|
212
|
+
>
|
|
213
|
+
React
|
|
214
|
+
</Chip>
|
|
215
|
+
);
|
|
216
|
+
const chip = screen.getByRole("button");
|
|
217
|
+
expect(chip.props.accessibilityActions).toEqual(
|
|
218
|
+
expect.arrayContaining([
|
|
219
|
+
expect.objectContaining({ name: "edit" }),
|
|
220
|
+
expect.objectContaining({ label: "Remove", name: "remove" }),
|
|
221
|
+
])
|
|
222
|
+
);
|
|
223
|
+
await fireEvent(chip, "accessibilityAction", { nativeEvent: { actionName: "edit" } });
|
|
224
|
+
expect(onAccessibilityAction).toHaveBeenCalledTimes(1);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
test("pressing the hidden control removes without toggling or pressing the chip", async () => {
|
|
228
|
+
const onClose = jest.fn();
|
|
229
|
+
const onPress = jest.fn();
|
|
230
|
+
const onSelectedChange = jest.fn();
|
|
231
|
+
await renderWithProviders(
|
|
232
|
+
<Chip closeTestID="close" onClose={onClose} onPress={onPress} onSelectedChange={onSelectedChange}>
|
|
233
|
+
React
|
|
234
|
+
</Chip>
|
|
235
|
+
);
|
|
236
|
+
await fireEvent(screen.getByTestId("close", { includeHiddenElements: true }), "accessibilityTap");
|
|
237
|
+
expect(onClose).toHaveBeenCalledTimes(1);
|
|
238
|
+
expect(onPress).not.toHaveBeenCalled();
|
|
239
|
+
expect(onSelectedChange).not.toHaveBeenCalled();
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
describe("compound parts", () => {
|
|
244
|
+
test("Label, StartContent, EndContent and CloseButton render inside the root", async () => {
|
|
245
|
+
const onClose = jest.fn();
|
|
246
|
+
await renderWithProviders(
|
|
247
|
+
<Chip onPress={() => {}}>
|
|
248
|
+
<Chip.StartContent>
|
|
249
|
+
<Chip.Label>Start</Chip.Label>
|
|
250
|
+
</Chip.StartContent>
|
|
251
|
+
<Chip.Label>Middle</Chip.Label>
|
|
252
|
+
<Chip.EndContent>
|
|
253
|
+
<Chip.Label>End</Chip.Label>
|
|
254
|
+
</Chip.EndContent>
|
|
255
|
+
<Chip.CloseButton accessibilityLabel="Dismiss" onPress={onClose} />
|
|
256
|
+
</Chip>
|
|
257
|
+
);
|
|
258
|
+
expect(screen.getByText("Start")).toBeOnTheScreen();
|
|
259
|
+
expect(screen.getByText("Middle")).toBeOnTheScreen();
|
|
260
|
+
expect(screen.getByText("End")).toBeOnTheScreen();
|
|
261
|
+
expect(screen.getByLabelText("Dismiss")).toBeOnTheScreen();
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
test.each([
|
|
265
|
+
["Chip.Label", () => <Chip.Label>x</Chip.Label>],
|
|
266
|
+
["Chip.CloseButton", () => <Chip.CloseButton />],
|
|
267
|
+
])("%s outside a Chip throws", async (name, element) => {
|
|
268
|
+
const original = console.error;
|
|
269
|
+
console.error = () => {};
|
|
270
|
+
try {
|
|
271
|
+
await expect(renderWithProviders(element())).rejects.toThrow(`${name} must be rendered inside a <Chip>.`);
|
|
272
|
+
} finally {
|
|
273
|
+
console.error = original;
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
});
|
|
@@ -23,6 +23,7 @@ no context.
|
|
|
23
23
|
| `circular-text.types.ts` | `CircularTextProps`, `CircularTextSpin`, `CircularTextPause` |
|
|
24
24
|
| `circular-text.variants.ts` | Geometry and resolvers, no RN imports |
|
|
25
25
|
| `circular-text.variants.test.ts` | |
|
|
26
|
+
| `circular-text.render.test.tsx` | Mounted under Jest — the ring announced once (repeat, fill, arc, label override), glyphs hidden, `centerContent` reachable, invalid radius/text renders nothing |
|
|
26
27
|
|
|
27
28
|
## Axes
|
|
28
29
|
|