@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,318 @@
|
|
|
1
|
+
import { describe, expect, jest, test } from "@jest/globals";
|
|
2
|
+
import { fireEvent, renderWithProviders, screen } from "../../test/render";
|
|
3
|
+
import { Steps } from "./steps";
|
|
4
|
+
import { useSteps, useStepsItem } from "./steps.context";
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
* Accessible names are matched by regex: RNTL derives a name from descendants
|
|
8
|
+
* hidden with `accessibilityElementsHidden` (the indicator's number), which
|
|
9
|
+
* native platforms skip.
|
|
10
|
+
*
|
|
11
|
+
* Not testable under Jest: the connectors (laid out with flex, no measurement),
|
|
12
|
+
* the glyph's `ZoomIn` entrance and the fade on a disabled step. Pixels and
|
|
13
|
+
* motion are verified in the playground on a simulator.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
function Flow({ props }: { props?: Partial<React.ComponentProps<typeof Steps>> }) {
|
|
17
|
+
return (
|
|
18
|
+
<Steps {...props}>
|
|
19
|
+
<Steps.Item step={0}>Account</Steps.Item>
|
|
20
|
+
<Steps.Item step={1} testID="step-shipping">
|
|
21
|
+
Shipping
|
|
22
|
+
</Steps.Item>
|
|
23
|
+
<Steps.Item step={2}>Payment</Steps.Item>
|
|
24
|
+
</Steps>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const activate = (el: Parameters<typeof fireEvent>[0]) => fireEvent(el, "accessibilityTap");
|
|
29
|
+
|
|
30
|
+
describe("Steps", () => {
|
|
31
|
+
test("each step is a button named by its title, with a position value", async () => {
|
|
32
|
+
await renderWithProviders(<Flow props={{ defaultValue: 1 }} />);
|
|
33
|
+
const done = screen.getByRole("button", { name: /Account/ });
|
|
34
|
+
const current = screen.getByRole("button", { name: /Shipping/ });
|
|
35
|
+
const upcoming = screen.getByRole("button", { name: /Payment/ });
|
|
36
|
+
expect(done).toHaveAccessibilityValue({ text: "Step 1 of 3, completed" });
|
|
37
|
+
expect(current).toHaveAccessibilityValue({ text: "Step 2 of 3, current" });
|
|
38
|
+
expect(upcoming).toHaveAccessibilityValue({ text: "Step 3 of 3, upcoming" });
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("only the current step is selected", async () => {
|
|
42
|
+
await renderWithProviders(<Flow props={{ defaultValue: 1 }} />);
|
|
43
|
+
expect(screen.getByRole("button", { name: /Account/ })).not.toBeSelected();
|
|
44
|
+
expect(screen.getByRole("button", { name: /Shipping/ })).toBeSelected();
|
|
45
|
+
expect(screen.getByRole("button", { name: /Payment/ })).not.toBeSelected();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test("a completed override keeps the current step selected", async () => {
|
|
49
|
+
await renderWithProviders(
|
|
50
|
+
<Steps defaultValue={1}>
|
|
51
|
+
<Steps.Item step={0}>Account</Steps.Item>
|
|
52
|
+
<Steps.Item completed step={1}>
|
|
53
|
+
Shipping
|
|
54
|
+
</Steps.Item>
|
|
55
|
+
</Steps>
|
|
56
|
+
);
|
|
57
|
+
const current = screen.getByRole("button", { name: /Shipping/ });
|
|
58
|
+
expect(current).toBeSelected();
|
|
59
|
+
expect(current).toHaveAccessibilityValue({ text: "Step 2 of 2, completed" });
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("the number is hidden from assistive technology but shown", async () => {
|
|
63
|
+
await renderWithProviders(<Flow props={{ defaultValue: 0 }} />);
|
|
64
|
+
expect(screen.getByText("2", { includeHiddenElements: true })).toBeOnTheScreen();
|
|
65
|
+
expect(screen.queryByText("2")).not.toBeOnTheScreen();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("isInvalid and isLoading are announced", async () => {
|
|
69
|
+
await renderWithProviders(
|
|
70
|
+
<Steps defaultValue={1}>
|
|
71
|
+
<Steps.Item isInvalid step={0}>
|
|
72
|
+
Account
|
|
73
|
+
</Steps.Item>
|
|
74
|
+
<Steps.Item isLoading step={1}>
|
|
75
|
+
Shipping
|
|
76
|
+
</Steps.Item>
|
|
77
|
+
</Steps>
|
|
78
|
+
);
|
|
79
|
+
expect(screen.getByRole("button", { name: /Account/ })).toHaveAccessibilityValue({
|
|
80
|
+
text: "Step 1 of 2, completed, has an error",
|
|
81
|
+
});
|
|
82
|
+
const loading = screen.getByRole("button", { name: /Shipping/ });
|
|
83
|
+
expect(loading).toHaveAccessibilityValue({ text: "Step 2 of 2, current, loading" });
|
|
84
|
+
expect(loading).toBeBusy();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test("Title and Description compose and name the step", async () => {
|
|
88
|
+
await renderWithProviders(
|
|
89
|
+
<Steps orientation="vertical">
|
|
90
|
+
<Steps.Item step={0}>
|
|
91
|
+
<Steps.Title>Order placed</Steps.Title>
|
|
92
|
+
<Steps.Description>We have your order.</Steps.Description>
|
|
93
|
+
</Steps.Item>
|
|
94
|
+
</Steps>
|
|
95
|
+
);
|
|
96
|
+
expect(screen.getByRole("button", { name: /Order placed/ })).toBeOnTheScreen();
|
|
97
|
+
expect(screen.getByText("We have your order.")).toBeOnTheScreen();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
describe("uncontrolled", () => {
|
|
101
|
+
test("a press moves the value and calls onValueChange with the step", async () => {
|
|
102
|
+
const onValueChange = jest.fn();
|
|
103
|
+
await renderWithProviders(<Flow props={{ onValueChange }} />);
|
|
104
|
+
await activate(screen.getByRole("button", { name: /Payment/ }));
|
|
105
|
+
expect(onValueChange).toHaveBeenCalledTimes(1);
|
|
106
|
+
expect(onValueChange).toHaveBeenCalledWith(2);
|
|
107
|
+
expect(screen.getByRole("button", { name: /Payment/ })).toBeSelected();
|
|
108
|
+
expect(screen.getByRole("button", { name: /Account/ })).not.toBeSelected();
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test("re-pressing the current step does not call onValueChange", async () => {
|
|
112
|
+
const onValueChange = jest.fn();
|
|
113
|
+
await renderWithProviders(<Flow props={{ defaultValue: 1, onValueChange }} />);
|
|
114
|
+
await activate(screen.getByRole("button", { name: /Shipping/ }));
|
|
115
|
+
expect(onValueChange).not.toHaveBeenCalled();
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test("a step's own onPress fires too", async () => {
|
|
119
|
+
const onPress = jest.fn();
|
|
120
|
+
await renderWithProviders(
|
|
121
|
+
<Steps>
|
|
122
|
+
<Steps.Item onPress={onPress} step={0}>
|
|
123
|
+
Account
|
|
124
|
+
</Steps.Item>
|
|
125
|
+
<Steps.Item onPress={onPress} step={1}>
|
|
126
|
+
Shipping
|
|
127
|
+
</Steps.Item>
|
|
128
|
+
</Steps>
|
|
129
|
+
);
|
|
130
|
+
await activate(screen.getByRole("button", { name: /Shipping/ }));
|
|
131
|
+
expect(onPress).toHaveBeenCalledTimes(1);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
describe("controlled", () => {
|
|
136
|
+
test("reports the change and waits for the prop", async () => {
|
|
137
|
+
const onValueChange = jest.fn();
|
|
138
|
+
const view = await renderWithProviders(<Flow props={{ onValueChange, value: 0 }} />);
|
|
139
|
+
await activate(screen.getByRole("button", { name: /Shipping/ }));
|
|
140
|
+
expect(onValueChange).toHaveBeenCalledWith(1);
|
|
141
|
+
expect(screen.getByRole("button", { name: /Account/ })).toBeSelected();
|
|
142
|
+
|
|
143
|
+
await view.rerender(<Flow props={{ onValueChange, value: 1 }} />);
|
|
144
|
+
expect(screen.getByRole("button", { name: /Shipping/ })).toBeSelected();
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test("a value with no onValueChange is a read-only display, not buttons", async () => {
|
|
148
|
+
await renderWithProviders(<Flow props={{ value: 1 }} />);
|
|
149
|
+
expect(screen.queryByRole("button")).not.toBeOnTheScreen();
|
|
150
|
+
const current = screen.getByTestId("step-shipping");
|
|
151
|
+
expect(current).toBeSelected();
|
|
152
|
+
expect(current).toHaveAccessibilityValue({ text: "Step 2 of 3, current" });
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test("isReadOnly forces a display even with onValueChange", async () => {
|
|
156
|
+
const onValueChange = jest.fn();
|
|
157
|
+
await renderWithProviders(<Flow props={{ isReadOnly: true, onValueChange, value: 0 }} />);
|
|
158
|
+
expect(screen.queryByRole("button")).not.toBeOnTheScreen();
|
|
159
|
+
expect(onValueChange).not.toHaveBeenCalled();
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
test("isReadOnly={false} keeps a controlled value without a handler pressable", async () => {
|
|
163
|
+
await renderWithProviders(<Flow props={{ isReadOnly: false, value: 0 }} />);
|
|
164
|
+
expect(screen.getAllByRole("button")).toHaveLength(3);
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
describe("disabled and busy", () => {
|
|
169
|
+
test("root isDisabled disables every step and blocks presses", async () => {
|
|
170
|
+
const onValueChange = jest.fn();
|
|
171
|
+
await renderWithProviders(<Flow props={{ isDisabled: true, onValueChange }} />);
|
|
172
|
+
for (const step of screen.getAllByRole("button")) expect(step).toBeDisabled();
|
|
173
|
+
await activate(screen.getByRole("button", { name: /Shipping/ }));
|
|
174
|
+
expect(onValueChange).not.toHaveBeenCalled();
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test("a step's isDisabled blocks only that step", async () => {
|
|
178
|
+
const onValueChange = jest.fn();
|
|
179
|
+
await renderWithProviders(
|
|
180
|
+
<Steps onValueChange={onValueChange}>
|
|
181
|
+
<Steps.Item step={0}>Account</Steps.Item>
|
|
182
|
+
<Steps.Item isDisabled step={1}>
|
|
183
|
+
Shipping
|
|
184
|
+
</Steps.Item>
|
|
185
|
+
<Steps.Item step={2}>Payment</Steps.Item>
|
|
186
|
+
</Steps>
|
|
187
|
+
);
|
|
188
|
+
expect(screen.getByRole("button", { name: /Shipping/ })).toBeDisabled();
|
|
189
|
+
expect(screen.getByRole("button", { name: /Payment/ })).not.toBeDisabled();
|
|
190
|
+
await activate(screen.getByRole("button", { name: /Shipping/ }));
|
|
191
|
+
expect(onValueChange).not.toHaveBeenCalled();
|
|
192
|
+
await activate(screen.getByRole("button", { name: /Payment/ }));
|
|
193
|
+
expect(onValueChange).toHaveBeenCalledWith(2);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
test("a loading step is busy, not disabled, and ignores presses", async () => {
|
|
197
|
+
const onValueChange = jest.fn();
|
|
198
|
+
await renderWithProviders(
|
|
199
|
+
<Steps onValueChange={onValueChange}>
|
|
200
|
+
<Steps.Item step={0}>Account</Steps.Item>
|
|
201
|
+
<Steps.Item isLoading step={1}>
|
|
202
|
+
Shipping
|
|
203
|
+
</Steps.Item>
|
|
204
|
+
</Steps>
|
|
205
|
+
);
|
|
206
|
+
const loading = screen.getByRole("button", { name: /Shipping/ });
|
|
207
|
+
expect(loading).toBeBusy();
|
|
208
|
+
expect(loading).not.toBeDisabled();
|
|
209
|
+
await activate(loading);
|
|
210
|
+
expect(onValueChange).not.toHaveBeenCalled();
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
test("isLinear blocks steps ahead of the value but not those behind", async () => {
|
|
214
|
+
const onValueChange = jest.fn();
|
|
215
|
+
await renderWithProviders(<Flow props={{ defaultValue: 1, isLinear: true, onValueChange }} />);
|
|
216
|
+
expect(screen.getByRole("button", { name: /Payment/ })).toBeDisabled();
|
|
217
|
+
expect(screen.getByRole("button", { name: /Account/ })).not.toBeDisabled();
|
|
218
|
+
|
|
219
|
+
await activate(screen.getByRole("button", { name: /Payment/ }));
|
|
220
|
+
expect(onValueChange).not.toHaveBeenCalled();
|
|
221
|
+
|
|
222
|
+
await activate(screen.getByRole("button", { name: /Account/ }));
|
|
223
|
+
expect(onValueChange).toHaveBeenCalledWith(0);
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
describe("panel", () => {
|
|
228
|
+
test("renders outside the trigger, so its controls are separate elements", async () => {
|
|
229
|
+
await renderWithProviders(
|
|
230
|
+
<Steps defaultValue={0}>
|
|
231
|
+
<Steps.Item step={0}>
|
|
232
|
+
Account
|
|
233
|
+
<Steps.Panel>
|
|
234
|
+
<Steps.Description>Panel body</Steps.Description>
|
|
235
|
+
</Steps.Panel>
|
|
236
|
+
</Steps.Item>
|
|
237
|
+
<Steps.Item step={1}>Shipping</Steps.Item>
|
|
238
|
+
</Steps>
|
|
239
|
+
);
|
|
240
|
+
expect(screen.getByText("Panel body")).toBeOnTheScreen();
|
|
241
|
+
expect(screen.getByRole("button", { name: /Account/ })).toBeOnTheScreen();
|
|
242
|
+
expect(screen.queryByRole("button", { name: /Panel body/ })).not.toBeOnTheScreen();
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
test("a press inside the panel does not move the stepper", async () => {
|
|
246
|
+
const onValueChange = jest.fn();
|
|
247
|
+
await renderWithProviders(
|
|
248
|
+
<Steps defaultValue={0} onValueChange={onValueChange}>
|
|
249
|
+
<Steps.Item step={0}>Account</Steps.Item>
|
|
250
|
+
<Steps.Item step={1}>
|
|
251
|
+
Shipping
|
|
252
|
+
<Steps.Panel>
|
|
253
|
+
<Steps.Title>Inner</Steps.Title>
|
|
254
|
+
</Steps.Panel>
|
|
255
|
+
</Steps.Item>
|
|
256
|
+
</Steps>
|
|
257
|
+
);
|
|
258
|
+
await fireEvent(screen.getByText("Inner"), "accessibilityTap");
|
|
259
|
+
expect(onValueChange).not.toHaveBeenCalled();
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
describe("hooks and parts outside their root", () => {
|
|
264
|
+
test("useSteps and useStepsItem expose the settled state", async () => {
|
|
265
|
+
function RootProbe() {
|
|
266
|
+
const root = useSteps();
|
|
267
|
+
return <Steps.Description>{`value ${root.value} of ${root.count}`}</Steps.Description>;
|
|
268
|
+
}
|
|
269
|
+
function ItemProbe() {
|
|
270
|
+
const item = useStepsItem();
|
|
271
|
+
return <Steps.Description>{`${item.status} ${item.step}`}</Steps.Description>;
|
|
272
|
+
}
|
|
273
|
+
await renderWithProviders(
|
|
274
|
+
<Steps defaultValue={1}>
|
|
275
|
+
<Steps.Item step={0}>
|
|
276
|
+
<Steps.Title>First</Steps.Title>
|
|
277
|
+
<ItemProbe />
|
|
278
|
+
</Steps.Item>
|
|
279
|
+
<Steps.Item step={1}>
|
|
280
|
+
<Steps.Title>Second</Steps.Title>
|
|
281
|
+
<ItemProbe />
|
|
282
|
+
<RootProbe />
|
|
283
|
+
</Steps.Item>
|
|
284
|
+
</Steps>
|
|
285
|
+
);
|
|
286
|
+
expect(screen.getByText("value 1 of 2")).toBeOnTheScreen();
|
|
287
|
+
expect(screen.getByText("completed 0")).toBeOnTheScreen();
|
|
288
|
+
expect(screen.getByText("current 1")).toBeOnTheScreen();
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
test.each([
|
|
292
|
+
["Steps.Item", <Steps.Item key="i" step={0} />, "Steps.Item must be rendered inside a <Steps>."],
|
|
293
|
+
["Steps.Indicator", <Steps.Indicator key="n" />, "Steps.Indicator must be rendered inside a <Steps.Item>."],
|
|
294
|
+
["Steps.Title", <Steps.Title key="t">x</Steps.Title>, "Steps.Title must be rendered inside a <Steps.Item>."],
|
|
295
|
+
["Steps.Panel", <Steps.Panel key="p" />, "Steps.Panel must be rendered inside a <Steps.Item>."],
|
|
296
|
+
])("%s throws outside its root", async (_name, element, message) => {
|
|
297
|
+
const spy = jest.spyOn(console, "error").mockImplementation(() => undefined);
|
|
298
|
+
try {
|
|
299
|
+
await expect(renderWithProviders(element)).rejects.toThrow(message);
|
|
300
|
+
} finally {
|
|
301
|
+
spy.mockRestore();
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
test("useSteps throws outside a Steps", async () => {
|
|
306
|
+
function Bare() {
|
|
307
|
+
useSteps();
|
|
308
|
+
return null;
|
|
309
|
+
}
|
|
310
|
+
const spy = jest.spyOn(console, "error").mockImplementation(() => undefined);
|
|
311
|
+
try {
|
|
312
|
+
await expect(renderWithProviders(<Bare />)).rejects.toThrow("useSteps must be called inside a <Steps>.");
|
|
313
|
+
} finally {
|
|
314
|
+
spy.mockRestore();
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
});
|
|
@@ -31,6 +31,7 @@ above the composer and the closing question. Compound root plus seventeen option
|
|
|
31
31
|
| `support.types.ts` | `SupportAvailability`, `SupportTicketStatus`, their tuples, `SupportSectionProps` |
|
|
32
32
|
| `support.variants.ts` | The slotted `tv()`, the badge/chip/icon-token constants, `resolveReplyColor` |
|
|
33
33
|
| `support.utils.ts` | Labels, spoken labels, the dot and the topic resolvers — no RN imports |
|
|
34
|
+
| `support.render.test.tsx` | Mounted under Jest — availability, channel/conversation/article/ticket presses, topics radiogroup (controlled, uncontrolled, disabled, outside-root error), agent typing and handoff announcements, replies, resolution |
|
|
34
35
|
| `support.variants.test.ts` | |
|
|
35
36
|
| `support.utils.test.ts` | |
|
|
36
37
|
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, jest, test } from "@jest/globals";
|
|
2
|
+
import { AccessibilityInfo, Text } from "react-native";
|
|
3
|
+
import { fireEvent, renderWithProviders, screen } from "../../test/render";
|
|
4
|
+
import { Button } from "../button";
|
|
5
|
+
import { Support } from "./support";
|
|
6
|
+
|
|
7
|
+
const ACTIVATE = { nativeEvent: { actionName: "activate" } };
|
|
8
|
+
|
|
9
|
+
const announce = jest.spyOn(AccessibilityInfo, "announceForAccessibility").mockImplementation(() => {});
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
announce.mockClear();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describe("Support.Status and availability", () => {
|
|
16
|
+
test("the root's availability is spoken first, then the caller's wording", async () => {
|
|
17
|
+
await renderWithProviders(
|
|
18
|
+
<Support availability="online">
|
|
19
|
+
<Support.Status replyTime="Typically replies in under an hour" />
|
|
20
|
+
</Support>
|
|
21
|
+
);
|
|
22
|
+
expect(screen.getByLabelText("Online. Typically replies in under an hour")).toBeOnTheScreen();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test("defaults to offline with no availability, and a part's own availability overrides the root", async () => {
|
|
26
|
+
await renderWithProviders(
|
|
27
|
+
<Support>
|
|
28
|
+
<Support.Status />
|
|
29
|
+
<Support.Status availability="online" replyTime="Here now" />
|
|
30
|
+
</Support>
|
|
31
|
+
);
|
|
32
|
+
expect(screen.getByLabelText("Offline")).toBeOnTheScreen();
|
|
33
|
+
expect(screen.getByLabelText("Online. Here now")).toBeOnTheScreen();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("Agent works with no Support root, defaulting to offline", async () => {
|
|
37
|
+
await renderWithProviders(<Support.Agent name="Omar Haddad" title="Support" />);
|
|
38
|
+
expect(screen.getByLabelText("Omar Haddad, Support, offline")).toBeOnTheScreen();
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe("Support.Channel", () => {
|
|
43
|
+
test("calls onPress on activation and announces a button", async () => {
|
|
44
|
+
const onPress = jest.fn();
|
|
45
|
+
await renderWithProviders(
|
|
46
|
+
<Support.Channels title="Get in touch">
|
|
47
|
+
<Support.Channel accessibilityLabel="Chat" icon={<Text>i</Text>} label="Chat" onPress={onPress} />
|
|
48
|
+
</Support.Channels>
|
|
49
|
+
);
|
|
50
|
+
expect(screen.getByRole("header", { name: "Get in touch" })).toBeOnTheScreen();
|
|
51
|
+
const row = screen.getByRole("button", { name: "Chat" });
|
|
52
|
+
await fireEvent(row, "accessibilityTap");
|
|
53
|
+
expect(onPress).toHaveBeenCalledTimes(1);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("a shut channel stays on screen, announced disabled, and ignores activation", async () => {
|
|
57
|
+
const onPress = jest.fn();
|
|
58
|
+
await renderWithProviders(
|
|
59
|
+
<Support.Channels>
|
|
60
|
+
<Support.Channel
|
|
61
|
+
accessibilityLabel="Call us"
|
|
62
|
+
icon={<Text>i</Text>}
|
|
63
|
+
isDisabled
|
|
64
|
+
label="Call us"
|
|
65
|
+
onPress={onPress}
|
|
66
|
+
/>
|
|
67
|
+
</Support.Channels>
|
|
68
|
+
);
|
|
69
|
+
const row = screen.getByLabelText("Call us");
|
|
70
|
+
expect(row).toBeDisabled();
|
|
71
|
+
await fireEvent(row, "accessibilityTap");
|
|
72
|
+
expect(onPress).not.toHaveBeenCalled();
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe("Support.Conversation", () => {
|
|
77
|
+
test("reads the row as one sentence, dot and status included", async () => {
|
|
78
|
+
await renderWithProviders(
|
|
79
|
+
<Support.Conversations title="Your requests">
|
|
80
|
+
<Support.Conversation
|
|
81
|
+
preview="We've issued the refund."
|
|
82
|
+
reference="#4821"
|
|
83
|
+
status="solved"
|
|
84
|
+
timestamp="2h"
|
|
85
|
+
title="Refund for order"
|
|
86
|
+
unread
|
|
87
|
+
/>
|
|
88
|
+
</Support.Conversations>
|
|
89
|
+
);
|
|
90
|
+
expect(
|
|
91
|
+
screen.getByLabelText("Refund for order, #4821, solved, unread reply, 2h. We've issued the refund.")
|
|
92
|
+
).toBeOnTheScreen();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test("unread wins over updated, and pending is labelled as waiting on the reader", async () => {
|
|
96
|
+
await renderWithProviders(
|
|
97
|
+
<Support.Conversations>
|
|
98
|
+
<Support.Conversation status="pending" title="Both" unread updated />
|
|
99
|
+
<Support.Conversation status="open" title="Moved" updated />
|
|
100
|
+
</Support.Conversations>
|
|
101
|
+
);
|
|
102
|
+
expect(screen.getByLabelText(/^Both, waiting on you, unread/i)).toBeOnTheScreen();
|
|
103
|
+
expect(screen.getByLabelText(/^Moved, open, updated/i)).toBeOnTheScreen();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test("onPress fires on activation and not when disabled", async () => {
|
|
107
|
+
const onPress = jest.fn();
|
|
108
|
+
await renderWithProviders(
|
|
109
|
+
<Support.Conversations>
|
|
110
|
+
<Support.Conversation onPress={onPress} status="open" title="Open one" />
|
|
111
|
+
<Support.Conversation isDisabled onPress={onPress} status="closed" title="Closed one" />
|
|
112
|
+
</Support.Conversations>
|
|
113
|
+
);
|
|
114
|
+
await fireEvent(screen.getByLabelText(/^Open one/), "accessibilityTap");
|
|
115
|
+
expect(onPress).toHaveBeenCalledTimes(1);
|
|
116
|
+
const disabled = screen.getByLabelText(/^Closed one/);
|
|
117
|
+
expect(disabled).toBeDisabled();
|
|
118
|
+
await fireEvent(disabled, "accessibilityTap");
|
|
119
|
+
expect(onPress).toHaveBeenCalledTimes(1);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
describe("Support.Article and Support.Ticket", () => {
|
|
124
|
+
test("an article is a button when it has onPress", async () => {
|
|
125
|
+
const onPress = jest.fn();
|
|
126
|
+
await renderWithProviders(
|
|
127
|
+
<Support.Articles title="Help centre">
|
|
128
|
+
<Support.Article collection="Billing" onPress={onPress} title="Change your plan" />
|
|
129
|
+
</Support.Articles>
|
|
130
|
+
);
|
|
131
|
+
await fireEvent(screen.getByRole("button"), "accessibilityTap");
|
|
132
|
+
expect(onPress).toHaveBeenCalledTimes(1);
|
|
133
|
+
expect(screen.getByText("Billing")).toBeOnTheScreen();
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test("a ticket shows its status badge and opens details on press", async () => {
|
|
137
|
+
const onPress = jest.fn();
|
|
138
|
+
await renderWithProviders(
|
|
139
|
+
<Support.Ticket onPress={onPress} reference="#4821" status="pending" title="Refund for order" />
|
|
140
|
+
);
|
|
141
|
+
expect(screen.getByText("Waiting on you")).toBeOnTheScreen();
|
|
142
|
+
await fireEvent(screen.getByRole("button"), "accessibilityTap");
|
|
143
|
+
expect(onPress).toHaveBeenCalledTimes(1);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test("a ticket with no onPress is not interactive", async () => {
|
|
147
|
+
await renderWithProviders(<Support.Ticket status="solved" title="Refund" />);
|
|
148
|
+
expect(screen.queryByRole("button")).not.toBeOnTheScreen();
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
describe("Support.Topics", () => {
|
|
153
|
+
function Group({
|
|
154
|
+
onValueChange,
|
|
155
|
+
...props
|
|
156
|
+
}: {
|
|
157
|
+
onValueChange?: (value: string) => void;
|
|
158
|
+
value?: string | null;
|
|
159
|
+
defaultValue?: string | null;
|
|
160
|
+
}) {
|
|
161
|
+
return (
|
|
162
|
+
<Support.Topics onValueChange={onValueChange} title="What is it about?" {...props}>
|
|
163
|
+
<Support.Topic description="Invoices, refunds and plans" label="Billing" value="billing" />
|
|
164
|
+
<Support.Topic label="Account" value="account" />
|
|
165
|
+
<Support.Topic isDisabled label="Legal" value="legal" />
|
|
166
|
+
</Support.Topics>
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
test("is a labelled radiogroup of radios named with their description", async () => {
|
|
171
|
+
await renderWithProviders(<Group />);
|
|
172
|
+
expect(screen.getByLabelText("What is it about?").props.accessibilityRole).toBe("radiogroup");
|
|
173
|
+
expect(screen.getAllByRole("radio")).toHaveLength(3);
|
|
174
|
+
const billing = screen.getByRole("radio", { name: "Billing. Invoices, refunds and plans" });
|
|
175
|
+
expect(billing).not.toBeChecked();
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
test("uncontrolled: defaultValue seeds it and a press moves the selection and reports it", async () => {
|
|
179
|
+
const onValueChange = jest.fn();
|
|
180
|
+
await renderWithProviders(<Group defaultValue="billing" onValueChange={onValueChange} />);
|
|
181
|
+
expect(screen.getByRole("radio", { name: /^Billing/ })).toBeChecked();
|
|
182
|
+
|
|
183
|
+
await fireEvent(screen.getByRole("radio", { name: "Account" }), "accessibilityTap");
|
|
184
|
+
expect(onValueChange).toHaveBeenCalledTimes(1);
|
|
185
|
+
expect(onValueChange).toHaveBeenCalledWith("account");
|
|
186
|
+
expect(screen.getByRole("radio", { name: "Account" })).toBeChecked();
|
|
187
|
+
expect(screen.getByRole("radio", { name: /^Billing/ })).not.toBeChecked();
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
test("pressing the selected topic keeps it and reports nothing", async () => {
|
|
191
|
+
const onValueChange = jest.fn();
|
|
192
|
+
await renderWithProviders(<Group defaultValue="account" onValueChange={onValueChange} />);
|
|
193
|
+
await fireEvent(screen.getByRole("radio", { name: "Account" }), "accessibilityAction", ACTIVATE);
|
|
194
|
+
expect(onValueChange).not.toHaveBeenCalled();
|
|
195
|
+
expect(screen.getByRole("radio", { name: "Account" })).toBeChecked();
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
test("controlled: reports the pick and waits for the prop", async () => {
|
|
199
|
+
const onValueChange = jest.fn();
|
|
200
|
+
const view = await renderWithProviders(<Group onValueChange={onValueChange} value="billing" />);
|
|
201
|
+
await fireEvent(screen.getByRole("radio", { name: "Account" }), "accessibilityTap");
|
|
202
|
+
expect(onValueChange).toHaveBeenCalledWith("account");
|
|
203
|
+
expect(screen.getByRole("radio", { name: "Account" })).not.toBeChecked();
|
|
204
|
+
|
|
205
|
+
await view.rerender(<Group onValueChange={onValueChange} value="account" />);
|
|
206
|
+
expect(screen.getByRole("radio", { name: "Account" })).toBeChecked();
|
|
207
|
+
expect(screen.getByRole("radio", { name: /^Billing/ })).not.toBeChecked();
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
test("a disabled topic is announced disabled and cannot be picked", async () => {
|
|
211
|
+
const onValueChange = jest.fn();
|
|
212
|
+
await renderWithProviders(<Group onValueChange={onValueChange} />);
|
|
213
|
+
const legal = screen.getByRole("radio", { name: "Legal" });
|
|
214
|
+
expect(legal).toBeDisabled();
|
|
215
|
+
await fireEvent(legal, "accessibilityTap");
|
|
216
|
+
expect(onValueChange).not.toHaveBeenCalled();
|
|
217
|
+
expect(legal).not.toBeChecked();
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
test("a Topic outside Support.Topics throws its documented error", async () => {
|
|
221
|
+
const spy = jest.spyOn(console, "error").mockImplementation(() => {});
|
|
222
|
+
await expect(renderWithProviders(<Support.Topic label="Billing" value="billing" />)).rejects.toThrow(
|
|
223
|
+
"useSupportTopics must be called inside a <Support.Topics>."
|
|
224
|
+
);
|
|
225
|
+
spy.mockRestore();
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
describe("Support.Agent", () => {
|
|
230
|
+
test("is one labelled element, and typing replaces the status line and announces once", async () => {
|
|
231
|
+
const view = await renderWithProviders(
|
|
232
|
+
<Support availability="online">
|
|
233
|
+
<Support.Agent name="Omar Haddad" title="Support" typingTestID="dots" />
|
|
234
|
+
</Support>
|
|
235
|
+
);
|
|
236
|
+
expect(screen.getByLabelText("Omar Haddad, Support, online")).toBeOnTheScreen();
|
|
237
|
+
expect(screen.queryByTestId("dots", { hidden: true })).not.toBeOnTheScreen();
|
|
238
|
+
expect(announce).not.toHaveBeenCalled();
|
|
239
|
+
|
|
240
|
+
await view.rerender(
|
|
241
|
+
<Support availability="online">
|
|
242
|
+
<Support.Agent name="Omar Haddad" title="Support" typing typingTestID="dots" />
|
|
243
|
+
</Support>
|
|
244
|
+
);
|
|
245
|
+
expect(screen.getByLabelText("Omar Haddad is typing")).toBeOnTheScreen();
|
|
246
|
+
expect(screen.getByText("Omar is typing")).toBeOnTheScreen();
|
|
247
|
+
expect(screen.getByTestId("dots", { hidden: true })).toBeOnTheScreen();
|
|
248
|
+
expect(announce).toHaveBeenCalledTimes(1);
|
|
249
|
+
expect(announce).toHaveBeenCalledWith("Omar Haddad is typing");
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
describe("Support.Handoff", () => {
|
|
254
|
+
test("announces the change of hands on mount", async () => {
|
|
255
|
+
await renderWithProviders(<Support.Handoff>You were passed to Omar.</Support.Handoff>);
|
|
256
|
+
expect(screen.getByLabelText("You were passed to Omar.")).toBeOnTheScreen();
|
|
257
|
+
expect(announce).toHaveBeenCalledWith("You were passed to Omar.");
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
test("announce={false} stays silent for a handoff that is history", async () => {
|
|
261
|
+
await renderWithProviders(<Support.Handoff announce={false}>You were passed to Omar.</Support.Handoff>);
|
|
262
|
+
expect(screen.getByText("You were passed to Omar.")).toBeOnTheScreen();
|
|
263
|
+
expect(announce).not.toHaveBeenCalled();
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
describe("Support.Replies and Support.Reply", () => {
|
|
268
|
+
test("each reply is a button that calls its own onPress", async () => {
|
|
269
|
+
const resolve = jest.fn();
|
|
270
|
+
const escalate = jest.fn();
|
|
271
|
+
await renderWithProviders(
|
|
272
|
+
<Support.Replies>
|
|
273
|
+
<Support.Reply label="That fixed it" onPress={resolve} />
|
|
274
|
+
<Support.Reply escalates label="Talk to a person" onPress={escalate} />
|
|
275
|
+
</Support.Replies>
|
|
276
|
+
);
|
|
277
|
+
await fireEvent(screen.getByRole("button", { name: "That fixed it" }), "accessibilityTap");
|
|
278
|
+
expect(resolve).toHaveBeenCalledTimes(1);
|
|
279
|
+
expect(escalate).not.toHaveBeenCalled();
|
|
280
|
+
|
|
281
|
+
await fireEvent(screen.getByRole("button", { name: "Talk to a person" }), "accessibilityTap");
|
|
282
|
+
expect(escalate).toHaveBeenCalledTimes(1);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
test("only the escalating reply carries the hint", async () => {
|
|
286
|
+
await renderWithProviders(
|
|
287
|
+
<Support.Replies>
|
|
288
|
+
<Support.Reply label="That fixed it" onPress={() => {}} />
|
|
289
|
+
<Support.Reply escalates label="Talk to a person" onPress={() => {}} />
|
|
290
|
+
</Support.Replies>
|
|
291
|
+
);
|
|
292
|
+
expect(screen.getByRole("button", { name: "Talk to a person" }).props.accessibilityHint).toBe("Talk to a person");
|
|
293
|
+
expect(screen.getByRole("button", { name: "That fixed it" }).props.accessibilityHint).toBeUndefined();
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
test("a disabled reply ignores activation", async () => {
|
|
297
|
+
const onPress = jest.fn();
|
|
298
|
+
await renderWithProviders(
|
|
299
|
+
<Support.Replies>
|
|
300
|
+
<Support.Reply isDisabled label="Later" onPress={onPress} />
|
|
301
|
+
</Support.Replies>
|
|
302
|
+
);
|
|
303
|
+
const reply = screen.getByRole("button", { name: "Later" });
|
|
304
|
+
expect(reply).toBeDisabled();
|
|
305
|
+
await fireEvent(reply, "accessibilityTap");
|
|
306
|
+
expect(onPress).not.toHaveBeenCalled();
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
describe("Support.Resolution and Support.Note", () => {
|
|
311
|
+
test("is a labelled group that leaves the caller's control its own role", async () => {
|
|
312
|
+
const onPress = jest.fn();
|
|
313
|
+
await renderWithProviders(
|
|
314
|
+
<Support.Resolution question="Did that help?">
|
|
315
|
+
<Button onPress={onPress}>Yes</Button>
|
|
316
|
+
</Support.Resolution>
|
|
317
|
+
);
|
|
318
|
+
expect(screen.getByText("Did that help?")).toBeOnTheScreen();
|
|
319
|
+
await fireEvent(screen.getByRole("button", { name: "Yes" }), "accessibilityTap");
|
|
320
|
+
expect(onPress).toHaveBeenCalledTimes(1);
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
test("a note renders its text", async () => {
|
|
324
|
+
await renderWithProviders(
|
|
325
|
+
<Support availability="away">
|
|
326
|
+
<Support.Note>Replies may take a day.</Support.Note>
|
|
327
|
+
</Support>
|
|
328
|
+
);
|
|
329
|
+
expect(screen.getByText("Replies may take a day.")).toBeOnTheScreen();
|
|
330
|
+
});
|
|
331
|
+
});
|
|
@@ -15,6 +15,7 @@ components built on it (`Card`, `Alert`) can read the plane they sit on.
|
|
|
15
15
|
| `surface.context.tsx` | `SurfaceProvider`, `useSurface()`, `useSurfaceContext()` |
|
|
16
16
|
| `surface.variants.ts` | The `tv()`, `SURFACE_FOREGROUND_TOKENS`, and the two pure resolvers — no RN imports |
|
|
17
17
|
| `surface.variants.test.ts` | |
|
|
18
|
+
| `surface.render.test.tsx` | Mounted under Jest — children and forwarded props, no default role, the context's variant/plane/material, nesting steps, tray reset, `useSurface` throwing outside a surface |
|
|
18
19
|
|
|
19
20
|
## Design
|
|
20
21
|
|