@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,655 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, jest, test } from "@jest/globals";
|
|
2
|
+
import { createRef } from "react";
|
|
3
|
+
import { fireEvent, renderWithProviders, screen } from "../../test/render";
|
|
4
|
+
import { Field } from "../field";
|
|
5
|
+
import { TagInput } from "./tag-input";
|
|
6
|
+
import { useTagInput } from "./tag-input.context";
|
|
7
|
+
import type { TagInputHandle } from "./tag-input.types";
|
|
8
|
+
import { TagInputChip } from "./tag-input-chip";
|
|
9
|
+
import { TagInputSuffix } from "./tag-input-suffix";
|
|
10
|
+
|
|
11
|
+
const LABEL = "Recipients";
|
|
12
|
+
|
|
13
|
+
function field() {
|
|
14
|
+
return screen.getByLabelText(LABEL);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function activate(element: ReturnType<typeof screen.getByLabelText>) {
|
|
18
|
+
return fireEvent(element, "accessibilityTap");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
describe("TagInput", () => {
|
|
22
|
+
let consoleError: jest.SpiedFunction<typeof console.error>;
|
|
23
|
+
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
consoleError = jest.spyOn(console, "error").mockImplementation(() => undefined);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
afterEach(() => {
|
|
29
|
+
consoleError.mockRestore();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe("rendering", () => {
|
|
33
|
+
test("is a text field named by its accessibilityLabel", async () => {
|
|
34
|
+
await renderWithProviders(<TagInput accessibilityLabel={LABEL} placeholder="Add a name" />);
|
|
35
|
+
expect(field()).toBeOnTheScreen();
|
|
36
|
+
expect(screen.getByPlaceholderText("Add a name")).toBeOnTheScreen();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("renders each default tag as a chip", async () => {
|
|
40
|
+
await renderWithProviders(<TagInput accessibilityLabel={LABEL} defaultValue={["design", "code"]} />);
|
|
41
|
+
expect(screen.getByLabelText("design")).toBeOnTheScreen();
|
|
42
|
+
expect(screen.getByLabelText("code")).toBeOnTheScreen();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test("the field's accessibilityValue carries the tag count", async () => {
|
|
46
|
+
await renderWithProviders(<TagInput accessibilityLabel={LABEL} defaultValue={["a", "b"]} />);
|
|
47
|
+
expect(field()).toHaveAccessibilityValue({ text: "2 tags" });
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("the placeholder shows only while there are no tags", async () => {
|
|
51
|
+
await renderWithProviders(<TagInput accessibilityLabel={LABEL} defaultValue={["a"]} placeholder="Add a name" />);
|
|
52
|
+
expect(screen.queryByPlaceholderText("Add a name")).not.toBeOnTheScreen();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test("showCount renders the counter, with the max when set", async () => {
|
|
56
|
+
await renderWithProviders(
|
|
57
|
+
<TagInput accessibilityLabel={LABEL} defaultValue={["a", "b"]} max={5} showCount testID="tags" />
|
|
58
|
+
);
|
|
59
|
+
expect(screen.getByTestId("tags-count")).toHaveTextContent("2/5");
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("derives part testIDs from the root testID", async () => {
|
|
63
|
+
await renderWithProviders(<TagInput accessibilityLabel={LABEL} defaultValue={["a"]} testID="tags" />);
|
|
64
|
+
expect(screen.getByTestId("tags")).toBeOnTheScreen();
|
|
65
|
+
expect(screen.getByTestId("tags-input")).toBeOnTheScreen();
|
|
66
|
+
expect(screen.getByTestId("tags-tag-0")).toBeOnTheScreen();
|
|
67
|
+
expect(screen.getByTestId("tags-tag-0-remove")).toBeOnTheScreen();
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe("adding a tag", () => {
|
|
72
|
+
test("submitEditing commits the draft as a tag and clears the field", async () => {
|
|
73
|
+
const onValueChange = jest.fn();
|
|
74
|
+
await renderWithProviders(<TagInput accessibilityLabel={LABEL} onValueChange={onValueChange} />);
|
|
75
|
+
await fireEvent.changeText(field(), "design");
|
|
76
|
+
expect(field()).toHaveDisplayValue("design");
|
|
77
|
+
|
|
78
|
+
await fireEvent(field(), "submitEditing");
|
|
79
|
+
expect(onValueChange).toHaveBeenCalledTimes(1);
|
|
80
|
+
expect(onValueChange).toHaveBeenCalledWith(["design"]);
|
|
81
|
+
expect(screen.getByLabelText("design")).toBeOnTheScreen();
|
|
82
|
+
expect(field()).toHaveDisplayValue("");
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test("a delimiter character commits the text before it", async () => {
|
|
86
|
+
const onValueChange = jest.fn();
|
|
87
|
+
await renderWithProviders(<TagInput accessibilityLabel={LABEL} onValueChange={onValueChange} />);
|
|
88
|
+
await fireEvent.changeText(field(), "design,");
|
|
89
|
+
expect(onValueChange).toHaveBeenCalledWith(["design"]);
|
|
90
|
+
expect(field()).toHaveDisplayValue("");
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test("a pasted text holding delimiters becomes several tags", async () => {
|
|
94
|
+
const onValueChange = jest.fn();
|
|
95
|
+
await renderWithProviders(<TagInput accessibilityLabel={LABEL} onValueChange={onValueChange} />);
|
|
96
|
+
await fireEvent.changeText(field(), "a,b,c,");
|
|
97
|
+
expect(onValueChange).toHaveBeenLastCalledWith(["a", "b", "c"]);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test("a custom delimiters prop replaces the comma", async () => {
|
|
101
|
+
const onValueChange = jest.fn();
|
|
102
|
+
await renderWithProviders(
|
|
103
|
+
<TagInput accessibilityLabel={LABEL} delimiters={[";"]} onValueChange={onValueChange} />
|
|
104
|
+
);
|
|
105
|
+
await fireEvent.changeText(field(), "a,");
|
|
106
|
+
expect(onValueChange).not.toHaveBeenCalled();
|
|
107
|
+
await fireEvent.changeText(field(), "a;");
|
|
108
|
+
expect(onValueChange).toHaveBeenCalledWith(["a"]);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test("tags are trimmed and run through transform", async () => {
|
|
112
|
+
const onValueChange = jest.fn();
|
|
113
|
+
await renderWithProviders(
|
|
114
|
+
<TagInput accessibilityLabel={LABEL} onValueChange={onValueChange} transform={(raw) => raw.toLowerCase()} />
|
|
115
|
+
);
|
|
116
|
+
await fireEvent.changeText(field(), " Design ");
|
|
117
|
+
await fireEvent(field(), "submitEditing");
|
|
118
|
+
expect(onValueChange).toHaveBeenCalledWith(["design"]);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test("submitting an empty draft adds nothing", async () => {
|
|
122
|
+
const onValueChange = jest.fn();
|
|
123
|
+
await renderWithProviders(<TagInput accessibilityLabel={LABEL} onValueChange={onValueChange} />);
|
|
124
|
+
await fireEvent(field(), "submitEditing");
|
|
125
|
+
expect(onValueChange).not.toHaveBeenCalled();
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test("announces an added tag through announce", async () => {
|
|
129
|
+
const announce = jest.fn();
|
|
130
|
+
await renderWithProviders(<TagInput accessibilityLabel={LABEL} announce={announce} />);
|
|
131
|
+
await fireEvent.changeText(field(), "design,");
|
|
132
|
+
expect(announce).toHaveBeenCalledTimes(1);
|
|
133
|
+
expect(announce.mock.calls[0]?.[0]).toEqual(expect.stringContaining("design"));
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test("announce={false} stays silent", async () => {
|
|
137
|
+
await renderWithProviders(<TagInput accessibilityLabel={LABEL} announce={false} />);
|
|
138
|
+
await fireEvent.changeText(field(), "design,");
|
|
139
|
+
expect(screen.getByLabelText("design")).toBeOnTheScreen();
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
test("blur commits the leftover text by default", async () => {
|
|
143
|
+
const onValueChange = jest.fn();
|
|
144
|
+
await renderWithProviders(<TagInput accessibilityLabel={LABEL} onValueChange={onValueChange} />);
|
|
145
|
+
await fireEvent.changeText(field(), "design");
|
|
146
|
+
await fireEvent(field(), "blur");
|
|
147
|
+
expect(onValueChange).toHaveBeenCalledWith(["design"]);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
test("blurBehavior clear throws the text away", async () => {
|
|
151
|
+
const onValueChange = jest.fn();
|
|
152
|
+
await renderWithProviders(
|
|
153
|
+
<TagInput accessibilityLabel={LABEL} blurBehavior="clear" onValueChange={onValueChange} />
|
|
154
|
+
);
|
|
155
|
+
await fireEvent.changeText(field(), "design");
|
|
156
|
+
await fireEvent(field(), "blur");
|
|
157
|
+
expect(onValueChange).not.toHaveBeenCalled();
|
|
158
|
+
expect(field()).toHaveDisplayValue("");
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test("blurBehavior keep leaves the text in the field", async () => {
|
|
162
|
+
const onValueChange = jest.fn();
|
|
163
|
+
await renderWithProviders(
|
|
164
|
+
<TagInput accessibilityLabel={LABEL} blurBehavior="keep" onValueChange={onValueChange} />
|
|
165
|
+
);
|
|
166
|
+
await fireEvent.changeText(field(), "design");
|
|
167
|
+
await fireEvent(field(), "blur");
|
|
168
|
+
expect(onValueChange).not.toHaveBeenCalled();
|
|
169
|
+
expect(field()).toHaveDisplayValue("design");
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
test("onFocus and onBlur still reach the caller", async () => {
|
|
173
|
+
const onFocus = jest.fn();
|
|
174
|
+
const onBlur = jest.fn();
|
|
175
|
+
await renderWithProviders(<TagInput accessibilityLabel={LABEL} onBlur={onBlur} onFocus={onFocus} />);
|
|
176
|
+
await fireEvent(field(), "focus");
|
|
177
|
+
expect(onFocus).toHaveBeenCalledTimes(1);
|
|
178
|
+
await fireEvent(field(), "blur");
|
|
179
|
+
expect(onBlur).toHaveBeenCalledTimes(1);
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
describe("rejections", () => {
|
|
184
|
+
test("a duplicate is refused with onReject, case-insensitively", async () => {
|
|
185
|
+
const onValueChange = jest.fn();
|
|
186
|
+
const onReject = jest.fn();
|
|
187
|
+
await renderWithProviders(
|
|
188
|
+
<TagInput
|
|
189
|
+
accessibilityLabel={LABEL}
|
|
190
|
+
defaultValue={["Design"]}
|
|
191
|
+
onReject={onReject}
|
|
192
|
+
onValueChange={onValueChange}
|
|
193
|
+
/>
|
|
194
|
+
);
|
|
195
|
+
await fireEvent.changeText(field(), "design,");
|
|
196
|
+
expect(onValueChange).not.toHaveBeenCalled();
|
|
197
|
+
expect(onReject).toHaveBeenCalledTimes(1);
|
|
198
|
+
expect(onReject).toHaveBeenCalledWith({ reason: "duplicate", tag: "design" });
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
test("allowDuplicates accepts a tag already in the list", async () => {
|
|
202
|
+
const onValueChange = jest.fn();
|
|
203
|
+
await renderWithProviders(
|
|
204
|
+
<TagInput accessibilityLabel={LABEL} allowDuplicates defaultValue={["a"]} onValueChange={onValueChange} />
|
|
205
|
+
);
|
|
206
|
+
await fireEvent.changeText(field(), "a,");
|
|
207
|
+
expect(onValueChange).toHaveBeenCalledWith(["a", "a"]);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
test("caseSensitiveDuplicates treats differing case as a new tag", async () => {
|
|
211
|
+
const onValueChange = jest.fn();
|
|
212
|
+
await renderWithProviders(
|
|
213
|
+
<TagInput
|
|
214
|
+
accessibilityLabel={LABEL}
|
|
215
|
+
caseSensitiveDuplicates
|
|
216
|
+
defaultValue={["Design"]}
|
|
217
|
+
onValueChange={onValueChange}
|
|
218
|
+
/>
|
|
219
|
+
);
|
|
220
|
+
await fireEvent.changeText(field(), "design,");
|
|
221
|
+
expect(onValueChange).toHaveBeenCalledWith(["Design", "design"]);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
test("max refuses a tag once the list is full, and hides the field", async () => {
|
|
225
|
+
const onValueChange = jest.fn();
|
|
226
|
+
const onReject = jest.fn();
|
|
227
|
+
await renderWithProviders(
|
|
228
|
+
<TagInput accessibilityLabel={LABEL} max={2} onReject={onReject} onValueChange={onValueChange} />
|
|
229
|
+
);
|
|
230
|
+
await fireEvent.changeText(field(), "a,b,");
|
|
231
|
+
expect(onValueChange).toHaveBeenLastCalledWith(["a", "b"]);
|
|
232
|
+
expect(screen.queryByLabelText(LABEL)).not.toBeOnTheScreen();
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
test("max refuses the overflowing piece of a paste with reason max", async () => {
|
|
236
|
+
const onValueChange = jest.fn();
|
|
237
|
+
const onReject = jest.fn();
|
|
238
|
+
await renderWithProviders(
|
|
239
|
+
<TagInput accessibilityLabel={LABEL} max={2} onReject={onReject} onValueChange={onValueChange} />
|
|
240
|
+
);
|
|
241
|
+
await fireEvent.changeText(field(), "a,b,c,");
|
|
242
|
+
expect(onValueChange).toHaveBeenLastCalledWith(["a", "b"]);
|
|
243
|
+
expect(onReject).toHaveBeenCalledWith({ reason: "max", tag: "c" });
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
test("allowOverflow accepts past max", async () => {
|
|
247
|
+
const onValueChange = jest.fn();
|
|
248
|
+
await renderWithProviders(
|
|
249
|
+
<TagInput
|
|
250
|
+
accessibilityLabel={LABEL}
|
|
251
|
+
allowOverflow
|
|
252
|
+
max={1}
|
|
253
|
+
onValueChange={onValueChange}
|
|
254
|
+
showCount
|
|
255
|
+
testID="tags"
|
|
256
|
+
/>
|
|
257
|
+
);
|
|
258
|
+
await fireEvent.changeText(field(), "a,b,");
|
|
259
|
+
expect(onValueChange).toHaveBeenLastCalledWith(["a", "b"]);
|
|
260
|
+
expect(screen.getByTestId("tags-count")).toHaveTextContent("2/1");
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
test("validate refuses a tag as invalid and leaves it in the field", async () => {
|
|
264
|
+
const onValueChange = jest.fn();
|
|
265
|
+
const onReject = jest.fn();
|
|
266
|
+
await renderWithProviders(
|
|
267
|
+
<TagInput
|
|
268
|
+
accessibilityLabel={LABEL}
|
|
269
|
+
onReject={onReject}
|
|
270
|
+
onValueChange={onValueChange}
|
|
271
|
+
validate={(tag) => tag.includes("@")}
|
|
272
|
+
/>
|
|
273
|
+
);
|
|
274
|
+
await fireEvent.changeText(field(), "nope");
|
|
275
|
+
await fireEvent(field(), "submitEditing");
|
|
276
|
+
expect(onValueChange).not.toHaveBeenCalled();
|
|
277
|
+
expect(onReject).toHaveBeenCalledWith({ reason: "invalid", tag: "nope" });
|
|
278
|
+
expect(field()).toHaveDisplayValue("nope");
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
test("a refusal is announced with the reject message", async () => {
|
|
282
|
+
const announce = jest.fn();
|
|
283
|
+
await renderWithProviders(
|
|
284
|
+
<TagInput
|
|
285
|
+
accessibilityLabel={LABEL}
|
|
286
|
+
announce={announce}
|
|
287
|
+
defaultValue={["a"]}
|
|
288
|
+
rejectMessages={{ duplicate: "Already added" }}
|
|
289
|
+
/>
|
|
290
|
+
);
|
|
291
|
+
await fireEvent.changeText(field(), "a,");
|
|
292
|
+
expect(announce).toHaveBeenCalledWith("Already added");
|
|
293
|
+
});
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
describe("removing a tag", () => {
|
|
297
|
+
test("each tag has a remove button named for it", async () => {
|
|
298
|
+
await renderWithProviders(<TagInput accessibilityLabel={LABEL} defaultValue={["design", "code"]} />);
|
|
299
|
+
expect(screen.getByRole("button", { name: "Remove design" })).toBeOnTheScreen();
|
|
300
|
+
expect(screen.getByRole("button", { name: "Remove code" })).toBeOnTheScreen();
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
test("removeAccessibilityLabel renames the remove button", async () => {
|
|
304
|
+
await renderWithProviders(
|
|
305
|
+
<TagInput
|
|
306
|
+
accessibilityLabel={LABEL}
|
|
307
|
+
defaultValue={["design"]}
|
|
308
|
+
removeAccessibilityLabel={(tag) => `Drop ${tag}`}
|
|
309
|
+
/>
|
|
310
|
+
);
|
|
311
|
+
expect(screen.getByRole("button", { name: "Drop design" })).toBeOnTheScreen();
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
test("activating the remove button removes that tag and reports the rest", async () => {
|
|
315
|
+
const onValueChange = jest.fn();
|
|
316
|
+
await renderWithProviders(
|
|
317
|
+
<TagInput accessibilityLabel={LABEL} defaultValue={["a", "b", "c"]} onValueChange={onValueChange} />
|
|
318
|
+
);
|
|
319
|
+
await activate(screen.getByRole("button", { name: "Remove b" }));
|
|
320
|
+
expect(onValueChange).toHaveBeenCalledTimes(1);
|
|
321
|
+
expect(onValueChange).toHaveBeenCalledWith(["a", "c"]);
|
|
322
|
+
expect(screen.queryByLabelText("b")).not.toBeOnTheScreen();
|
|
323
|
+
expect(screen.getByLabelText("a")).toBeOnTheScreen();
|
|
324
|
+
expect(screen.getByLabelText("c")).toBeOnTheScreen();
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
test("the chip's remove accessibility action removes the tag", async () => {
|
|
328
|
+
const onValueChange = jest.fn();
|
|
329
|
+
await renderWithProviders(
|
|
330
|
+
<TagInput accessibilityLabel={LABEL} defaultValue={["a", "b"]} onValueChange={onValueChange} testID="tags" />
|
|
331
|
+
);
|
|
332
|
+
await fireEvent(screen.getByTestId("tags-tag-0"), "accessibilityAction", {
|
|
333
|
+
nativeEvent: { actionName: "remove" },
|
|
334
|
+
});
|
|
335
|
+
expect(onValueChange).toHaveBeenCalledWith(["b"]);
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
test("a removal is announced", async () => {
|
|
339
|
+
const announce = jest.fn();
|
|
340
|
+
await renderWithProviders(<TagInput accessibilityLabel={LABEL} announce={announce} defaultValue={["a"]} />);
|
|
341
|
+
await activate(screen.getByRole("button", { name: "Remove a" }));
|
|
342
|
+
expect(announce).toHaveBeenCalledTimes(1);
|
|
343
|
+
expect(announce.mock.calls[0]?.[0]).toEqual(expect.stringContaining("a"));
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
test("isClearable shows a clear-all button that empties tags and draft", async () => {
|
|
347
|
+
const onValueChange = jest.fn();
|
|
348
|
+
await renderWithProviders(
|
|
349
|
+
<TagInput
|
|
350
|
+
accessibilityLabel={LABEL}
|
|
351
|
+
defaultInputValue="half"
|
|
352
|
+
defaultValue={["a", "b"]}
|
|
353
|
+
isClearable
|
|
354
|
+
onValueChange={onValueChange}
|
|
355
|
+
/>
|
|
356
|
+
);
|
|
357
|
+
await activate(screen.getByRole("button", { name: "Clear all" }));
|
|
358
|
+
expect(onValueChange).toHaveBeenCalledWith([]);
|
|
359
|
+
expect(screen.queryByLabelText("a")).not.toBeOnTheScreen();
|
|
360
|
+
expect(field()).toHaveDisplayValue("");
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
test("the clear button is absent when there is nothing to clear", async () => {
|
|
364
|
+
await renderWithProviders(<TagInput accessibilityLabel={LABEL} isClearable />);
|
|
365
|
+
expect(screen.queryByRole("button", { name: "Clear all" })).not.toBeOnTheScreen();
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
test("clearAccessibilityLabel renames the clear button", async () => {
|
|
369
|
+
await renderWithProviders(
|
|
370
|
+
<TagInput accessibilityLabel={LABEL} clearAccessibilityLabel="Reset" defaultValue={["a"]} isClearable />
|
|
371
|
+
);
|
|
372
|
+
expect(screen.getByRole("button", { name: "Reset" })).toBeOnTheScreen();
|
|
373
|
+
});
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
describe("backspace on an empty field", () => {
|
|
377
|
+
test("the first press arms the last tag and the second removes it", async () => {
|
|
378
|
+
const onValueChange = jest.fn();
|
|
379
|
+
await renderWithProviders(
|
|
380
|
+
<TagInput accessibilityLabel={LABEL} defaultValue={["a", "b"]} onValueChange={onValueChange} />
|
|
381
|
+
);
|
|
382
|
+
await fireEvent(field(), "keyPress", { nativeEvent: { key: "Backspace" } });
|
|
383
|
+
expect(onValueChange).not.toHaveBeenCalled();
|
|
384
|
+
expect(screen.getByLabelText("b")).toBeOnTheScreen();
|
|
385
|
+
|
|
386
|
+
await fireEvent(field(), "keyPress", { nativeEvent: { key: "Backspace" } });
|
|
387
|
+
expect(onValueChange).toHaveBeenCalledWith(["a"]);
|
|
388
|
+
expect(screen.queryByLabelText("b")).not.toBeOnTheScreen();
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
test("another key disarms, so the next Backspace only arms again", async () => {
|
|
392
|
+
const onValueChange = jest.fn();
|
|
393
|
+
await renderWithProviders(
|
|
394
|
+
<TagInput accessibilityLabel={LABEL} defaultValue={["a"]} onValueChange={onValueChange} />
|
|
395
|
+
);
|
|
396
|
+
await fireEvent(field(), "keyPress", { nativeEvent: { key: "Backspace" } });
|
|
397
|
+
await fireEvent(field(), "keyPress", { nativeEvent: { key: "x" } });
|
|
398
|
+
await fireEvent(field(), "keyPress", { nativeEvent: { key: "Backspace" } });
|
|
399
|
+
expect(onValueChange).not.toHaveBeenCalled();
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
test("does nothing while the draft holds text", async () => {
|
|
403
|
+
const onValueChange = jest.fn();
|
|
404
|
+
await renderWithProviders(
|
|
405
|
+
<TagInput accessibilityLabel={LABEL} defaultInputValue="x" defaultValue={["a"]} onValueChange={onValueChange} />
|
|
406
|
+
);
|
|
407
|
+
await fireEvent(field(), "keyPress", { nativeEvent: { key: "Backspace" } });
|
|
408
|
+
await fireEvent(field(), "keyPress", { nativeEvent: { key: "Backspace" } });
|
|
409
|
+
expect(onValueChange).not.toHaveBeenCalled();
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
test("onKeyPress still reaches the caller", async () => {
|
|
413
|
+
const onKeyPress = jest.fn();
|
|
414
|
+
await renderWithProviders(<TagInput accessibilityLabel={LABEL} onKeyPress={onKeyPress} />);
|
|
415
|
+
await fireEvent(field(), "keyPress", { nativeEvent: { key: "a" } });
|
|
416
|
+
expect(onKeyPress).toHaveBeenCalledTimes(1);
|
|
417
|
+
});
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
describe("controlled and uncontrolled", () => {
|
|
421
|
+
test("uncontrolled: defaultValue seeds the tags and adding updates them", async () => {
|
|
422
|
+
await renderWithProviders(<TagInput accessibilityLabel={LABEL} defaultValue={["a"]} />);
|
|
423
|
+
expect(screen.getByLabelText("a")).toBeOnTheScreen();
|
|
424
|
+
await fireEvent.changeText(field(), "b,");
|
|
425
|
+
expect(screen.getByLabelText("b")).toBeOnTheScreen();
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
test("controlled: reports a change and waits for the rerender", async () => {
|
|
429
|
+
const onValueChange = jest.fn();
|
|
430
|
+
const view = await renderWithProviders(
|
|
431
|
+
<TagInput accessibilityLabel={LABEL} onValueChange={onValueChange} value={["a"]} />
|
|
432
|
+
);
|
|
433
|
+
await fireEvent.changeText(field(), "b,");
|
|
434
|
+
expect(onValueChange).toHaveBeenCalledWith(["a", "b"]);
|
|
435
|
+
expect(screen.queryByLabelText("b")).not.toBeOnTheScreen();
|
|
436
|
+
|
|
437
|
+
await view.rerender(<TagInput accessibilityLabel={LABEL} onValueChange={onValueChange} value={["a", "b"]} />);
|
|
438
|
+
expect(screen.getByLabelText("b")).toBeOnTheScreen();
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
test("controlled: removing reports and waits for the rerender", async () => {
|
|
442
|
+
const onValueChange = jest.fn();
|
|
443
|
+
const view = await renderWithProviders(
|
|
444
|
+
<TagInput accessibilityLabel={LABEL} onValueChange={onValueChange} value={["a", "b"]} />
|
|
445
|
+
);
|
|
446
|
+
await activate(screen.getByRole("button", { name: "Remove a" }));
|
|
447
|
+
expect(onValueChange).toHaveBeenCalledWith(["b"]);
|
|
448
|
+
expect(screen.getByLabelText("a")).toBeOnTheScreen();
|
|
449
|
+
|
|
450
|
+
await view.rerender(<TagInput accessibilityLabel={LABEL} onValueChange={onValueChange} value={["b"]} />);
|
|
451
|
+
expect(screen.queryByLabelText("a")).not.toBeOnTheScreen();
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
test("controlled draft: inputValue is shown and typing reports onInputValueChange", async () => {
|
|
455
|
+
const onInputValueChange = jest.fn();
|
|
456
|
+
const view = await renderWithProviders(
|
|
457
|
+
<TagInput accessibilityLabel={LABEL} inputValue="ab" onInputValueChange={onInputValueChange} />
|
|
458
|
+
);
|
|
459
|
+
expect(field()).toHaveDisplayValue("ab");
|
|
460
|
+
await fireEvent.changeText(field(), "abc");
|
|
461
|
+
expect(onInputValueChange).toHaveBeenCalledWith("abc");
|
|
462
|
+
|
|
463
|
+
await view.rerender(
|
|
464
|
+
<TagInput accessibilityLabel={LABEL} inputValue="abc" onInputValueChange={onInputValueChange} />
|
|
465
|
+
);
|
|
466
|
+
expect(field()).toHaveDisplayValue("abc");
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
test("defaultInputValue seeds the draft", async () => {
|
|
470
|
+
await renderWithProviders(<TagInput accessibilityLabel={LABEL} defaultInputValue="seed" />);
|
|
471
|
+
expect(field()).toHaveDisplayValue("seed");
|
|
472
|
+
});
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
describe("ref handle", () => {
|
|
476
|
+
test("add commits text and returns null, or the first rejection's reason", async () => {
|
|
477
|
+
const ref = createRef<TagInputHandle>();
|
|
478
|
+
const onValueChange = jest.fn();
|
|
479
|
+
await renderWithProviders(<TagInput accessibilityLabel={LABEL} onValueChange={onValueChange} ref={ref} />);
|
|
480
|
+
|
|
481
|
+
await fireEvent(field(), "focus");
|
|
482
|
+
expect(ref.current?.add("a")).toBeNull();
|
|
483
|
+
expect(onValueChange).toHaveBeenLastCalledWith(["a"]);
|
|
484
|
+
expect(ref.current?.add("")).toBe("empty");
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
test("clear empties the tags", async () => {
|
|
488
|
+
const ref = createRef<TagInputHandle>();
|
|
489
|
+
const onValueChange = jest.fn();
|
|
490
|
+
await renderWithProviders(
|
|
491
|
+
<TagInput accessibilityLabel={LABEL} defaultValue={["a"]} onValueChange={onValueChange} ref={ref} />
|
|
492
|
+
);
|
|
493
|
+
await fireEvent(field(), "focus");
|
|
494
|
+
ref.current?.clear();
|
|
495
|
+
expect(onValueChange).toHaveBeenCalledWith([]);
|
|
496
|
+
});
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
describe("renderTag", () => {
|
|
500
|
+
test("draws a custom tag and hands it a working remove", async () => {
|
|
501
|
+
const onValueChange = jest.fn();
|
|
502
|
+
const { Text } = jest.requireActual<typeof import("react-native")>("react-native");
|
|
503
|
+
await renderWithProviders(
|
|
504
|
+
<TagInput
|
|
505
|
+
accessibilityLabel={LABEL}
|
|
506
|
+
defaultValue={["a", "b"]}
|
|
507
|
+
onValueChange={onValueChange}
|
|
508
|
+
renderTag={(tag, state) => (
|
|
509
|
+
<Text accessibilityRole="button" accessibilityLabel={`Custom ${tag}`} onPress={state.remove}>
|
|
510
|
+
{tag}
|
|
511
|
+
</Text>
|
|
512
|
+
)}
|
|
513
|
+
/>
|
|
514
|
+
);
|
|
515
|
+
const custom = screen.getByRole("button", { name: "Custom a" });
|
|
516
|
+
expect(custom).toBeOnTheScreen();
|
|
517
|
+
await fireEvent.press(custom);
|
|
518
|
+
expect(onValueChange).toHaveBeenCalledWith(["b"]);
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
test("isRemovable is false while disabled", async () => {
|
|
522
|
+
const seen: boolean[] = [];
|
|
523
|
+
await renderWithProviders(
|
|
524
|
+
<TagInput
|
|
525
|
+
accessibilityLabel={LABEL}
|
|
526
|
+
defaultValue={["a"]}
|
|
527
|
+
isDisabled
|
|
528
|
+
renderTag={(_tag, state) => {
|
|
529
|
+
seen.push(state.isRemovable);
|
|
530
|
+
return null;
|
|
531
|
+
}}
|
|
532
|
+
/>
|
|
533
|
+
);
|
|
534
|
+
expect(seen.every((removable) => removable === false)).toBe(true);
|
|
535
|
+
expect(seen.length).toBeGreaterThan(0);
|
|
536
|
+
});
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
describe("disabled", () => {
|
|
540
|
+
test("the field is not editable", async () => {
|
|
541
|
+
await renderWithProviders(<TagInput accessibilityLabel={LABEL} isDisabled />);
|
|
542
|
+
expect(field()).toBeDisabled();
|
|
543
|
+
expect(field().props.editable).toBe(false);
|
|
544
|
+
});
|
|
545
|
+
|
|
546
|
+
test("with tags there are no remove buttons, and the field is hidden", async () => {
|
|
547
|
+
await renderWithProviders(<TagInput accessibilityLabel={LABEL} defaultValue={["a"]} isDisabled />);
|
|
548
|
+
expect(screen.getByLabelText("a")).toBeOnTheScreen();
|
|
549
|
+
expect(screen.queryByRole("button", { name: "Remove a" })).not.toBeOnTheScreen();
|
|
550
|
+
expect(screen.queryByLabelText(LABEL)).not.toBeOnTheScreen();
|
|
551
|
+
});
|
|
552
|
+
|
|
553
|
+
test("the chip's remove action does nothing", async () => {
|
|
554
|
+
const onValueChange = jest.fn();
|
|
555
|
+
await renderWithProviders(
|
|
556
|
+
<TagInput
|
|
557
|
+
accessibilityLabel={LABEL}
|
|
558
|
+
defaultValue={["a"]}
|
|
559
|
+
isDisabled
|
|
560
|
+
onValueChange={onValueChange}
|
|
561
|
+
testID="tags"
|
|
562
|
+
/>
|
|
563
|
+
);
|
|
564
|
+
await fireEvent(screen.getByTestId("tags-tag-0"), "accessibilityAction", {
|
|
565
|
+
nativeEvent: { actionName: "remove" },
|
|
566
|
+
});
|
|
567
|
+
expect(onValueChange).not.toHaveBeenCalled();
|
|
568
|
+
expect(screen.getByLabelText("a")).toBeOnTheScreen();
|
|
569
|
+
});
|
|
570
|
+
|
|
571
|
+
test("the clear button is hidden", async () => {
|
|
572
|
+
await renderWithProviders(<TagInput accessibilityLabel={LABEL} defaultValue={["a"]} isClearable isDisabled />);
|
|
573
|
+
expect(screen.queryByRole("button", { name: "Clear all" })).not.toBeOnTheScreen();
|
|
574
|
+
});
|
|
575
|
+
|
|
576
|
+
test("inherits disabled from an enclosing Field", async () => {
|
|
577
|
+
await renderWithProviders(
|
|
578
|
+
<Field isDisabled>
|
|
579
|
+
<Field.Label>Recipients</Field.Label>
|
|
580
|
+
<TagInput />
|
|
581
|
+
</Field>
|
|
582
|
+
);
|
|
583
|
+
expect(await screen.findByLabelText(LABEL)).toBeDisabled();
|
|
584
|
+
});
|
|
585
|
+
});
|
|
586
|
+
|
|
587
|
+
describe("read-only", () => {
|
|
588
|
+
test("shows the tags with no field and no remove or clear controls", async () => {
|
|
589
|
+
const onValueChange = jest.fn();
|
|
590
|
+
await renderWithProviders(
|
|
591
|
+
<TagInput
|
|
592
|
+
accessibilityLabel={LABEL}
|
|
593
|
+
defaultValue={["a"]}
|
|
594
|
+
isClearable
|
|
595
|
+
isReadOnly
|
|
596
|
+
onValueChange={onValueChange}
|
|
597
|
+
/>
|
|
598
|
+
);
|
|
599
|
+
expect(screen.getByLabelText("a")).toBeOnTheScreen();
|
|
600
|
+
expect(screen.queryByLabelText(LABEL)).not.toBeOnTheScreen();
|
|
601
|
+
expect(screen.queryByRole("button")).not.toBeOnTheScreen();
|
|
602
|
+
expect(onValueChange).not.toHaveBeenCalled();
|
|
603
|
+
});
|
|
604
|
+
});
|
|
605
|
+
|
|
606
|
+
describe("inside a Field", () => {
|
|
607
|
+
test("Field.Label becomes the field's accessible name", async () => {
|
|
608
|
+
await renderWithProviders(
|
|
609
|
+
<Field>
|
|
610
|
+
<Field.Label>Recipients</Field.Label>
|
|
611
|
+
<TagInput />
|
|
612
|
+
</Field>
|
|
613
|
+
);
|
|
614
|
+
expect(await screen.findByLabelText(LABEL)).toBeOnTheScreen();
|
|
615
|
+
});
|
|
616
|
+
});
|
|
617
|
+
|
|
618
|
+
describe("parts outside a TagInput", () => {
|
|
619
|
+
test("useTagInput throws outside a TagInput", async () => {
|
|
620
|
+
function Reader() {
|
|
621
|
+
useTagInput();
|
|
622
|
+
return null;
|
|
623
|
+
}
|
|
624
|
+
await expect(renderWithProviders(<Reader />)).rejects.toThrow("useTagInput must be called inside a <TagInput>.");
|
|
625
|
+
});
|
|
626
|
+
|
|
627
|
+
test("the chip throws outside a TagInput", async () => {
|
|
628
|
+
await expect(renderWithProviders(<TagInputChip index={0} tag="a" />)).rejects.toThrow(
|
|
629
|
+
"TagInput.Chip must be rendered inside a <TagInput>."
|
|
630
|
+
);
|
|
631
|
+
});
|
|
632
|
+
|
|
633
|
+
test("the suffix throws outside a TagInput", async () => {
|
|
634
|
+
await expect(
|
|
635
|
+
renderWithProviders(<TagInputSuffix clearAccessibilityLabel="Clear" isClearable showCount />)
|
|
636
|
+
).rejects.toThrow("TagInput.Suffix must be rendered inside a <TagInput>.");
|
|
637
|
+
});
|
|
638
|
+
|
|
639
|
+
test("useTagInput inside a renderTag sees the live tags", async () => {
|
|
640
|
+
const { Text } = jest.requireActual<typeof import("react-native")>("react-native");
|
|
641
|
+
function Probe() {
|
|
642
|
+
const { tags } = useTagInput();
|
|
643
|
+
return <Text>{`count:${tags.length}`}</Text>;
|
|
644
|
+
}
|
|
645
|
+
await renderWithProviders(
|
|
646
|
+
<TagInput
|
|
647
|
+
accessibilityLabel={LABEL}
|
|
648
|
+
defaultValue={["a", "b"]}
|
|
649
|
+
renderTag={(tag) => (tag === "a" ? <Probe /> : null)}
|
|
650
|
+
/>
|
|
651
|
+
);
|
|
652
|
+
expect(screen.getByText("count:2")).toBeOnTheScreen();
|
|
653
|
+
});
|
|
654
|
+
});
|
|
655
|
+
});
|
|
@@ -16,6 +16,7 @@ own text inheritance through classNames. Compound root plus thirteen presets:
|
|
|
16
16
|
| `text.context.tsx` | `TextClassProvider`, `useTextClass()` |
|
|
17
17
|
| `text.variants.ts` | Pure `tv()` + `resolveTextClass`, no RN imports |
|
|
18
18
|
| `text.variants.test.ts` | |
|
|
19
|
+
| `text.render.test.tsx` | Mounted under Jest — heading/link roles per preset, `onPress`, font-scaling props, a11y passthrough, class-cascade context |
|
|
19
20
|
|
|
20
21
|
## Design
|
|
21
22
|
|