@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,361 @@
|
|
|
1
|
+
import { describe, expect, jest, test } from "@jest/globals";
|
|
2
|
+
import { Text } from "react-native";
|
|
3
|
+
import { fireEvent, renderWithProviders, screen } from "../../test/render";
|
|
4
|
+
import { Checkbox } from "../checkbox";
|
|
5
|
+
import { Slider } from "../slider";
|
|
6
|
+
import { Switch } from "../switch";
|
|
7
|
+
import { Field } from "./field";
|
|
8
|
+
import { useField } from "./field.context";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Touches go through Gesture Handler, which Jest cannot drive, so the label
|
|
12
|
+
* press is exercised through the row's accessibility tap — the same path a
|
|
13
|
+
* screen reader's activation takes. The visual feedback of the row is not
|
|
14
|
+
* asserted.
|
|
15
|
+
*/
|
|
16
|
+
function VolumeSlider() {
|
|
17
|
+
return (
|
|
18
|
+
<Slider defaultValue={30}>
|
|
19
|
+
<Slider.Track>
|
|
20
|
+
<Slider.Fill />
|
|
21
|
+
<Slider.Thumb index={0} />
|
|
22
|
+
</Slider.Track>
|
|
23
|
+
</Slider>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
describe("Field", () => {
|
|
28
|
+
test("renders its label, control and description", async () => {
|
|
29
|
+
await renderWithProviders(
|
|
30
|
+
<Field>
|
|
31
|
+
<Field.Label>Notifications</Field.Label>
|
|
32
|
+
<Switch />
|
|
33
|
+
<Field.Description>Push alerts for new messages.</Field.Description>
|
|
34
|
+
</Field>
|
|
35
|
+
);
|
|
36
|
+
expect(screen.getByText("Notifications")).toBeOnTheScreen();
|
|
37
|
+
expect(screen.getByText("Push alerts for new messages.")).toBeOnTheScreen();
|
|
38
|
+
expect(screen.getByRole("switch")).toBeOnTheScreen();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("a field of static text is layout, not an interactive row", async () => {
|
|
42
|
+
await renderWithProviders(
|
|
43
|
+
<Field testID="row">
|
|
44
|
+
<Field.Label>Name</Field.Label>
|
|
45
|
+
<Field.Description>Shown on invoices.</Field.Description>
|
|
46
|
+
</Field>
|
|
47
|
+
);
|
|
48
|
+
expect(screen.getByTestId("row")).not.toHaveProp("onAccessibilityTap");
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe("label press", () => {
|
|
52
|
+
test("an activation on the row toggles a Switch", async () => {
|
|
53
|
+
const onSelectedChange = jest.fn();
|
|
54
|
+
await renderWithProviders(
|
|
55
|
+
<Field testID="row">
|
|
56
|
+
<Field.Label>Notifications</Field.Label>
|
|
57
|
+
<Switch onSelectedChange={onSelectedChange} />
|
|
58
|
+
</Field>
|
|
59
|
+
);
|
|
60
|
+
expect(screen.getByRole("switch")).not.toBeChecked();
|
|
61
|
+
|
|
62
|
+
await fireEvent(screen.getByTestId("row"), "accessibilityTap");
|
|
63
|
+
expect(onSelectedChange).toHaveBeenCalledTimes(1);
|
|
64
|
+
expect(onSelectedChange).toHaveBeenLastCalledWith(true);
|
|
65
|
+
expect(screen.getByRole("switch")).toBeChecked();
|
|
66
|
+
|
|
67
|
+
await fireEvent(screen.getByTestId("row"), "accessibilityTap");
|
|
68
|
+
expect(onSelectedChange).toHaveBeenLastCalledWith(false);
|
|
69
|
+
expect(screen.getByRole("switch")).not.toBeChecked();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test("an activation on the row ticks a Checkbox", async () => {
|
|
73
|
+
const onCheckedChange = jest.fn();
|
|
74
|
+
await renderWithProviders(
|
|
75
|
+
<Field testID="row">
|
|
76
|
+
<Field.Label>Accept the terms</Field.Label>
|
|
77
|
+
<Checkbox onCheckedChange={onCheckedChange} />
|
|
78
|
+
</Field>
|
|
79
|
+
);
|
|
80
|
+
await fireEvent(screen.getByTestId("row"), "accessibilityTap");
|
|
81
|
+
expect(onCheckedChange).toHaveBeenCalledTimes(1);
|
|
82
|
+
expect(onCheckedChange).toHaveBeenLastCalledWith(true);
|
|
83
|
+
expect(screen.getByRole("checkbox")).toBeChecked();
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test("the row stays out of the accessibility tree; the control is the element", async () => {
|
|
87
|
+
await renderWithProviders(
|
|
88
|
+
<Field testID="row">
|
|
89
|
+
<Field.Label>Notifications</Field.Label>
|
|
90
|
+
<Switch />
|
|
91
|
+
</Field>
|
|
92
|
+
);
|
|
93
|
+
expect(screen.getByTestId("row")).toHaveProp("accessible", false);
|
|
94
|
+
expect(screen.getAllByRole("switch")).toHaveLength(1);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test("a disabled Field does not fire the Switch", async () => {
|
|
98
|
+
const onSelectedChange = jest.fn();
|
|
99
|
+
await renderWithProviders(
|
|
100
|
+
<Field isDisabled testID="row">
|
|
101
|
+
<Field.Label>Notifications</Field.Label>
|
|
102
|
+
<Switch onSelectedChange={onSelectedChange} />
|
|
103
|
+
</Field>
|
|
104
|
+
);
|
|
105
|
+
expect(screen.getByRole("switch")).toBeDisabled();
|
|
106
|
+
await fireEvent(screen.getByTestId("row"), "accessibilityTap");
|
|
107
|
+
await fireEvent(screen.getByTestId("row"), "accessibilityAction", { nativeEvent: { actionName: "activate" } });
|
|
108
|
+
expect(onSelectedChange).not.toHaveBeenCalled();
|
|
109
|
+
expect(screen.getByRole("switch")).not.toBeChecked();
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test("a disabled Field does not fire the Checkbox", async () => {
|
|
113
|
+
const onCheckedChange = jest.fn();
|
|
114
|
+
await renderWithProviders(
|
|
115
|
+
<Field isDisabled testID="row">
|
|
116
|
+
<Field.Label>Accept the terms</Field.Label>
|
|
117
|
+
<Checkbox onCheckedChange={onCheckedChange} />
|
|
118
|
+
</Field>
|
|
119
|
+
);
|
|
120
|
+
expect(screen.getByRole("checkbox")).toBeDisabled();
|
|
121
|
+
await fireEvent(screen.getByTestId("row"), "accessibilityTap");
|
|
122
|
+
expect(onCheckedChange).not.toHaveBeenCalled();
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test("a disabled Switch inside an enabled Field ignores the label press", async () => {
|
|
126
|
+
const onSelectedChange = jest.fn();
|
|
127
|
+
await renderWithProviders(
|
|
128
|
+
<Field testID="row">
|
|
129
|
+
<Field.Label>Notifications</Field.Label>
|
|
130
|
+
<Switch isDisabled onSelectedChange={onSelectedChange} />
|
|
131
|
+
</Field>
|
|
132
|
+
);
|
|
133
|
+
expect(screen.getByRole("switch")).toBeDisabled();
|
|
134
|
+
await fireEvent(screen.getByTestId("row"), "accessibilityTap");
|
|
135
|
+
expect(onSelectedChange).not.toHaveBeenCalled();
|
|
136
|
+
expect(screen.getByRole("switch")).not.toBeChecked();
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test("a disabled Checkbox inside an enabled Field ignores the label press", async () => {
|
|
140
|
+
const onCheckedChange = jest.fn();
|
|
141
|
+
await renderWithProviders(
|
|
142
|
+
<Field testID="row">
|
|
143
|
+
<Field.Label>Accept the terms</Field.Label>
|
|
144
|
+
<Checkbox isDisabled onCheckedChange={onCheckedChange} />
|
|
145
|
+
</Field>
|
|
146
|
+
);
|
|
147
|
+
expect(screen.getByRole("checkbox")).toBeDisabled();
|
|
148
|
+
await fireEvent(screen.getByTestId("row"), "accessibilityTap");
|
|
149
|
+
expect(onCheckedChange).not.toHaveBeenCalled();
|
|
150
|
+
expect(screen.getByRole("checkbox")).not.toBeChecked();
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test("the row stops driving a control once it unmounts", async () => {
|
|
154
|
+
const onSelectedChange = jest.fn();
|
|
155
|
+
const view = await renderWithProviders(
|
|
156
|
+
<Field testID="row">
|
|
157
|
+
<Field.Label>Notifications</Field.Label>
|
|
158
|
+
<Switch onSelectedChange={onSelectedChange} />
|
|
159
|
+
</Field>
|
|
160
|
+
);
|
|
161
|
+
await view.rerender(
|
|
162
|
+
<Field testID="row">
|
|
163
|
+
<Field.Label>Notifications</Field.Label>
|
|
164
|
+
</Field>
|
|
165
|
+
);
|
|
166
|
+
expect(screen.queryByRole("switch")).not.toBeOnTheScreen();
|
|
167
|
+
expect(screen.getByTestId("row")).not.toHaveProp("onAccessibilityTap");
|
|
168
|
+
expect(onSelectedChange).not.toHaveBeenCalled();
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
describe("state cascade", () => {
|
|
173
|
+
test("isDisabled disables the control inside", async () => {
|
|
174
|
+
await renderWithProviders(
|
|
175
|
+
<Field isDisabled>
|
|
176
|
+
<Field.Label>Notifications</Field.Label>
|
|
177
|
+
<Switch />
|
|
178
|
+
</Field>
|
|
179
|
+
);
|
|
180
|
+
expect(screen.getByRole("switch")).toBeDisabled();
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
test("an explicit isDisabled={false} on the control wins", async () => {
|
|
184
|
+
await renderWithProviders(
|
|
185
|
+
<Field isDisabled>
|
|
186
|
+
<Field.Label>Notifications</Field.Label>
|
|
187
|
+
<Switch isDisabled={false} />
|
|
188
|
+
</Field>
|
|
189
|
+
);
|
|
190
|
+
expect(screen.getByRole("switch")).toHaveProp("accessibilityState", { checked: false, disabled: false });
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
test("useField reads isInvalid, isDisabled and orientation", async () => {
|
|
194
|
+
function Probe() {
|
|
195
|
+
const field = useField();
|
|
196
|
+
return (
|
|
197
|
+
<Text testID="probe">{`${field.isInvalid}|${field.isDisabled}|${field.orientation}|${field.label}`}</Text>
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
await renderWithProviders(
|
|
201
|
+
<Field isDisabled isInvalid orientation="horizontal">
|
|
202
|
+
<Field.Label>Email</Field.Label>
|
|
203
|
+
<Probe />
|
|
204
|
+
</Field>
|
|
205
|
+
);
|
|
206
|
+
expect(screen.getByTestId("probe")).toHaveTextContent("true|true|horizontal|Email");
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
test("useField outside a Field throws its documented error", async () => {
|
|
210
|
+
function Probe() {
|
|
211
|
+
useField();
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
const original = console.error;
|
|
215
|
+
console.error = () => {};
|
|
216
|
+
try {
|
|
217
|
+
await expect(renderWithProviders(<Probe />)).rejects.toThrow("useField must be called inside a <Field>.");
|
|
218
|
+
} finally {
|
|
219
|
+
console.error = original;
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
describe("label, description and error wiring", () => {
|
|
225
|
+
test("a string label becomes a Slider thumb's accessible name", async () => {
|
|
226
|
+
await renderWithProviders(
|
|
227
|
+
<Field>
|
|
228
|
+
<Field.Label>Volume</Field.Label>
|
|
229
|
+
<VolumeSlider />
|
|
230
|
+
</Field>
|
|
231
|
+
);
|
|
232
|
+
expect(screen.getByRole("adjustable", { name: "Volume" })).toBeOnTheScreen();
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
test("the control drops the name when the label unmounts", async () => {
|
|
236
|
+
const view = await renderWithProviders(
|
|
237
|
+
<Field>
|
|
238
|
+
<Field.Label>Volume</Field.Label>
|
|
239
|
+
<VolumeSlider />
|
|
240
|
+
</Field>
|
|
241
|
+
);
|
|
242
|
+
await view.rerender(
|
|
243
|
+
<Field>
|
|
244
|
+
<VolumeSlider />
|
|
245
|
+
</Field>
|
|
246
|
+
);
|
|
247
|
+
expect(screen.queryByRole("adjustable", { name: "Volume" })).not.toBeOnTheScreen();
|
|
248
|
+
expect(screen.getByRole("adjustable")).toBeOnTheScreen();
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
test("an element label lends no name to the control", async () => {
|
|
252
|
+
await renderWithProviders(
|
|
253
|
+
<Field>
|
|
254
|
+
<Field.Label>
|
|
255
|
+
<Text>Volume</Text>
|
|
256
|
+
</Field.Label>
|
|
257
|
+
<VolumeSlider />
|
|
258
|
+
</Field>
|
|
259
|
+
);
|
|
260
|
+
expect(screen.queryByRole("adjustable", { name: "Volume" })).not.toBeOnTheScreen();
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
test("the error is announced politely as an alert", async () => {
|
|
264
|
+
await renderWithProviders(
|
|
265
|
+
<Field isInvalid>
|
|
266
|
+
<Field.Label>Email</Field.Label>
|
|
267
|
+
<Field.Error>Enter a valid email.</Field.Error>
|
|
268
|
+
</Field>
|
|
269
|
+
);
|
|
270
|
+
const error = screen.getByRole("alert");
|
|
271
|
+
expect(error).toHaveTextContent("Enter a valid email.");
|
|
272
|
+
expect(error).toHaveProp("accessibilityLiveRegion", "polite");
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
test("an error with no children renders nothing", async () => {
|
|
276
|
+
await renderWithProviders(
|
|
277
|
+
<Field isInvalid>
|
|
278
|
+
<Field.Label>Email</Field.Label>
|
|
279
|
+
<Field.Error>{""}</Field.Error>
|
|
280
|
+
<Field.Error>{null}</Field.Error>
|
|
281
|
+
<Field.Error>{false}</Field.Error>
|
|
282
|
+
</Field>
|
|
283
|
+
);
|
|
284
|
+
expect(screen.queryByRole("alert")).not.toBeOnTheScreen();
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
test("an error appears and clears as its message changes", async () => {
|
|
288
|
+
const view = await renderWithProviders(
|
|
289
|
+
<Field isInvalid>
|
|
290
|
+
<Field.Error>Too short.</Field.Error>
|
|
291
|
+
</Field>
|
|
292
|
+
);
|
|
293
|
+
expect(screen.getByRole("alert")).toBeOnTheScreen();
|
|
294
|
+
await view.rerender(
|
|
295
|
+
<Field>
|
|
296
|
+
<Field.Error>{undefined}</Field.Error>
|
|
297
|
+
</Field>
|
|
298
|
+
);
|
|
299
|
+
expect(screen.queryByRole("alert")).not.toBeOnTheScreen();
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
test("an error is shown even when the field is not marked invalid", async () => {
|
|
303
|
+
await renderWithProviders(
|
|
304
|
+
<Field>
|
|
305
|
+
<Field.Error>Required.</Field.Error>
|
|
306
|
+
</Field>
|
|
307
|
+
);
|
|
308
|
+
expect(screen.getByRole("alert")).toHaveTextContent("Required.");
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
test("the description and the label are plain text, not controls", async () => {
|
|
312
|
+
await renderWithProviders(
|
|
313
|
+
<Field>
|
|
314
|
+
<Field.Label>Name</Field.Label>
|
|
315
|
+
<Field.Description>Shown on invoices.</Field.Description>
|
|
316
|
+
</Field>
|
|
317
|
+
);
|
|
318
|
+
expect(screen.queryByRole("alert")).not.toBeOnTheScreen();
|
|
319
|
+
expect(screen.queryByRole("button")).not.toBeOnTheScreen();
|
|
320
|
+
expect(screen.getByText("Shown on invoices.")).toBeOnTheScreen();
|
|
321
|
+
});
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
describe("compound parts", () => {
|
|
325
|
+
test("Set, Legend, Group, Content and Separator render without a Field", async () => {
|
|
326
|
+
await renderWithProviders(
|
|
327
|
+
<Field.Set>
|
|
328
|
+
<Field.Legend>Profile</Field.Legend>
|
|
329
|
+
<Field.Legend variant="label">Nested</Field.Legend>
|
|
330
|
+
<Field.Description>Shown on invoices and emails.</Field.Description>
|
|
331
|
+
<Field.Group>
|
|
332
|
+
<Field orientation="horizontal">
|
|
333
|
+
<Field.Content>
|
|
334
|
+
<Field.Label>Username</Field.Label>
|
|
335
|
+
</Field.Content>
|
|
336
|
+
</Field>
|
|
337
|
+
<Field.Separator>or</Field.Separator>
|
|
338
|
+
</Field.Group>
|
|
339
|
+
</Field.Set>
|
|
340
|
+
);
|
|
341
|
+
expect(screen.getByText("Profile")).toBeOnTheScreen();
|
|
342
|
+
expect(screen.getByText("Nested")).toBeOnTheScreen();
|
|
343
|
+
expect(screen.getByText("Shown on invoices and emails.")).toBeOnTheScreen();
|
|
344
|
+
expect(screen.getByText("Username")).toBeOnTheScreen();
|
|
345
|
+
expect(screen.getByText("or")).toBeOnTheScreen();
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
test("Label, Description and Error work outside a Field with default state", async () => {
|
|
349
|
+
await renderWithProviders(
|
|
350
|
+
<>
|
|
351
|
+
<Field.Label>Loose</Field.Label>
|
|
352
|
+
<Field.Description>Described.</Field.Description>
|
|
353
|
+
<Field.Error>Broken.</Field.Error>
|
|
354
|
+
</>
|
|
355
|
+
);
|
|
356
|
+
expect(screen.getByText("Loose")).toBeOnTheScreen();
|
|
357
|
+
expect(screen.getByText("Described.")).toBeOnTheScreen();
|
|
358
|
+
expect(screen.getByRole("alert")).toBeOnTheScreen();
|
|
359
|
+
});
|
|
360
|
+
});
|
|
361
|
+
});
|
|
@@ -20,6 +20,7 @@ the back, a profile with details behind it. A compound root plus `FlipCard.Front
|
|
|
20
20
|
| `flip-card.types.ts` | `FlipCardFaceProps`, shared by the two faces |
|
|
21
21
|
| `flip-card.variants.ts` | Slotted `tv()`, motion presets, every pure resolver; no RN imports |
|
|
22
22
|
| `flip-card.variants.test.ts` | |
|
|
23
|
+
| `flip-card.render.test.tsx` | Mounted under Jest — face state (controlled, uncontrolled, ref), the activate action per trigger, the hidden face leaving the accessibility tree, `FlipCard.Trigger`, `useFlipCard`, parts outside a root throwing. The drag itself is not reachable |
|
|
23
24
|
|
|
24
25
|
## Design
|
|
25
26
|
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import { describe, expect, jest, test } from "@jest/globals";
|
|
2
|
+
import { createRef } from "react";
|
|
3
|
+
import { Text } from "react-native";
|
|
4
|
+
import { act, fireEvent, renderWithProviders, screen } from "../../test/render";
|
|
5
|
+
import { FlipCard, type FlipCardHandle, type FlipCardProps } from "./flip-card";
|
|
6
|
+
import { useFlipCard } from "./flip-card.context";
|
|
7
|
+
|
|
8
|
+
const activate = { nativeEvent: { actionName: "activate" } };
|
|
9
|
+
|
|
10
|
+
function Faces() {
|
|
11
|
+
return (
|
|
12
|
+
<>
|
|
13
|
+
<FlipCard.Front>
|
|
14
|
+
<Text>Bonjour</Text>
|
|
15
|
+
</FlipCard.Front>
|
|
16
|
+
<FlipCard.Back>
|
|
17
|
+
<Text>Hello</Text>
|
|
18
|
+
</FlipCard.Back>
|
|
19
|
+
</>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function Card(props: Partial<FlipCardProps>) {
|
|
24
|
+
return (
|
|
25
|
+
<FlipCard accessibilityLabel="Flashcard" {...(props as FlipCardProps)}>
|
|
26
|
+
<Faces />
|
|
27
|
+
</FlipCard>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function expectFront() {
|
|
32
|
+
expect(screen.getByText("Bonjour")).toBeOnTheScreen();
|
|
33
|
+
expect(screen.queryByText("Hello")).not.toBeOnTheScreen();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function expectBack() {
|
|
37
|
+
expect(screen.getByText("Hello")).toBeOnTheScreen();
|
|
38
|
+
expect(screen.queryByText("Bonjour")).not.toBeOnTheScreen();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
describe("FlipCard", () => {
|
|
42
|
+
test("renders both faces, the card named and the back hidden from assistive tech", async () => {
|
|
43
|
+
await renderWithProviders(<Card />);
|
|
44
|
+
expect(screen.getByLabelText("Flashcard")).toBeOnTheScreen();
|
|
45
|
+
expectFront();
|
|
46
|
+
expect(screen.getByText("Hello", { includeHiddenElements: true })).toBeOnTheScreen();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test("defaultFace=back starts on the back and hides the front", async () => {
|
|
50
|
+
await renderWithProviders(<Card defaultFace="back" />);
|
|
51
|
+
expectBack();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("an activation action turns an uncontrolled card and reports the face", async () => {
|
|
55
|
+
const onFaceChange = jest.fn();
|
|
56
|
+
await renderWithProviders(<Card onFaceChange={onFaceChange} />);
|
|
57
|
+
|
|
58
|
+
await fireEvent(screen.getByLabelText("Flashcard"), "accessibilityAction", activate);
|
|
59
|
+
expectBack();
|
|
60
|
+
expect(onFaceChange).toHaveBeenLastCalledWith("back");
|
|
61
|
+
|
|
62
|
+
await fireEvent(screen.getByLabelText("Flashcard"), "accessibilityAction", activate);
|
|
63
|
+
expectFront();
|
|
64
|
+
expect(onFaceChange).toHaveBeenLastCalledWith("front");
|
|
65
|
+
expect(onFaceChange).toHaveBeenCalledTimes(2);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("offers a Flip card action under press, and none under manual", async () => {
|
|
69
|
+
const view = await renderWithProviders(<Card />);
|
|
70
|
+
expect(screen.getByLabelText("Flashcard")).toHaveProp("accessibilityActions", [
|
|
71
|
+
{ label: "Flip card", name: "activate" },
|
|
72
|
+
]);
|
|
73
|
+
|
|
74
|
+
await view.rerender(<Card trigger="manual" />);
|
|
75
|
+
expect(screen.getByLabelText("Flashcard")).toHaveProp("accessibilityActions", []);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test("controlled: reports the turn and waits for the face prop", async () => {
|
|
79
|
+
const onFaceChange = jest.fn();
|
|
80
|
+
const view = await renderWithProviders(<Card face="front" onFaceChange={onFaceChange} />);
|
|
81
|
+
|
|
82
|
+
await fireEvent(screen.getByLabelText("Flashcard"), "accessibilityAction", activate);
|
|
83
|
+
expect(onFaceChange).toHaveBeenCalledWith("back");
|
|
84
|
+
expectFront();
|
|
85
|
+
|
|
86
|
+
await view.rerender(<Card face="back" onFaceChange={onFaceChange} />);
|
|
87
|
+
expectBack();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test("isDisabled is announced, offers no action and ignores activation", async () => {
|
|
91
|
+
const onFaceChange = jest.fn();
|
|
92
|
+
await renderWithProviders(<Card isDisabled onFaceChange={onFaceChange} />);
|
|
93
|
+
const card = screen.getByLabelText("Flashcard");
|
|
94
|
+
expect(card).toBeDisabled();
|
|
95
|
+
expect(card).toHaveProp("accessibilityActions", []);
|
|
96
|
+
|
|
97
|
+
await fireEvent(card, "accessibilityAction", activate);
|
|
98
|
+
expect(onFaceChange).not.toHaveBeenCalled();
|
|
99
|
+
expectFront();
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test("the ref turns a disabled card, flipTo is a no-op on the showing face", async () => {
|
|
103
|
+
const ref = createRef<FlipCardHandle>();
|
|
104
|
+
const onFaceChange = jest.fn();
|
|
105
|
+
await renderWithProviders(
|
|
106
|
+
<FlipCard isDisabled onFaceChange={onFaceChange} ref={ref}>
|
|
107
|
+
<Faces />
|
|
108
|
+
</FlipCard>
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
await act(async () => ref.current?.flipTo("front"));
|
|
112
|
+
expect(onFaceChange).not.toHaveBeenCalled();
|
|
113
|
+
|
|
114
|
+
await act(async () => ref.current?.flip());
|
|
115
|
+
expectBack();
|
|
116
|
+
expect(onFaceChange).toHaveBeenCalledWith("back");
|
|
117
|
+
|
|
118
|
+
await act(async () => ref.current?.flipTo("front"));
|
|
119
|
+
expectFront();
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test("swipe: the visible face is one element carrying the Flip card action", async () => {
|
|
123
|
+
const onFaceChange = jest.fn();
|
|
124
|
+
await renderWithProviders(<Card trigger="swipe" onFaceChange={onFaceChange} />);
|
|
125
|
+
|
|
126
|
+
const [root, front, ...others] = screen.getAllByLabelText("Flashcard");
|
|
127
|
+
expect(root).toHaveProp("accessible", false);
|
|
128
|
+
expect(others).toHaveLength(0);
|
|
129
|
+
expect(front).toHaveProp("accessible", true);
|
|
130
|
+
await fireEvent(front, "accessibilityAction", activate);
|
|
131
|
+
expect(onFaceChange).toHaveBeenCalledWith("back");
|
|
132
|
+
expectBack();
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test("FlipCard.Trigger turns to the other face and names itself", async () => {
|
|
136
|
+
const onFaceChange = jest.fn();
|
|
137
|
+
await renderWithProviders(
|
|
138
|
+
<FlipCard trigger="manual" onFaceChange={onFaceChange}>
|
|
139
|
+
<Faces />
|
|
140
|
+
<FlipCard.Trigger />
|
|
141
|
+
</FlipCard>
|
|
142
|
+
);
|
|
143
|
+
const trigger = screen.getByRole("button", { name: "Flip card" });
|
|
144
|
+
expect(trigger).toHaveProp("accessibilityHint", "Shows the back");
|
|
145
|
+
|
|
146
|
+
await fireEvent(trigger, "accessibilityTap");
|
|
147
|
+
expectBack();
|
|
148
|
+
expect(onFaceChange).toHaveBeenCalledWith("back");
|
|
149
|
+
expect(screen.getByRole("button", { name: "Flip card" })).toHaveProp("accessibilityHint", "Shows the front");
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test("FlipCard.Trigger to=front is a no-op on the front, to=back turns", async () => {
|
|
153
|
+
const onFaceChange = jest.fn();
|
|
154
|
+
await renderWithProviders(
|
|
155
|
+
<FlipCard trigger="manual" onFaceChange={onFaceChange}>
|
|
156
|
+
<Faces />
|
|
157
|
+
<FlipCard.Trigger to="front">
|
|
158
|
+
<Text>Front</Text>
|
|
159
|
+
</FlipCard.Trigger>
|
|
160
|
+
<FlipCard.Trigger to="back">
|
|
161
|
+
<Text>Back</Text>
|
|
162
|
+
</FlipCard.Trigger>
|
|
163
|
+
</FlipCard>
|
|
164
|
+
);
|
|
165
|
+
await fireEvent(screen.getByRole("button", { name: "Front" }), "accessibilityTap");
|
|
166
|
+
expect(onFaceChange).not.toHaveBeenCalled();
|
|
167
|
+
|
|
168
|
+
await fireEvent(screen.getByRole("button", { name: "Back" }), "accessibilityTap");
|
|
169
|
+
expect(onFaceChange).toHaveBeenCalledWith("back");
|
|
170
|
+
expectBack();
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
test("FlipCard.Trigger is blocked by the card's isDisabled and its own disabled", async () => {
|
|
174
|
+
const onFaceChange = jest.fn();
|
|
175
|
+
const view = await renderWithProviders(
|
|
176
|
+
<FlipCard trigger="manual" isDisabled onFaceChange={onFaceChange}>
|
|
177
|
+
<Faces />
|
|
178
|
+
<FlipCard.Trigger />
|
|
179
|
+
</FlipCard>
|
|
180
|
+
);
|
|
181
|
+
expect(screen.getByRole("button", { name: "Flip card" })).toBeDisabled();
|
|
182
|
+
await fireEvent(screen.getByRole("button", { name: "Flip card" }), "accessibilityTap");
|
|
183
|
+
|
|
184
|
+
await view.rerender(
|
|
185
|
+
<FlipCard trigger="manual" onFaceChange={onFaceChange}>
|
|
186
|
+
<Faces />
|
|
187
|
+
<FlipCard.Trigger disabled />
|
|
188
|
+
</FlipCard>
|
|
189
|
+
);
|
|
190
|
+
expect(screen.getByRole("button", { name: "Flip card" })).toBeDisabled();
|
|
191
|
+
await fireEvent(screen.getByRole("button", { name: "Flip card" }), "accessibilityTap");
|
|
192
|
+
expect(onFaceChange).not.toHaveBeenCalled();
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
test("useFlipCard follows the face and turns the card from a custom child", async () => {
|
|
196
|
+
function Reader() {
|
|
197
|
+
const { face, flip } = useFlipCard();
|
|
198
|
+
return <Text onPress={flip}>{`showing ${face}`}</Text>;
|
|
199
|
+
}
|
|
200
|
+
await renderWithProviders(
|
|
201
|
+
<FlipCard trigger="manual">
|
|
202
|
+
<Faces />
|
|
203
|
+
<Reader />
|
|
204
|
+
</FlipCard>
|
|
205
|
+
);
|
|
206
|
+
expect(screen.getByText("showing front")).toBeOnTheScreen();
|
|
207
|
+
await fireEvent.press(screen.getByText("showing front"));
|
|
208
|
+
expect(screen.getByText("showing back")).toBeOnTheScreen();
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
test("parts outside a FlipCard throw their documented errors", async () => {
|
|
212
|
+
const spy = jest.spyOn(console, "error").mockImplementation(() => undefined);
|
|
213
|
+
try {
|
|
214
|
+
await expect(
|
|
215
|
+
renderWithProviders(
|
|
216
|
+
<FlipCard.Front>
|
|
217
|
+
<Text>x</Text>
|
|
218
|
+
</FlipCard.Front>
|
|
219
|
+
)
|
|
220
|
+
).rejects.toThrow("FlipCard.Front must be rendered inside a <FlipCard>.");
|
|
221
|
+
await expect(
|
|
222
|
+
renderWithProviders(
|
|
223
|
+
<FlipCard.Back>
|
|
224
|
+
<Text>x</Text>
|
|
225
|
+
</FlipCard.Back>
|
|
226
|
+
)
|
|
227
|
+
).rejects.toThrow("FlipCard.Back must be rendered inside a <FlipCard>.");
|
|
228
|
+
await expect(renderWithProviders(<FlipCard.Trigger />)).rejects.toThrow(
|
|
229
|
+
"FlipCard.Trigger must be rendered inside a <FlipCard>."
|
|
230
|
+
);
|
|
231
|
+
function Orphan() {
|
|
232
|
+
useFlipCard();
|
|
233
|
+
return null;
|
|
234
|
+
}
|
|
235
|
+
await expect(renderWithProviders(<Orphan />)).rejects.toThrow("useFlipCard must be called inside a <FlipCard>.");
|
|
236
|
+
} finally {
|
|
237
|
+
spy.mockRestore();
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
test("a transparent back warns that the front shows through", async () => {
|
|
242
|
+
const warn = jest.spyOn(console, "warn").mockImplementation(() => undefined);
|
|
243
|
+
try {
|
|
244
|
+
await renderWithProviders(
|
|
245
|
+
<FlipCard>
|
|
246
|
+
<FlipCard.Front>
|
|
247
|
+
<Text>Bonjour</Text>
|
|
248
|
+
</FlipCard.Front>
|
|
249
|
+
<FlipCard.Back variant="transparent">
|
|
250
|
+
<Text>Hello</Text>
|
|
251
|
+
</FlipCard.Back>
|
|
252
|
+
</FlipCard>
|
|
253
|
+
);
|
|
254
|
+
expect(warn).toHaveBeenCalledWith(expect.stringContaining("FlipCard.Back"));
|
|
255
|
+
} finally {
|
|
256
|
+
warn.mockRestore();
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
});
|
|
@@ -28,6 +28,7 @@ parts: `Background`, `Node`, `Handle`, `Edge`, `Group`, `Controls`, `MiniMap`, a
|
|
|
28
28
|
| `flow-geometry.test.ts` | Every side pair, every variant, overlap, zero size, fit, zoom, clamp |
|
|
29
29
|
| `flow.variants.ts` | The slotted `tv()`, the defaults, and every non-geometry resolver — no RN imports |
|
|
30
30
|
| `flow.variants.test.ts` | |
|
|
31
|
+
| `flow.render.test.tsx` | Mounted under Jest — node labels and selected state, the assistive actions (activate, move, connect, delete) and their callbacks, `isValidConnection`, Controls labels, zoom/fit/lock behaviour, and every part's outside-a-root error. Drags, pinch and drawn edges are not reachable without a touch system or Skia |
|
|
31
32
|
|
|
32
33
|
## Design
|
|
33
34
|
|