@yext/visual-editor 2.0.0-beta.12 → 2.0.0-beta.13
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/dist/{SectionLibraryVisualEditorProvider-DJezMczO.js → SectionLibraryVisualEditorProvider-64whofF8.js} +3128 -3105
- package/dist/cli/assets/directory-locator-source/components/sections/locator/Filters.test.tsx +1 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/Filters.tsx +9 -8
- package/dist/cli/assets/directory-locator-source/components/sections/locator/Locator.tsx +61 -1
- package/dist/cli/assets/directory-locator-source/components/sections/locator/LocatorFields.test.ts +66 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/LocatorRadius.test.ts +316 -34
- package/dist/cli/assets/directory-locator-source/components/sections/locator/LocatorResultCard.tsx +4 -1
- package/dist/cli/assets/directory-locator-source/components/sections/locator/LocatorWrapper.test.ts +370 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/LocatorWrapper.tsx +223 -25
- package/dist/cli/assets/directory-locator-source/components/sections/locator/Map.tsx +91 -12
- package/dist/cli/assets/directory-locator-source/components/sections/locator/Results.tsx +11 -6
- package/dist/cli/assets/directory-locator-source/components/sections/locator/distanceUnits.ts +7 -0
- package/dist/cli/yextve.js +1 -1
- package/dist/{createYextFieldTransforms-B3f0jVg6.d.ts → createYextFieldTransforms-w-U4b5Zf.d.ts} +5 -2
- package/dist/index.d.ts +20 -4
- package/dist/locales/platform/cs/visual-editor.json +6 -0
- package/dist/locales/platform/da/visual-editor.json +6 -0
- package/dist/locales/platform/de/visual-editor.json +6 -0
- package/dist/locales/platform/en/visual-editor.json +6 -0
- package/dist/locales/platform/en-GB/visual-editor.json +6 -0
- package/dist/locales/platform/es/visual-editor.json +6 -0
- package/dist/locales/platform/et/visual-editor.json +6 -0
- package/dist/locales/platform/fi/visual-editor.json +6 -0
- package/dist/locales/platform/fr/visual-editor.json +6 -0
- package/dist/locales/platform/hr/visual-editor.json +6 -0
- package/dist/locales/platform/hu/visual-editor.json +6 -0
- package/dist/locales/platform/it/visual-editor.json +6 -0
- package/dist/locales/platform/ja/visual-editor.json +6 -0
- package/dist/locales/platform/lt/visual-editor.json +6 -0
- package/dist/locales/platform/lv/visual-editor.json +6 -0
- package/dist/locales/platform/nb/visual-editor.json +6 -0
- package/dist/locales/platform/nl/visual-editor.json +6 -0
- package/dist/locales/platform/pl/visual-editor.json +6 -0
- package/dist/locales/platform/pt/visual-editor.json +6 -0
- package/dist/locales/platform/ro/visual-editor.json +6 -0
- package/dist/locales/platform/sk/visual-editor.json +6 -0
- package/dist/locales/platform/sv/visual-editor.json +6 -0
- package/dist/locales/platform/tr/visual-editor.json +6 -0
- package/dist/locales/platform/zh/visual-editor.json +6 -0
- package/dist/locales/platform/zh-TW/visual-editor.json +6 -0
- package/dist/section-library-support.js +55 -55
- package/dist/sectionLibrarySupport.d.ts +2 -2
- package/dist/{visual-editor-DuxrpEsM.js → visual-editor-B84T0Hz5.js} +67 -61
- package/dist/{visual-editor-bjHpuHcP.js → visual-editor-B8eVGZjZ.js} +6 -0
- package/dist/{visual-editor-89bNoCOk.js → visual-editor-BTv1Bren.js} +58 -52
- package/dist/{visual-editor-BWDv00Sj.js → visual-editor-BWJvQ6QT.js} +100 -94
- package/dist/{visual-editor-BPOG2TRh.js → visual-editor-BWk-Ri1i.js} +69 -63
- package/dist/{visual-editor-DuH1uy-p.js → visual-editor-BdM7VUac.js} +57 -51
- package/dist/{visual-editor-D_Xqs07E.js → visual-editor-BmM2bYhg.js} +92 -86
- package/dist/{visual-editor-CiE_sZgp.js → visual-editor-BuRftlWt.js} +79 -73
- package/dist/{visual-editor-BEiQqs_Z.js → visual-editor-BxnbtD_z.js} +59 -53
- package/dist/{visual-editor-DVI-AF67.js → visual-editor-C4Nretnd.js} +34 -28
- package/dist/{visual-editor-BmfXE4Nt.js → visual-editor-CFE4ijeV.js} +36 -30
- package/dist/{visual-editor-CJMynoK2.js → visual-editor-CMfDvLU2.js} +49 -43
- package/dist/{visual-editor-DSYNp8sQ.js → visual-editor-CauX7_Ur.js} +23 -17
- package/dist/{visual-editor-C5aegP-t.js → visual-editor-D5d9meOo.js} +22 -16
- package/dist/{visual-editor-dWLAQOr6.js → visual-editor-D9U8TxD-.js} +47 -41
- package/dist/{visual-editor-C_SC4gLo.js → visual-editor-DBZwjDQd.js} +43 -37
- package/dist/{visual-editor-TsYZAz_J.js → visual-editor-DI6rS2dP.js} +112 -106
- package/dist/{visual-editor-8Okvw03s.js → visual-editor-DOioJ5CW.js} +62 -56
- package/dist/{visual-editor-BfzO6vuG.js → visual-editor-D_EvXM08.js} +48 -42
- package/dist/{visual-editor-yqgcCbY4.js → visual-editor-DguhAL12.js} +6 -0
- package/dist/{visual-editor-C7Ne5NW6.js → visual-editor-DmsRSmAI.js} +54 -48
- package/dist/{visual-editor-B-9-8VqT.js → visual-editor-DnNNHiLS.js} +49 -43
- package/dist/{visual-editor-Crc50YSl.js → visual-editor-DvksDrGT.js} +36 -30
- package/dist/{visual-editor-DcNe0Txh.js → visual-editor-XsBMHUSs.js} +62 -56
- package/dist/{visual-editor-d-SdfYpR.js → visual-editor-kiT3ocKi.js} +36 -30
- package/dist/visual-editor.js +6727 -6388
- package/package.json +1 -1
package/dist/cli/assets/directory-locator-source/components/sections/locator/LocatorResultCard.tsx
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
import { Body, BodyProps } from "../../atoms/body.tsx";
|
|
16
16
|
import { CTA, CTAVariant } from "../../atoms/cta.tsx";
|
|
17
17
|
import { Heading } from "../../atoms/heading.tsx";
|
|
18
|
+
import type { DistanceUnit } from "./distanceUnits.ts";
|
|
18
19
|
import { Image } from "../../atoms/image.tsx";
|
|
19
20
|
import { msg, pt } from "../../../utils/i18n/platform.ts";
|
|
20
21
|
import { PhoneAtom } from "../../atoms/phone.tsx";
|
|
@@ -846,12 +847,14 @@ export const LocatorResultCard = React.memo(
|
|
|
846
847
|
result,
|
|
847
848
|
resultCardProps: props,
|
|
848
849
|
distanceDisplay = "distanceFromUser",
|
|
850
|
+
distanceUnit,
|
|
849
851
|
searchLocationName,
|
|
850
852
|
isSelected,
|
|
851
853
|
}: {
|
|
852
854
|
result: CardProps<Location>["result"];
|
|
853
855
|
resultCardProps: LocatorResultCardProps;
|
|
854
856
|
distanceDisplay?: DistanceDisplayOption;
|
|
857
|
+
distanceUnit?: DistanceUnit;
|
|
855
858
|
searchLocationName?: string;
|
|
856
859
|
isSelected?: boolean;
|
|
857
860
|
}): React.JSX.Element => {
|
|
@@ -869,7 +872,7 @@ export const LocatorResultCard = React.memo(
|
|
|
869
872
|
? result.distanceFromFilter
|
|
870
873
|
: undefined;
|
|
871
874
|
|
|
872
|
-
const unit = getPreferredDistanceUnit(i18n.language);
|
|
875
|
+
const unit = distanceUnit ?? getPreferredDistanceUnit(i18n.language);
|
|
873
876
|
const unitLabel = unit === "mile" ? "mi" : "km"; // Abbreviations do not need translation
|
|
874
877
|
const displayDistance =
|
|
875
878
|
typeof distance === "number"
|
package/dist/cli/assets/directory-locator-source/components/sections/locator/LocatorWrapper.test.ts
ADDED
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import {
|
|
3
|
+
act,
|
|
4
|
+
cleanup,
|
|
5
|
+
fireEvent,
|
|
6
|
+
render,
|
|
7
|
+
screen,
|
|
8
|
+
} from "@testing-library/react";
|
|
9
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
10
|
+
import type { OnDragHandler, OnSelectParams } from "@yext/search-ui-react";
|
|
11
|
+
import type { State } from "@yext/search-headless-react";
|
|
12
|
+
import type { WithPuckProps } from "@puckeditor/core";
|
|
13
|
+
import type { StreamDocument } from "../../../utils/types/StreamDocument.ts";
|
|
14
|
+
import type { LocatorProps } from "./Locator.tsx";
|
|
15
|
+
import { LocatorWrapper } from "./LocatorWrapper.tsx";
|
|
16
|
+
|
|
17
|
+
const mocks = vi.hoisted(() => ({
|
|
18
|
+
streamDocument: { id: "locator", locale: "en" } as StreamDocument,
|
|
19
|
+
onDrag: undefined as OnDragHandler | undefined,
|
|
20
|
+
cameraPolicy: undefined as React.MutableRefObject<boolean> | undefined,
|
|
21
|
+
onSelect: undefined as ((params: OnSelectParams) => void) | undefined,
|
|
22
|
+
onOpenNow: undefined as ((selected: boolean) => void) | undefined,
|
|
23
|
+
onCurrentLocation: undefined as
|
|
24
|
+
((position: GeolocationPosition) => void) | undefined,
|
|
25
|
+
actions: {
|
|
26
|
+
setSessionTrackingEnabled: vi.fn(),
|
|
27
|
+
setFacetAllowList: vi.fn(),
|
|
28
|
+
setVerticalLimit: vi.fn(),
|
|
29
|
+
setOffset: vi.fn(),
|
|
30
|
+
setStaticFilters: vi.fn(),
|
|
31
|
+
setFilterOption: vi.fn(),
|
|
32
|
+
executeVerticalQuery: vi.fn(),
|
|
33
|
+
},
|
|
34
|
+
state: {
|
|
35
|
+
vertical: { results: [], resultsCount: 0, offset: 0 },
|
|
36
|
+
filters: { static: [], facets: [] },
|
|
37
|
+
searchStatus: { isLoading: false },
|
|
38
|
+
},
|
|
39
|
+
}));
|
|
40
|
+
|
|
41
|
+
vi.mock("../../../hooks/useDocument.tsx", () => ({
|
|
42
|
+
useDocument: (): StreamDocument => mocks.streamDocument,
|
|
43
|
+
}));
|
|
44
|
+
vi.mock("../../../utils/searchHeadlessConfig.ts", () => ({
|
|
45
|
+
createSearchHeadlessConfig: () => ({}),
|
|
46
|
+
createSearchAnalyticsConfig: () => ({}),
|
|
47
|
+
}));
|
|
48
|
+
vi.mock("react-i18next", async (importOriginal) => ({
|
|
49
|
+
...(await importOriginal<typeof import("react-i18next")>()),
|
|
50
|
+
useTranslation: () => ({
|
|
51
|
+
t: (_key: string, fallback: string): string => fallback,
|
|
52
|
+
i18n: { language: "en" },
|
|
53
|
+
}),
|
|
54
|
+
}));
|
|
55
|
+
vi.mock("@yext/pages-components", async (importOriginal) => ({
|
|
56
|
+
...(await importOriginal<typeof import("@yext/pages-components")>()),
|
|
57
|
+
useAnalytics: () => undefined,
|
|
58
|
+
}));
|
|
59
|
+
vi.mock("@yext/search-headless-react", async (importOriginal) => ({
|
|
60
|
+
...(await importOriginal<typeof import("@yext/search-headless-react")>()),
|
|
61
|
+
provideHeadless: () => mocks.actions,
|
|
62
|
+
useSearchActions: () => mocks.actions,
|
|
63
|
+
useSearchState: (selector: (state: State) => unknown): unknown =>
|
|
64
|
+
selector(mocks.state as unknown as State),
|
|
65
|
+
SearchHeadlessProvider: ({ children }: React.PropsWithChildren) => children,
|
|
66
|
+
}));
|
|
67
|
+
vi.mock("@yext/search-ui-react", async (importOriginal) => ({
|
|
68
|
+
...(await importOriginal<typeof import("@yext/search-ui-react")>()),
|
|
69
|
+
AnalyticsProvider: ({ children }: React.PropsWithChildren) => children,
|
|
70
|
+
SearchI18nextProvider: ({ children }: React.PropsWithChildren) => children,
|
|
71
|
+
useAnalytics: () => undefined,
|
|
72
|
+
executeSearch: (): void => {
|
|
73
|
+
mocks.actions.executeVerticalQuery();
|
|
74
|
+
},
|
|
75
|
+
AppliedFilters: () => null,
|
|
76
|
+
FilterSearch: (props: {
|
|
77
|
+
onSelect: typeof mocks.onSelect;
|
|
78
|
+
geolocationProps: { handleClick: typeof mocks.onCurrentLocation };
|
|
79
|
+
}) => {
|
|
80
|
+
mocks.onSelect = props.onSelect;
|
|
81
|
+
mocks.onCurrentLocation = props.geolocationProps.handleClick;
|
|
82
|
+
return null;
|
|
83
|
+
},
|
|
84
|
+
}));
|
|
85
|
+
vi.mock("./Map.tsx", async (importOriginal) => ({
|
|
86
|
+
...(await importOriginal<typeof import("./Map.tsx")>()),
|
|
87
|
+
LocatorMap: ({
|
|
88
|
+
onDragHandler,
|
|
89
|
+
preserveMapView,
|
|
90
|
+
}: {
|
|
91
|
+
onDragHandler: OnDragHandler;
|
|
92
|
+
preserveMapView: React.MutableRefObject<boolean>;
|
|
93
|
+
}) => {
|
|
94
|
+
mocks.cameraPolicy = preserveMapView;
|
|
95
|
+
mocks.onDrag = onDragHandler;
|
|
96
|
+
return null;
|
|
97
|
+
},
|
|
98
|
+
}));
|
|
99
|
+
vi.mock("./Filters.tsx", async (importOriginal) => ({
|
|
100
|
+
...(await importOriginal<typeof import("./Filters.tsx")>()),
|
|
101
|
+
FilterModal: ({
|
|
102
|
+
handleOpenNowClick,
|
|
103
|
+
}: {
|
|
104
|
+
handleOpenNowClick: (selected: boolean) => void;
|
|
105
|
+
}) => {
|
|
106
|
+
mocks.onOpenNow = handleOpenNowClick;
|
|
107
|
+
return null;
|
|
108
|
+
},
|
|
109
|
+
}));
|
|
110
|
+
vi.mock("./Results.tsx", () => ({
|
|
111
|
+
RESULTS_LIMIT: 20,
|
|
112
|
+
ResultsCountSummary: () => null,
|
|
113
|
+
}));
|
|
114
|
+
|
|
115
|
+
/** Send the map callback with a center and a radius in meters. */
|
|
116
|
+
const moveMap = (latitude: number, radius: number): void => {
|
|
117
|
+
act((): void => {
|
|
118
|
+
mocks.onDrag?.(
|
|
119
|
+
{
|
|
120
|
+
latitude,
|
|
121
|
+
longitude: -74,
|
|
122
|
+
distanceTo: (): number => radius,
|
|
123
|
+
} as unknown as Parameters<OnDragHandler>[0],
|
|
124
|
+
{
|
|
125
|
+
getNorthEast: () => ({ latitude: latitude + 1, longitude: -73 }),
|
|
126
|
+
} as Parameters<OnDragHandler>[1]
|
|
127
|
+
);
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
describe("Locator map search", () => {
|
|
132
|
+
beforeEach((): void => {
|
|
133
|
+
vi.useFakeTimers();
|
|
134
|
+
vi.clearAllMocks();
|
|
135
|
+
mocks.streamDocument.__ = undefined;
|
|
136
|
+
mocks.onDrag = undefined;
|
|
137
|
+
window.history.replaceState({}, "", "/?q=40,-74,10000&ref=test");
|
|
138
|
+
});
|
|
139
|
+
afterEach((): void => {
|
|
140
|
+
cleanup();
|
|
141
|
+
vi.useRealTimers();
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it.each([undefined, false, true])(
|
|
145
|
+
"when autoSearchOnMapMove is %s then map search uses the selected mode",
|
|
146
|
+
(autoSearchOnMapMove): void => {
|
|
147
|
+
render(
|
|
148
|
+
React.createElement(LocatorWrapper, {
|
|
149
|
+
autoSearchOnMapMove,
|
|
150
|
+
filters: { openNowButton: false, showDistanceOptions: false },
|
|
151
|
+
resultCard: [],
|
|
152
|
+
locationStyles: [],
|
|
153
|
+
puck: {
|
|
154
|
+
metadata: {},
|
|
155
|
+
isEditing: false,
|
|
156
|
+
dragRef: null,
|
|
157
|
+
renderDropZone: () => null,
|
|
158
|
+
},
|
|
159
|
+
} as WithPuckProps<LocatorProps>)
|
|
160
|
+
);
|
|
161
|
+
expect(mocks.actions.executeVerticalQuery).toHaveBeenCalledTimes(1);
|
|
162
|
+
act((): void => {
|
|
163
|
+
vi.advanceTimersByTime(1000);
|
|
164
|
+
});
|
|
165
|
+
expect(mocks.actions.executeVerticalQuery).toHaveBeenCalledTimes(1);
|
|
166
|
+
moveMap(41, 5000);
|
|
167
|
+
act((): void => {
|
|
168
|
+
vi.advanceTimersByTime(400);
|
|
169
|
+
});
|
|
170
|
+
moveMap(42, 2000);
|
|
171
|
+
act((): void => {
|
|
172
|
+
vi.advanceTimersByTime(499);
|
|
173
|
+
});
|
|
174
|
+
expect(mocks.actions.executeVerticalQuery).toHaveBeenCalledTimes(1);
|
|
175
|
+
act((): void => {
|
|
176
|
+
vi.advanceTimersByTime(1);
|
|
177
|
+
});
|
|
178
|
+
if (!autoSearchOnMapMove) {
|
|
179
|
+
expect(mocks.actions.executeVerticalQuery).toHaveBeenCalledTimes(1);
|
|
180
|
+
fireEvent.click(
|
|
181
|
+
screen.getByRole("button", { name: "Search This Area" })
|
|
182
|
+
);
|
|
183
|
+
} else {
|
|
184
|
+
expect(
|
|
185
|
+
screen.queryByRole("button", { name: "Search This Area" })
|
|
186
|
+
).toBeNull();
|
|
187
|
+
}
|
|
188
|
+
expect(mocks.actions.executeVerticalQuery).toHaveBeenCalledTimes(2);
|
|
189
|
+
expect(mocks.cameraPolicy?.current).toBe(!!autoSearchOnMapMove);
|
|
190
|
+
expect(mocks.actions.setOffset).toHaveBeenLastCalledWith(0);
|
|
191
|
+
expect(mocks.actions.setStaticFilters).toHaveBeenLastCalledWith([
|
|
192
|
+
expect.objectContaining({
|
|
193
|
+
filter: expect.objectContaining({
|
|
194
|
+
value: {
|
|
195
|
+
lat: 42,
|
|
196
|
+
lng: -74,
|
|
197
|
+
radius: 2000,
|
|
198
|
+
name: "Custom Search Area",
|
|
199
|
+
},
|
|
200
|
+
}),
|
|
201
|
+
}),
|
|
202
|
+
expect.objectContaining({ selected: false }),
|
|
203
|
+
]);
|
|
204
|
+
expect(new URLSearchParams(window.location.search).get("q")).toBe(
|
|
205
|
+
"42,-74,2000"
|
|
206
|
+
);
|
|
207
|
+
expect(new URLSearchParams(window.location.search).get("ref")).toBe(
|
|
208
|
+
"test"
|
|
209
|
+
);
|
|
210
|
+
act((): void => {
|
|
211
|
+
vi.advanceTimersByTime(1000);
|
|
212
|
+
});
|
|
213
|
+
expect(mocks.actions.executeVerticalQuery).toHaveBeenCalledTimes(2);
|
|
214
|
+
}
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
it.each([
|
|
218
|
+
"disable",
|
|
219
|
+
"disableMap",
|
|
220
|
+
"unmount",
|
|
221
|
+
"navigate",
|
|
222
|
+
"select",
|
|
223
|
+
"geolocate",
|
|
224
|
+
])(
|
|
225
|
+
"when %s occurs then the pending map search is canceled",
|
|
226
|
+
(action): void => {
|
|
227
|
+
const props = {
|
|
228
|
+
autoSearchOnMapMove: true,
|
|
229
|
+
filters: { openNowButton: false, showDistanceOptions: false },
|
|
230
|
+
resultCard: [],
|
|
231
|
+
locationStyles: [],
|
|
232
|
+
puck: {
|
|
233
|
+
metadata: {},
|
|
234
|
+
isEditing: false,
|
|
235
|
+
dragRef: null,
|
|
236
|
+
renderDropZone: () => null,
|
|
237
|
+
},
|
|
238
|
+
} as WithPuckProps<LocatorProps>;
|
|
239
|
+
const { rerender, unmount } = render(
|
|
240
|
+
React.createElement(LocatorWrapper, props)
|
|
241
|
+
);
|
|
242
|
+
moveMap(41, 5000);
|
|
243
|
+
act((): void => {
|
|
244
|
+
vi.advanceTimersByTime(400);
|
|
245
|
+
});
|
|
246
|
+
act((): void => {
|
|
247
|
+
if (action === "disable") {
|
|
248
|
+
rerender(
|
|
249
|
+
React.createElement(LocatorWrapper, {
|
|
250
|
+
...props,
|
|
251
|
+
autoSearchOnMapMove: false,
|
|
252
|
+
})
|
|
253
|
+
);
|
|
254
|
+
} else if (action === "disableMap") {
|
|
255
|
+
(window as unknown as { disableMap: () => void }).disableMap();
|
|
256
|
+
} else if (action === "unmount") {
|
|
257
|
+
unmount();
|
|
258
|
+
} else if (action === "navigate") {
|
|
259
|
+
window.history.replaceState({}, "", "/?q=39,-73,3000");
|
|
260
|
+
window.dispatchEvent(new PopStateEvent("popstate"));
|
|
261
|
+
} else if (action === "select") {
|
|
262
|
+
mocks.onSelect?.({
|
|
263
|
+
newDisplayName: "Boston",
|
|
264
|
+
newFilter: {
|
|
265
|
+
kind: "fieldValue",
|
|
266
|
+
fieldId: "builtin.location",
|
|
267
|
+
matcher: "$near",
|
|
268
|
+
value: { lat: 42, lng: -71, radius: 3000 },
|
|
269
|
+
},
|
|
270
|
+
} as OnSelectParams);
|
|
271
|
+
} else {
|
|
272
|
+
mocks.onCurrentLocation?.({
|
|
273
|
+
coords: { latitude: 43, longitude: -72, accuracy: 100 },
|
|
274
|
+
} as GeolocationPosition);
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
const searchCount = mocks.actions.executeVerticalQuery.mock.calls.length;
|
|
278
|
+
act((): void => {
|
|
279
|
+
vi.advanceTimersByTime(1000);
|
|
280
|
+
});
|
|
281
|
+
expect(mocks.actions.executeVerticalQuery).toHaveBeenCalledTimes(
|
|
282
|
+
searchCount
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
it("when Open Now changes during the delay then map search uses the current filter", (): void => {
|
|
288
|
+
render(
|
|
289
|
+
React.createElement(LocatorWrapper, {
|
|
290
|
+
autoSearchOnMapMove: true,
|
|
291
|
+
filters: { openNowButton: true, showDistanceOptions: false },
|
|
292
|
+
resultCard: [],
|
|
293
|
+
locationStyles: [],
|
|
294
|
+
puck: {
|
|
295
|
+
metadata: {},
|
|
296
|
+
isEditing: false,
|
|
297
|
+
dragRef: null,
|
|
298
|
+
renderDropZone: () => null,
|
|
299
|
+
},
|
|
300
|
+
} as WithPuckProps<LocatorProps>)
|
|
301
|
+
);
|
|
302
|
+
moveMap(41, 5000);
|
|
303
|
+
act((): void => {
|
|
304
|
+
vi.advanceTimersByTime(400);
|
|
305
|
+
});
|
|
306
|
+
act((): void => {
|
|
307
|
+
mocks.onOpenNow?.(true);
|
|
308
|
+
});
|
|
309
|
+
expect(mocks.actions.executeVerticalQuery).toHaveBeenCalledTimes(2);
|
|
310
|
+
act((): void => {
|
|
311
|
+
vi.advanceTimersByTime(100);
|
|
312
|
+
});
|
|
313
|
+
expect(mocks.actions.executeVerticalQuery).toHaveBeenCalledTimes(3);
|
|
314
|
+
expect(mocks.actions.setStaticFilters).toHaveBeenLastCalledWith([
|
|
315
|
+
expect.objectContaining({
|
|
316
|
+
filter: expect.objectContaining({
|
|
317
|
+
value: expect.objectContaining({ lat: 41, radius: 5000 }),
|
|
318
|
+
}),
|
|
319
|
+
}),
|
|
320
|
+
expect.objectContaining({ selected: true }),
|
|
321
|
+
]);
|
|
322
|
+
});
|
|
323
|
+
it.each(["select", "geolocate", "navigate", "filter"])(
|
|
324
|
+
"when %s follows automatic area search then camera changes are allowed",
|
|
325
|
+
(action: string): void => {
|
|
326
|
+
render(
|
|
327
|
+
React.createElement(LocatorWrapper, {
|
|
328
|
+
autoSearchOnMapMove: true,
|
|
329
|
+
filters: { openNowButton: true, showDistanceOptions: false },
|
|
330
|
+
resultCard: [],
|
|
331
|
+
locationStyles: [],
|
|
332
|
+
puck: {
|
|
333
|
+
metadata: {},
|
|
334
|
+
isEditing: false,
|
|
335
|
+
dragRef: null,
|
|
336
|
+
renderDropZone: () => null,
|
|
337
|
+
},
|
|
338
|
+
} as WithPuckProps<LocatorProps>)
|
|
339
|
+
);
|
|
340
|
+
moveMap(41, 5000);
|
|
341
|
+
act((): void => {
|
|
342
|
+
vi.advanceTimersByTime(500);
|
|
343
|
+
});
|
|
344
|
+
expect(mocks.cameraPolicy?.current).toBe(true);
|
|
345
|
+
act((): void => {
|
|
346
|
+
if (action === "select") {
|
|
347
|
+
mocks.onSelect?.({
|
|
348
|
+
newDisplayName: "Boston",
|
|
349
|
+
newFilter: {
|
|
350
|
+
kind: "fieldValue",
|
|
351
|
+
fieldId: "builtin.location",
|
|
352
|
+
matcher: "$near",
|
|
353
|
+
value: { lat: 42, lng: -71, radius: 3000 },
|
|
354
|
+
},
|
|
355
|
+
} as OnSelectParams);
|
|
356
|
+
} else if (action === "geolocate") {
|
|
357
|
+
mocks.onCurrentLocation?.({
|
|
358
|
+
coords: { latitude: 43, longitude: -72, accuracy: 100 },
|
|
359
|
+
} as GeolocationPosition);
|
|
360
|
+
} else if (action === "navigate") {
|
|
361
|
+
window.history.replaceState({}, "", "/?q=39,-73,3000");
|
|
362
|
+
window.dispatchEvent(new PopStateEvent("popstate"));
|
|
363
|
+
} else {
|
|
364
|
+
mocks.onOpenNow?.(true);
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
expect(mocks.cameraPolicy?.current).toBe(false);
|
|
368
|
+
}
|
|
369
|
+
);
|
|
370
|
+
});
|