@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,460 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, jest, test } from "@jest/globals";
|
|
2
|
+
import { LocationManager } from "@maplibre/maplibre-react-native";
|
|
3
|
+
import { act } from "@testing-library/react-native";
|
|
4
|
+
import type { ReactElement } from "react";
|
|
5
|
+
import { fireEvent, renderWithProviders, screen } from "../../test/render";
|
|
6
|
+
import { Text } from "../text";
|
|
7
|
+
// biome-ignore lint/suspicious/noShadowRestrictedNames: the component is a map; consumers import it by name from its own subpath
|
|
8
|
+
import { Map } from "./map";
|
|
9
|
+
import { useMap } from "./map.context";
|
|
10
|
+
import type { LngLat } from "./map.types";
|
|
11
|
+
|
|
12
|
+
const WELLINGTON: LngLat = [174.776, -41.286];
|
|
13
|
+
|
|
14
|
+
/** Mounts a map and lays it out, since the native map only mounts once its root has been measured. */
|
|
15
|
+
async function renderMap(element: ReactElement) {
|
|
16
|
+
const view = await renderWithProviders(element);
|
|
17
|
+
await fireEvent(screen.getByTestId("map-root"), "layout", {
|
|
18
|
+
nativeEvent: { layout: { height: 300, width: 400, x: 0, y: 0 } },
|
|
19
|
+
});
|
|
20
|
+
return view;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function FindOnMap(): ReactElement {
|
|
24
|
+
const handle = useMap();
|
|
25
|
+
return <Map.Label>{typeof handle.flyTo}</Map.Label>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
describe("Map", () => {
|
|
29
|
+
test("mounts the native map only after the root is measured", async () => {
|
|
30
|
+
await renderWithProviders(<Map center={WELLINGTON} testID="map-root" zoom={12} />);
|
|
31
|
+
expect(screen.queryByTestId("maplibre-Map")).not.toBeOnTheScreen();
|
|
32
|
+
|
|
33
|
+
await fireEvent(screen.getByTestId("map-root"), "layout", {
|
|
34
|
+
nativeEvent: { layout: { height: 300, width: 400, x: 0, y: 0 } },
|
|
35
|
+
});
|
|
36
|
+
expect(screen.getByTestId("maplibre-Map")).toBeOnTheScreen();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("ignores a zero-sized layout", async () => {
|
|
40
|
+
await renderWithProviders(<Map center={WELLINGTON} testID="map-root" zoom={12} />);
|
|
41
|
+
await fireEvent(screen.getByTestId("map-root"), "layout", {
|
|
42
|
+
nativeEvent: { layout: { height: 0, width: 0, x: 0, y: 0 } },
|
|
43
|
+
});
|
|
44
|
+
expect(screen.queryByTestId("maplibre-Map")).not.toBeOnTheScreen();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("the native map is announced as Map by default and takes a custom label", async () => {
|
|
48
|
+
const view = await renderMap(<Map center={WELLINGTON} testID="map-root" zoom={12} />);
|
|
49
|
+
expect(screen.getByTestId("maplibre-Map").props.accessibilityLabel).toBe("Map");
|
|
50
|
+
|
|
51
|
+
await view.rerender(<Map accessibilityLabel="Store finder" center={WELLINGTON} testID="map-root" zoom={12} />);
|
|
52
|
+
expect(screen.getByTestId("maplibre-Map").props.accessibilityLabel).toBe("Store finder");
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test("onReady fires on the first load only", async () => {
|
|
56
|
+
const onReady = jest.fn();
|
|
57
|
+
await renderMap(<Map center={WELLINGTON} onReady={onReady} testID="map-root" zoom={12} />);
|
|
58
|
+
const map = screen.getByTestId("maplibre-Map");
|
|
59
|
+
await fireEvent(map, "didFinishLoadingMap");
|
|
60
|
+
await fireEvent(map, "didFinishLoadingMap");
|
|
61
|
+
expect(onReady).toHaveBeenCalledTimes(1);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test("onViewStateChange reports the camera with a fresh centre tuple", async () => {
|
|
65
|
+
const onViewStateChange = jest.fn();
|
|
66
|
+
await renderMap(<Map center={WELLINGTON} onViewStateChange={onViewStateChange} testID="map-root" zoom={12} />);
|
|
67
|
+
await fireEvent(screen.getByTestId("maplibre-Map"), "regionDidChange", {
|
|
68
|
+
nativeEvent: { bearing: 10, center: [1, 2], pitch: 20, zoom: 5 },
|
|
69
|
+
});
|
|
70
|
+
expect(onViewStateChange).toHaveBeenCalledWith({ bearing: 10, center: [1, 2], pitch: 20, zoom: 5 });
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test("onPress reports the tapped coordinate, and is not wired when absent", async () => {
|
|
74
|
+
const onPress = jest.fn();
|
|
75
|
+
const view = await renderMap(<Map center={WELLINGTON} onPress={onPress} testID="map-root" zoom={12} />);
|
|
76
|
+
await fireEvent(screen.getByTestId("maplibre-Map"), "press", { nativeEvent: { lngLat: [174.5, -41.5] } });
|
|
77
|
+
expect(onPress).toHaveBeenCalledWith([174.5, -41.5]);
|
|
78
|
+
|
|
79
|
+
await view.rerender(<Map center={WELLINGTON} testID="map-root" zoom={12} />);
|
|
80
|
+
expect(screen.getByTestId("maplibre-Map").props.onPress).toBeUndefined();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test("isInteractive={false} turns every gesture off", async () => {
|
|
84
|
+
await renderMap(<Map center={WELLINGTON} isInteractive={false} testID="map-root" zoom={12} />);
|
|
85
|
+
const props = screen.getByTestId("maplibre-Map").props;
|
|
86
|
+
expect(props.dragPan).toBe(false);
|
|
87
|
+
expect(props.touchRotate).toBe(false);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test("rotation is off by default and on with isRotatable", async () => {
|
|
91
|
+
const view = await renderMap(<Map center={WELLINGTON} testID="map-root" zoom={12} />);
|
|
92
|
+
expect(screen.getByTestId("maplibre-Map").props.touchRotate).toBe(false);
|
|
93
|
+
|
|
94
|
+
await view.rerender(<Map center={WELLINGTON} isRotatable testID="map-root" zoom={12} />);
|
|
95
|
+
expect(screen.getByTestId("maplibre-Map").props.touchRotate).toBe(true);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test("changing the initial view after mount warns and does not remount the map", async () => {
|
|
99
|
+
const warn = jest.spyOn(console, "warn").mockImplementation(() => undefined);
|
|
100
|
+
const view = await renderMap(<Map center={WELLINGTON} testID="map-root" zoom={12} />);
|
|
101
|
+
expect(warn).not.toHaveBeenCalled();
|
|
102
|
+
|
|
103
|
+
await view.rerender(<Map center={[0, 0]} testID="map-root" zoom={3} />);
|
|
104
|
+
expect(warn).toHaveBeenCalledTimes(1);
|
|
105
|
+
expect(screen.getByTestId("maplibre-Map")).toBeOnTheScreen();
|
|
106
|
+
warn.mockRestore();
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test("a rerender with an equal centre array does not warn", async () => {
|
|
110
|
+
const warn = jest.spyOn(console, "warn").mockImplementation(() => undefined);
|
|
111
|
+
const view = await renderMap(<Map center={[174.776, -41.286]} testID="map-root" zoom={12} />);
|
|
112
|
+
await view.rerender(<Map center={[174.776, -41.286]} testID="map-root" zoom={12} />);
|
|
113
|
+
expect(warn).not.toHaveBeenCalled();
|
|
114
|
+
warn.mockRestore();
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test("useMap hands the camera handle to a descendant", async () => {
|
|
118
|
+
await renderMap(
|
|
119
|
+
<Map center={WELLINGTON} testID="map-root" zoom={12}>
|
|
120
|
+
<FindOnMap />
|
|
121
|
+
</Map>
|
|
122
|
+
);
|
|
123
|
+
expect(screen.getByText("function")).toBeOnTheScreen();
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// Markers and popups are deliberately not `accessible`: a popup inside a marker holds interactive
|
|
128
|
+
// children (a Close button), and an accessible parent would group them into one element, hiding the
|
|
129
|
+
// button from VoiceOver and from e2e lookups. So these query by label/testID and read the role off props.
|
|
130
|
+
describe("Map.Marker", () => {
|
|
131
|
+
test("renders its children and repeats the testID on its content", async () => {
|
|
132
|
+
await renderMap(
|
|
133
|
+
<Map center={WELLINGTON} testID="map-root" zoom={12}>
|
|
134
|
+
<Map.Marker accessibilityLabel="Te Papa" lngLat={[174.782, -41.29]} testID="museum">
|
|
135
|
+
<Map.Label>Te Papa</Map.Label>
|
|
136
|
+
</Map.Marker>
|
|
137
|
+
</Map>
|
|
138
|
+
);
|
|
139
|
+
expect(screen.getByTestId("museum")).toBeOnTheScreen();
|
|
140
|
+
expect(screen.getByTestId("museum-content")).toBeOnTheScreen();
|
|
141
|
+
expect(screen.getByText("Te Papa")).toBeOnTheScreen();
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test("with onPress it is a button named by its label, and its press calls back without reaching the map", async () => {
|
|
145
|
+
const onPress = jest.fn();
|
|
146
|
+
const onMapPress = jest.fn();
|
|
147
|
+
const stopPropagation = jest.fn();
|
|
148
|
+
await renderMap(
|
|
149
|
+
<Map center={WELLINGTON} onPress={onMapPress} testID="map-root" zoom={12}>
|
|
150
|
+
<Map.Marker accessibilityLabel="Te Papa" lngLat={[174.782, -41.29]} onPress={onPress} />
|
|
151
|
+
</Map>
|
|
152
|
+
);
|
|
153
|
+
const marker = screen.getByLabelText("Te Papa");
|
|
154
|
+
expect(marker.props.accessibilityRole).toBe("button");
|
|
155
|
+
await fireEvent(marker, "press", { stopPropagation });
|
|
156
|
+
expect(onPress).toHaveBeenCalledTimes(1);
|
|
157
|
+
expect(stopPropagation).toHaveBeenCalledTimes(1);
|
|
158
|
+
expect(onMapPress).not.toHaveBeenCalled();
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test("without onPress it is not a button", async () => {
|
|
162
|
+
await renderMap(
|
|
163
|
+
<Map center={WELLINGTON} testID="map-root" zoom={12}>
|
|
164
|
+
<Map.Marker accessibilityLabel="Te Papa" lngLat={[174.782, -41.29]} />
|
|
165
|
+
</Map>
|
|
166
|
+
);
|
|
167
|
+
expect(screen.getByLabelText("Te Papa").props.accessibilityRole).toBeUndefined();
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test("a marker with an explicit anchor takes no pin offset", async () => {
|
|
171
|
+
await renderMap(
|
|
172
|
+
<Map center={WELLINGTON} testID="map-root" zoom={12}>
|
|
173
|
+
<Map.Marker anchor="bottom" lngLat={[174.782, -41.29]} testID="museum">
|
|
174
|
+
<Map.Pin />
|
|
175
|
+
</Map.Marker>
|
|
176
|
+
</Map>
|
|
177
|
+
);
|
|
178
|
+
expect(screen.getByTestId("museum")).toBeOnTheScreen();
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
describe("Map.Popup", () => {
|
|
183
|
+
test("inside a marker it renders its title and body as a summary", async () => {
|
|
184
|
+
await renderMap(
|
|
185
|
+
<Map center={WELLINGTON} testID="map-root" zoom={12}>
|
|
186
|
+
<Map.Marker lngLat={[174.782, -41.29]}>
|
|
187
|
+
<Map.Popup title="Te Papa">
|
|
188
|
+
<Text>Open until 6</Text>
|
|
189
|
+
</Map.Popup>
|
|
190
|
+
<Map.Pin />
|
|
191
|
+
</Map.Marker>
|
|
192
|
+
</Map>
|
|
193
|
+
);
|
|
194
|
+
expect(screen.getByTestId("maplibre-Marker")).toBeOnTheScreen();
|
|
195
|
+
expect(screen.getByText("Te Papa")).toBeOnTheScreen();
|
|
196
|
+
expect(screen.getByText("Open until 6")).toBeOnTheScreen();
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
test("on its own coordinate it becomes a marker of its own", async () => {
|
|
200
|
+
await renderMap(
|
|
201
|
+
<Map center={WELLINGTON} testID="map-root" zoom={12}>
|
|
202
|
+
<Map.Popup lngLat={[174.782, -41.29]} title="Lookout" />
|
|
203
|
+
</Map>
|
|
204
|
+
);
|
|
205
|
+
expect(screen.getByText("Lookout")).toBeOnTheScreen();
|
|
206
|
+
expect(screen.getByTestId("maplibre-Marker")).toBeOnTheScreen();
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
test("outside a marker and with no lngLat it draws nothing and warns", async () => {
|
|
210
|
+
const warn = jest.spyOn(console, "warn").mockImplementation(() => undefined);
|
|
211
|
+
await renderMap(
|
|
212
|
+
<Map center={WELLINGTON} testID="map-root" zoom={12}>
|
|
213
|
+
<Map.Popup title="Nowhere" />
|
|
214
|
+
</Map>
|
|
215
|
+
);
|
|
216
|
+
expect(screen.queryByText("Nowhere")).not.toBeOnTheScreen();
|
|
217
|
+
expect(warn).toHaveBeenCalledTimes(1);
|
|
218
|
+
warn.mockRestore();
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
describe("Map.Controls", () => {
|
|
223
|
+
test("zoom is on by default, labelled by what it does, and nothing else is", async () => {
|
|
224
|
+
await renderMap(
|
|
225
|
+
<Map center={WELLINGTON} testID="map-root" zoom={12}>
|
|
226
|
+
<Map.Controls />
|
|
227
|
+
</Map>
|
|
228
|
+
);
|
|
229
|
+
expect(screen.getByRole("button", { name: "Zoom in" })).toBeOnTheScreen();
|
|
230
|
+
expect(screen.getByRole("button", { name: "Zoom out" })).toBeOnTheScreen();
|
|
231
|
+
expect(screen.queryByRole("button", { name: "Point north" })).not.toBeOnTheScreen();
|
|
232
|
+
expect(screen.queryByRole("button", { name: "Recenter map" })).not.toBeOnTheScreen();
|
|
233
|
+
expect(screen.queryByRole("button", { name: "Show my location" })).not.toBeOnTheScreen();
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
test("compass and recenter appear when asked for, and showZoom={false} hides the zoom pair", async () => {
|
|
237
|
+
await renderMap(
|
|
238
|
+
<Map center={WELLINGTON} testID="map-root" zoom={12}>
|
|
239
|
+
<Map.Controls showCompass showRecenter showZoom={false} />
|
|
240
|
+
</Map>
|
|
241
|
+
);
|
|
242
|
+
expect(screen.getByRole("button", { name: "Point north" })).toBeOnTheScreen();
|
|
243
|
+
expect(screen.getByRole("button", { name: "Recenter map" })).toBeOnTheScreen();
|
|
244
|
+
expect(screen.queryByRole("button", { name: "Zoom in" })).not.toBeOnTheScreen();
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
test("the buttons can be activated without throwing", async () => {
|
|
248
|
+
await renderMap(
|
|
249
|
+
<Map center={WELLINGTON} testID="map-root" zoom={12}>
|
|
250
|
+
<Map.Controls showCompass showRecenter />
|
|
251
|
+
</Map>
|
|
252
|
+
);
|
|
253
|
+
for (const name of ["Zoom in", "Zoom out", "Point north", "Recenter map"]) {
|
|
254
|
+
await fireEvent(screen.getByRole("button", { name }), "accessibilityTap");
|
|
255
|
+
}
|
|
256
|
+
expect(screen.getByRole("button", { name: "Zoom in" })).toBeOnTheScreen();
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
test("unmounting the controls takes them off the overlay layer", async () => {
|
|
260
|
+
const view = await renderMap(
|
|
261
|
+
<Map center={WELLINGTON} testID="map-root" zoom={12}>
|
|
262
|
+
<Map.Controls />
|
|
263
|
+
</Map>
|
|
264
|
+
);
|
|
265
|
+
expect(screen.getByRole("button", { name: "Zoom in" })).toBeOnTheScreen();
|
|
266
|
+
await view.rerender(<Map center={WELLINGTON} testID="map-root" zoom={12} />);
|
|
267
|
+
expect(screen.queryByRole("button", { name: "Zoom in" })).not.toBeOnTheScreen();
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
describe("Map.Route and Map.Arc", () => {
|
|
272
|
+
test("a route renders a source, and its press calls back without reaching the map", async () => {
|
|
273
|
+
const onPress = jest.fn();
|
|
274
|
+
const onMapPress = jest.fn();
|
|
275
|
+
const stopPropagation = jest.fn();
|
|
276
|
+
await renderMap(
|
|
277
|
+
<Map center={WELLINGTON} onPress={onMapPress} testID="map-root" zoom={12}>
|
|
278
|
+
<Map.Route coordinates={[WELLINGTON, [174.8, -41.3]]} onPress={onPress} />
|
|
279
|
+
</Map>
|
|
280
|
+
);
|
|
281
|
+
const source = screen.getByTestId("maplibre-GeoJSONSource");
|
|
282
|
+
await fireEvent(source, "press", { stopPropagation });
|
|
283
|
+
expect(onPress).toHaveBeenCalledTimes(1);
|
|
284
|
+
expect(stopPropagation).toHaveBeenCalledTimes(1);
|
|
285
|
+
expect(onMapPress).not.toHaveBeenCalled();
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
test("a route with no onPress has no press handler and no hitbox", async () => {
|
|
289
|
+
await renderMap(
|
|
290
|
+
<Map center={WELLINGTON} testID="map-root" zoom={12}>
|
|
291
|
+
<Map.Route coordinates={[WELLINGTON, [174.8, -41.3]]} />
|
|
292
|
+
</Map>
|
|
293
|
+
);
|
|
294
|
+
const props = screen.getByTestId("maplibre-GeoJSONSource").props;
|
|
295
|
+
expect(props.onPress).toBeUndefined();
|
|
296
|
+
expect(props.hitbox).toBeUndefined();
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
test("an arc renders a source from its endpoints", async () => {
|
|
300
|
+
await renderMap(
|
|
301
|
+
<Map center={WELLINGTON} testID="map-root" zoom={12}>
|
|
302
|
+
<Map.Arc from={WELLINGTON} to={[174.8, -41.3]} />
|
|
303
|
+
</Map>
|
|
304
|
+
);
|
|
305
|
+
expect(screen.getByTestId("maplibre-GeoJSONSource")).toBeOnTheScreen();
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
type PositionListener = Parameters<typeof LocationManager.addListener>[0];
|
|
310
|
+
|
|
311
|
+
describe("location", () => {
|
|
312
|
+
let listeners: PositionListener[];
|
|
313
|
+
let addListener: jest.SpiedFunction<typeof LocationManager.addListener>;
|
|
314
|
+
let removeListener: jest.SpiedFunction<typeof LocationManager.removeListener>;
|
|
315
|
+
let requestPermissions: jest.SpiedFunction<typeof LocationManager.requestPermissions>;
|
|
316
|
+
|
|
317
|
+
beforeEach(() => {
|
|
318
|
+
listeners = [];
|
|
319
|
+
requestPermissions = jest.spyOn(LocationManager, "requestPermissions");
|
|
320
|
+
addListener = jest.spyOn(LocationManager, "addListener").mockImplementation((listener) => {
|
|
321
|
+
listeners.push(listener);
|
|
322
|
+
});
|
|
323
|
+
removeListener = jest.spyOn(LocationManager, "removeListener");
|
|
324
|
+
});
|
|
325
|
+
afterEach(() => {
|
|
326
|
+
jest.restoreAllMocks();
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
const fix = (
|
|
330
|
+
longitude: number,
|
|
331
|
+
latitude: number,
|
|
332
|
+
heading: number | null = null
|
|
333
|
+
): PositionListener extends (position: infer P) => void ? P : never =>
|
|
334
|
+
({ coords: { heading, latitude, longitude }, timestamp: 0 }) as never;
|
|
335
|
+
|
|
336
|
+
const deliver = async (longitude: number, latitude: number) => {
|
|
337
|
+
await act(async () => {
|
|
338
|
+
for (const listener of listeners) listener(fix(longitude, latitude));
|
|
339
|
+
});
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
test("showLocate requests permission, listens, and labels the locate button", async () => {
|
|
343
|
+
const view = await renderMap(
|
|
344
|
+
<Map center={WELLINGTON} testID="map-root" zoom={12}>
|
|
345
|
+
<Map.Controls showLocate />
|
|
346
|
+
</Map>
|
|
347
|
+
);
|
|
348
|
+
expect(screen.getByRole("button", { name: "Show my location" })).toBeOnTheScreen();
|
|
349
|
+
expect(requestPermissions).toHaveBeenCalledTimes(1);
|
|
350
|
+
expect(addListener).toHaveBeenCalledTimes(1);
|
|
351
|
+
|
|
352
|
+
await view.unmount();
|
|
353
|
+
expect(removeListener).toHaveBeenCalledWith(listeners[0]);
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
test("without showLocate nothing asks for location", async () => {
|
|
357
|
+
await renderMap(
|
|
358
|
+
<Map center={WELLINGTON} testID="map-root" zoom={12}>
|
|
359
|
+
<Map.Controls />
|
|
360
|
+
</Map>
|
|
361
|
+
);
|
|
362
|
+
expect(requestPermissions).not.toHaveBeenCalled();
|
|
363
|
+
expect(addListener).not.toHaveBeenCalled();
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
test("a locate press after a fix calls onLocate with it", async () => {
|
|
367
|
+
const onLocate = jest.fn();
|
|
368
|
+
await renderMap(
|
|
369
|
+
<Map center={WELLINGTON} testID="map-root" zoom={12}>
|
|
370
|
+
<Map.Controls onLocate={onLocate} showLocate />
|
|
371
|
+
</Map>
|
|
372
|
+
);
|
|
373
|
+
await deliver(174.9, -41.4);
|
|
374
|
+
await fireEvent(screen.getByRole("button", { name: "Show my location" }), "accessibilityTap");
|
|
375
|
+
expect(onLocate).toHaveBeenCalledWith([174.9, -41.4]);
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
test("a locate press before the first fix waits for it", async () => {
|
|
379
|
+
const onLocate = jest.fn();
|
|
380
|
+
await renderMap(
|
|
381
|
+
<Map center={WELLINGTON} testID="map-root" zoom={12}>
|
|
382
|
+
<Map.Controls onLocate={onLocate} showLocate />
|
|
383
|
+
</Map>
|
|
384
|
+
);
|
|
385
|
+
await fireEvent(screen.getByRole("button", { name: "Show my location" }), "accessibilityTap");
|
|
386
|
+
expect(onLocate).not.toHaveBeenCalled();
|
|
387
|
+
await deliver(174.9, -41.4);
|
|
388
|
+
expect(onLocate).toHaveBeenCalledTimes(1);
|
|
389
|
+
expect(onLocate).toHaveBeenCalledWith([174.9, -41.4]);
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
test("Map.UserLocation draws nothing until a fix, then the dot, and lets go on unmount", async () => {
|
|
393
|
+
const view = await renderMap(
|
|
394
|
+
<Map center={WELLINGTON} testID="map-root" zoom={12}>
|
|
395
|
+
<Map.UserLocation />
|
|
396
|
+
</Map>
|
|
397
|
+
);
|
|
398
|
+
expect(requestPermissions).toHaveBeenCalledTimes(1);
|
|
399
|
+
expect(screen.queryByTestId("maplibre-GeoJSONSource")).not.toBeOnTheScreen();
|
|
400
|
+
|
|
401
|
+
await deliver(174.9, -41.4);
|
|
402
|
+
expect(screen.getByTestId("maplibre-GeoJSONSource")).toBeOnTheScreen();
|
|
403
|
+
expect(screen.queryByTestId("maplibre-Marker")).not.toBeOnTheScreen();
|
|
404
|
+
|
|
405
|
+
await view.rerender(<Map center={WELLINGTON} testID="map-root" zoom={12} />);
|
|
406
|
+
expect(removeListener).toHaveBeenCalledWith(listeners[0]);
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
test("the heading cone shows only with showsHeading and a known heading", async () => {
|
|
410
|
+
await renderMap(
|
|
411
|
+
<Map center={WELLINGTON} testID="map-root" zoom={12}>
|
|
412
|
+
<Map.UserLocation showsHeading />
|
|
413
|
+
</Map>
|
|
414
|
+
);
|
|
415
|
+
await act(async () => {
|
|
416
|
+
for (const listener of listeners) listener(fix(174.9, -41.4, null));
|
|
417
|
+
});
|
|
418
|
+
expect(screen.queryByTestId("maplibre-Marker")).not.toBeOnTheScreen();
|
|
419
|
+
|
|
420
|
+
await act(async () => {
|
|
421
|
+
for (const listener of listeners) listener(fix(174.9, -41.4, 90));
|
|
422
|
+
});
|
|
423
|
+
expect(screen.getByTestId("maplibre-Marker")).toBeOnTheScreen();
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
test("Map.UserLocation outside a Map throws its documented error", async () => {
|
|
427
|
+
const consoleError = console.error;
|
|
428
|
+
console.error = () => undefined;
|
|
429
|
+
try {
|
|
430
|
+
await expect(renderWithProviders(<Map.UserLocation />)).rejects.toThrow(
|
|
431
|
+
"Map.UserLocation must be rendered inside a <Map>."
|
|
432
|
+
);
|
|
433
|
+
} finally {
|
|
434
|
+
console.error = consoleError;
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
describe("compound parts outside a Map", () => {
|
|
440
|
+
const parts: ReadonlyArray<[string, ReactElement, string]> = [
|
|
441
|
+
["Map.Marker", <Map.Marker key="m" lngLat={WELLINGTON} />, "Map.Marker must be rendered inside a <Map>."],
|
|
442
|
+
["Map.Popup", <Map.Popup key="p" lngLat={WELLINGTON} />, "Map.Popup must be rendered inside a <Map>."],
|
|
443
|
+
["Map.Controls", <Map.Controls key="c" />, "Map.Controls must be rendered inside a <Map>."],
|
|
444
|
+
["Map.Route", <Map.Route coordinates={[WELLINGTON]} key="r" />, "Map.Route must be rendered inside a <Map>."],
|
|
445
|
+
["useMap", <FindOnMap key="u" />, "useMap must be called inside a <Map>."],
|
|
446
|
+
];
|
|
447
|
+
|
|
448
|
+
let consoleError: typeof console.error;
|
|
449
|
+
beforeEach(() => {
|
|
450
|
+
consoleError = console.error;
|
|
451
|
+
console.error = () => undefined;
|
|
452
|
+
});
|
|
453
|
+
afterEach(() => {
|
|
454
|
+
console.error = consoleError;
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
test.each(parts)("%s throws its documented error", async (_name, element, message) => {
|
|
458
|
+
await expect(renderWithProviders(element)).rejects.toThrow(message);
|
|
459
|
+
});
|
|
460
|
+
});
|
|
@@ -24,6 +24,7 @@ parts.
|
|
|
24
24
|
| `markdown-editor-preview.tsx` | `MarkdownEditor.Preview` — the preview pane |
|
|
25
25
|
| `markdown-editor-render.tsx` | Internal: parsed blocks → `Text` presets |
|
|
26
26
|
| `*.test.ts` | Commands, parser, variants |
|
|
27
|
+
| `markdown-editor.render.test.tsx` | Mounted under Jest — toolbar actions through `accessibilityTap`, the caret lighting a toggle (`accessibilityState.checked`), controlled and uncontrolled value and mode, preview output, link allow-list, disabled / read-only / `Field` cascade, the handle, `useMarkdownEditor`, parts outside the root throwing. The `activate` action is Android-only and not driven (Jest reports iOS) |
|
|
27
28
|
|
|
28
29
|
## Design
|
|
29
30
|
|