@yext/visual-editor 2.0.0-beta.11 → 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-DJMXab-H.js → SectionLibraryVisualEditorProvider-64whofF8.js} +5861 -5761
- 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.test.tsx +1 -1
- package/dist/cli/assets/directory-locator-source/components/sections/locator/Locator.tsx +104 -0
- 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 +700 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/LocatorResultCard.tsx +29 -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 +270 -39
- 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/assets/directory-locator-source/sectionLibrarySupport.ts +4 -0
- package/dist/cli/yextve.js +3 -3
- package/dist/{createYextFieldTransforms-B7vqqb3m.d.ts → createYextFieldTransforms-w-U4b5Zf.d.ts} +27 -17
- package/dist/index.d.ts +36 -11
- package/dist/locales/platform/cs/visual-editor.json +10 -0
- package/dist/locales/platform/da/visual-editor.json +10 -0
- package/dist/locales/platform/de/visual-editor.json +10 -0
- package/dist/locales/platform/en/visual-editor.json +10 -0
- package/dist/locales/platform/en-GB/visual-editor.json +10 -0
- package/dist/locales/platform/es/visual-editor.json +10 -0
- package/dist/locales/platform/et/visual-editor.json +10 -0
- package/dist/locales/platform/fi/visual-editor.json +10 -0
- package/dist/locales/platform/fr/visual-editor.json +10 -0
- package/dist/locales/platform/hr/visual-editor.json +10 -0
- package/dist/locales/platform/hu/visual-editor.json +10 -0
- package/dist/locales/platform/it/visual-editor.json +10 -0
- package/dist/locales/platform/ja/visual-editor.json +10 -0
- package/dist/locales/platform/lt/visual-editor.json +10 -0
- package/dist/locales/platform/lv/visual-editor.json +10 -0
- package/dist/locales/platform/nb/visual-editor.json +10 -0
- package/dist/locales/platform/nl/visual-editor.json +10 -0
- package/dist/locales/platform/pl/visual-editor.json +10 -0
- package/dist/locales/platform/pt/visual-editor.json +10 -0
- package/dist/locales/platform/ro/visual-editor.json +10 -0
- package/dist/locales/platform/sk/visual-editor.json +10 -0
- package/dist/locales/platform/sv/visual-editor.json +10 -0
- package/dist/locales/platform/tr/visual-editor.json +10 -0
- package/dist/locales/platform/zh/visual-editor.json +10 -0
- package/dist/locales/platform/zh-TW/visual-editor.json +10 -0
- package/dist/plugin/plugin.js +2 -1
- package/dist/plugin/vite-plugin/layout-generation/modelProxy.d.ts +1 -1
- package/dist/section-library-support.js +67 -67
- package/dist/sectionLibrarySupport.d.ts +2 -2
- package/dist/{visual-editor-DTE5kxrA.js → visual-editor-B84T0Hz5.js} +84 -74
- package/dist/{visual-editor-6mKs9VUe.js → visual-editor-B8eVGZjZ.js} +26 -16
- package/dist/{visual-editor-Bs3wAslG.js → visual-editor-BTv1Bren.js} +62 -52
- package/dist/{visual-editor-DkHhrFsX.js → visual-editor-BWJvQ6QT.js} +110 -100
- package/dist/{visual-editor-D7VeTRK_.js → visual-editor-BWk-Ri1i.js} +73 -63
- package/dist/{visual-editor-LXMNWXry.js → visual-editor-BdM7VUac.js} +76 -66
- package/dist/{visual-editor-ClC6hoz3.js → visual-editor-BmM2bYhg.js} +82 -72
- package/dist/{visual-editor-qJW0uCiQ.js → visual-editor-BuRftlWt.js} +89 -79
- package/dist/{visual-editor-DjTEbi-1.js → visual-editor-BxnbtD_z.js} +63 -53
- package/dist/{visual-editor-CcfUKpnd.js → visual-editor-C4Nretnd.js} +59 -49
- package/dist/{visual-editor-Duishbsa.js → visual-editor-CFE4ijeV.js} +54 -44
- package/dist/{visual-editor-DtL-Zuv_.js → visual-editor-CMfDvLU2.js} +86 -76
- package/dist/{visual-editor-BK6fTU7k.js → visual-editor-CauX7_Ur.js} +27 -17
- package/dist/{visual-editor-QpGupjY5.js → visual-editor-D5d9meOo.js} +93 -83
- package/dist/{visual-editor-gEaWoNRu.js → visual-editor-D9U8TxD-.js} +51 -41
- package/dist/{visual-editor-CtQwadxQ.js → visual-editor-DBZwjDQd.js} +47 -37
- package/dist/{visual-editor-_TatCCAS.js → visual-editor-DI6rS2dP.js} +116 -106
- package/dist/{visual-editor-sOPDMkOR.js → visual-editor-DOioJ5CW.js} +84 -74
- package/dist/{visual-editor-zKhC7_0C.js → visual-editor-D_EvXM08.js} +71 -61
- package/dist/{visual-editor-BruRrJYN.js → visual-editor-DguhAL12.js} +10 -0
- package/dist/{visual-editor-CHWtMtlu.js → visual-editor-DmsRSmAI.js} +90 -80
- package/dist/{visual-editor-vomNdlNO.js → visual-editor-DnNNHiLS.js} +86 -76
- package/dist/{visual-editor-C9TLeAzP.js → visual-editor-DvksDrGT.js} +59 -49
- package/dist/{visual-editor-tPb7n5l8.js → visual-editor-XsBMHUSs.js} +66 -56
- package/dist/{visual-editor-gjpr-NAN.js → visual-editor-kiT3ocKi.js} +60 -50
- package/dist/visual-editor.css +1 -1
- package/dist/visual-editor.js +7003 -6609
- package/package.json +3 -3
package/dist/cli/assets/directory-locator-source/components/sections/locator/LocatorRadius.test.ts
ADDED
|
@@ -0,0 +1,700 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import {
|
|
3
|
+
act,
|
|
4
|
+
cleanup,
|
|
5
|
+
fireEvent,
|
|
6
|
+
render,
|
|
7
|
+
screen,
|
|
8
|
+
waitFor,
|
|
9
|
+
} from "@testing-library/react";
|
|
10
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
11
|
+
import {
|
|
12
|
+
Matcher,
|
|
13
|
+
type NearFilterValue,
|
|
14
|
+
type SelectableStaticFilter,
|
|
15
|
+
} from "@yext/search-headless-react";
|
|
16
|
+
import { getUserLocation, type FilterSearch } from "@yext/search-ui-react";
|
|
17
|
+
import type { FilterModal } from "./Filters.tsx";
|
|
18
|
+
import type { LocatorMap } from "./Map.tsx";
|
|
19
|
+
import type { LocatorProps } from "./Locator.tsx";
|
|
20
|
+
import { LocatorWrapper } from "./LocatorWrapper.tsx";
|
|
21
|
+
import type { StreamDocument } from "../../../utils/types/StreamDocument.ts";
|
|
22
|
+
|
|
23
|
+
const mocks = vi.hoisted(() => ({
|
|
24
|
+
locale: "en",
|
|
25
|
+
streamDocument: {} as StreamDocument,
|
|
26
|
+
state: {
|
|
27
|
+
vertical: { results: [], resultsCount: 0, offset: 0 },
|
|
28
|
+
filters: { static: [] as SelectableStaticFilter[], facets: [] },
|
|
29
|
+
searchStatus: { isLoading: false },
|
|
30
|
+
},
|
|
31
|
+
filterSearch: {} as React.ComponentProps<typeof FilterSearch>,
|
|
32
|
+
filterModal: {} as React.ComponentProps<typeof FilterModal>,
|
|
33
|
+
map: {} as React.ComponentProps<typeof LocatorMap>,
|
|
34
|
+
actions: {
|
|
35
|
+
setSessionTrackingEnabled: vi.fn(),
|
|
36
|
+
setFacetAllowList: vi.fn(),
|
|
37
|
+
setOffset: vi.fn(),
|
|
38
|
+
setVerticalLimit: vi.fn(),
|
|
39
|
+
setStaticFilters: vi.fn(),
|
|
40
|
+
setFilterOption: vi.fn(),
|
|
41
|
+
executeVerticalQuery: vi.fn(),
|
|
42
|
+
executeFilterSearch: vi.fn(),
|
|
43
|
+
resetFacets: vi.fn(),
|
|
44
|
+
},
|
|
45
|
+
}));
|
|
46
|
+
|
|
47
|
+
vi.mock("@yext/search-headless-react", async (importOriginal) => ({
|
|
48
|
+
...(await importOriginal<typeof import("@yext/search-headless-react")>()),
|
|
49
|
+
provideHeadless: () => mocks.actions,
|
|
50
|
+
SearchHeadlessProvider: ({ children }: React.PropsWithChildren) => children,
|
|
51
|
+
useSearchActions: () => mocks.actions,
|
|
52
|
+
useSearchState: (selector: (state: typeof mocks.state) => unknown) =>
|
|
53
|
+
selector(mocks.state),
|
|
54
|
+
}));
|
|
55
|
+
vi.mock("@yext/search-ui-react", () => ({
|
|
56
|
+
AnalyticsProvider: ({ children }: React.PropsWithChildren) => children,
|
|
57
|
+
SearchI18nextProvider: ({ children }: React.PropsWithChildren) => children,
|
|
58
|
+
useAnalytics: () => undefined,
|
|
59
|
+
AppliedFilters: () => null,
|
|
60
|
+
Pagination: () => null,
|
|
61
|
+
VerticalResults: () => null,
|
|
62
|
+
FilterSearch: (props: typeof mocks.filterSearch) => {
|
|
63
|
+
mocks.filterSearch = props;
|
|
64
|
+
return null;
|
|
65
|
+
},
|
|
66
|
+
getUserLocation: vi
|
|
67
|
+
.fn()
|
|
68
|
+
.mockRejectedValue(new Error("Geolocation unavailable")),
|
|
69
|
+
executeSearch: () => mocks.actions.executeVerticalQuery(),
|
|
70
|
+
}));
|
|
71
|
+
vi.mock("@yext/pages-components", () => ({ useAnalytics: () => undefined }));
|
|
72
|
+
vi.mock("react-i18next", async (importOriginal) => ({
|
|
73
|
+
...(await importOriginal<typeof import("react-i18next")>()),
|
|
74
|
+
useTranslation: () => ({
|
|
75
|
+
t: (_key: string, fallback: string) => fallback,
|
|
76
|
+
i18n: { language: mocks.locale },
|
|
77
|
+
}),
|
|
78
|
+
}));
|
|
79
|
+
vi.mock("../../../hooks/useDocument.tsx", () => ({
|
|
80
|
+
useDocument: () => ({
|
|
81
|
+
...mocks.streamDocument,
|
|
82
|
+
id: "locator",
|
|
83
|
+
locale: mocks.locale,
|
|
84
|
+
}),
|
|
85
|
+
}));
|
|
86
|
+
vi.mock("../../../hooks/useViewport.ts", () => ({
|
|
87
|
+
getViewport: () => ({ isMobile: false }),
|
|
88
|
+
useWindowWidth: () => 1024,
|
|
89
|
+
}));
|
|
90
|
+
vi.mock("../../../utils/searchHeadlessConfig.ts", () => ({
|
|
91
|
+
createSearchHeadlessConfig: () => ({}),
|
|
92
|
+
createSearchAnalyticsConfig: () => ({}),
|
|
93
|
+
}));
|
|
94
|
+
vi.mock("./Map.tsx", async (importOriginal) => ({
|
|
95
|
+
...(await importOriginal<typeof import("./Map.tsx")>()),
|
|
96
|
+
LocatorMap: (props: typeof mocks.map) => {
|
|
97
|
+
mocks.map = props;
|
|
98
|
+
return null;
|
|
99
|
+
},
|
|
100
|
+
LoadingMapPlaceholder: () => null,
|
|
101
|
+
}));
|
|
102
|
+
vi.mock("./Filters.tsx", async (importOriginal) => ({
|
|
103
|
+
...(await importOriginal<typeof import("./Filters.tsx")>()),
|
|
104
|
+
FilterModal: (props: typeof mocks.filterModal) => {
|
|
105
|
+
mocks.filterModal = props;
|
|
106
|
+
return null;
|
|
107
|
+
},
|
|
108
|
+
}));
|
|
109
|
+
vi.mock("./Results.tsx", () => ({
|
|
110
|
+
RESULTS_LIMIT: 20,
|
|
111
|
+
MobileLocatorResultsSection: () => null,
|
|
112
|
+
ResultsCountSummary: () => null,
|
|
113
|
+
translateDistanceUnit: (_t: unknown, unit: string) =>
|
|
114
|
+
unit === "mile" ? "miles" : "kilometers",
|
|
115
|
+
}));
|
|
116
|
+
vi.mock("./LocatorResultCard.tsx", () => ({
|
|
117
|
+
DEFAULT_LOCATOR_RESULT_CARD_PROPS: {},
|
|
118
|
+
LocatorResultCard: () => null,
|
|
119
|
+
}));
|
|
120
|
+
|
|
121
|
+
const suggestedValue = { lat: 38.9, lng: -77.1, radius: 12000 };
|
|
122
|
+
const searchResponse = {
|
|
123
|
+
sections: [
|
|
124
|
+
{
|
|
125
|
+
results: [
|
|
126
|
+
{
|
|
127
|
+
value: "Arlington",
|
|
128
|
+
filter: {
|
|
129
|
+
kind: "fieldValue" as const,
|
|
130
|
+
fieldId: "builtin.location",
|
|
131
|
+
matcher: Matcher.Near,
|
|
132
|
+
value: suggestedValue,
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
},
|
|
137
|
+
],
|
|
138
|
+
};
|
|
139
|
+
const getLocationFilter = () =>
|
|
140
|
+
mocks.state.filters.static.find(
|
|
141
|
+
({ filter }) =>
|
|
142
|
+
filter.kind === "fieldValue" && filter.fieldId === "builtin.location"
|
|
143
|
+
)?.filter;
|
|
144
|
+
const getRadius = () =>
|
|
145
|
+
(getLocationFilter() as { value: NearFilterValue } | undefined)?.value.radius;
|
|
146
|
+
const createLocator = (
|
|
147
|
+
radius?: LocatorProps["defaultSearchRadius"],
|
|
148
|
+
distanceProps?: Pick<
|
|
149
|
+
LocatorProps,
|
|
150
|
+
"defaultDistanceUnit" | "showDistanceUnitToggle"
|
|
151
|
+
>
|
|
152
|
+
) =>
|
|
153
|
+
React.createElement(LocatorWrapper, {
|
|
154
|
+
locationStyles: [],
|
|
155
|
+
resultCard: [],
|
|
156
|
+
filters: { openNowButton: false, showDistanceOptions: true },
|
|
157
|
+
defaultSearchRadius: radius,
|
|
158
|
+
...distanceProps,
|
|
159
|
+
puck: {
|
|
160
|
+
metadata: {},
|
|
161
|
+
isEditing: false,
|
|
162
|
+
dragRef: null,
|
|
163
|
+
renderDropZone: () => null,
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
const renderLocator = (
|
|
167
|
+
radius?: LocatorProps["defaultSearchRadius"],
|
|
168
|
+
distanceProps?: Pick<
|
|
169
|
+
LocatorProps,
|
|
170
|
+
"defaultDistanceUnit" | "showDistanceUnitToggle"
|
|
171
|
+
>
|
|
172
|
+
) => render(createLocator(radius, distanceProps));
|
|
173
|
+
const selectSuggestion = async () =>
|
|
174
|
+
act(async () => {
|
|
175
|
+
mocks.filterSearch.onSelect?.({
|
|
176
|
+
currentFilter: undefined,
|
|
177
|
+
setCurrentFilter: vi.fn(),
|
|
178
|
+
executeFilterSearch: mocks.actions.executeFilterSearch,
|
|
179
|
+
newFilter: {
|
|
180
|
+
kind: "fieldValue",
|
|
181
|
+
fieldId: "builtin.location",
|
|
182
|
+
matcher: Matcher.Near,
|
|
183
|
+
value: suggestedValue,
|
|
184
|
+
},
|
|
185
|
+
newDisplayName: "Arlington",
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
beforeEach(() => {
|
|
190
|
+
vi.clearAllMocks();
|
|
191
|
+
vi.mocked(getUserLocation).mockRejectedValue(
|
|
192
|
+
new Error("Geolocation unavailable")
|
|
193
|
+
);
|
|
194
|
+
mocks.locale = "en";
|
|
195
|
+
mocks.streamDocument = {};
|
|
196
|
+
mocks.state.filters = { static: [], facets: [] };
|
|
197
|
+
window.history.replaceState(null, "", "/");
|
|
198
|
+
mocks.actions.setStaticFilters.mockImplementation(
|
|
199
|
+
(filters: SelectableStaticFilter[]) => {
|
|
200
|
+
mocks.state.filters = { ...mocks.state.filters, static: filters };
|
|
201
|
+
}
|
|
202
|
+
);
|
|
203
|
+
mocks.actions.executeFilterSearch.mockResolvedValue(searchResponse);
|
|
204
|
+
});
|
|
205
|
+
afterEach(() => {
|
|
206
|
+
cleanup();
|
|
207
|
+
window.history.replaceState(null, "", "/");
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
describe("Locator default search radius", () => {
|
|
211
|
+
it("uses the latest selection when a pending location lookup resolves", async () => {
|
|
212
|
+
window.history.replaceState(null, "", "/?q=Arlington");
|
|
213
|
+
let finishSearch!: (response: typeof searchResponse) => void;
|
|
214
|
+
mocks.actions.executeFilterSearch.mockImplementationOnce(
|
|
215
|
+
() =>
|
|
216
|
+
new Promise<typeof searchResponse>((resolve) => {
|
|
217
|
+
finishSearch = resolve;
|
|
218
|
+
})
|
|
219
|
+
);
|
|
220
|
+
const radius = { value: 50, unit: "mile" } as const;
|
|
221
|
+
const { rerender } = renderLocator(radius, { defaultDistanceUnit: "mile" });
|
|
222
|
+
await waitFor(() =>
|
|
223
|
+
expect(mocks.actions.executeFilterSearch).toHaveBeenCalledTimes(1)
|
|
224
|
+
);
|
|
225
|
+
await act(async () => mocks.filterModal.handleDistanceClick(5, "mile"));
|
|
226
|
+
await act(async () =>
|
|
227
|
+
rerender(createLocator(radius, { defaultDistanceUnit: "kilometer" }))
|
|
228
|
+
);
|
|
229
|
+
await act(async () => finishSearch(searchResponse));
|
|
230
|
+
expect(getRadius()).toBeCloseTo(5000);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it.each([
|
|
234
|
+
{ name: "automatic coordinates", query: "", expectedBase: 25000 },
|
|
235
|
+
{ name: "Search suggestion", query: "?q=Arlington", expectedBase: 12000 },
|
|
236
|
+
{
|
|
237
|
+
name: "explicit map area",
|
|
238
|
+
query: "?q=38.9,-77.1,40233.6",
|
|
239
|
+
expectedBase: 40233.6,
|
|
240
|
+
},
|
|
241
|
+
])(
|
|
242
|
+
"restores the $name base radius after a unit change",
|
|
243
|
+
async ({ query, expectedBase }) => {
|
|
244
|
+
window.history.replaceState(null, "", `/${query}`);
|
|
245
|
+
const { rerender } = renderLocator(undefined, {
|
|
246
|
+
defaultDistanceUnit: "mile",
|
|
247
|
+
});
|
|
248
|
+
await waitFor(() => expect(getRadius()).toBeDefined());
|
|
249
|
+
await act(async () => mocks.filterModal.handleDistanceClick(5, "mile"));
|
|
250
|
+
await act(async () =>
|
|
251
|
+
rerender(createLocator(undefined, { defaultDistanceUnit: "kilometer" }))
|
|
252
|
+
);
|
|
253
|
+
await act(async () =>
|
|
254
|
+
mocks.filterModal.handleDistanceClick(5, "kilometer")
|
|
255
|
+
);
|
|
256
|
+
expect(getRadius()).toBeCloseTo(expectedBase);
|
|
257
|
+
}
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
it("keeps geolocation accuracy as the minimum automatic base radius", async () => {
|
|
261
|
+
vi.mocked(getUserLocation).mockResolvedValue({
|
|
262
|
+
coords: { latitude: 38.9, longitude: -77.1, accuracy: 30000 },
|
|
263
|
+
} as GeolocationPosition);
|
|
264
|
+
const { rerender } = renderLocator(undefined, {
|
|
265
|
+
defaultDistanceUnit: "mile",
|
|
266
|
+
});
|
|
267
|
+
await waitFor(() => expect(getRadius()).toBeCloseTo(40233.6));
|
|
268
|
+
await act(async () => mocks.filterModal.handleDistanceClick(5, "mile"));
|
|
269
|
+
await act(async () =>
|
|
270
|
+
rerender(createLocator(undefined, { defaultDistanceUnit: "kilometer" }))
|
|
271
|
+
);
|
|
272
|
+
await act(async () =>
|
|
273
|
+
mocks.filterModal.handleDistanceClick(5, "kilometer")
|
|
274
|
+
);
|
|
275
|
+
expect(getRadius()).toBeCloseTo(30000);
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
it.each<{
|
|
279
|
+
name: string;
|
|
280
|
+
radius?: LocatorProps["defaultSearchRadius"];
|
|
281
|
+
expectedRadius: number;
|
|
282
|
+
}>([
|
|
283
|
+
{ name: "automatic radius", expectedRadius: 25000 },
|
|
284
|
+
{
|
|
285
|
+
name: "configured radius",
|
|
286
|
+
radius: { value: 50, unit: "mile" },
|
|
287
|
+
expectedRadius: 80467.2,
|
|
288
|
+
},
|
|
289
|
+
])(
|
|
290
|
+
"uses the current unit after pending geolocation with $name",
|
|
291
|
+
async ({ radius, expectedRadius }) => {
|
|
292
|
+
let finishGeolocation!: (position: GeolocationPosition) => void;
|
|
293
|
+
vi.mocked(getUserLocation).mockImplementationOnce(
|
|
294
|
+
() =>
|
|
295
|
+
new Promise<GeolocationPosition>((resolve) => {
|
|
296
|
+
finishGeolocation = resolve;
|
|
297
|
+
})
|
|
298
|
+
);
|
|
299
|
+
renderLocator(radius, {
|
|
300
|
+
defaultDistanceUnit: "mile",
|
|
301
|
+
showDistanceUnitToggle: true,
|
|
302
|
+
});
|
|
303
|
+
await waitFor(() => expect(getUserLocation).toHaveBeenCalledTimes(1));
|
|
304
|
+
await act(async () => fireEvent.click(screen.getByText("km")));
|
|
305
|
+
await act(async () =>
|
|
306
|
+
finishGeolocation({
|
|
307
|
+
coords: { latitude: 38.9, longitude: -77.1, accuracy: 10 },
|
|
308
|
+
} as GeolocationPosition)
|
|
309
|
+
);
|
|
310
|
+
await waitFor(() => expect(getRadius()).toBeCloseTo(expectedRadius));
|
|
311
|
+
await act(async () =>
|
|
312
|
+
mocks.filterModal.handleDistanceClick(5, "kilometer")
|
|
313
|
+
);
|
|
314
|
+
await act(async () => mocks.filterModal.handleClearFiltersClick());
|
|
315
|
+
expect(getRadius()).toBeCloseTo(expectedRadius);
|
|
316
|
+
}
|
|
317
|
+
);
|
|
318
|
+
|
|
319
|
+
it("restarts a cancelled initialization after a unit change", async () => {
|
|
320
|
+
window.history.replaceState(null, "", "/?q=Arlington");
|
|
321
|
+
let finishFirstSearch!: (response: typeof searchResponse) => void;
|
|
322
|
+
mocks.actions.executeFilterSearch.mockImplementationOnce(
|
|
323
|
+
() =>
|
|
324
|
+
new Promise<typeof searchResponse>((resolve) => {
|
|
325
|
+
finishFirstSearch = resolve;
|
|
326
|
+
})
|
|
327
|
+
);
|
|
328
|
+
const { rerender } = renderLocator(undefined, {
|
|
329
|
+
defaultDistanceUnit: "mile",
|
|
330
|
+
});
|
|
331
|
+
await waitFor(() =>
|
|
332
|
+
expect(mocks.actions.executeFilterSearch).toHaveBeenCalledTimes(1)
|
|
333
|
+
);
|
|
334
|
+
await act(async () => mocks.filterModal.handleDistanceClick(5, "mile"));
|
|
335
|
+
await act(async () =>
|
|
336
|
+
rerender(createLocator(undefined, { defaultDistanceUnit: "kilometer" }))
|
|
337
|
+
);
|
|
338
|
+
await act(async () => finishFirstSearch(searchResponse));
|
|
339
|
+
await waitFor(() =>
|
|
340
|
+
expect(mocks.actions.executeFilterSearch).toHaveBeenCalledTimes(2)
|
|
341
|
+
);
|
|
342
|
+
expect(getRadius()).toBeCloseTo(5000);
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
it.each<{
|
|
346
|
+
name: string;
|
|
347
|
+
radius?: LocatorProps["defaultSearchRadius"];
|
|
348
|
+
expectedInitialRadius: number;
|
|
349
|
+
}>([
|
|
350
|
+
{
|
|
351
|
+
name: "with a configured search radius",
|
|
352
|
+
radius: { value: 50, unit: "mile" },
|
|
353
|
+
expectedInitialRadius: 80467.2,
|
|
354
|
+
},
|
|
355
|
+
{
|
|
356
|
+
name: "with an automatic search radius",
|
|
357
|
+
expectedInitialRadius: 40233.6,
|
|
358
|
+
},
|
|
359
|
+
])(
|
|
360
|
+
"updates the applied distance filter when the configured unit changes $name",
|
|
361
|
+
async ({ radius, expectedInitialRadius }) => {
|
|
362
|
+
const { rerender } = renderLocator(radius, {
|
|
363
|
+
defaultDistanceUnit: "mile",
|
|
364
|
+
});
|
|
365
|
+
await waitFor(() =>
|
|
366
|
+
expect(getRadius()).toBeCloseTo(expectedInitialRadius)
|
|
367
|
+
);
|
|
368
|
+
await selectSuggestion();
|
|
369
|
+
await act(async () => mocks.filterModal.handleDistanceClick(5, "mile"));
|
|
370
|
+
expect(getRadius()).toBeCloseTo(8046.72);
|
|
371
|
+
const searchesBeforeChange =
|
|
372
|
+
mocks.actions.executeVerticalQuery.mock.calls.length;
|
|
373
|
+
|
|
374
|
+
await act(async () =>
|
|
375
|
+
rerender(createLocator(radius, { defaultDistanceUnit: "kilometer" }))
|
|
376
|
+
);
|
|
377
|
+
expect(mocks.filterModal.distanceUnit).toBe("kilometer");
|
|
378
|
+
expect(mocks.filterModal.selectedDistanceOption).toBe(5);
|
|
379
|
+
expect(mocks.actions.executeVerticalQuery.mock.calls.length).toBe(
|
|
380
|
+
searchesBeforeChange + 1
|
|
381
|
+
);
|
|
382
|
+
expect(getRadius()).toBeCloseTo(5000);
|
|
383
|
+
}
|
|
384
|
+
);
|
|
385
|
+
|
|
386
|
+
it("uses the configured unit and updates an active distance filter when switched", async () => {
|
|
387
|
+
renderLocator(undefined, {
|
|
388
|
+
defaultDistanceUnit: "kilometer",
|
|
389
|
+
showDistanceUnitToggle: true,
|
|
390
|
+
});
|
|
391
|
+
await waitFor(() => expect(getRadius()).toBeCloseTo(25000));
|
|
392
|
+
expect(mocks.filterModal.distanceUnit).toBe("kilometer");
|
|
393
|
+
await selectSuggestion();
|
|
394
|
+
await act(async () =>
|
|
395
|
+
mocks.filterModal.handleDistanceClick(5, "kilometer")
|
|
396
|
+
);
|
|
397
|
+
expect(getRadius()).toBeCloseTo(5000);
|
|
398
|
+
expect(mocks.filterModal.selectedDistanceOption).toBe(5);
|
|
399
|
+
|
|
400
|
+
for (const { label, unit, radius } of [
|
|
401
|
+
{ label: "mi", unit: "mile", radius: 8046.72 },
|
|
402
|
+
{ label: "km", unit: "kilometer", radius: 5000 },
|
|
403
|
+
]) {
|
|
404
|
+
const queriesBeforeSwitch =
|
|
405
|
+
mocks.actions.executeVerticalQuery.mock.calls.length;
|
|
406
|
+
const lookupsBeforeSwitch =
|
|
407
|
+
mocks.actions.executeFilterSearch.mock.calls.length;
|
|
408
|
+
const button = screen.getByText(label);
|
|
409
|
+
await act(async (): Promise<void> => {
|
|
410
|
+
fireEvent.click(button);
|
|
411
|
+
});
|
|
412
|
+
expect(button.getAttribute("aria-pressed")).toBe("true");
|
|
413
|
+
expect(mocks.filterModal.distanceUnit).toBe(unit);
|
|
414
|
+
expect(getRadius()).toBeCloseTo(radius);
|
|
415
|
+
expect(mocks.actions.executeVerticalQuery).toHaveBeenCalledTimes(
|
|
416
|
+
queriesBeforeSwitch + 1
|
|
417
|
+
);
|
|
418
|
+
expect(mocks.actions.executeFilterSearch).toHaveBeenCalledTimes(
|
|
419
|
+
lookupsBeforeSwitch
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
it.each([
|
|
425
|
+
{ entityTypes: ["ce_warehouse"] },
|
|
426
|
+
{ entityTypes: ["ce_warehouse", "location"] },
|
|
427
|
+
{ entityTypes: ["location", "ce_warehouse"] },
|
|
428
|
+
])(
|
|
429
|
+
"uses a configured entity type for autocomplete and URL lookup: $entityTypes",
|
|
430
|
+
async ({ entityTypes }) => {
|
|
431
|
+
mocks.streamDocument = {
|
|
432
|
+
_pageset: JSON.stringify({
|
|
433
|
+
typeConfig: {
|
|
434
|
+
locatorConfig: {
|
|
435
|
+
entityTypeScope: entityTypes.map((entityType) => ({
|
|
436
|
+
entityType,
|
|
437
|
+
})),
|
|
438
|
+
},
|
|
439
|
+
},
|
|
440
|
+
}),
|
|
441
|
+
};
|
|
442
|
+
window.history.replaceState(null, "", "/?q=Arlington");
|
|
443
|
+
renderLocator();
|
|
444
|
+
|
|
445
|
+
expect(mocks.filterSearch.searchFields).toEqual([
|
|
446
|
+
{ fieldApiName: "builtin.location", entityType: entityTypes[0] },
|
|
447
|
+
]);
|
|
448
|
+
await waitFor(() => {
|
|
449
|
+
expect(mocks.actions.executeFilterSearch).toHaveBeenCalledWith(
|
|
450
|
+
"Arlington",
|
|
451
|
+
false,
|
|
452
|
+
[
|
|
453
|
+
{
|
|
454
|
+
fieldApiName: "builtin.location",
|
|
455
|
+
entityType: entityTypes[0],
|
|
456
|
+
fetchEntities: false,
|
|
457
|
+
},
|
|
458
|
+
]
|
|
459
|
+
);
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
);
|
|
463
|
+
|
|
464
|
+
it.each<{
|
|
465
|
+
name: string;
|
|
466
|
+
query: string;
|
|
467
|
+
radius?: LocatorProps["defaultSearchRadius"];
|
|
468
|
+
locale?: string;
|
|
469
|
+
expected: number;
|
|
470
|
+
}>([
|
|
471
|
+
{
|
|
472
|
+
name: "uses Search's suggested radius when automatic",
|
|
473
|
+
query: "?q=Arlington",
|
|
474
|
+
expected: 12000,
|
|
475
|
+
},
|
|
476
|
+
{
|
|
477
|
+
name: "overrides named searches in miles",
|
|
478
|
+
query: "?q=Arlington",
|
|
479
|
+
radius: { value: 50, unit: "mile" },
|
|
480
|
+
expected: 80467.2,
|
|
481
|
+
},
|
|
482
|
+
{
|
|
483
|
+
name: "overrides legacy initialLocation searches in kilometers",
|
|
484
|
+
query: "?initialLocation=Arlington",
|
|
485
|
+
radius: { value: 60, unit: "kilometer" },
|
|
486
|
+
expected: 60000,
|
|
487
|
+
},
|
|
488
|
+
{
|
|
489
|
+
name: "uses the configured radius for initial coordinates",
|
|
490
|
+
query: "",
|
|
491
|
+
radius: { value: 50, unit: "kilometer" },
|
|
492
|
+
expected: 50000,
|
|
493
|
+
},
|
|
494
|
+
{
|
|
495
|
+
name: "uses 25 miles for automatic English coordinates",
|
|
496
|
+
query: "",
|
|
497
|
+
expected: 40233.6,
|
|
498
|
+
},
|
|
499
|
+
{
|
|
500
|
+
name: "uses 25 kilometers for automatic French coordinates",
|
|
501
|
+
query: "",
|
|
502
|
+
locale: "fr",
|
|
503
|
+
expected: 25000,
|
|
504
|
+
},
|
|
505
|
+
{
|
|
506
|
+
name: "converts configured miles independently of locale",
|
|
507
|
+
query: "?q=Arlington",
|
|
508
|
+
locale: "fr",
|
|
509
|
+
radius: { value: 50, unit: "mile" },
|
|
510
|
+
expected: 80467.2,
|
|
511
|
+
},
|
|
512
|
+
{
|
|
513
|
+
name: "preserves explicit URL areas",
|
|
514
|
+
query: "?q=38.9,-77.1,9000",
|
|
515
|
+
radius: { value: 50, unit: "mile" },
|
|
516
|
+
expected: 9000,
|
|
517
|
+
},
|
|
518
|
+
{
|
|
519
|
+
name: "treats cleared values as automatic",
|
|
520
|
+
query: "?q=Arlington",
|
|
521
|
+
radius: { unit: "mile" },
|
|
522
|
+
expected: 12000,
|
|
523
|
+
},
|
|
524
|
+
{
|
|
525
|
+
name: "treats zero as automatic",
|
|
526
|
+
query: "?q=Arlington",
|
|
527
|
+
radius: { value: 0, unit: "mile" },
|
|
528
|
+
expected: 12000,
|
|
529
|
+
},
|
|
530
|
+
{
|
|
531
|
+
name: "uses the locale fallback for zero coordinate radius",
|
|
532
|
+
query: "",
|
|
533
|
+
radius: { value: 0, unit: "kilometer" },
|
|
534
|
+
expected: 40233.6,
|
|
535
|
+
},
|
|
536
|
+
])("$name", async ({ query, radius, locale = "en", expected }) => {
|
|
537
|
+
mocks.locale = locale;
|
|
538
|
+
window.history.replaceState(null, "", `/${query}`);
|
|
539
|
+
renderLocator(radius);
|
|
540
|
+
await waitFor(() => expect(getRadius()).toBeCloseTo(expected));
|
|
541
|
+
expect(mocks.filterSearch.geolocationProps?.radius).toBeCloseTo(
|
|
542
|
+
radius?.value
|
|
543
|
+
? radius.value * (radius.unit === "mile" ? 1 : 1 / 1.609344)
|
|
544
|
+
: locale === "en"
|
|
545
|
+
? 25
|
|
546
|
+
: 25 / 1.609344
|
|
547
|
+
);
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
it("uses the configured radius for suggestions and restores it after distance overrides", async () => {
|
|
551
|
+
renderLocator({ value: 50, unit: "mile" });
|
|
552
|
+
await waitFor(() => expect(getRadius()).toBeCloseTo(80467.2));
|
|
553
|
+
await selectSuggestion();
|
|
554
|
+
expect(getRadius()).toBeCloseTo(80467.2);
|
|
555
|
+
await act(async () => mocks.filterModal.handleDistanceClick(5, "mile"));
|
|
556
|
+
expect(getRadius()).toBeCloseTo(8046.72);
|
|
557
|
+
await selectSuggestion();
|
|
558
|
+
expect(getRadius()).toBeCloseTo(8046.72);
|
|
559
|
+
await act(async () => mocks.filterModal.handleDistanceClick(5, "mile"));
|
|
560
|
+
expect(getRadius()).toBeCloseTo(80467.2);
|
|
561
|
+
await act(async () => mocks.filterModal.handleDistanceClick(5, "mile"));
|
|
562
|
+
await act(async () => mocks.filterModal.handleClearFiltersClick());
|
|
563
|
+
expect(getRadius()).toBeCloseTo(80467.2);
|
|
564
|
+
});
|
|
565
|
+
|
|
566
|
+
it.each(["builtin.region", "address.countryCode"])(
|
|
567
|
+
"preserves %s boundary filters",
|
|
568
|
+
async (fieldId) => {
|
|
569
|
+
const filter = {
|
|
570
|
+
kind: "fieldValue" as const,
|
|
571
|
+
fieldId,
|
|
572
|
+
matcher: Matcher.Equals,
|
|
573
|
+
value: "VA",
|
|
574
|
+
};
|
|
575
|
+
mocks.actions.executeFilterSearch.mockResolvedValue({
|
|
576
|
+
sections: [{ results: [{ value: "Virginia", filter }] }],
|
|
577
|
+
});
|
|
578
|
+
window.history.replaceState(null, "", "/?q=Virginia");
|
|
579
|
+
renderLocator({ value: 50, unit: "mile" });
|
|
580
|
+
await waitFor(() =>
|
|
581
|
+
expect(mocks.actions.executeVerticalQuery).toHaveBeenCalled()
|
|
582
|
+
);
|
|
583
|
+
expect(mocks.state.filters.static[0].filter).toEqual(filter);
|
|
584
|
+
await act(async () =>
|
|
585
|
+
mocks.filterSearch.onSelect?.({
|
|
586
|
+
currentFilter: undefined,
|
|
587
|
+
setCurrentFilter: vi.fn(),
|
|
588
|
+
executeFilterSearch: mocks.actions.executeFilterSearch,
|
|
589
|
+
newFilter: filter,
|
|
590
|
+
newDisplayName: "Virginia",
|
|
591
|
+
})
|
|
592
|
+
);
|
|
593
|
+
expect(mocks.state.filters.static[0].filter).toEqual(filter);
|
|
594
|
+
}
|
|
595
|
+
);
|
|
596
|
+
|
|
597
|
+
it.each<{
|
|
598
|
+
radius?: LocatorProps["defaultSearchRadius"];
|
|
599
|
+
locale: string;
|
|
600
|
+
accuracy: number;
|
|
601
|
+
expected: number;
|
|
602
|
+
}>([
|
|
603
|
+
{
|
|
604
|
+
radius: { value: 50, unit: "kilometer" },
|
|
605
|
+
locale: "en",
|
|
606
|
+
accuracy: 10,
|
|
607
|
+
expected: 50000,
|
|
608
|
+
},
|
|
609
|
+
{
|
|
610
|
+
radius: { value: 50, unit: "kilometer" },
|
|
611
|
+
locale: "en",
|
|
612
|
+
accuracy: 100000,
|
|
613
|
+
expected: 100000,
|
|
614
|
+
},
|
|
615
|
+
{
|
|
616
|
+
radius: { value: 50, unit: "mile" },
|
|
617
|
+
locale: "en",
|
|
618
|
+
accuracy: 100000,
|
|
619
|
+
expected: 100000,
|
|
620
|
+
},
|
|
621
|
+
{ locale: "en", accuracy: 100000, expected: 100000 },
|
|
622
|
+
{ locale: "fr", accuracy: 10, expected: 25000 },
|
|
623
|
+
{ locale: "fr", accuracy: 100000, expected: 100000 },
|
|
624
|
+
])(
|
|
625
|
+
"respects initial geolocation accuracy $accuracy with radius $radius in $locale",
|
|
626
|
+
async ({ radius, locale, accuracy, expected }) => {
|
|
627
|
+
mocks.locale = locale;
|
|
628
|
+
vi.mocked(getUserLocation).mockResolvedValue({
|
|
629
|
+
coords: { latitude: 38.9, longitude: -77.1, accuracy },
|
|
630
|
+
} as GeolocationPosition);
|
|
631
|
+
renderLocator(radius);
|
|
632
|
+
await waitFor(() => expect(getRadius()).toBeCloseTo(expected));
|
|
633
|
+
await act(async () =>
|
|
634
|
+
mocks.filterModal.handleDistanceClick(
|
|
635
|
+
5,
|
|
636
|
+
locale === "en" ? "mile" : "kilometer"
|
|
637
|
+
)
|
|
638
|
+
);
|
|
639
|
+
await act(async () => mocks.filterModal.handleClearFiltersClick());
|
|
640
|
+
expect(getRadius()).toBeCloseTo(expected);
|
|
641
|
+
}
|
|
642
|
+
);
|
|
643
|
+
|
|
644
|
+
it.each([10, 10000])(
|
|
645
|
+
"preserves the selected distance and configured base with initial accuracy %s",
|
|
646
|
+
async (accuracy) => {
|
|
647
|
+
renderLocator({ value: 50, unit: "kilometer" });
|
|
648
|
+
await waitFor(() => expect(getRadius()).toBe(50000));
|
|
649
|
+
await act(async () => mocks.filterModal.handleDistanceClick(5, "mile"));
|
|
650
|
+
vi.mocked(getUserLocation).mockResolvedValue({
|
|
651
|
+
coords: { latitude: 38.9, longitude: -77.1, accuracy },
|
|
652
|
+
} as GeolocationPosition);
|
|
653
|
+
await act(async () =>
|
|
654
|
+
window.dispatchEvent(new PopStateEvent("popstate"))
|
|
655
|
+
);
|
|
656
|
+
await waitFor(() =>
|
|
657
|
+
expect(getRadius()).toBeCloseTo(Math.max(accuracy, 8046.72))
|
|
658
|
+
);
|
|
659
|
+
await act(async () => mocks.filterModal.handleClearFiltersClick());
|
|
660
|
+
expect(getRadius()).toBe(50000);
|
|
661
|
+
}
|
|
662
|
+
);
|
|
663
|
+
|
|
664
|
+
it.each([10, 100000])(
|
|
665
|
+
"respects current-location accuracy of %s meters and restores the base radius",
|
|
666
|
+
async (accuracy) => {
|
|
667
|
+
renderLocator({ value: 50, unit: "kilometer" });
|
|
668
|
+
await waitFor(() => expect(getRadius()).toBe(50000));
|
|
669
|
+
await act(async () => mocks.filterModal.handleDistanceClick(5, "mile"));
|
|
670
|
+
await act(async () =>
|
|
671
|
+
mocks.filterSearch.geolocationProps?.handleClick?.({
|
|
672
|
+
coords: { latitude: 38.9, longitude: -77.1, accuracy },
|
|
673
|
+
} as GeolocationPosition)
|
|
674
|
+
);
|
|
675
|
+
expect(getRadius()).toBeCloseTo(Math.max(accuracy, 8046.72));
|
|
676
|
+
await act(async () => mocks.filterModal.handleClearFiltersClick());
|
|
677
|
+
expect(getRadius()).toBe(Math.max(accuracy, 50000));
|
|
678
|
+
}
|
|
679
|
+
);
|
|
680
|
+
|
|
681
|
+
it("preserves a map search area and clears the previous distance selection", async () => {
|
|
682
|
+
renderLocator({ value: 50, unit: "mile" });
|
|
683
|
+
await waitFor(() => expect(getRadius()).toBeCloseTo(80467.2));
|
|
684
|
+
await act(async () => mocks.filterModal.handleDistanceClick(5, "mile"));
|
|
685
|
+
await act(async () =>
|
|
686
|
+
mocks.map.onDragHandler?.(
|
|
687
|
+
{ latitude: 38.9, longitude: -77.1, distanceTo: () => 9000 } as any,
|
|
688
|
+
{ getNorthEast: () => ({}) } as any
|
|
689
|
+
)
|
|
690
|
+
);
|
|
691
|
+
await act(async () =>
|
|
692
|
+
screen.getByRole("button", { name: "Search This Area" }).click()
|
|
693
|
+
);
|
|
694
|
+
expect(getRadius()).toBe(9000);
|
|
695
|
+
expect(mocks.filterModal.selectedDistanceOption).toBeNull();
|
|
696
|
+
await act(async () => mocks.filterModal.handleDistanceClick(5, "mile"));
|
|
697
|
+
await act(async () => mocks.filterModal.handleClearFiltersClick());
|
|
698
|
+
expect(getRadius()).toBe(9000);
|
|
699
|
+
});
|
|
700
|
+
});
|