@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,191 @@
|
|
|
1
|
+
import { afterEach, describe, expect, jest, test } from "@jest/globals";
|
|
2
|
+
import type { ComponentProps } from "react";
|
|
3
|
+
import { View } from "react-native";
|
|
4
|
+
import { useSharedValue } from "react-native-reanimated";
|
|
5
|
+
import { act, fireEvent, renderWithProviders, screen } from "../../test/render";
|
|
6
|
+
import { DelacourProvider } from "../provider";
|
|
7
|
+
import { ScrollText } from "./scroll-text";
|
|
8
|
+
|
|
9
|
+
const SENTENCE = "We build interfaces that move";
|
|
10
|
+
|
|
11
|
+
function layoutEvent(width: number) {
|
|
12
|
+
return { nativeEvent: { layout: { x: 0, y: 0, width, height: 20 } } };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function textLayoutEvent(lines: readonly string[]) {
|
|
16
|
+
return {
|
|
17
|
+
nativeEvent: {
|
|
18
|
+
lines: lines.map((text, index) => ({
|
|
19
|
+
text,
|
|
20
|
+
x: 0,
|
|
21
|
+
y: index * 20,
|
|
22
|
+
width: 100,
|
|
23
|
+
height: 20,
|
|
24
|
+
ascender: 16,
|
|
25
|
+
descender: 4,
|
|
26
|
+
capHeight: 12,
|
|
27
|
+
xHeight: 8,
|
|
28
|
+
})),
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The hidden space-glyph probe the block measures its column gap from. */
|
|
34
|
+
async function measureSpace(width = 4) {
|
|
35
|
+
const probe = screen.getAllByText(" ", { includeHiddenElements: true })[0];
|
|
36
|
+
await fireEvent(probe, "layout", layoutEvent(width));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function ProgressText({
|
|
40
|
+
value = 0.5,
|
|
41
|
+
children = SENTENCE,
|
|
42
|
+
...props
|
|
43
|
+
}: { value?: number } & Partial<ComponentProps<typeof ScrollText>>) {
|
|
44
|
+
const progress = useSharedValue(value);
|
|
45
|
+
return (
|
|
46
|
+
<ScrollText source={{ kind: "progress", progress }} testID="scroll-text" {...props}>
|
|
47
|
+
{children}
|
|
48
|
+
</ScrollText>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
describe("ScrollText", () => {
|
|
53
|
+
afterEach(() => {
|
|
54
|
+
jest.restoreAllMocks();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("warns once, and renders revealed, when the default screen source has no Screen above it", async () => {
|
|
58
|
+
const warn = jest.spyOn(console, "warn").mockImplementation(() => undefined);
|
|
59
|
+
await renderWithProviders(<ScrollText testID="scroll-text">{SENTENCE}</ScrollText>);
|
|
60
|
+
expect(screen.getByTestId("scroll-text")).toBeOnTheScreen();
|
|
61
|
+
expect(warn).toHaveBeenCalledTimes(1);
|
|
62
|
+
expect(warn.mock.calls[0]?.[0]).toContain("needs a <Screen>");
|
|
63
|
+
|
|
64
|
+
await renderWithProviders(<ScrollText>{SENTENCE}</ScrollText>);
|
|
65
|
+
expect(warn).toHaveBeenCalledTimes(1);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("is one accessible text element named by its whole string", async () => {
|
|
69
|
+
await renderWithProviders(<ProgressText />);
|
|
70
|
+
const block = screen.getByRole("text", { name: SENTENCE });
|
|
71
|
+
expect(block).toBe(screen.getByTestId("scroll-text"));
|
|
72
|
+
expect(block.props.accessible).toBe(true);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test("accessibilityLabel overrides the string as the block's name", async () => {
|
|
76
|
+
await renderWithProviders(<ProgressText accessibilityLabel="Our promise" />);
|
|
77
|
+
expect(screen.getByRole("text", { name: "Our promise" })).toBeOnTheScreen();
|
|
78
|
+
expect(screen.queryByRole("text", { name: SENTENCE })).not.toBeOnTheScreen();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test("before measuring, the plain string stands in and is hidden from assistive technology", async () => {
|
|
82
|
+
await renderWithProviders(<ProgressText />);
|
|
83
|
+
expect(screen.getAllByText(SENTENCE, { includeHiddenElements: true }).length).toBeGreaterThan(0);
|
|
84
|
+
expect(screen.queryByText(SENTENCE)).not.toBeOnTheScreen();
|
|
85
|
+
expect(screen.getAllByRole("text", { name: SENTENCE })).toHaveLength(1);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test("word split: every word becomes its own piece, all hidden, the block announced once", async () => {
|
|
89
|
+
await renderWithProviders(<ProgressText />);
|
|
90
|
+
await measureSpace();
|
|
91
|
+
|
|
92
|
+
for (const word of SENTENCE.split(" ")) {
|
|
93
|
+
expect(screen.getByText(word, { includeHiddenElements: true })).toBeOnTheScreen();
|
|
94
|
+
expect(screen.queryByText(word)).not.toBeOnTheScreen();
|
|
95
|
+
}
|
|
96
|
+
expect(screen.getAllByRole("text", { name: SENTENCE })).toHaveLength(1);
|
|
97
|
+
expect(screen.queryAllByRole("text", { name: "build" })).toHaveLength(0);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test("character split: one hidden piece per grapheme, still announced whole once", async () => {
|
|
101
|
+
await renderWithProviders(<ProgressText split="character">Hi you</ProgressText>);
|
|
102
|
+
await measureSpace();
|
|
103
|
+
|
|
104
|
+
for (const glyph of ["H", "i", "y", "o", "u"]) {
|
|
105
|
+
expect(screen.getByText(glyph, { includeHiddenElements: true })).toBeOnTheScreen();
|
|
106
|
+
expect(screen.queryByText(glyph)).not.toBeOnTheScreen();
|
|
107
|
+
}
|
|
108
|
+
expect(screen.getAllByRole("text", { name: "Hi you" })).toHaveLength(1);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test("line split: pieces are the lines the measurer reports, hidden, the block announced whole", async () => {
|
|
112
|
+
await renderWithProviders(<ProgressText split="line" />);
|
|
113
|
+
const measurer = screen.getAllByText(SENTENCE, { includeHiddenElements: true })[0];
|
|
114
|
+
await fireEvent(measurer, "textLayout", textLayoutEvent(["We build interfaces", "that move"]));
|
|
115
|
+
|
|
116
|
+
expect(screen.getByText("We build interfaces", { includeHiddenElements: true })).toBeOnTheScreen();
|
|
117
|
+
expect(screen.getByText("that move", { includeHiddenElements: true })).toBeOnTheScreen();
|
|
118
|
+
expect(screen.queryByText("that move")).not.toBeOnTheScreen();
|
|
119
|
+
expect(screen.getAllByRole("text", { name: SENTENCE })).toHaveLength(1);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test("line split: re-reporting identical lines does not change what is rendered", async () => {
|
|
123
|
+
await renderWithProviders(<ProgressText split="line" />);
|
|
124
|
+
const measurer = screen.getAllByText(SENTENCE, { includeHiddenElements: true })[0];
|
|
125
|
+
const event = textLayoutEvent(["We build interfaces", "that move"]);
|
|
126
|
+
await fireEvent(measurer, "textLayout", event);
|
|
127
|
+
await fireEvent(measurer, "textLayout", event);
|
|
128
|
+
expect(screen.getAllByText("that move", { includeHiddenElements: true })).toHaveLength(1);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test("every effect keeps the text present and the block announced once", async () => {
|
|
132
|
+
const effects = [
|
|
133
|
+
{ kind: "colour" },
|
|
134
|
+
{ kind: "fade" },
|
|
135
|
+
{ kind: "rise", distance: 12 },
|
|
136
|
+
{ kind: "highlight" },
|
|
137
|
+
] as const;
|
|
138
|
+
for (const effect of effects) {
|
|
139
|
+
const view = await renderWithProviders(<ProgressText effect={effect} />);
|
|
140
|
+
await measureSpace();
|
|
141
|
+
expect(screen.getByText("interfaces", { includeHiddenElements: true })).toBeOnTheScreen();
|
|
142
|
+
expect(screen.getAllByRole("text", { name: SENTENCE })).toHaveLength(1);
|
|
143
|
+
await view.unmount();
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test("an offset source renders the block and survives its scroll host scrolling", async () => {
|
|
148
|
+
function Host() {
|
|
149
|
+
const scrollY = useSharedValue(0);
|
|
150
|
+
return (
|
|
151
|
+
<View testID="host" onLayout={() => undefined}>
|
|
152
|
+
<ScrollText source={{ kind: "offset", scrollY }} testID="scroll-text">
|
|
153
|
+
{SENTENCE}
|
|
154
|
+
</ScrollText>
|
|
155
|
+
</View>
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
await renderWithProviders(<Host />);
|
|
159
|
+
await fireEvent.scroll(screen.getByTestId("host"), {
|
|
160
|
+
nativeEvent: {
|
|
161
|
+
contentOffset: { x: 0, y: 200 },
|
|
162
|
+
contentSize: { width: 390, height: 2000 },
|
|
163
|
+
layoutMeasurement: { width: 390, height: 800 },
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
await act(async () => {
|
|
167
|
+
await fireEvent(screen.getByTestId("scroll-text"), "layout", layoutEvent(300));
|
|
168
|
+
});
|
|
169
|
+
expect(screen.getByRole("text", { name: SENTENCE })).toBeOnTheScreen();
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
test("a progress source needs no Screen and does not warn", async () => {
|
|
173
|
+
const warn = jest.spyOn(console, "warn").mockImplementation(() => undefined);
|
|
174
|
+
await renderWithProviders(<ProgressText />);
|
|
175
|
+
expect(warn.mock.calls.filter(([message]) => String(message).includes("needs a <Screen>"))).toHaveLength(0);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
test("calm motion: pieces are present, hidden, and the block is announced once", async () => {
|
|
179
|
+
await renderWithProviders(
|
|
180
|
+
<DelacourProvider isMotionCalm>
|
|
181
|
+
<ProgressText value={0} />
|
|
182
|
+
</DelacourProvider>
|
|
183
|
+
);
|
|
184
|
+
await measureSpace();
|
|
185
|
+
for (const word of SENTENCE.split(" ")) {
|
|
186
|
+
expect(screen.getByText(word, { includeHiddenElements: true })).toBeOnTheScreen();
|
|
187
|
+
expect(screen.queryByText(word)).not.toBeOnTheScreen();
|
|
188
|
+
}
|
|
189
|
+
expect(screen.getAllByRole("text", { name: SENTENCE })).toHaveLength(1);
|
|
190
|
+
});
|
|
191
|
+
});
|
|
@@ -23,6 +23,7 @@ optional Cancel action and debounced change reporting, over `Input.Group`. Root
|
|
|
23
23
|
| `search-bar.variants.test.ts` | |
|
|
24
24
|
| `search-bar.debounce.ts` | `createDebouncer`, a debounce state machine with the clock injected |
|
|
25
25
|
| `search-bar.debounce.test.ts` | |
|
|
26
|
+
| `search-bar.render.test.tsx` | Mounted under Jest — search role and name, typing, debounce, clear, Cancel modes, disabled, tokens, handle, parts outside the root |
|
|
26
27
|
|
|
27
28
|
## Design
|
|
28
29
|
|
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, jest, test } from "@jest/globals";
|
|
2
|
+
import { createRef } from "react";
|
|
3
|
+
import { act, fireEvent, renderWithProviders, screen } from "../../test/render";
|
|
4
|
+
import { Field } from "../field";
|
|
5
|
+
import { SearchBar } from "./search-bar";
|
|
6
|
+
import type { SearchBarHandle } from "./search-bar.types";
|
|
7
|
+
|
|
8
|
+
const TOKENS = [
|
|
9
|
+
{ id: "a", label: "Open" },
|
|
10
|
+
{ id: "b", label: "Mine" },
|
|
11
|
+
] as const;
|
|
12
|
+
|
|
13
|
+
/** Reports the Cancel's measuring frame so the bar swaps it for the real, revealed row. */
|
|
14
|
+
async function settleCancel(testID: string): Promise<void> {
|
|
15
|
+
const cancel = screen.getByTestId(testID, { includeHiddenElements: true });
|
|
16
|
+
let node = cancel.parent;
|
|
17
|
+
while (node) {
|
|
18
|
+
if (typeof node.props.onLayout === "function") {
|
|
19
|
+
await fireEvent(node, "layout", { nativeEvent: { layout: { height: 40, width: 80, x: 0, y: 0 } } });
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
node = node.parent;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
describe("SearchBar", () => {
|
|
27
|
+
test("is a search field named by its placeholder", async () => {
|
|
28
|
+
await renderWithProviders(<SearchBar />);
|
|
29
|
+
const input = screen.getByLabelText("Search");
|
|
30
|
+
expect(input).toBeOnTheScreen();
|
|
31
|
+
expect(input.props.accessibilityRole).toBe("search");
|
|
32
|
+
expect(screen.getByPlaceholderText("Search")).toBeOnTheScreen();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("an accessibilityLabel beats the placeholder as the name", async () => {
|
|
36
|
+
await renderWithProviders(<SearchBar accessibilityLabel="Find people" placeholder="Name" />);
|
|
37
|
+
expect(screen.getByLabelText("Find people")).toBeOnTheScreen();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("a Field.Label names the field", async () => {
|
|
41
|
+
await renderWithProviders(
|
|
42
|
+
<Field>
|
|
43
|
+
<Field.Label>Directory</Field.Label>
|
|
44
|
+
<SearchBar />
|
|
45
|
+
</Field>
|
|
46
|
+
);
|
|
47
|
+
expect(await screen.findByLabelText("Directory")).toBeOnTheScreen();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("search keyboard defaults are set and overridable", async () => {
|
|
51
|
+
await renderWithProviders(<SearchBar returnKeyType="done" />);
|
|
52
|
+
const input = screen.getByLabelText("Search");
|
|
53
|
+
expect(input.props.returnKeyType).toBe("done");
|
|
54
|
+
expect(input.props.autoCorrect).toBe(false);
|
|
55
|
+
expect(input.props.autoCapitalize).toBe("none");
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test("isLoading reports busy and swaps the clear button for a spinner", async () => {
|
|
59
|
+
const view = await renderWithProviders(<SearchBar defaultValue="abc" />);
|
|
60
|
+
expect(screen.getByLabelText("Search")).not.toBeBusy();
|
|
61
|
+
expect(screen.getByRole("button", { name: "Clear search" })).toBeOnTheScreen();
|
|
62
|
+
|
|
63
|
+
await view.rerender(<SearchBar defaultValue="abc" isLoading />);
|
|
64
|
+
expect(screen.getByLabelText("Search")).toBeBusy();
|
|
65
|
+
expect(screen.queryByRole("button", { name: "Clear search" })).not.toBeOnTheScreen();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
describe("typing", () => {
|
|
69
|
+
test("uncontrolled: defaultValue seeds it, typing updates it and reports onValueChange", async () => {
|
|
70
|
+
const onValueChange = jest.fn();
|
|
71
|
+
await renderWithProviders(<SearchBar defaultValue="a" onValueChange={onValueChange} />);
|
|
72
|
+
expect(screen.getByLabelText("Search")).toHaveDisplayValue("a");
|
|
73
|
+
|
|
74
|
+
await fireEvent.changeText(screen.getByLabelText("Search"), "ab");
|
|
75
|
+
expect(onValueChange).toHaveBeenLastCalledWith("ab");
|
|
76
|
+
expect(screen.getByLabelText("Search")).toHaveDisplayValue("ab");
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test("controlled: reports the change and waits for the value prop", async () => {
|
|
80
|
+
const onValueChange = jest.fn();
|
|
81
|
+
const view = await renderWithProviders(<SearchBar onValueChange={onValueChange} value="one" />);
|
|
82
|
+
await fireEvent.changeText(screen.getByLabelText("Search"), "two");
|
|
83
|
+
expect(onValueChange).toHaveBeenCalledWith("two");
|
|
84
|
+
expect(screen.getByLabelText("Search")).toHaveDisplayValue("one");
|
|
85
|
+
|
|
86
|
+
await view.rerender(<SearchBar onValueChange={onValueChange} value="two" />);
|
|
87
|
+
expect(screen.getByLabelText("Search")).toHaveDisplayValue("two");
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test("onSubmit receives the text and onSubmitEditing the event", async () => {
|
|
91
|
+
const onSubmit = jest.fn();
|
|
92
|
+
const onSubmitEditing = jest.fn();
|
|
93
|
+
await renderWithProviders(
|
|
94
|
+
<SearchBar defaultValue="cats" onSubmit={onSubmit} onSubmitEditing={onSubmitEditing} />
|
|
95
|
+
);
|
|
96
|
+
await fireEvent(screen.getByLabelText("Search"), "submitEditing", { nativeEvent: { text: "cats" } });
|
|
97
|
+
expect(onSubmit).toHaveBeenCalledWith("cats");
|
|
98
|
+
expect(onSubmitEditing).toHaveBeenCalledTimes(1);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test("onFocusChange and onFocus/onBlur follow focus", async () => {
|
|
102
|
+
const onFocusChange = jest.fn();
|
|
103
|
+
const onFocus = jest.fn();
|
|
104
|
+
const onBlur = jest.fn();
|
|
105
|
+
await renderWithProviders(<SearchBar onBlur={onBlur} onFocus={onFocus} onFocusChange={onFocusChange} />);
|
|
106
|
+
const input = screen.getByLabelText("Search");
|
|
107
|
+
await fireEvent(input, "focus");
|
|
108
|
+
expect(onFocusChange).toHaveBeenLastCalledWith(true);
|
|
109
|
+
expect(onFocus).toHaveBeenCalledTimes(1);
|
|
110
|
+
await fireEvent(input, "blur");
|
|
111
|
+
expect(onFocusChange).toHaveBeenLastCalledWith(false);
|
|
112
|
+
expect(onBlur).toHaveBeenCalledTimes(1);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
describe("debounce", () => {
|
|
117
|
+
beforeEach(() => {
|
|
118
|
+
jest.useFakeTimers();
|
|
119
|
+
});
|
|
120
|
+
afterEach(() => {
|
|
121
|
+
jest.useRealTimers();
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test("with no debounce, onDebouncedChange fires at once", async () => {
|
|
125
|
+
const onDebouncedChange = jest.fn();
|
|
126
|
+
await renderWithProviders(<SearchBar onDebouncedChange={onDebouncedChange} />);
|
|
127
|
+
await fireEvent.changeText(screen.getByLabelText("Search"), "a");
|
|
128
|
+
expect(onDebouncedChange).toHaveBeenCalledWith("a");
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test("waits for the pause, then reports the last text once", async () => {
|
|
132
|
+
const onDebouncedChange = jest.fn();
|
|
133
|
+
await renderWithProviders(<SearchBar debounce={300} onDebouncedChange={onDebouncedChange} />);
|
|
134
|
+
const input = screen.getByLabelText("Search");
|
|
135
|
+
await fireEvent.changeText(input, "a");
|
|
136
|
+
await fireEvent.changeText(input, "ab");
|
|
137
|
+
expect(onDebouncedChange).not.toHaveBeenCalled();
|
|
138
|
+
|
|
139
|
+
await jest.advanceTimersByTimeAsync(300);
|
|
140
|
+
expect(onDebouncedChange).toHaveBeenCalledTimes(1);
|
|
141
|
+
expect(onDebouncedChange).toHaveBeenCalledWith("ab");
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test("the search key flushes a pending debounce first", async () => {
|
|
145
|
+
const onDebouncedChange = jest.fn();
|
|
146
|
+
const onSubmit = jest.fn();
|
|
147
|
+
await renderWithProviders(<SearchBar debounce={300} onDebouncedChange={onDebouncedChange} onSubmit={onSubmit} />);
|
|
148
|
+
const input = screen.getByLabelText("Search");
|
|
149
|
+
await fireEvent.changeText(input, "dog");
|
|
150
|
+
await fireEvent(input, "submitEditing", { nativeEvent: { text: "dog" } });
|
|
151
|
+
expect(onDebouncedChange).toHaveBeenCalledWith("dog");
|
|
152
|
+
expect(onSubmit).toHaveBeenCalledWith("dog");
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test("clear reports an empty string at once and drops the pending text", async () => {
|
|
156
|
+
const onDebouncedChange = jest.fn();
|
|
157
|
+
await renderWithProviders(<SearchBar debounce={300} onDebouncedChange={onDebouncedChange} />);
|
|
158
|
+
await fireEvent.changeText(screen.getByLabelText("Search"), "dog");
|
|
159
|
+
await fireEvent(screen.getByRole("button", { name: "Clear search" }), "accessibilityTap");
|
|
160
|
+
expect(onDebouncedChange).toHaveBeenCalledTimes(1);
|
|
161
|
+
expect(onDebouncedChange).toHaveBeenCalledWith("");
|
|
162
|
+
|
|
163
|
+
await jest.advanceTimersByTimeAsync(300);
|
|
164
|
+
expect(onDebouncedChange).toHaveBeenCalledTimes(1);
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
describe("clear button", () => {
|
|
169
|
+
test("is absent while the field is empty and appears with text", async () => {
|
|
170
|
+
await renderWithProviders(<SearchBar />);
|
|
171
|
+
expect(screen.queryByRole("button", { name: "Clear search" })).not.toBeOnTheScreen();
|
|
172
|
+
|
|
173
|
+
await fireEvent.changeText(screen.getByLabelText("Search"), "a");
|
|
174
|
+
expect(screen.getByRole("button", { name: "Clear search" })).toBeOnTheScreen();
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test("empties the field, reports it and fires onClear", async () => {
|
|
178
|
+
const onClear = jest.fn();
|
|
179
|
+
const onValueChange = jest.fn();
|
|
180
|
+
await renderWithProviders(<SearchBar defaultValue="abc" onClear={onClear} onValueChange={onValueChange} />);
|
|
181
|
+
await fireEvent(screen.getByRole("button", { name: "Clear search" }), "accessibilityTap");
|
|
182
|
+
|
|
183
|
+
expect(onClear).toHaveBeenCalledTimes(1);
|
|
184
|
+
expect(onValueChange).toHaveBeenLastCalledWith("");
|
|
185
|
+
expect(screen.getByLabelText("Search")).toHaveDisplayValue("");
|
|
186
|
+
expect(screen.queryByRole("button", { name: "Clear search" })).not.toBeOnTheScreen();
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
test("controlled: asks for an empty value and waits for the rerender", async () => {
|
|
190
|
+
const onValueChange = jest.fn();
|
|
191
|
+
const view = await renderWithProviders(<SearchBar onValueChange={onValueChange} value="abc" />);
|
|
192
|
+
await fireEvent(screen.getByRole("button", { name: "Clear search" }), "accessibilityTap");
|
|
193
|
+
expect(onValueChange).toHaveBeenCalledWith("");
|
|
194
|
+
expect(screen.getByLabelText("Search")).toHaveDisplayValue("abc");
|
|
195
|
+
|
|
196
|
+
await view.rerender(<SearchBar onValueChange={onValueChange} value="" />);
|
|
197
|
+
expect(screen.getByLabelText("Search")).toHaveDisplayValue("");
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
test("clearAccessibilityLabel renames it", async () => {
|
|
201
|
+
await renderWithProviders(<SearchBar clearAccessibilityLabel="Erase" defaultValue="a" />);
|
|
202
|
+
expect(screen.getByRole("button", { name: "Erase" })).toBeOnTheScreen();
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
test("is absent when disabled or read-only", async () => {
|
|
206
|
+
const view = await renderWithProviders(<SearchBar defaultValue="a" isDisabled />);
|
|
207
|
+
expect(screen.queryByRole("button", { name: "Clear search" })).not.toBeOnTheScreen();
|
|
208
|
+
|
|
209
|
+
await view.rerender(<SearchBar defaultValue="a" readOnly />);
|
|
210
|
+
expect(screen.queryByRole("button", { name: "Clear search" })).not.toBeOnTheScreen();
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
describe("cancel", () => {
|
|
215
|
+
test("focus mode: hidden from assistive tech until the field is focused", async () => {
|
|
216
|
+
await renderWithProviders(<SearchBar testID="bar" />);
|
|
217
|
+
await settleCancel("bar-cancel");
|
|
218
|
+
expect(screen.queryByRole("button", { name: "Cancel" })).not.toBeOnTheScreen();
|
|
219
|
+
|
|
220
|
+
await fireEvent(screen.getByLabelText("Search"), "focus");
|
|
221
|
+
expect(screen.getByRole("button", { name: "Cancel" })).toBeOnTheScreen();
|
|
222
|
+
|
|
223
|
+
await fireEvent(screen.getByLabelText("Search"), "blur");
|
|
224
|
+
expect(screen.queryByRole("button", { name: "Cancel" })).not.toBeOnTheScreen();
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
test("never mode: renders no Cancel", async () => {
|
|
228
|
+
await renderWithProviders(<SearchBar cancel="never" testID="bar" />);
|
|
229
|
+
expect(screen.queryByTestId("bar-cancel", { includeHiddenElements: true })).not.toBeOnTheScreen();
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
test("always mode: Cancel is available without focus", async () => {
|
|
233
|
+
await renderWithProviders(<SearchBar cancel="always" testID="bar" />);
|
|
234
|
+
await settleCancel("bar-cancel");
|
|
235
|
+
expect(screen.getByRole("button", { name: "Cancel" })).toBeOnTheScreen();
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
test("pressing it empties the text and fires onCancel", async () => {
|
|
239
|
+
const onCancel = jest.fn();
|
|
240
|
+
const onValueChange = jest.fn();
|
|
241
|
+
await renderWithProviders(
|
|
242
|
+
<SearchBar cancel="always" defaultValue="abc" onCancel={onCancel} onValueChange={onValueChange} testID="bar" />
|
|
243
|
+
);
|
|
244
|
+
await settleCancel("bar-cancel");
|
|
245
|
+
await fireEvent(screen.getByRole("button", { name: "Cancel" }), "accessibilityTap");
|
|
246
|
+
|
|
247
|
+
expect(onCancel).toHaveBeenCalledTimes(1);
|
|
248
|
+
expect(onValueChange).toHaveBeenLastCalledWith("");
|
|
249
|
+
expect(screen.getByLabelText("Search")).toHaveDisplayValue("");
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
test("on an empty field it still fires onCancel but reports no value change", async () => {
|
|
253
|
+
const onCancel = jest.fn();
|
|
254
|
+
const onValueChange = jest.fn();
|
|
255
|
+
await renderWithProviders(
|
|
256
|
+
<SearchBar cancel="always" onCancel={onCancel} onValueChange={onValueChange} testID="bar" />
|
|
257
|
+
);
|
|
258
|
+
await settleCancel("bar-cancel");
|
|
259
|
+
await fireEvent(screen.getByRole("button", { name: "Cancel" }), "accessibilityTap");
|
|
260
|
+
expect(onCancel).toHaveBeenCalledTimes(1);
|
|
261
|
+
expect(onValueChange).not.toHaveBeenCalled();
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
test("cancelLabel renames it", async () => {
|
|
265
|
+
await renderWithProviders(<SearchBar cancel="always" cancelLabel="Close" testID="bar" />);
|
|
266
|
+
await settleCancel("bar-cancel");
|
|
267
|
+
expect(screen.getByRole("button", { name: "Close" })).toBeOnTheScreen();
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
test("a SearchBar.Cancel child replaces the default and runs its own onPress before cancelling", async () => {
|
|
271
|
+
const onPress = jest.fn();
|
|
272
|
+
const onCancel = jest.fn();
|
|
273
|
+
await renderWithProviders(
|
|
274
|
+
<SearchBar cancel="always" onCancel={onCancel} testID="bar">
|
|
275
|
+
<SearchBar.Cancel onPress={onPress}>Done</SearchBar.Cancel>
|
|
276
|
+
</SearchBar>
|
|
277
|
+
);
|
|
278
|
+
await settleCancel("bar-cancel");
|
|
279
|
+
await fireEvent(screen.getByRole("button", { name: "Done" }), "accessibilityTap");
|
|
280
|
+
expect(onPress).toHaveBeenCalledTimes(1);
|
|
281
|
+
expect(onCancel).toHaveBeenCalledTimes(1);
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
describe("disabled", () => {
|
|
286
|
+
test("isDisabled makes the field not editable and announced disabled", async () => {
|
|
287
|
+
await renderWithProviders(<SearchBar isDisabled />);
|
|
288
|
+
const input = screen.getByLabelText("Search");
|
|
289
|
+
expect(input).toBeDisabled();
|
|
290
|
+
expect(input.props.editable).toBe(false);
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
test("a disabled Field disables it and an own isDisabled={false} opts out", async () => {
|
|
294
|
+
await renderWithProviders(
|
|
295
|
+
<Field isDisabled>
|
|
296
|
+
<SearchBar accessibilityLabel="A" />
|
|
297
|
+
<SearchBar accessibilityLabel="B" isDisabled={false} />
|
|
298
|
+
</Field>
|
|
299
|
+
);
|
|
300
|
+
expect(screen.getByLabelText("A")).toBeDisabled();
|
|
301
|
+
expect(screen.getByLabelText("B")).not.toBeDisabled();
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
test("a disabled bar shows no Cancel even when always", async () => {
|
|
305
|
+
await renderWithProviders(<SearchBar cancel="always" isDisabled testID="bar" />);
|
|
306
|
+
await settleCancel("bar-cancel");
|
|
307
|
+
expect(screen.queryByRole("button", { name: "Cancel" })).not.toBeOnTheScreen();
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
test("Backspace on an empty disabled bar removes no token", async () => {
|
|
311
|
+
const onTokenRemove = jest.fn();
|
|
312
|
+
await renderWithProviders(<SearchBar isDisabled onTokenRemove={onTokenRemove} tokens={TOKENS} />);
|
|
313
|
+
await fireEvent(screen.getByLabelText("Search"), "keyPress", { nativeEvent: { key: "Backspace" } });
|
|
314
|
+
expect(onTokenRemove).not.toHaveBeenCalled();
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
describe("tokens", () => {
|
|
319
|
+
test("renders each token's label", async () => {
|
|
320
|
+
await renderWithProviders(<SearchBar tokens={TOKENS} />);
|
|
321
|
+
expect(screen.getByText("Open")).toBeOnTheScreen();
|
|
322
|
+
expect(screen.getByText("Mine")).toBeOnTheScreen();
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
test("a token's remove control is named for it and calls onTokenRemove", async () => {
|
|
326
|
+
const onTokenRemove = jest.fn();
|
|
327
|
+
await renderWithProviders(<SearchBar onTokenRemove={onTokenRemove} tokens={TOKENS} />);
|
|
328
|
+
await fireEvent(screen.getByRole("button", { name: "Remove Open" }), "accessibilityTap");
|
|
329
|
+
expect(onTokenRemove).toHaveBeenCalledWith(TOKENS[0]);
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
test("Backspace on an empty field removes the last token", async () => {
|
|
333
|
+
const onTokenRemove = jest.fn();
|
|
334
|
+
await renderWithProviders(<SearchBar onTokenRemove={onTokenRemove} tokens={TOKENS} />);
|
|
335
|
+
await fireEvent(screen.getByLabelText("Search"), "keyPress", { nativeEvent: { key: "Backspace" } });
|
|
336
|
+
expect(onTokenRemove).toHaveBeenCalledWith(TOKENS[1]);
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
test("Backspace with text edits the text and removes no token", async () => {
|
|
340
|
+
const onTokenRemove = jest.fn();
|
|
341
|
+
await renderWithProviders(<SearchBar defaultValue="a" onTokenRemove={onTokenRemove} tokens={TOKENS} />);
|
|
342
|
+
await fireEvent(screen.getByLabelText("Search"), "keyPress", { nativeEvent: { key: "Backspace" } });
|
|
343
|
+
expect(onTokenRemove).not.toHaveBeenCalled();
|
|
344
|
+
});
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
describe("handle", () => {
|
|
348
|
+
test("ref.clear empties the field like the clear button", async () => {
|
|
349
|
+
const ref = createRef<SearchBarHandle>();
|
|
350
|
+
const onClear = jest.fn();
|
|
351
|
+
await renderWithProviders(<SearchBar defaultValue="abc" onClear={onClear} ref={ref} />);
|
|
352
|
+
await fireEvent(screen.getByLabelText("Search"), "focus");
|
|
353
|
+
await act(async () => {
|
|
354
|
+
ref.current?.clear();
|
|
355
|
+
});
|
|
356
|
+
expect(onClear).toHaveBeenCalledTimes(1);
|
|
357
|
+
expect(await screen.findByDisplayValue("")).toBeOnTheScreen();
|
|
358
|
+
});
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
describe("parts outside the root", () => {
|
|
362
|
+
let errorSpy: typeof console.error;
|
|
363
|
+
beforeEach(() => {
|
|
364
|
+
errorSpy = console.error;
|
|
365
|
+
console.error = () => undefined;
|
|
366
|
+
});
|
|
367
|
+
afterEach(() => {
|
|
368
|
+
console.error = errorSpy;
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
test("SearchBar.Cancel throws outside a SearchBar", async () => {
|
|
372
|
+
await expect(renderWithProviders(<SearchBar.Cancel />)).rejects.toThrow(
|
|
373
|
+
"SearchBar.Cancel must be rendered inside a <SearchBar>."
|
|
374
|
+
);
|
|
375
|
+
});
|
|
376
|
+
});
|
|
377
|
+
});
|
|
@@ -35,6 +35,7 @@ const sections = useScrollSections({ readingLine: 96 });
|
|
|
35
35
|
| `section-progress.context.tsx` | The root's context and `useSectionProgress` |
|
|
36
36
|
| `section-progress.variants.ts` | Pure `tv()` slots + every resolver, no RN imports |
|
|
37
37
|
| `section-progress.variants.test.ts` | |
|
|
38
|
+
| `section-progress.render.test.tsx` | Mounted under Jest — pill name/value/expanded, open state (controlled and not), item selection and picks, disabled item, part-outside-root error |
|
|
38
39
|
|
|
39
40
|
There is no `section-progress.types.ts`: every prop type has exactly one consumer, and the house
|
|
40
41
|
rule keeps such a type in its consumer's file.
|