@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,217 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, jest, test } from "@jest/globals";
|
|
2
|
+
import type { ReactElement } from "react";
|
|
3
|
+
import { fireEvent, renderWithProviders, screen } from "../../test/render";
|
|
4
|
+
import { Button } from "../button";
|
|
5
|
+
import { Tour, type TourProps } from "./tour";
|
|
6
|
+
import { useTour } from "./tour.context";
|
|
7
|
+
|
|
8
|
+
function StartButton(): ReactElement {
|
|
9
|
+
const tour = useTour();
|
|
10
|
+
return <Button onPress={() => tour.start()}>Start tour</Button>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function StatusReader(): ReactElement {
|
|
14
|
+
const tour = useTour();
|
|
15
|
+
return <Button onPress={() => tour.goTo(3)}>{`Step ${tour.step} index ${tour.index} of ${tour.total}`}</Button>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function Steps(props: Omit<TourProps, "children">): ReactElement {
|
|
19
|
+
return (
|
|
20
|
+
<Tour testID="tour" {...props}>
|
|
21
|
+
<StartButton />
|
|
22
|
+
<StatusReader />
|
|
23
|
+
<Tour.Step description="Find anything." order={1} title="Search">
|
|
24
|
+
<Button>Search</Button>
|
|
25
|
+
</Tour.Step>
|
|
26
|
+
<Tour.Step description="Start writing." order={2} title="New note">
|
|
27
|
+
<Button>Compose</Button>
|
|
28
|
+
</Tour.Step>
|
|
29
|
+
<Tour.Step order={3} title="Profile">
|
|
30
|
+
<Button>Account</Button>
|
|
31
|
+
</Tour.Step>
|
|
32
|
+
</Tour>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const press = (testID: string) => fireEvent(screen.getByTestId(testID), "accessibilityTap");
|
|
37
|
+
|
|
38
|
+
// Each Tour.Step is measured with measureInWindow, which never resolves under Jest, so the hole and
|
|
39
|
+
// card placement are never computed here. The card, its text and its actions still mount as soon as
|
|
40
|
+
// the tour is open, so these tests drive the start/next/back/skip/finish flows through them and
|
|
41
|
+
// leave hole geometry to the pure resolver suite and the playground.
|
|
42
|
+
describe("Tour", () => {
|
|
43
|
+
beforeEach(() => {
|
|
44
|
+
jest.useFakeTimers();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
afterEach(() => {
|
|
48
|
+
jest.useRealTimers();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("shows no card while closed", async () => {
|
|
52
|
+
await renderWithProviders(<Steps />);
|
|
53
|
+
expect(screen.queryByTestId("tour-card")).not.toBeOnTheScreen();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("defaultOpen shows the first step announced as a header with position, title and description", async () => {
|
|
57
|
+
await renderWithProviders(<Steps defaultOpen />);
|
|
58
|
+
expect(screen.getByTestId("tour-card")).toBeOnTheScreen();
|
|
59
|
+
expect(screen.getByRole("header", { name: "Step 1 of 3. Search. Find anything." })).toBeOnTheScreen();
|
|
60
|
+
expect(screen.getByText("1 of 3")).toBeOnTheScreen();
|
|
61
|
+
expect(screen.getByText("Find anything.")).toBeOnTheScreen();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test("useTour().start opens the tour from inside", async () => {
|
|
65
|
+
await renderWithProviders(<Steps />);
|
|
66
|
+
await fireEvent(screen.getByRole("button", { name: "Start tour" }), "accessibilityTap");
|
|
67
|
+
expect(screen.getByRole("header", { name: /^Step 1 of 3/ })).toBeOnTheScreen();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test("Next and Back move through the steps, Back is absent on the first", async () => {
|
|
71
|
+
const onStepChange = jest.fn();
|
|
72
|
+
await renderWithProviders(<Steps defaultOpen onStepChange={onStepChange} />);
|
|
73
|
+
expect(screen.queryByTestId("tour-back")).not.toBeOnTheScreen();
|
|
74
|
+
|
|
75
|
+
await press("tour-next");
|
|
76
|
+
expect(screen.getByRole("header", { name: "Step 2 of 3. New note. Start writing." })).toBeOnTheScreen();
|
|
77
|
+
expect(screen.getByText("2 of 3")).toBeOnTheScreen();
|
|
78
|
+
expect(onStepChange).toHaveBeenLastCalledWith(2);
|
|
79
|
+
|
|
80
|
+
await press("tour-back");
|
|
81
|
+
expect(screen.getByRole("header", { name: /^Step 1 of 3/ })).toBeOnTheScreen();
|
|
82
|
+
expect(onStepChange).toHaveBeenLastCalledWith(1);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test("the last step offers Done instead of Next and no Skip, and Done finishes", async () => {
|
|
86
|
+
const onFinish = jest.fn();
|
|
87
|
+
const onSkip = jest.fn();
|
|
88
|
+
const onOpenChange = jest.fn();
|
|
89
|
+
await renderWithProviders(
|
|
90
|
+
<Steps defaultOpen defaultStep={3} onFinish={onFinish} onOpenChange={onOpenChange} onSkip={onSkip} />
|
|
91
|
+
);
|
|
92
|
+
expect(screen.getByRole("button", { name: "Done" })).toBeOnTheScreen();
|
|
93
|
+
expect(screen.queryByRole("button", { name: "Next" })).not.toBeOnTheScreen();
|
|
94
|
+
expect(screen.queryByTestId("tour-skip")).not.toBeOnTheScreen();
|
|
95
|
+
|
|
96
|
+
await press("tour-next");
|
|
97
|
+
expect(onFinish).toHaveBeenCalledTimes(1);
|
|
98
|
+
expect(onSkip).not.toHaveBeenCalled();
|
|
99
|
+
expect(onOpenChange).toHaveBeenLastCalledWith(false);
|
|
100
|
+
expect(screen.queryByTestId("tour-card")).not.toBeOnTheScreen();
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test("Skip closes the tour and calls onSkip, not onFinish", async () => {
|
|
104
|
+
const onFinish = jest.fn();
|
|
105
|
+
const onSkip = jest.fn();
|
|
106
|
+
await renderWithProviders(<Steps defaultOpen onFinish={onFinish} onSkip={onSkip} />);
|
|
107
|
+
await press("tour-skip");
|
|
108
|
+
expect(onSkip).toHaveBeenCalledTimes(1);
|
|
109
|
+
expect(onFinish).not.toHaveBeenCalled();
|
|
110
|
+
expect(screen.queryByTestId("tour-card")).not.toBeOnTheScreen();
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test("hasSkip={false} and hasProgress={false} drop Skip and the visible position", async () => {
|
|
114
|
+
await renderWithProviders(<Steps defaultOpen hasProgress={false} hasSkip={false} />);
|
|
115
|
+
expect(screen.queryByTestId("tour-skip")).not.toBeOnTheScreen();
|
|
116
|
+
expect(screen.queryByText("1 of 3")).not.toBeOnTheScreen();
|
|
117
|
+
expect(screen.getByRole("header", { name: /^Step 1 of 3/ })).toBeOnTheScreen();
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test("labels replace the action text and the announcement", async () => {
|
|
121
|
+
await renderWithProviders(
|
|
122
|
+
<Steps
|
|
123
|
+
defaultOpen
|
|
124
|
+
labels={{ next: "Continue", skip: "Not now", announcement: (current, total) => `Stop ${current}/${total}` }}
|
|
125
|
+
/>
|
|
126
|
+
);
|
|
127
|
+
expect(screen.getByRole("button", { name: "Continue" })).toBeOnTheScreen();
|
|
128
|
+
expect(screen.getByRole("button", { name: "Not now" })).toBeOnTheScreen();
|
|
129
|
+
expect(screen.getByRole("header", { name: /^Stop 1\/3\. Search\./ })).toBeOnTheScreen();
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test("defaultStep opens on that step", async () => {
|
|
133
|
+
await renderWithProviders(<Steps defaultOpen defaultStep={2} />);
|
|
134
|
+
expect(screen.getByRole("header", { name: /^Step 2 of 3\. New note/ })).toBeOnTheScreen();
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
test("uncontrolled open: onOpenChange reports start and skip", async () => {
|
|
138
|
+
const onOpenChange = jest.fn();
|
|
139
|
+
await renderWithProviders(<Steps onOpenChange={onOpenChange} />);
|
|
140
|
+
await fireEvent(screen.getByRole("button", { name: "Start tour" }), "accessibilityTap");
|
|
141
|
+
expect(onOpenChange).toHaveBeenLastCalledWith(true);
|
|
142
|
+
await press("tour-skip");
|
|
143
|
+
expect(onOpenChange).toHaveBeenLastCalledWith(false);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test("controlled isOpen: Skip asks, but the card stays until the parent rerenders", async () => {
|
|
147
|
+
const onOpenChange = jest.fn();
|
|
148
|
+
const { rerender } = await renderWithProviders(<Steps isOpen onOpenChange={onOpenChange} />);
|
|
149
|
+
await press("tour-skip");
|
|
150
|
+
expect(onOpenChange).toHaveBeenCalledWith(false);
|
|
151
|
+
expect(screen.getByTestId("tour-card")).toBeOnTheScreen();
|
|
152
|
+
|
|
153
|
+
await rerender(<Steps isOpen={false} onOpenChange={onOpenChange} />);
|
|
154
|
+
expect(screen.queryByTestId("tour-card")).not.toBeOnTheScreen();
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
test("controlled step: Next asks, the card moves only when step changes", async () => {
|
|
158
|
+
const onStepChange = jest.fn();
|
|
159
|
+
const { rerender } = await renderWithProviders(<Steps isOpen onStepChange={onStepChange} step={1} />);
|
|
160
|
+
await press("tour-next");
|
|
161
|
+
expect(onStepChange).toHaveBeenCalledWith(2);
|
|
162
|
+
expect(screen.getByRole("header", { name: /^Step 1 of 3/ })).toBeOnTheScreen();
|
|
163
|
+
|
|
164
|
+
await rerender(<Steps isOpen onStepChange={onStepChange} step={2} />);
|
|
165
|
+
expect(screen.getByRole("header", { name: /^Step 2 of 3/ })).toBeOnTheScreen();
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test("useTour exposes step, index and total, and goTo jumps to a registered order", async () => {
|
|
169
|
+
await renderWithProviders(<Steps />);
|
|
170
|
+
expect(screen.getByRole("button", { name: "Step 1 index 0 of 3" })).toBeOnTheScreen();
|
|
171
|
+
await fireEvent(screen.getByRole("button", { name: "Step 1 index 0 of 3" }), "accessibilityTap");
|
|
172
|
+
expect(screen.getByRole("button", { name: "Step 3 index 2 of 3" })).toBeOnTheScreen();
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
test("a non-interactive tour hides the app beneath from assistive technology", async () => {
|
|
176
|
+
await renderWithProviders(<Steps />);
|
|
177
|
+
expect(screen.getByRole("button", { name: "Search" })).toBeOnTheScreen();
|
|
178
|
+
await fireEvent(screen.getByRole("button", { name: "Start tour" }), "accessibilityTap");
|
|
179
|
+
expect(screen.queryByRole("button", { name: "Search" })).not.toBeOnTheScreen();
|
|
180
|
+
expect(screen.getByRole("button", { name: "Next" })).toBeOnTheScreen();
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
test("an interactive tour keeps the app reachable", async () => {
|
|
184
|
+
await renderWithProviders(<Steps defaultOpen isInteractive />);
|
|
185
|
+
expect(screen.getByRole("button", { name: "Search" })).toBeOnTheScreen();
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
test("an interactive tour draws its card inside the root", async () => {
|
|
189
|
+
await renderWithProviders(<Steps defaultOpen isInteractive />);
|
|
190
|
+
expect(screen.getByTestId("tour-card")).toBeOnTheScreen();
|
|
191
|
+
expect(screen.getByRole("button", { name: "Next" })).toBeOnTheScreen();
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
test("Tour.Step outside a Tour throws its documented error", async () => {
|
|
195
|
+
const spy = jest.spyOn(console, "error").mockImplementation(() => undefined);
|
|
196
|
+
try {
|
|
197
|
+
await expect(
|
|
198
|
+
renderWithProviders(
|
|
199
|
+
<Tour.Step order={1} title="Lonely">
|
|
200
|
+
<Button>Orphan</Button>
|
|
201
|
+
</Tour.Step>
|
|
202
|
+
)
|
|
203
|
+
).rejects.toThrow("Tour.Step must be rendered inside a <Tour>.");
|
|
204
|
+
} finally {
|
|
205
|
+
spy.mockRestore();
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
test("useTour outside a Tour throws its documented error", async () => {
|
|
210
|
+
const spy = jest.spyOn(console, "error").mockImplementation(() => undefined);
|
|
211
|
+
try {
|
|
212
|
+
await expect(renderWithProviders(<StartButton />)).rejects.toThrow("useTour must be called inside a <Tour>.");
|
|
213
|
+
} finally {
|
|
214
|
+
spy.mockRestore();
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
});
|
|
@@ -25,6 +25,7 @@ are selected.
|
|
|
25
25
|
| `tree.types.ts` | `TreeSlotProps`, shared by `Tree.Icon` and `Tree.Actions` |
|
|
26
26
|
| `tree.variants.ts` | Pure `tv()` slots, the constants and every resolver — no RN imports |
|
|
27
27
|
| `tree.variants.test.ts` | |
|
|
28
|
+
| `tree.render.test.tsx` | Mounted under Jest — row role, name and level value, expanded and selected state, expand and selection callbacks (controlled and uncontrolled), disabled nodes, nesting, parts outside their root |
|
|
28
29
|
|
|
29
30
|
## Design
|
|
30
31
|
|
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, jest, test } from "@jest/globals";
|
|
2
|
+
import type { ReactElement } from "react";
|
|
3
|
+
import { fireEvent, renderWithProviders, screen } from "../../test/render";
|
|
4
|
+
import { Tree, type TreeProps } from "./tree";
|
|
5
|
+
import { TreeGroup } from "./tree-group";
|
|
6
|
+
import { TreeIndicator } from "./tree-indicator";
|
|
7
|
+
import { TreeItem } from "./tree-item";
|
|
8
|
+
import { TreeTrigger } from "./tree-trigger";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The list root is deliberately not `accessible` (that would merge every row
|
|
12
|
+
* into one element), so RNTL's role query cannot find it; its role is asserted
|
|
13
|
+
* from the prop. The chevron is a Pressable hidden from assistive technology, so its own press
|
|
14
|
+
* is not reachable by role or accessibility action under Jest. The row's
|
|
15
|
+
* expand / collapse custom actions and `accessibilityTap` are tested instead;
|
|
16
|
+
* the indicator's hit slop, rotation and haptics are playground-only.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
function activate(element: ReturnType<typeof screen.getByRole>) {
|
|
20
|
+
return fireEvent(element, "accessibilityTap");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function customAction(element: ReturnType<typeof screen.getByRole>, actionName: string) {
|
|
24
|
+
return fireEvent(element, "accessibilityAction", { nativeEvent: { actionName } });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function Demo(props: TreeProps): ReactElement {
|
|
28
|
+
return (
|
|
29
|
+
<Tree {...props}>
|
|
30
|
+
<Tree.Item value="src">
|
|
31
|
+
<Tree.Trigger>src</Tree.Trigger>
|
|
32
|
+
<Tree.Group>
|
|
33
|
+
<Tree.Item value="index">
|
|
34
|
+
<Tree.Trigger>index.ts</Tree.Trigger>
|
|
35
|
+
</Tree.Item>
|
|
36
|
+
<Tree.Item value="lib">
|
|
37
|
+
<Tree.Trigger>lib</Tree.Trigger>
|
|
38
|
+
<Tree.Group>
|
|
39
|
+
<Tree.Item value="util">
|
|
40
|
+
<Tree.Trigger>util.ts</Tree.Trigger>
|
|
41
|
+
</Tree.Item>
|
|
42
|
+
</Tree.Group>
|
|
43
|
+
</Tree.Item>
|
|
44
|
+
</Tree.Group>
|
|
45
|
+
</Tree.Item>
|
|
46
|
+
<Tree.Item value="readme">
|
|
47
|
+
<Tree.Trigger>README.md</Tree.Trigger>
|
|
48
|
+
</Tree.Item>
|
|
49
|
+
</Tree>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
describe("Tree", () => {
|
|
54
|
+
test("renders a list of rows named by their labels, with their depth as the value", async () => {
|
|
55
|
+
await renderWithProviders(<Demo defaultExpanded={["src", "lib"]} testID="tree" />);
|
|
56
|
+
expect(screen.getByTestId("tree").props.accessibilityRole).toBe("list");
|
|
57
|
+
expect(screen.getByRole("button", { name: "src" })).toHaveAccessibilityValue({ text: "Level 1" });
|
|
58
|
+
expect(screen.getByRole("button", { name: "index.ts" })).toHaveAccessibilityValue({ text: "Level 2" });
|
|
59
|
+
expect(screen.getByRole("button", { name: "util.ts" })).toHaveAccessibilityValue({ text: "Level 3" });
|
|
60
|
+
expect(screen.getByRole("button", { name: "README.md" })).toHaveAccessibilityValue({ text: "Level 1" });
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe("expansion", () => {
|
|
64
|
+
test("a branch announces expanded state and a leaf announces none", async () => {
|
|
65
|
+
await renderWithProviders(<Demo defaultExpanded={["src"]} />);
|
|
66
|
+
expect(screen.getByRole("button", { name: "src" })).toBeExpanded();
|
|
67
|
+
expect(screen.getByRole("button", { name: "lib" })).toBeCollapsed();
|
|
68
|
+
expect(screen.getByRole("button", { name: "index.ts" })).not.toBeExpanded();
|
|
69
|
+
expect(screen.getByRole("button", { name: "index.ts" })).not.toBeCollapsed();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test("a closed branch unmounts its children", async () => {
|
|
73
|
+
await renderWithProviders(<Demo />);
|
|
74
|
+
expect(screen.getByRole("button", { name: "src" })).toBeCollapsed();
|
|
75
|
+
expect(screen.queryByRole("button", { name: "index.ts" })).not.toBeOnTheScreen();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test("uncontrolled: pressing a branch row opens it, then closes it, reporting each", async () => {
|
|
79
|
+
const onExpandedChange = jest.fn();
|
|
80
|
+
await renderWithProviders(<Demo onExpandedChange={onExpandedChange} />);
|
|
81
|
+
|
|
82
|
+
await activate(screen.getByRole("button", { name: "src" }));
|
|
83
|
+
expect(screen.getByRole("button", { name: "src" })).toBeExpanded();
|
|
84
|
+
expect(screen.getByRole("button", { name: "index.ts" })).toBeOnTheScreen();
|
|
85
|
+
expect(onExpandedChange).toHaveBeenLastCalledWith(["src"], { isExpanded: true, value: "src" });
|
|
86
|
+
|
|
87
|
+
await activate(screen.getByRole("button", { name: "src" }));
|
|
88
|
+
expect(screen.getByRole("button", { name: "src" })).toBeCollapsed();
|
|
89
|
+
expect(screen.queryByRole("button", { name: "index.ts" })).not.toBeOnTheScreen();
|
|
90
|
+
expect(onExpandedChange).toHaveBeenLastCalledWith([], { isExpanded: false, value: "src" });
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test("reopening a branch restores what was open inside it", async () => {
|
|
94
|
+
await renderWithProviders(<Demo defaultExpanded={["src", "lib"]} />);
|
|
95
|
+
await activate(screen.getByRole("button", { name: "src" }));
|
|
96
|
+
await activate(screen.getByRole("button", { name: "src" }));
|
|
97
|
+
expect(screen.getByRole("button", { name: "util.ts" })).toBeOnTheScreen();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test("the expand and collapse custom actions toggle a branch, and only the one that applies", async () => {
|
|
101
|
+
const onExpandedChange = jest.fn();
|
|
102
|
+
await renderWithProviders(<Demo onExpandedChange={onExpandedChange} />);
|
|
103
|
+
|
|
104
|
+
await customAction(screen.getByRole("button", { name: "src" }), "collapse");
|
|
105
|
+
expect(onExpandedChange).not.toHaveBeenCalled();
|
|
106
|
+
|
|
107
|
+
await customAction(screen.getByRole("button", { name: "src" }), "expand");
|
|
108
|
+
expect(screen.getByRole("button", { name: "src" })).toBeExpanded();
|
|
109
|
+
expect(onExpandedChange).toHaveBeenCalledTimes(1);
|
|
110
|
+
|
|
111
|
+
await customAction(screen.getByRole("button", { name: "src" }), "expand");
|
|
112
|
+
expect(onExpandedChange).toHaveBeenCalledTimes(1);
|
|
113
|
+
|
|
114
|
+
await customAction(screen.getByRole("button", { name: "src" }), "collapse");
|
|
115
|
+
expect(screen.getByRole("button", { name: "src" })).toBeCollapsed();
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test("controlled: reports the change and waits for the prop", async () => {
|
|
119
|
+
const onExpandedChange = jest.fn();
|
|
120
|
+
const view = await renderWithProviders(<Demo expanded={[]} onExpandedChange={onExpandedChange} />);
|
|
121
|
+
|
|
122
|
+
await activate(screen.getByRole("button", { name: "src" }));
|
|
123
|
+
expect(onExpandedChange).toHaveBeenCalledWith(["src"], { isExpanded: true, value: "src" });
|
|
124
|
+
expect(screen.getByRole("button", { name: "src" })).toBeCollapsed();
|
|
125
|
+
|
|
126
|
+
await view.rerender(<Demo expanded={["src"]} onExpandedChange={onExpandedChange} />);
|
|
127
|
+
expect(screen.getByRole("button", { name: "src" })).toBeExpanded();
|
|
128
|
+
expect(screen.getByRole("button", { name: "index.ts" })).toBeOnTheScreen();
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test("expandOnPress={false} leaves the row's press without a toggle", async () => {
|
|
132
|
+
const onExpandedChange = jest.fn();
|
|
133
|
+
await renderWithProviders(<Demo expandOnPress={false} onExpandedChange={onExpandedChange} />);
|
|
134
|
+
await activate(screen.getByRole("button", { name: "src" }));
|
|
135
|
+
expect(onExpandedChange).not.toHaveBeenCalled();
|
|
136
|
+
expect(screen.getByRole("button", { name: "src" })).toBeCollapsed();
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test("hasChildren marks a node a branch before its group renders", async () => {
|
|
140
|
+
await renderWithProviders(
|
|
141
|
+
<Tree>
|
|
142
|
+
<Tree.Item hasChildren value="lazy">
|
|
143
|
+
<Tree.Trigger>Lazy</Tree.Trigger>
|
|
144
|
+
</Tree.Item>
|
|
145
|
+
</Tree>
|
|
146
|
+
);
|
|
147
|
+
expect(screen.getByRole("button", { name: "Lazy" })).toBeCollapsed();
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
describe("selection", () => {
|
|
152
|
+
test("selectionMode none announces no selected state and reports nothing", async () => {
|
|
153
|
+
await renderWithProviders(<Demo defaultExpanded={["src"]} />);
|
|
154
|
+
expect(screen.getByRole("button", { name: "index.ts" })).not.toBeSelected();
|
|
155
|
+
expect(screen.getByRole("button", { name: "index.ts" }).props.accessibilityState).not.toHaveProperty("selected");
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
test("single, uncontrolled: defaultValue seeds it and a press moves it", async () => {
|
|
159
|
+
const onValueChange = jest.fn();
|
|
160
|
+
await renderWithProviders(
|
|
161
|
+
<Demo defaultExpanded={["src"]} defaultValue="index" onValueChange={onValueChange} selectionMode="single" />
|
|
162
|
+
);
|
|
163
|
+
expect(screen.getByRole("button", { name: "index.ts" })).toBeSelected();
|
|
164
|
+
expect(screen.getByRole("button", { name: "README.md" })).not.toBeSelected();
|
|
165
|
+
|
|
166
|
+
await activate(screen.getByRole("button", { name: "README.md" }));
|
|
167
|
+
expect(screen.getByRole("button", { name: "README.md" })).toBeSelected();
|
|
168
|
+
expect(screen.getByRole("button", { name: "index.ts" })).not.toBeSelected();
|
|
169
|
+
expect(onValueChange).toHaveBeenCalledTimes(1);
|
|
170
|
+
expect(onValueChange).toHaveBeenLastCalledWith("readme");
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
test("single: re-pressing the selected node does not report again", async () => {
|
|
174
|
+
const onValueChange = jest.fn();
|
|
175
|
+
await renderWithProviders(<Demo defaultValue="readme" onValueChange={onValueChange} selectionMode="single" />);
|
|
176
|
+
await activate(screen.getByRole("button", { name: "README.md" }));
|
|
177
|
+
expect(onValueChange).not.toHaveBeenCalled();
|
|
178
|
+
expect(screen.getByRole("button", { name: "README.md" })).toBeSelected();
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
test("single: pressing a branch row both selects and toggles it", async () => {
|
|
182
|
+
const onValueChange = jest.fn();
|
|
183
|
+
await renderWithProviders(<Demo onValueChange={onValueChange} selectionMode="single" />);
|
|
184
|
+
await activate(screen.getByRole("button", { name: "src" }));
|
|
185
|
+
expect(onValueChange).toHaveBeenCalledWith("src");
|
|
186
|
+
expect(screen.getByRole("button", { name: "src" })).toBeSelected();
|
|
187
|
+
expect(screen.getByRole("button", { name: "src" })).toBeExpanded();
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
test("single, controlled: reports the press and waits for the prop", async () => {
|
|
191
|
+
const onValueChange = jest.fn();
|
|
192
|
+
const view = await renderWithProviders(
|
|
193
|
+
<Demo onValueChange={onValueChange} selectionMode="single" value="readme" />
|
|
194
|
+
);
|
|
195
|
+
expect(screen.getByRole("button", { name: "README.md" })).toBeSelected();
|
|
196
|
+
|
|
197
|
+
await activate(screen.getByRole("button", { name: "src" }));
|
|
198
|
+
expect(onValueChange).toHaveBeenCalledWith("src");
|
|
199
|
+
expect(screen.getByRole("button", { name: "src" })).not.toBeSelected();
|
|
200
|
+
expect(screen.getByRole("button", { name: "README.md" })).toBeSelected();
|
|
201
|
+
|
|
202
|
+
await view.rerender(<Demo onValueChange={onValueChange} selectionMode="single" value="src" />);
|
|
203
|
+
expect(screen.getByRole("button", { name: "src" })).toBeSelected();
|
|
204
|
+
expect(screen.getByRole("button", { name: "README.md" })).not.toBeSelected();
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
test("multiple, uncontrolled: presses add and remove, reporting the whole selection", async () => {
|
|
208
|
+
const onValueChange = jest.fn();
|
|
209
|
+
await renderWithProviders(
|
|
210
|
+
<Demo
|
|
211
|
+
defaultExpanded={["src"]}
|
|
212
|
+
defaultValue={["index"]}
|
|
213
|
+
onValueChange={onValueChange}
|
|
214
|
+
selectionMode="multiple"
|
|
215
|
+
/>
|
|
216
|
+
);
|
|
217
|
+
expect(screen.getByRole("button", { name: "index.ts" })).toBeSelected();
|
|
218
|
+
|
|
219
|
+
await activate(screen.getByRole("button", { name: "README.md" }));
|
|
220
|
+
expect(onValueChange).toHaveBeenLastCalledWith(["index", "readme"]);
|
|
221
|
+
expect(screen.getByRole("button", { name: "README.md" })).toBeSelected();
|
|
222
|
+
expect(screen.getByRole("button", { name: "index.ts" })).toBeSelected();
|
|
223
|
+
|
|
224
|
+
await activate(screen.getByRole("button", { name: "index.ts" }));
|
|
225
|
+
expect(onValueChange).toHaveBeenLastCalledWith(["readme"]);
|
|
226
|
+
expect(screen.getByRole("button", { name: "index.ts" })).not.toBeSelected();
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
test("multiple, controlled: reports the press and waits for the prop", async () => {
|
|
230
|
+
const onValueChange = jest.fn();
|
|
231
|
+
const view = await renderWithProviders(
|
|
232
|
+
<Demo onValueChange={onValueChange} selectionMode="multiple" value={[]} />
|
|
233
|
+
);
|
|
234
|
+
await activate(screen.getByRole("button", { name: "README.md" }));
|
|
235
|
+
expect(onValueChange).toHaveBeenCalledWith(["readme"]);
|
|
236
|
+
expect(screen.getByRole("button", { name: "README.md" })).not.toBeSelected();
|
|
237
|
+
|
|
238
|
+
await view.rerender(<Demo onValueChange={onValueChange} selectionMode="multiple" value={["readme"]} />);
|
|
239
|
+
expect(screen.getByRole("button", { name: "README.md" })).toBeSelected();
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
test("a row with nothing to do is inert: a leaf in a tree that does not select", async () => {
|
|
243
|
+
const onExpandedChange = jest.fn();
|
|
244
|
+
await renderWithProviders(<Demo defaultExpanded={["src"]} onExpandedChange={onExpandedChange} />);
|
|
245
|
+
await activate(screen.getByRole("button", { name: "README.md" }));
|
|
246
|
+
expect(onExpandedChange).not.toHaveBeenCalled();
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
test("a caller's onPress on the trigger runs after the press", async () => {
|
|
250
|
+
const onPress = jest.fn();
|
|
251
|
+
await renderWithProviders(
|
|
252
|
+
<Tree>
|
|
253
|
+
<Tree.Item value="a">
|
|
254
|
+
<Tree.Trigger onPress={onPress}>Alpha</Tree.Trigger>
|
|
255
|
+
</Tree.Item>
|
|
256
|
+
</Tree>
|
|
257
|
+
);
|
|
258
|
+
await activate(screen.getByRole("button", { name: "Alpha" }));
|
|
259
|
+
expect(onPress).toHaveBeenCalledTimes(1);
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
describe("disabled", () => {
|
|
264
|
+
test("a disabled item is announced, offers no action and ignores presses", async () => {
|
|
265
|
+
const onExpandedChange = jest.fn();
|
|
266
|
+
const onValueChange = jest.fn();
|
|
267
|
+
await renderWithProviders(
|
|
268
|
+
<Tree onExpandedChange={onExpandedChange} onValueChange={onValueChange} selectionMode="single">
|
|
269
|
+
<Tree.Item isDisabled value="locked">
|
|
270
|
+
<Tree.Trigger>Locked</Tree.Trigger>
|
|
271
|
+
<Tree.Group>
|
|
272
|
+
<Tree.Item value="child">
|
|
273
|
+
<Tree.Trigger>Child</Tree.Trigger>
|
|
274
|
+
</Tree.Item>
|
|
275
|
+
</Tree.Group>
|
|
276
|
+
</Tree.Item>
|
|
277
|
+
<Tree.Item value="open">
|
|
278
|
+
<Tree.Trigger>Open</Tree.Trigger>
|
|
279
|
+
</Tree.Item>
|
|
280
|
+
</Tree>
|
|
281
|
+
);
|
|
282
|
+
const locked = screen.getByRole("button", { name: "Locked" });
|
|
283
|
+
expect(locked).toBeDisabled();
|
|
284
|
+
expect(locked.props.accessibilityActions ?? []).toEqual([]);
|
|
285
|
+
expect(screen.getByRole("button", { name: "Open" })).toBeEnabled();
|
|
286
|
+
|
|
287
|
+
await activate(locked);
|
|
288
|
+
await customAction(locked, "expand");
|
|
289
|
+
expect(onExpandedChange).not.toHaveBeenCalled();
|
|
290
|
+
expect(onValueChange).not.toHaveBeenCalled();
|
|
291
|
+
expect(screen.queryByRole("button", { name: "Child" })).not.toBeOnTheScreen();
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
test("the tree's isDisabled disables every node", async () => {
|
|
295
|
+
const onExpandedChange = jest.fn();
|
|
296
|
+
await renderWithProviders(<Demo isDisabled onExpandedChange={onExpandedChange} />);
|
|
297
|
+
expect(screen.getByRole("button", { name: "src" })).toBeDisabled();
|
|
298
|
+
expect(screen.getByRole("button", { name: "README.md" })).toBeDisabled();
|
|
299
|
+
await activate(screen.getByRole("button", { name: "src" }));
|
|
300
|
+
expect(onExpandedChange).not.toHaveBeenCalled();
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
test("the tree's isDisabled={false} wins over a node's own isDisabled", async () => {
|
|
304
|
+
await renderWithProviders(
|
|
305
|
+
<Tree isDisabled={false}>
|
|
306
|
+
<Tree.Item isDisabled value="a">
|
|
307
|
+
<Tree.Trigger>Alpha</Tree.Trigger>
|
|
308
|
+
</Tree.Item>
|
|
309
|
+
</Tree>
|
|
310
|
+
);
|
|
311
|
+
expect(screen.getByRole("button", { name: "Alpha" })).toBeEnabled();
|
|
312
|
+
});
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
describe("parts", () => {
|
|
316
|
+
test("Label, Icon and Actions render inside a trigger; Actions stay outside the row's element", async () => {
|
|
317
|
+
await renderWithProviders(
|
|
318
|
+
<Tree>
|
|
319
|
+
<Tree.Item value="a">
|
|
320
|
+
<Tree.Trigger>
|
|
321
|
+
<Tree.Label>Alpha</Tree.Label>
|
|
322
|
+
<Tree.Actions>
|
|
323
|
+
<Tree.Icon testID="trailing" />
|
|
324
|
+
</Tree.Actions>
|
|
325
|
+
</Tree.Trigger>
|
|
326
|
+
</Tree.Item>
|
|
327
|
+
</Tree>
|
|
328
|
+
);
|
|
329
|
+
expect(screen.getByRole("button", { name: "Alpha" })).toBeOnTheScreen();
|
|
330
|
+
expect(screen.getByTestId("trailing")).toBeOnTheScreen();
|
|
331
|
+
expect(screen.getByRole("button", { name: "Alpha" })).not.toContainElement(screen.getByTestId("trailing"));
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
test("the indicator is hidden from assistive technology", async () => {
|
|
335
|
+
await renderWithProviders(<Demo />);
|
|
336
|
+
expect(screen.queryAllByRole("button", { includeHiddenElements: false })).toHaveLength(2);
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
describe("outside its root", () => {
|
|
341
|
+
let errorSpy: ReturnType<typeof jest.spyOn>;
|
|
342
|
+
beforeEach(() => {
|
|
343
|
+
errorSpy = jest.spyOn(console, "error").mockImplementation(() => {});
|
|
344
|
+
});
|
|
345
|
+
afterEach(() => {
|
|
346
|
+
errorSpy.mockRestore();
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
test("Tree.Item outside a Tree throws", async () => {
|
|
350
|
+
await expect(
|
|
351
|
+
renderWithProviders(
|
|
352
|
+
<TreeItem value="a">
|
|
353
|
+
<TreeTrigger>A</TreeTrigger>
|
|
354
|
+
</TreeItem>
|
|
355
|
+
)
|
|
356
|
+
).rejects.toThrow("Tree.Item must be rendered inside a <Tree>.");
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
test("Tree.Trigger outside a Tree throws", async () => {
|
|
360
|
+
await expect(renderWithProviders(<TreeTrigger>A</TreeTrigger>)).rejects.toThrow(
|
|
361
|
+
"Tree.Trigger must be rendered inside a <Tree>."
|
|
362
|
+
);
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
test("Tree.Trigger inside a Tree but outside an Item throws", async () => {
|
|
366
|
+
await expect(
|
|
367
|
+
renderWithProviders(
|
|
368
|
+
<Tree>
|
|
369
|
+
<TreeTrigger>A</TreeTrigger>
|
|
370
|
+
</Tree>
|
|
371
|
+
)
|
|
372
|
+
).rejects.toThrow("Tree.Trigger must be rendered inside a <Tree.Item>.");
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
test("Tree.Group inside a Tree but outside an Item throws", async () => {
|
|
376
|
+
await expect(
|
|
377
|
+
renderWithProviders(
|
|
378
|
+
<Tree>
|
|
379
|
+
<TreeGroup />
|
|
380
|
+
</Tree>
|
|
381
|
+
)
|
|
382
|
+
).rejects.toThrow("Tree.Group must be rendered inside a <Tree.Item>.");
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
test("Tree.Indicator inside a Tree but outside an Item throws", async () => {
|
|
386
|
+
await expect(
|
|
387
|
+
renderWithProviders(
|
|
388
|
+
<Tree>
|
|
389
|
+
<TreeIndicator />
|
|
390
|
+
</Tree>
|
|
391
|
+
)
|
|
392
|
+
).rejects.toThrow("Tree.Indicator must be rendered inside a <Tree.Item>.");
|
|
393
|
+
});
|
|
394
|
+
});
|
|
395
|
+
});
|
package/src/display-name.test.ts
CHANGED
|
@@ -19,14 +19,20 @@ const SRC = import.meta.dirname;
|
|
|
19
19
|
* two cannot share a file.
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* Every component `.tsx` under `src/`, as a path → source map. Render tests and
|
|
24
|
+
* the `test/` kit they share are not the library: their fixtures never reach a
|
|
25
|
+
* DevTools tree a consumer reads.
|
|
26
|
+
*/
|
|
23
27
|
function sources(): Map<string, string> {
|
|
24
28
|
const found = new Map<string, string>();
|
|
25
29
|
const walk = (dir: string): void => {
|
|
26
30
|
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
27
31
|
const path = join(dir, entry.name);
|
|
28
|
-
if (entry.isDirectory())
|
|
29
|
-
|
|
32
|
+
if (entry.isDirectory()) {
|
|
33
|
+
if (path !== join(SRC, "test")) walk(path);
|
|
34
|
+
} else if (entry.name.endsWith(".tsx") && !entry.name.endsWith(".test.tsx"))
|
|
35
|
+
found.set(path, readFileSync(path, "utf-8"));
|
|
30
36
|
}
|
|
31
37
|
};
|
|
32
38
|
walk(SRC);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { existsSync, readdirSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
|
|
5
|
+
const COMPONENTS = join(import.meta.dirname, "components");
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Every component folder must carry a `{name}.render.test.tsx`.
|
|
9
|
+
*
|
|
10
|
+
* Render tests run under Jest (`test:render`), which `bun test` cannot do — so,
|
|
11
|
+
* like `docs.test.ts`, this reads the folder tree and imports nothing.
|
|
12
|
+
*/
|
|
13
|
+
function componentFolders(): string[] {
|
|
14
|
+
return readdirSync(COMPONENTS, { withFileTypes: true })
|
|
15
|
+
.filter((entry) => entry.isDirectory())
|
|
16
|
+
.map((entry) => entry.name)
|
|
17
|
+
.sort();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const hasRenderTest = (name: string): boolean => existsSync(join(COMPONENTS, name, `${name}.render.test.tsx`));
|
|
21
|
+
|
|
22
|
+
describe("render tests", () => {
|
|
23
|
+
test("every component has one", () => {
|
|
24
|
+
const missing = componentFolders().filter((name) => !hasRenderTest(name));
|
|
25
|
+
expect(missing).toEqual([]);
|
|
26
|
+
});
|
|
27
|
+
});
|