@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,316 @@
|
|
|
1
|
+
import { afterEach, describe, expect, jest, test } from "@jest/globals";
|
|
2
|
+
import type { ReactElement } from "react";
|
|
3
|
+
import { renderWithProviders, screen } from "../../test/render";
|
|
4
|
+
import { Timeline } from "./timeline";
|
|
5
|
+
import { useTimeline, useTimelineItem } from "./timeline.context";
|
|
6
|
+
|
|
7
|
+
type EventData = { id: string; title: string };
|
|
8
|
+
|
|
9
|
+
const EVENTS: readonly EventData[] = [
|
|
10
|
+
{ id: "a", title: "Placed" },
|
|
11
|
+
{ id: "b", title: "Packed" },
|
|
12
|
+
{ id: "c", title: "Shipped" },
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Three labelled events, returned as an array rather than a component: the root
|
|
17
|
+
* counts its direct `Timeline.Item` children, and a wrapper would hide them.
|
|
18
|
+
*/
|
|
19
|
+
function events(tones: readonly ("default" | "success" | "destructive")[] = []): ReactElement[] {
|
|
20
|
+
return EVENTS.map((event, index) => (
|
|
21
|
+
<Timeline.Item accessibilityLabel={event.title} key={event.id} step={index} tone={tones[index] ?? "default"}>
|
|
22
|
+
<Timeline.Title>{event.title}</Timeline.Title>
|
|
23
|
+
<Timeline.Description>{`${event.title} description`}</Timeline.Description>
|
|
24
|
+
</Timeline.Item>
|
|
25
|
+
));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Renders `ui` expecting a throw, with React's error logging silenced and restored. */
|
|
29
|
+
async function expectThrow(ui: ReactElement, message: string): Promise<void> {
|
|
30
|
+
const error = jest.spyOn(console, "error").mockImplementation(() => undefined);
|
|
31
|
+
const warn = jest.spyOn(console, "warn").mockImplementation(() => undefined);
|
|
32
|
+
try {
|
|
33
|
+
await expect(renderWithProviders(ui)).rejects.toThrow(message);
|
|
34
|
+
} finally {
|
|
35
|
+
error.mockRestore();
|
|
36
|
+
warn.mockRestore();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
afterEach(() => {
|
|
41
|
+
jest.restoreAllMocks();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe("Timeline", () => {
|
|
45
|
+
test("each event is one accessible element that merges its text and reads position and status", async () => {
|
|
46
|
+
await renderWithProviders(<Timeline value={1}>{events()}</Timeline>);
|
|
47
|
+
expect(screen.getByLabelText("Placed")).toHaveAccessibilityValue({ text: "Event 1 of 3, completed" });
|
|
48
|
+
expect(screen.getByLabelText("Packed")).toHaveAccessibilityValue({ text: "Event 2 of 3, current" });
|
|
49
|
+
expect(screen.getByLabelText("Shipped")).toHaveAccessibilityValue({ text: "Event 3 of 3, upcoming" });
|
|
50
|
+
expect(screen.getByText("Packed description")).toBeOnTheScreen();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test("the default value leaves every event upcoming", async () => {
|
|
54
|
+
await renderWithProviders(<Timeline>{events()}</Timeline>);
|
|
55
|
+
expect(screen.getByLabelText("Placed")).toHaveAccessibilityValue({ text: "Event 1 of 3, upcoming" });
|
|
56
|
+
expect(screen.getByLabelText("Shipped")).toHaveAccessibilityValue({ text: "Event 3 of 3, upcoming" });
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test("changing value moves the current event", async () => {
|
|
60
|
+
const view = await renderWithProviders(<Timeline value={0}>{events()}</Timeline>);
|
|
61
|
+
expect(screen.getByLabelText("Placed")).toHaveAccessibilityValue({ text: "Event 1 of 3, current" });
|
|
62
|
+
await view.rerender(<Timeline value={2}>{events()}</Timeline>);
|
|
63
|
+
expect(screen.getByLabelText("Placed")).toHaveAccessibilityValue({ text: "Event 1 of 3, completed" });
|
|
64
|
+
expect(screen.getByLabelText("Shipped")).toHaveAccessibilityValue({ text: "Event 3 of 3, current" });
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test("isCompleted overrides an upcoming event but never demotes the current one", async () => {
|
|
68
|
+
await renderWithProviders(
|
|
69
|
+
<Timeline value={1}>
|
|
70
|
+
<Timeline.Item accessibilityLabel="Early" isCompleted step={0}>
|
|
71
|
+
<Timeline.Title>Early</Timeline.Title>
|
|
72
|
+
</Timeline.Item>
|
|
73
|
+
<Timeline.Item accessibilityLabel="Now" isCompleted={false} step={1}>
|
|
74
|
+
<Timeline.Title>Now</Timeline.Title>
|
|
75
|
+
</Timeline.Item>
|
|
76
|
+
<Timeline.Item accessibilityLabel="Later" isCompleted step={2}>
|
|
77
|
+
<Timeline.Title>Later</Timeline.Title>
|
|
78
|
+
</Timeline.Item>
|
|
79
|
+
</Timeline>
|
|
80
|
+
);
|
|
81
|
+
expect(screen.getByLabelText("Now")).toHaveAccessibilityValue({ text: "Event 2 of 3, current" });
|
|
82
|
+
expect(screen.getByLabelText("Later")).toHaveAccessibilityValue({ text: "Event 3 of 3, completed" });
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test("a tone is announced; the destructive tone reads as error and the default is silent", async () => {
|
|
86
|
+
await renderWithProviders(<Timeline value={2}>{events(["success", "destructive", "default"])}</Timeline>);
|
|
87
|
+
expect(screen.getByLabelText("Placed")).toHaveAccessibilityValue({ text: "Event 1 of 3, completed, success" });
|
|
88
|
+
expect(screen.getByLabelText("Packed")).toHaveAccessibilityValue({ text: "Event 2 of 3, completed, error" });
|
|
89
|
+
expect(screen.getByLabelText("Shipped")).toHaveAccessibilityValue({ text: "Event 3 of 3, current" });
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test("the marker is hidden from assistive technology; the numbered variant shows the position", async () => {
|
|
93
|
+
await renderWithProviders(
|
|
94
|
+
<Timeline value={0} variant="numbered">
|
|
95
|
+
{events()}
|
|
96
|
+
</Timeline>
|
|
97
|
+
);
|
|
98
|
+
expect(screen.queryByText("2")).not.toBeOnTheScreen();
|
|
99
|
+
expect(screen.getByText("2", { hidden: true })).toBeOnTheScreen();
|
|
100
|
+
expect(screen.getByText("3", { hidden: true })).toBeOnTheScreen();
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test("a Timeline.Indicator written among the children is lifted into the marker", async () => {
|
|
104
|
+
await renderWithProviders(
|
|
105
|
+
<Timeline value={0} variant="icon">
|
|
106
|
+
<Timeline.Item accessibilityLabel="Custom" step={0}>
|
|
107
|
+
<Timeline.Indicator testID="marker" />
|
|
108
|
+
<Timeline.Title>Custom</Timeline.Title>
|
|
109
|
+
</Timeline.Item>
|
|
110
|
+
</Timeline>
|
|
111
|
+
);
|
|
112
|
+
expect(screen.getByTestId("marker", { hidden: true })).toBeOnTheScreen();
|
|
113
|
+
expect(screen.getByText("Custom")).toBeOnTheScreen();
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test("an event counted alone claims its position without a total when the root could not count", async () => {
|
|
117
|
+
const warn = jest.spyOn(console, "warn").mockImplementation(() => undefined);
|
|
118
|
+
function Wrapped(): ReactElement {
|
|
119
|
+
return <>{events()}</>;
|
|
120
|
+
}
|
|
121
|
+
await renderWithProviders(
|
|
122
|
+
<Timeline value={0}>
|
|
123
|
+
<Wrapped />
|
|
124
|
+
</Timeline>
|
|
125
|
+
);
|
|
126
|
+
expect(screen.getByLabelText("Placed")).toHaveAccessibilityValue({ text: "Event 1, current" });
|
|
127
|
+
expect(warn).toHaveBeenCalledWith(expect.stringContaining("found no <Timeline.Item>"));
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test("a Timeline.Item with no step warns", async () => {
|
|
131
|
+
const warn = jest.spyOn(console, "warn").mockImplementation(() => undefined);
|
|
132
|
+
await renderWithProviders(
|
|
133
|
+
<Timeline value={0}>
|
|
134
|
+
<Timeline.Item>
|
|
135
|
+
<Timeline.Title>Lost</Timeline.Title>
|
|
136
|
+
</Timeline.Item>
|
|
137
|
+
</Timeline>
|
|
138
|
+
);
|
|
139
|
+
expect(warn).toHaveBeenCalledWith(expect.stringContaining("Timeline.Item: no step"));
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
test("the masthead is a header", async () => {
|
|
143
|
+
await renderWithProviders(
|
|
144
|
+
<Timeline value={0}>
|
|
145
|
+
<Timeline.Masthead label="Order" title="Order 4021" />
|
|
146
|
+
{events()}
|
|
147
|
+
</Timeline>
|
|
148
|
+
);
|
|
149
|
+
expect(screen.getByRole("header")).toBeOnTheScreen();
|
|
150
|
+
expect(screen.getByText("Order 4021")).toBeOnTheScreen();
|
|
151
|
+
expect(screen.getByText("Order")).toBeOnTheScreen();
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test("aside, trailing, meta, date and stats render inside an item", async () => {
|
|
155
|
+
await renderWithProviders(
|
|
156
|
+
<Timeline value={0}>
|
|
157
|
+
<Timeline.Item accessibilityLabel="Rich" step={0}>
|
|
158
|
+
<Timeline.Aside>
|
|
159
|
+
<Timeline.Date>9:41</Timeline.Date>
|
|
160
|
+
</Timeline.Aside>
|
|
161
|
+
<Timeline.Trailing>
|
|
162
|
+
<Timeline.Meta>Auckland</Timeline.Meta>
|
|
163
|
+
</Timeline.Trailing>
|
|
164
|
+
<Timeline.Title>Rich</Timeline.Title>
|
|
165
|
+
<Timeline.Stats>
|
|
166
|
+
<Timeline.Stat label="Distance" value="12 km" />
|
|
167
|
+
</Timeline.Stats>
|
|
168
|
+
</Timeline.Item>
|
|
169
|
+
</Timeline>
|
|
170
|
+
);
|
|
171
|
+
expect(screen.getByText("9:41")).toBeOnTheScreen();
|
|
172
|
+
expect(screen.getByText("Auckland")).toBeOnTheScreen();
|
|
173
|
+
expect(screen.getByText("Distance")).toBeOnTheScreen();
|
|
174
|
+
expect(screen.getByText("12 km")).toBeOnTheScreen();
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test("a custom part reads the root and item through useTimeline and useTimelineItem", async () => {
|
|
178
|
+
function Probe(): ReactElement {
|
|
179
|
+
const root = useTimeline();
|
|
180
|
+
const item = useTimelineItem();
|
|
181
|
+
return <Timeline.Title>{`${root.orientation}/${root.count}/${item.step}/${item.status}`}</Timeline.Title>;
|
|
182
|
+
}
|
|
183
|
+
await renderWithProviders(
|
|
184
|
+
<Timeline value={0}>
|
|
185
|
+
<Timeline.Item step={0}>
|
|
186
|
+
<Probe />
|
|
187
|
+
</Timeline.Item>
|
|
188
|
+
</Timeline>
|
|
189
|
+
);
|
|
190
|
+
expect(screen.getByText("vertical/1/0/current")).toBeOnTheScreen();
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
test("an item used outside a timeline throws its documented error", async () => {
|
|
194
|
+
await expectThrow(
|
|
195
|
+
<Timeline.Item step={0}>
|
|
196
|
+
<Timeline.Title>Orphan</Timeline.Title>
|
|
197
|
+
</Timeline.Item>,
|
|
198
|
+
"Timeline.Item must be rendered inside a <Timeline> or <Timeline.List>."
|
|
199
|
+
);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
test("the masthead used outside a timeline throws", async () => {
|
|
203
|
+
await expectThrow(
|
|
204
|
+
<Timeline.Masthead title="Orphan" />,
|
|
205
|
+
"Timeline.Masthead must be rendered inside a <Timeline> or <Timeline.List>."
|
|
206
|
+
);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
test.each([
|
|
210
|
+
["Timeline.Title", <Timeline.Title key="p">x</Timeline.Title>],
|
|
211
|
+
["Timeline.Description", <Timeline.Description key="p">x</Timeline.Description>],
|
|
212
|
+
["Timeline.Date", <Timeline.Date key="p">x</Timeline.Date>],
|
|
213
|
+
["Timeline.Meta", <Timeline.Meta key="p">x</Timeline.Meta>],
|
|
214
|
+
["Timeline.Indicator", <Timeline.Indicator key="p" />],
|
|
215
|
+
["Timeline.Stat", <Timeline.Stat key="p" label="a" value="b" />],
|
|
216
|
+
])("%s outside a Timeline.Item throws inside a timeline", async (name, part) => {
|
|
217
|
+
await expectThrow(<Timeline value={0}>{part}</Timeline>, `${name} must be rendered inside a <Timeline.Item>.`);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
test("the hooks throw outside their roots", async () => {
|
|
221
|
+
function UsesRoot(): null {
|
|
222
|
+
useTimeline();
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
function UsesItem(): null {
|
|
226
|
+
useTimelineItem();
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
await expectThrow(<UsesRoot />, "useTimeline must be called inside a <Timeline> or <Timeline.List>.");
|
|
230
|
+
await expectThrow(
|
|
231
|
+
<Timeline value={0}>
|
|
232
|
+
<UsesItem />
|
|
233
|
+
</Timeline>,
|
|
234
|
+
"useTimelineItem must be called inside a <Timeline.Item>."
|
|
235
|
+
);
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
describe("Timeline horizontal", () => {
|
|
240
|
+
test("each column is one accessible element with the same position and status", async () => {
|
|
241
|
+
await renderWithProviders(
|
|
242
|
+
<Timeline orientation="horizontal" value={1}>
|
|
243
|
+
{events()}
|
|
244
|
+
</Timeline>
|
|
245
|
+
);
|
|
246
|
+
expect(screen.getByLabelText("Placed")).toHaveAccessibilityValue({ text: "Event 1 of 3, completed" });
|
|
247
|
+
expect(screen.getByLabelText("Packed")).toHaveAccessibilityValue({ text: "Event 2 of 3, current" });
|
|
248
|
+
expect(screen.getByText("Shipped")).toBeOnTheScreen();
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
test("a column with no content is a tick, hidden from assistive technology", async () => {
|
|
252
|
+
await renderWithProviders(
|
|
253
|
+
<Timeline orientation="horizontal" value={0}>
|
|
254
|
+
{events()}
|
|
255
|
+
<Timeline.Item step={3} testID="gap" />
|
|
256
|
+
</Timeline>
|
|
257
|
+
);
|
|
258
|
+
expect(screen.queryByTestId("gap")).not.toBeOnTheScreen();
|
|
259
|
+
const gap = screen.getByTestId("gap", { hidden: true });
|
|
260
|
+
expect(gap).toHaveProp("accessible", false);
|
|
261
|
+
expect(gap).toHaveProp("accessibilityElementsHidden", true);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
test("the masthead renders above the strip as a header", async () => {
|
|
265
|
+
await renderWithProviders(
|
|
266
|
+
<Timeline orientation="horizontal" value={0}>
|
|
267
|
+
<Timeline.Masthead title="Season" />
|
|
268
|
+
{events()}
|
|
269
|
+
</Timeline>
|
|
270
|
+
);
|
|
271
|
+
expect(screen.getByRole("header")).toBeOnTheScreen();
|
|
272
|
+
expect(screen.getByText("Season")).toBeOnTheScreen();
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
describe("Timeline.List", () => {
|
|
277
|
+
test("supplies each item's step and count from the data, so renderItem needs neither", async () => {
|
|
278
|
+
await renderWithProviders(
|
|
279
|
+
<Timeline.List
|
|
280
|
+
data={EVENTS}
|
|
281
|
+
keyExtractor={(event) => event.id}
|
|
282
|
+
renderItem={({ item }) => (
|
|
283
|
+
<Timeline.Item accessibilityLabel={item.title}>
|
|
284
|
+
<Timeline.Title>{item.title}</Timeline.Title>
|
|
285
|
+
</Timeline.Item>
|
|
286
|
+
)}
|
|
287
|
+
value={1}
|
|
288
|
+
/>
|
|
289
|
+
);
|
|
290
|
+
expect(screen.getByLabelText("Placed")).toHaveAccessibilityValue({ text: "Event 1 of 3, completed" });
|
|
291
|
+
expect(screen.getByLabelText("Packed")).toHaveAccessibilityValue({ text: "Event 2 of 3, current" });
|
|
292
|
+
expect(screen.getByLabelText("Shipped")).toHaveAccessibilityValue({ text: "Event 3 of 3, upcoming" });
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
test("horizontal lists render their columns and an empty list renders none", async () => {
|
|
296
|
+
const view = await renderWithProviders(
|
|
297
|
+
<Timeline.List
|
|
298
|
+
data={EVENTS}
|
|
299
|
+
itemWidth={120}
|
|
300
|
+
keyExtractor={(event) => event.id}
|
|
301
|
+
orientation="horizontal"
|
|
302
|
+
renderItem={({ item }) => (
|
|
303
|
+
<Timeline.Item accessibilityLabel={item.title}>
|
|
304
|
+
<Timeline.Title>{item.title}</Timeline.Title>
|
|
305
|
+
</Timeline.Item>
|
|
306
|
+
)}
|
|
307
|
+
value={0}
|
|
308
|
+
/>
|
|
309
|
+
);
|
|
310
|
+
expect(screen.getByLabelText("Placed")).toHaveAccessibilityValue({ text: "Event 1 of 3, current" });
|
|
311
|
+
await view.rerender(
|
|
312
|
+
<Timeline.List data={[]} orientation="horizontal" renderItem={() => <Timeline.Item />} value={0} />
|
|
313
|
+
);
|
|
314
|
+
expect(screen.queryByLabelText("Placed")).not.toBeOnTheScreen();
|
|
315
|
+
});
|
|
316
|
+
});
|
|
@@ -29,6 +29,7 @@ once, it draws the store) and `<Toast>` (the card, compound, also usable inside
|
|
|
29
29
|
| `toast-viewport.tsx` | `ToastViewport` — two stacks in the overlay `toast` band; insets, keyboard, `AppState`, screen reader |
|
|
30
30
|
| `toast-item.tsx` | One drawn toast: entrance, depth, exit, clock, swipe, announcement, haptic |
|
|
31
31
|
| `*.test.ts` | The store, the clock and the resolvers |
|
|
32
|
+
| `toast.render.test.tsx` | Mounted under Jest — the viewport drawing `toast()` calls, title/description, action and close, alert role and live region, assistive `activate`/`dismiss`, fake-timer auto-dismiss, custom `render`, parts outside a `Toast` |
|
|
32
33
|
|
|
33
34
|
## Design
|
|
34
35
|
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, jest, test } from "@jest/globals";
|
|
2
|
+
import type { ReactElement, ReactNode } from "react";
|
|
3
|
+
import { AccessibilityInfo } from "react-native";
|
|
4
|
+
import { act, fireEvent, renderWithProviders, screen } from "../../test/render";
|
|
5
|
+
import { OverlayProvider } from "../overlay";
|
|
6
|
+
import { Toast } from "./toast";
|
|
7
|
+
import { createToastApi, createToastStore, type ToastApi, type ToastStore } from "./toast.store";
|
|
8
|
+
import { ToastViewport } from "./toast-viewport";
|
|
9
|
+
|
|
10
|
+
function Overlays({ children }: { children: ReactNode }): ReactElement {
|
|
11
|
+
return <OverlayProvider>{children}</OverlayProvider>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type Harness = { store: ToastStore; toast: ToastApi };
|
|
15
|
+
|
|
16
|
+
function makeHarness(): Harness {
|
|
17
|
+
const store = createToastStore();
|
|
18
|
+
return { store, toast: createToastApi(store) };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function mountViewport(harness: Harness): Promise<void> {
|
|
22
|
+
await renderWithProviders(<ToastViewport store={harness.store} />, { wrapper: Overlays });
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Swipe-to-dismiss is a Gesture Handler pan on the card and carries no testID, so it is not driven here;
|
|
26
|
+
// its decision logic (resolveToastDrag / resolveToastRelease) is covered by toast.variants.test.ts.
|
|
27
|
+
describe("Toast", () => {
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
jest.useFakeTimers();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
afterEach(() => {
|
|
33
|
+
jest.useRealTimers();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("renders nothing until a toast is shown", async () => {
|
|
37
|
+
const harness = makeHarness();
|
|
38
|
+
await mountViewport(harness);
|
|
39
|
+
expect(screen.queryByTestId(/^toast-/)).not.toBeOnTheScreen();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("a shown toast draws its title and description", async () => {
|
|
43
|
+
const harness = makeHarness();
|
|
44
|
+
await mountViewport(harness);
|
|
45
|
+
await act(async () => {
|
|
46
|
+
harness.toast.show({ title: "Saved", description: "Your changes are live." });
|
|
47
|
+
});
|
|
48
|
+
expect(screen.getByText("Saved")).toBeOnTheScreen();
|
|
49
|
+
expect(screen.getByText("Your changes are live.")).toBeOnTheScreen();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test("a plain string is the title", async () => {
|
|
53
|
+
const harness = makeHarness();
|
|
54
|
+
await mountViewport(harness);
|
|
55
|
+
await act(async () => {
|
|
56
|
+
harness.toast("Link copied");
|
|
57
|
+
});
|
|
58
|
+
expect(screen.getByText("Link copied")).toBeOnTheScreen();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test("the card is one accessible element with a polite live region", async () => {
|
|
62
|
+
const harness = makeHarness();
|
|
63
|
+
await mountViewport(harness);
|
|
64
|
+
await act(async () => {
|
|
65
|
+
harness.toast.info("Heads up");
|
|
66
|
+
});
|
|
67
|
+
const card = screen.getByTestId(/^toast-toast-\d+$/);
|
|
68
|
+
expect(card.props.accessible).toBe(true);
|
|
69
|
+
expect(card.props.accessibilityLiveRegion).toBe("polite");
|
|
70
|
+
expect(card.props.accessibilityRole).toBe("none");
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test("an error toast is announced as an alert", async () => {
|
|
74
|
+
const harness = makeHarness();
|
|
75
|
+
await mountViewport(harness);
|
|
76
|
+
await act(async () => {
|
|
77
|
+
harness.toast.error("Upload failed");
|
|
78
|
+
});
|
|
79
|
+
expect(screen.getByRole("alert")).toBeOnTheScreen();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("each revision is announced to a screen reader", async () => {
|
|
83
|
+
const announce = jest.spyOn(AccessibilityInfo, "announceForAccessibility");
|
|
84
|
+
const announceWithOptions = jest.spyOn(AccessibilityInfo, "announceForAccessibilityWithOptions");
|
|
85
|
+
const harness = makeHarness();
|
|
86
|
+
await mountViewport(harness);
|
|
87
|
+
await act(async () => {
|
|
88
|
+
harness.toast.success("Saved");
|
|
89
|
+
});
|
|
90
|
+
expect(announce.mock.calls.length + announceWithOptions.mock.calls.length).toBeGreaterThan(0);
|
|
91
|
+
announce.mockRestore();
|
|
92
|
+
announceWithOptions.mockRestore();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test("the action runs its callback and hides the toast", async () => {
|
|
96
|
+
const onPress = jest.fn();
|
|
97
|
+
const harness = makeHarness();
|
|
98
|
+
await mountViewport(harness);
|
|
99
|
+
await act(async () => {
|
|
100
|
+
harness.toast.show({ title: "Archived", action: { label: "Undo", onPress } });
|
|
101
|
+
});
|
|
102
|
+
await fireEvent(screen.getByRole("button", { name: "Undo" }), "accessibilityTap");
|
|
103
|
+
expect(onPress).toHaveBeenCalledTimes(1);
|
|
104
|
+
expect(harness.store.getSnapshot()[0]?.isExiting).toBe(true);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test("the close control hides the toast", async () => {
|
|
108
|
+
const harness = makeHarness();
|
|
109
|
+
await mountViewport(harness);
|
|
110
|
+
await act(async () => {
|
|
111
|
+
harness.toast.show({ title: "Saved" });
|
|
112
|
+
});
|
|
113
|
+
await fireEvent(screen.getByRole("button", { name: "Dismiss" }), "accessibilityTap");
|
|
114
|
+
expect(harness.store.getSnapshot()[0]?.isExiting).toBe(true);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test("a loading toast has no close control", async () => {
|
|
118
|
+
const harness = makeHarness();
|
|
119
|
+
await mountViewport(harness);
|
|
120
|
+
await act(async () => {
|
|
121
|
+
harness.toast.show({ title: "Saving", isLoading: true });
|
|
122
|
+
});
|
|
123
|
+
expect(screen.getByText("Saving")).toBeOnTheScreen();
|
|
124
|
+
expect(screen.queryByRole("button", { name: "Dismiss" })).not.toBeOnTheScreen();
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test("the card exposes activate, escape and dismiss actions to assistive tech", async () => {
|
|
128
|
+
const onPress = jest.fn();
|
|
129
|
+
const harness = makeHarness();
|
|
130
|
+
await mountViewport(harness);
|
|
131
|
+
await act(async () => {
|
|
132
|
+
harness.toast.show({ title: "Archived", action: { label: "Undo", onPress } });
|
|
133
|
+
});
|
|
134
|
+
const card = screen.getByTestId(/^toast-toast-\d+$/);
|
|
135
|
+
const names = (card.props.accessibilityActions as { name: string }[]).map((action) => action.name);
|
|
136
|
+
expect(names).toEqual(expect.arrayContaining(["activate", "escape", "dismiss"]));
|
|
137
|
+
|
|
138
|
+
await fireEvent(card, "accessibilityAction", { nativeEvent: { actionName: "activate" } });
|
|
139
|
+
expect(onPress).toHaveBeenCalledTimes(1);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
test("a screen reader's dismiss action hides the toast", async () => {
|
|
143
|
+
const harness = makeHarness();
|
|
144
|
+
await mountViewport(harness);
|
|
145
|
+
await act(async () => {
|
|
146
|
+
harness.toast("Link copied");
|
|
147
|
+
});
|
|
148
|
+
await fireEvent(screen.getByTestId(/^toast-toast-\d+$/), "accessibilityAction", {
|
|
149
|
+
nativeEvent: { actionName: "dismiss" },
|
|
150
|
+
});
|
|
151
|
+
expect(harness.store.getSnapshot()[0]?.isExiting).toBe(true);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test("auto-dismisses once its duration has run", async () => {
|
|
155
|
+
const harness = makeHarness();
|
|
156
|
+
await mountViewport(harness);
|
|
157
|
+
await act(async () => {
|
|
158
|
+
harness.toast.show({ title: "Gone soon", duration: 1000 });
|
|
159
|
+
});
|
|
160
|
+
expect(harness.store.getSnapshot()[0]?.isExiting).toBe(false);
|
|
161
|
+
await act(async () => {
|
|
162
|
+
jest.advanceTimersByTime(999);
|
|
163
|
+
});
|
|
164
|
+
expect(harness.store.getSnapshot()[0]?.isExiting).toBe(false);
|
|
165
|
+
await act(async () => {
|
|
166
|
+
jest.advanceTimersByTime(2);
|
|
167
|
+
});
|
|
168
|
+
expect(harness.store.getSnapshot()[0]?.isExiting).toBe(true);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
test("duration 0 stays until hidden", async () => {
|
|
172
|
+
const harness = makeHarness();
|
|
173
|
+
await mountViewport(harness);
|
|
174
|
+
await act(async () => {
|
|
175
|
+
harness.toast.show({ title: "Persistent", duration: 0 });
|
|
176
|
+
});
|
|
177
|
+
await act(async () => {
|
|
178
|
+
jest.advanceTimersByTime(60_000);
|
|
179
|
+
});
|
|
180
|
+
expect(harness.store.getSnapshot()[0]?.isExiting).toBe(false);
|
|
181
|
+
expect(screen.getByText("Persistent")).toBeOnTheScreen();
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
test("toast.hideAll marks every toast as leaving", async () => {
|
|
185
|
+
const harness = makeHarness();
|
|
186
|
+
await mountViewport(harness);
|
|
187
|
+
await act(async () => {
|
|
188
|
+
harness.toast.show({ title: "One", duration: 0 });
|
|
189
|
+
harness.toast.show({ title: "Two", duration: 0 });
|
|
190
|
+
});
|
|
191
|
+
await act(async () => {
|
|
192
|
+
harness.toast.hideAll();
|
|
193
|
+
});
|
|
194
|
+
expect(harness.store.getSnapshot().every((item) => item.isExiting)).toBe(true);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
test("toast.update changes the text in place", async () => {
|
|
198
|
+
const harness = makeHarness();
|
|
199
|
+
await mountViewport(harness);
|
|
200
|
+
let id = "";
|
|
201
|
+
await act(async () => {
|
|
202
|
+
id = harness.toast.show({ title: "Saving", duration: 0 }).id;
|
|
203
|
+
});
|
|
204
|
+
await act(async () => {
|
|
205
|
+
harness.toast.update(id, { title: "Saved" });
|
|
206
|
+
});
|
|
207
|
+
expect(screen.getByText("Saved")).toBeOnTheScreen();
|
|
208
|
+
expect(screen.queryByText("Saving")).not.toBeOnTheScreen();
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
test("a custom render hides the toast it is drawn in without an onHide", async () => {
|
|
212
|
+
const harness = makeHarness();
|
|
213
|
+
await mountViewport(harness);
|
|
214
|
+
await act(async () => {
|
|
215
|
+
harness.toast.show({
|
|
216
|
+
duration: 0,
|
|
217
|
+
render: () => (
|
|
218
|
+
<Toast status="success">
|
|
219
|
+
<Toast.Content>
|
|
220
|
+
<Toast.Title>Invite sent</Toast.Title>
|
|
221
|
+
</Toast.Content>
|
|
222
|
+
<Toast.Close />
|
|
223
|
+
</Toast>
|
|
224
|
+
),
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
expect(screen.getByText("Invite sent")).toBeOnTheScreen();
|
|
228
|
+
await fireEvent(screen.getByRole("button", { name: "Dismiss" }), "accessibilityTap");
|
|
229
|
+
expect(harness.store.getSnapshot()[0]?.isExiting).toBe(true);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
test("a part used outside a Toast throws its documented error", async () => {
|
|
233
|
+
const spy = jest.spyOn(console, "error").mockImplementation(() => {});
|
|
234
|
+
try {
|
|
235
|
+
await expect(renderWithProviders(<Toast.Close />)).rejects.toThrow(
|
|
236
|
+
"Toast.Close must be rendered inside a <Toast>."
|
|
237
|
+
);
|
|
238
|
+
await expect(renderWithProviders(<Toast.Title>x</Toast.Title>)).rejects.toThrow(
|
|
239
|
+
"Toast.Title must be rendered inside a <Toast>."
|
|
240
|
+
);
|
|
241
|
+
} finally {
|
|
242
|
+
spy.mockRestore();
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
});
|
|
@@ -16,6 +16,7 @@ selection. Compound root plus `ToggleButton.Label` and `ToggleButton.Group`.
|
|
|
16
16
|
| `toggle-button.context.tsx` | `ToggleButtonContext` and `ToggleButtonGroupContext`, with their hooks |
|
|
17
17
|
| `toggle-button.variants.ts` | The appearance table, the group's `tv()` and three pure resolvers |
|
|
18
18
|
| `toggle-button.variants.test.ts` | |
|
|
19
|
+
| `toggle-button.render.test.tsx` | Mounted under Jest — roles and checked/selected state, standalone and grouped selection (controlled and uncontrolled), disabled/busy, render-function children, part errors outside the root |
|
|
19
20
|
|
|
20
21
|
There is no `toggle-button.types.ts`: every prop type here has exactly one
|
|
21
22
|
consumer, so each lives beside the component it types. See
|