@yext/visual-editor 1.4.14 → 2.0.0-beta.10
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-DN65KSX7.js +119824 -0
- package/dist/SectionLibraryVisualEditorProvider.css +1 -0
- package/dist/cli/assets/directory-locator-source/components/contentBlocks/Address.tsx +251 -0
- package/dist/cli/assets/directory-locator-source/components/contentBlocks/HeadingText.tsx +147 -0
- package/dist/cli/assets/directory-locator-source/components/contentBlocks/HoursStatus.tsx +157 -0
- package/dist/cli/assets/directory-locator-source/components/contentBlocks/HoursTable.tsx +164 -0
- package/dist/cli/assets/directory-locator-source/components/contentBlocks/MapboxStaticMap.tsx +205 -0
- package/dist/cli/assets/directory-locator-source/components/contentBlocks/Phone.tsx +155 -0
- package/dist/cli/assets/directory-locator-source/components/contentBlocks/image/EmptyImageState.tsx +168 -0
- package/dist/cli/assets/directory-locator-source/components/contentBlocks/image/Image.tsx +275 -0
- package/dist/cli/assets/directory-locator-source/components/contentBlocks/image/styling.ts +66 -0
- package/dist/cli/assets/directory-locator-source/components/contentBlocks/index.ts +13 -0
- package/dist/cli/assets/directory-locator-source/components/sections/Breadcrumbs.tsx +298 -0
- package/dist/cli/assets/directory-locator-source/components/sections/directory/Directory.test.tsx +872 -0
- package/dist/cli/assets/directory-locator-source/components/sections/directory/Directory.tsx +298 -0
- package/dist/cli/assets/directory-locator-source/components/sections/directory/DirectoryCard.tsx +507 -0
- package/dist/cli/assets/directory-locator-source/components/sections/directory/DirectoryWrapper.tsx +499 -0
- package/dist/cli/assets/directory-locator-source/components/sections/directory/directoryChildReference.test.tsx +226 -0
- package/dist/cli/assets/directory-locator-source/components/sections/directory/directoryChildReference.tsx +98 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/Filters.test.tsx +147 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/Filters.tsx +691 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/Locator.test.tsx +1551 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/Locator.tsx +541 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/LocatorFields.test.ts +43 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/LocatorResultCard.tsx +1594 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/LocatorWrapper.tsx +1157 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/Map.tsx +304 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/MapPinIcon.tsx +160 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/Results.tsx +267 -0
- package/dist/cli/assets/directory-locator-source/sectionLibrarySupport.ts +277 -0
- package/dist/cli/yextve.js +16992 -0
- package/dist/createYextFieldTransforms-CrIkiJ_X.d.ts +2157 -0
- package/dist/index.d.ts +534 -6352
- package/dist/locales/page/cs/visual-editor.json +85 -0
- package/dist/locales/page/da/visual-editor.json +73 -0
- package/dist/locales/page/de/visual-editor.json +73 -0
- package/dist/locales/page/en/visual-editor.json +73 -0
- package/dist/locales/page/en-GB/visual-editor.json +73 -0
- package/dist/locales/page/es/visual-editor.json +79 -0
- package/dist/locales/page/et/visual-editor.json +73 -0
- package/dist/locales/page/fi/visual-editor.json +73 -0
- package/dist/locales/page/fr/visual-editor.json +79 -0
- package/dist/locales/page/hr/visual-editor.json +79 -0
- package/dist/locales/page/hu/visual-editor.json +73 -0
- package/dist/locales/page/it/visual-editor.json +79 -0
- package/dist/locales/page/ja/visual-editor.json +73 -0
- package/dist/locales/page/lt/visual-editor.json +85 -0
- package/dist/locales/page/lv/visual-editor.json +77 -0
- package/dist/locales/page/nb/visual-editor.json +73 -0
- package/dist/locales/page/nl/visual-editor.json +73 -0
- package/dist/locales/page/pl/visual-editor.json +85 -0
- package/dist/locales/page/pt/visual-editor.json +79 -0
- package/dist/locales/page/ro/visual-editor.json +79 -0
- package/dist/locales/page/sk/visual-editor.json +85 -0
- package/dist/locales/page/sv/visual-editor.json +73 -0
- package/dist/locales/page/tr/visual-editor.json +73 -0
- package/dist/locales/page/zh/visual-editor.json +73 -0
- package/dist/locales/page/zh-TW/visual-editor.json +73 -0
- package/dist/locales/platform/cs/visual-editor.json +651 -0
- package/dist/locales/platform/da/visual-editor.json +625 -0
- package/dist/locales/platform/de/visual-editor.json +625 -0
- package/dist/locales/platform/en/visual-editor.json +625 -0
- package/dist/locales/platform/en-GB/visual-editor.json +625 -0
- package/dist/locales/platform/es/visual-editor.json +638 -0
- package/dist/locales/platform/et/visual-editor.json +625 -0
- package/dist/locales/platform/fi/visual-editor.json +625 -0
- package/dist/locales/platform/fr/visual-editor.json +638 -0
- package/dist/locales/platform/hr/visual-editor.json +638 -0
- package/dist/locales/platform/hu/visual-editor.json +625 -0
- package/dist/locales/platform/it/visual-editor.json +638 -0
- package/dist/locales/platform/ja/visual-editor.json +625 -0
- package/dist/locales/platform/lt/visual-editor.json +651 -0
- package/dist/locales/platform/lv/visual-editor.json +633 -0
- package/dist/locales/platform/nb/visual-editor.json +625 -0
- package/dist/locales/platform/nl/visual-editor.json +625 -0
- package/dist/locales/platform/pl/visual-editor.json +651 -0
- package/dist/locales/platform/pt/visual-editor.json +638 -0
- package/dist/locales/platform/ro/visual-editor.json +638 -0
- package/dist/locales/platform/sk/visual-editor.json +651 -0
- package/dist/locales/platform/sv/visual-editor.json +625 -0
- package/dist/locales/platform/tr/visual-editor.json +625 -0
- package/dist/locales/platform/zh/visual-editor.json +625 -0
- package/dist/locales/platform/zh-TW/visual-editor.json +625 -0
- package/dist/plugin/internal/layoutGeneration/limits.d.ts +28 -0
- package/dist/plugin/internal/sectionLibraryValidation/builtInTranslationResources.d.ts +3 -0
- package/dist/plugin/internal/sectionLibraryValidation/stages/api/api.d.ts +7 -0
- package/dist/plugin/internal/sectionLibraryValidation/stages/api/libraryMetadata.d.ts +7 -0
- package/dist/plugin/internal/sectionLibraryValidation/stages/code/importRules.d.ts +13 -0
- package/dist/plugin/internal/sectionLibraryValidation/stages/code/validateCode.d.ts +10 -0
- package/dist/plugin/internal/sectionLibraryValidation/stages/code/xssRules.d.ts +7 -0
- package/dist/plugin/internal/sectionLibraryValidation/stages/structure/structure.d.ts +7 -0
- package/dist/plugin/internal/sectionLibraryValidation/types.d.ts +48 -0
- package/dist/plugin/internal/sectionLibraryValidation/validateSectionLibrary.d.ts +8 -0
- package/dist/plugin/internal/sectionLibraryValidation/validationError.d.ts +6 -0
- package/dist/plugin/plugin.js +7013 -5873
- package/dist/plugin/types/entityFields.d.ts +21 -0
- package/dist/plugin/types/generationPrompts.d.ts +19 -0
- package/dist/plugin/types/generationSettings.d.ts +12 -0
- package/dist/plugin/types/images.d.ts +62 -0
- package/dist/plugin/types/sectionLibrary.d.ts +101 -0
- package/dist/plugin/types/types.d.ts +204 -0
- package/dist/plugin/types/videos.d.ts +24 -0
- package/dist/plugin/utils/i18n/locales.d.ts +5 -0
- package/dist/plugin/utils/i18n/translationResources.d.ts +41 -0
- package/dist/plugin/utils/normalizeLocale.d.ts +8 -0
- package/dist/plugin/utils/plainText.d.ts +6 -0
- package/dist/plugin/vite-plugin/index.d.ts +2 -0
- package/dist/plugin/vite-plugin/layout-generation/generationLogger.d.ts +5 -0
- package/dist/plugin/vite-plugin/layout-generation/generationReports.d.ts +13 -0
- package/dist/plugin/vite-plugin/layout-generation/middleware.d.ts +14 -0
- package/dist/plugin/vite-plugin/layout-generation/modelProxy.d.ts +9 -0
- package/dist/plugin/vite-plugin/layout-generation/prompts.d.ts +17 -0
- package/dist/plugin/vite-plugin/layout-generation/settings.d.ts +3 -0
- package/dist/plugin/vite-plugin/local-editor/artifacts.d.ts +20 -0
- package/dist/plugin/vite-plugin/local-editor/config.d.ts +11 -0
- package/dist/plugin/vite-plugin/local-editor/data.d.ts +12 -0
- package/dist/plugin/vite-plugin/local-editor/entityFields.d.ts +13 -0
- package/dist/plugin/vite-plugin/local-editor/fixtureData.d.ts +12 -0
- package/dist/plugin/vite-plugin/local-editor/generatedFiles.d.ts +33 -0
- package/dist/plugin/vite-plugin/local-editor/server.d.ts +34 -0
- package/dist/plugin/vite-plugin/local-editor/types.d.ts +125 -0
- package/dist/plugin/vite-plugin/local-editor/utils.d.ts +16 -0
- package/dist/plugin/vite-plugin/plugin.d.ts +8 -0
- package/dist/plugin/vite-plugin/section-library/migrationRegistry.d.ts +6 -0
- package/dist/plugin/vite-plugin/section-library/sectionFrontmatter.d.ts +3 -0
- package/dist/plugin/vite-plugin/section-library/sectionLibraryGenerator.d.ts +21 -0
- package/dist/plugin/vite-plugin/section-library/sharedComponentRegistry.d.ts +16 -0
- package/dist/section-library-support.js +178 -0
- package/dist/sectionLibrarySupport.d.ts +703 -0
- package/dist/style.css +1 -1
- package/dist/visual-editor-6mKs9VUe.js +842 -0
- package/dist/visual-editor-BK6fTU7k.js +804 -0
- package/dist/visual-editor-BXYlpe7B.js +145 -0
- package/dist/visual-editor-BruRrJYN.js +804 -0
- package/dist/visual-editor-Bs3wAslG.js +804 -0
- package/dist/visual-editor-Bxy81Ezy.js +145 -0
- package/dist/visual-editor-C0vq2BRM.js +145 -0
- package/dist/visual-editor-C9TLeAzP.js +804 -0
- package/dist/visual-editor-CCgmYV5S.js +169 -0
- package/dist/visual-editor-CERViyTJ.js +145 -0
- package/dist/visual-editor-CHWtMtlu.js +823 -0
- package/dist/visual-editor-CcfUKpnd.js +804 -0
- package/dist/visual-editor-CjORnP1D.js +169 -0
- package/dist/visual-editor-ClC6hoz3.js +804 -0
- package/dist/visual-editor-CmomGJB8.js +157 -0
- package/dist/visual-editor-CtQwadxQ.js +842 -0
- package/dist/visual-editor-Cymg8ID2.js +169 -0
- package/dist/visual-editor-D2Hk1nhM.js +145 -0
- package/dist/visual-editor-D7VeTRK_.js +816 -0
- package/dist/visual-editor-D8MRFn5x.js +157 -0
- package/dist/visual-editor-DOXtCqRv.js +145 -0
- package/dist/visual-editor-DQEd3xwY.js +145 -0
- package/dist/visual-editor-DTE5kxrA.js +804 -0
- package/dist/visual-editor-DUngIOnE.js +157 -0
- package/dist/visual-editor-DeZVZYfd.js +169 -0
- package/dist/visual-editor-DfJMZpiP.js +145 -0
- package/dist/visual-editor-DgAsQK9D.js +145 -0
- package/dist/visual-editor-Dhi__-7_.js +145 -0
- package/dist/visual-editor-DjTEbi-1.js +842 -0
- package/dist/visual-editor-DjdqpJU-.js +145 -0
- package/dist/visual-editor-DkHhrFsX.js +804 -0
- package/dist/visual-editor-DtL-Zuv_.js +804 -0
- package/dist/visual-editor-Duishbsa.js +842 -0
- package/dist/visual-editor-DvuH3jyL.js +157 -0
- package/dist/visual-editor-LXMNWXry.js +823 -0
- package/dist/visual-editor-QpGupjY5.js +823 -0
- package/dist/visual-editor-TfVDfO5_.js +145 -0
- package/dist/visual-editor-W_ZDmMFn.js +145 -0
- package/dist/visual-editor-_TatCCAS.js +804 -0
- package/dist/visual-editor-b7ALusk8.js +145 -0
- package/dist/visual-editor-erGXf3kS.js +157 -0
- package/dist/visual-editor-gEaWoNRu.js +804 -0
- package/dist/visual-editor-gjpr-NAN.js +804 -0
- package/dist/visual-editor-qJW0uCiQ.js +804 -0
- package/dist/visual-editor-sOPDMkOR.js +823 -0
- package/dist/visual-editor-tPb7n5l8.js +823 -0
- package/dist/visual-editor-vomNdlNO.js +804 -0
- package/dist/visual-editor-xnDHZFuO.js +153 -0
- package/dist/visual-editor-yiWZqIH0.js +157 -0
- package/dist/visual-editor-zKhC7_0C.js +823 -0
- package/dist/visual-editor.css +1 -0
- package/dist/visual-editor.js +18578 -137536
- package/package.json +50 -26
- package/dist/editor.css +0 -1
- package/dist/visual-editor-6pnSx-yp.js +0 -223
- package/dist/visual-editor-9ZW3nq5u.js +0 -247
- package/dist/visual-editor-B1RXDqNi.js +0 -1063
- package/dist/visual-editor-BAahiZ1l.js +0 -223
- package/dist/visual-editor-BC2LjdoF.js +0 -223
- package/dist/visual-editor-BPnfBfk1.js +0 -1051
- package/dist/visual-editor-BQiE5eVW.js +0 -1051
- package/dist/visual-editor-BTv-6Pnk.js +0 -1051
- package/dist/visual-editor-BUWp03gX.js +0 -235
- package/dist/visual-editor-Bb3c6iGV.js +0 -223
- package/dist/visual-editor-BipczqTj.js +0 -1075
- package/dist/visual-editor-BlIUd_n_.js +0 -1051
- package/dist/visual-editor-BoPLXEu2.js +0 -223
- package/dist/visual-editor-Bzmpi_9a.js +0 -1063
- package/dist/visual-editor-C38IiBTR.js +0 -235
- package/dist/visual-editor-C9tacnim.js +0 -247
- package/dist/visual-editor-CVa3iu5h.js +0 -1051
- package/dist/visual-editor-CXTL8Ik0.js +0 -1051
- package/dist/visual-editor-CYeahjFX.js +0 -231
- package/dist/visual-editor-CZ2SM6Jc.js +0 -1063
- package/dist/visual-editor-CZDmQI-A.js +0 -1063
- package/dist/visual-editor-C_cHJ6BN.js +0 -1051
- package/dist/visual-editor-Cf3nFbw3.js +0 -235
- package/dist/visual-editor-CiR0metz.js +0 -1051
- package/dist/visual-editor-CoX_NnS-.js +0 -223
- package/dist/visual-editor-Cu8II23Y.js +0 -223
- package/dist/visual-editor-CvXFxocc.js +0 -1063
- package/dist/visual-editor-Cxu6nkib.js +0 -1051
- package/dist/visual-editor-D-3VVfjR.js +0 -223
- package/dist/visual-editor-D-ktbg7q.js +0 -223
- package/dist/visual-editor-D9G5eAAU.js +0 -1051
- package/dist/visual-editor-D9MrqEya.js +0 -223
- package/dist/visual-editor-DAKXBbjV.js +0 -1075
- package/dist/visual-editor-DBmJk7ZR.js +0 -235
- package/dist/visual-editor-DG-c2LU9.js +0 -1051
- package/dist/visual-editor-DI_Vk989.js +0 -1051
- package/dist/visual-editor-DOOYgnjP.js +0 -235
- package/dist/visual-editor-DRx3Ax_O.js +0 -1075
- package/dist/visual-editor-DZ66sria.js +0 -1051
- package/dist/visual-editor-DZTPhYcr.js +0 -247
- package/dist/visual-editor-DcH7WJVI.js +0 -223
- package/dist/visual-editor-DdYXgEbR.js +0 -1059
- package/dist/visual-editor-DeWzgcue.js +0 -1063
- package/dist/visual-editor-Dm5ZNn8C.js +0 -223
- package/dist/visual-editor-DqLCIWPQ.js +0 -1051
- package/dist/visual-editor-NoU28r5Y.js +0 -223
- package/dist/visual-editor-WjrJ9nPc.js +0 -235
- package/dist/visual-editor-_h-sdbID.js +0 -223
- package/dist/visual-editor-r4gSQqFM.js +0 -1075
- package/dist/visual-editor-ujQ29mao.js +0 -247
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import { Config, resolveAllData } from "@puckeditor/core";
|
|
4
|
+
import { Directory } from "./Directory.tsx";
|
|
5
|
+
import { SlotsCategoryComponents } from "../../testing/SlotComponents.tsx";
|
|
6
|
+
import { defaultDirectoryCardSlotData } from "./DirectoryCard.tsx";
|
|
7
|
+
import { backgroundColors } from "../../../utils/themeConfigOptions.ts";
|
|
8
|
+
|
|
9
|
+
const cityDocument = {
|
|
10
|
+
locale: "en",
|
|
11
|
+
_site: {
|
|
12
|
+
name: "Example Business",
|
|
13
|
+
},
|
|
14
|
+
__: {
|
|
15
|
+
isPrimaryLocale: true,
|
|
16
|
+
},
|
|
17
|
+
_pageset: JSON.stringify({
|
|
18
|
+
config: {
|
|
19
|
+
urlTemplate: {
|
|
20
|
+
primary: "[[address.region]]/[[address.city]]/[[address.line1]]",
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
}),
|
|
24
|
+
dm_directoryChildren: [
|
|
25
|
+
{
|
|
26
|
+
address: {
|
|
27
|
+
city: "Arlington",
|
|
28
|
+
countryCode: "US",
|
|
29
|
+
line1: "1101 Wilson Blvd",
|
|
30
|
+
postalCode: "22209",
|
|
31
|
+
region: "VA",
|
|
32
|
+
},
|
|
33
|
+
mainPhone: "+12025551010",
|
|
34
|
+
hours: {
|
|
35
|
+
monday: { openIntervals: [{ start: "09:00", end: "17:00" }] },
|
|
36
|
+
},
|
|
37
|
+
name: "Galaxy Grill Rosslyn",
|
|
38
|
+
timezone: "America/New_York",
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
address: {
|
|
42
|
+
city: "Arlington",
|
|
43
|
+
countryCode: "US",
|
|
44
|
+
line1: "4320 Fairfax Dr",
|
|
45
|
+
postalCode: "22201",
|
|
46
|
+
region: "VA",
|
|
47
|
+
},
|
|
48
|
+
mainPhone: "+12025551011",
|
|
49
|
+
name: "Galaxy Grill Ballston",
|
|
50
|
+
timezone: "America/New_York",
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
name: "Arlington",
|
|
54
|
+
meta: { entityType: { id: "dm_city", uid: 456 }, locale: "en" },
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const directoryProps = {
|
|
58
|
+
styles: {
|
|
59
|
+
backgroundColor: {
|
|
60
|
+
bgColor: "bg-palette-primary-dark",
|
|
61
|
+
textColor: "text-white",
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
slots: {
|
|
65
|
+
TitleSlot: [],
|
|
66
|
+
SiteNameSlot: [],
|
|
67
|
+
BreadcrumbsSlot: [],
|
|
68
|
+
DirectoryGrid: [
|
|
69
|
+
{
|
|
70
|
+
type: "DirectoryGrid",
|
|
71
|
+
props: {
|
|
72
|
+
slots: {
|
|
73
|
+
CardSlot: [],
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
describe("directoryChildReference", () => {
|
|
82
|
+
it("stores directory cards as child references and keeps card titles in the title slot", async () => {
|
|
83
|
+
const puckConfig: Config = {
|
|
84
|
+
components: { Directory, ...SlotsCategoryComponents },
|
|
85
|
+
root: {
|
|
86
|
+
render: () => React.createElement(React.Fragment),
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const resolvedData = await resolveAllData(
|
|
91
|
+
{
|
|
92
|
+
root: {
|
|
93
|
+
props: {},
|
|
94
|
+
},
|
|
95
|
+
content: [
|
|
96
|
+
{
|
|
97
|
+
type: "Directory",
|
|
98
|
+
props: directoryProps,
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
},
|
|
102
|
+
puckConfig,
|
|
103
|
+
{
|
|
104
|
+
streamDocument: cityDocument,
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
const cards =
|
|
109
|
+
resolvedData.content[0]?.props?.slots?.DirectoryGrid?.[0]?.props?.slots
|
|
110
|
+
?.CardSlot ?? [];
|
|
111
|
+
const firstCard = cards[0];
|
|
112
|
+
|
|
113
|
+
expect(cards).toHaveLength(2);
|
|
114
|
+
expect(firstCard?.props?.parentData).toEqual({
|
|
115
|
+
childRef: { childIndex: 0 },
|
|
116
|
+
});
|
|
117
|
+
expect(firstCard?.props?.parentData?.profile).toBeUndefined();
|
|
118
|
+
expect(firstCard?.props?.data).toEqual(
|
|
119
|
+
expect.objectContaining({
|
|
120
|
+
cardTitle: "Galaxy Grill Ballston",
|
|
121
|
+
})
|
|
122
|
+
);
|
|
123
|
+
expect(firstCard?.props?.field).toBe("name");
|
|
124
|
+
expect(firstCard?.props?.slots?.HeadingSlot?.[0]?.type).toBe(
|
|
125
|
+
"HeadingTextSlot"
|
|
126
|
+
);
|
|
127
|
+
expect(
|
|
128
|
+
firstCard?.props?.slots?.HeadingSlot?.[0]?.props?.data?.text
|
|
129
|
+
).toEqual({
|
|
130
|
+
field: "",
|
|
131
|
+
constantValue: {
|
|
132
|
+
defaultValue: "[[name]]",
|
|
133
|
+
},
|
|
134
|
+
constantValueEnabled: true,
|
|
135
|
+
});
|
|
136
|
+
expect(
|
|
137
|
+
firstCard?.props?.slots?.HeadingSlot?.[0]?.props?.parentData
|
|
138
|
+
).toEqual({
|
|
139
|
+
field: "name",
|
|
140
|
+
text: "Galaxy Grill Ballston",
|
|
141
|
+
});
|
|
142
|
+
expect(
|
|
143
|
+
firstCard?.props?.slots?.AddressSlot?.[0]?.props?.data?.address?.field
|
|
144
|
+
).toBe("address");
|
|
145
|
+
expect(
|
|
146
|
+
firstCard?.props?.slots?.PhoneSlot?.[0]?.props?.data?.number?.field
|
|
147
|
+
).toBe("mainPhone");
|
|
148
|
+
expect(
|
|
149
|
+
firstCard?.props?.slots?.HoursSlot?.[0]?.props?.data?.hours?.field
|
|
150
|
+
).toBe("hours");
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("preserves slot styles when directory cards are re-resolved", async () => {
|
|
154
|
+
const puckConfig: Config = {
|
|
155
|
+
components: { Directory, ...SlotsCategoryComponents },
|
|
156
|
+
root: {
|
|
157
|
+
render: () => React.createElement(React.Fragment),
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
const seededCard = defaultDirectoryCardSlotData("DirectoryCard-seeded", 0);
|
|
161
|
+
seededCard.props.slots.HeadingSlot[0]!.props.styles.color =
|
|
162
|
+
backgroundColors.color1.value;
|
|
163
|
+
seededCard.props.slots.AddressSlot[0]!.props.styles.color =
|
|
164
|
+
backgroundColors.color2.value;
|
|
165
|
+
seededCard.props.slots.PhoneSlot[0]!.props.styles.color =
|
|
166
|
+
backgroundColors.color3.value;
|
|
167
|
+
seededCard.props.slots.HoursSlot[0]!.props.styles.timeFormat = "24h";
|
|
168
|
+
seededCard.props.slots.HoursSlot[0]!.props.styles.bodyVariant = "sm";
|
|
169
|
+
|
|
170
|
+
const resolvedData = await resolveAllData(
|
|
171
|
+
{
|
|
172
|
+
root: {
|
|
173
|
+
props: {},
|
|
174
|
+
},
|
|
175
|
+
content: [
|
|
176
|
+
{
|
|
177
|
+
type: "Directory",
|
|
178
|
+
props: {
|
|
179
|
+
...directoryProps,
|
|
180
|
+
slots: {
|
|
181
|
+
...directoryProps.slots,
|
|
182
|
+
DirectoryGrid: [
|
|
183
|
+
{
|
|
184
|
+
type: "DirectoryGrid",
|
|
185
|
+
props: {
|
|
186
|
+
slots: {
|
|
187
|
+
CardSlot: [seededCard],
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
],
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
],
|
|
196
|
+
},
|
|
197
|
+
puckConfig,
|
|
198
|
+
{
|
|
199
|
+
streamDocument: cityDocument,
|
|
200
|
+
}
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
const cards =
|
|
204
|
+
resolvedData.content[0]?.props?.slots?.DirectoryGrid?.[0]?.props?.slots
|
|
205
|
+
?.CardSlot ?? [];
|
|
206
|
+
|
|
207
|
+
expect(cards).toHaveLength(2);
|
|
208
|
+
for (const card of cards) {
|
|
209
|
+
expect(
|
|
210
|
+
card?.props?.slots?.HeadingSlot?.[0]?.props?.styles?.color
|
|
211
|
+
).toEqual(backgroundColors.color1.value);
|
|
212
|
+
expect(
|
|
213
|
+
card?.props?.slots?.AddressSlot?.[0]?.props?.styles?.color
|
|
214
|
+
).toEqual(backgroundColors.color2.value);
|
|
215
|
+
expect(card?.props?.slots?.PhoneSlot?.[0]?.props?.styles?.color).toEqual(
|
|
216
|
+
backgroundColors.color3.value
|
|
217
|
+
);
|
|
218
|
+
expect(
|
|
219
|
+
card?.props?.slots?.HoursSlot?.[0]?.props?.styles?.timeFormat
|
|
220
|
+
).toBe("24h");
|
|
221
|
+
expect(
|
|
222
|
+
card?.props?.slots?.HoursSlot?.[0]?.props?.styles?.bodyVariant
|
|
223
|
+
).toBe("sm");
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
});
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import {
|
|
3
|
+
isDirectoryGrid,
|
|
4
|
+
sortAlphabetically,
|
|
5
|
+
} from "../../../utils/directory/utils.ts";
|
|
6
|
+
|
|
7
|
+
export type DirectoryChildReference = {
|
|
8
|
+
childIndex: number;
|
|
9
|
+
childId?: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
type DirectoryChild = {
|
|
13
|
+
id?: string;
|
|
14
|
+
name?: string;
|
|
15
|
+
[key: string]: any;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const DirectoryChildrenContext = React.createContext<DirectoryChild[]>([]);
|
|
19
|
+
|
|
20
|
+
export const DirectoryChildrenProvider = ({
|
|
21
|
+
children,
|
|
22
|
+
directoryChildren,
|
|
23
|
+
}: {
|
|
24
|
+
children: React.ReactNode;
|
|
25
|
+
directoryChildren: DirectoryChild[];
|
|
26
|
+
}) => (
|
|
27
|
+
<DirectoryChildrenContext.Provider value={directoryChildren}>
|
|
28
|
+
{children}
|
|
29
|
+
</DirectoryChildrenContext.Provider>
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
export const useDirectoryChildren = (): DirectoryChild[] =>
|
|
33
|
+
React.useContext(DirectoryChildrenContext);
|
|
34
|
+
|
|
35
|
+
export const getSortedDirectoryChildren = (
|
|
36
|
+
directoryChildren: unknown
|
|
37
|
+
): DirectoryChild[] => {
|
|
38
|
+
if (
|
|
39
|
+
!Array.isArray(directoryChildren) ||
|
|
40
|
+
!isDirectoryGrid(directoryChildren)
|
|
41
|
+
) {
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return sortAlphabetically([...directoryChildren], "name");
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const createDirectoryChildReference = (
|
|
49
|
+
child: DirectoryChild | undefined,
|
|
50
|
+
childIndex: number
|
|
51
|
+
): DirectoryChildReference => ({
|
|
52
|
+
childIndex,
|
|
53
|
+
...(typeof child?.id === "string" ? { childId: child.id } : {}),
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
export const matchesDirectoryChildReference = (
|
|
57
|
+
childReference: DirectoryChildReference | undefined,
|
|
58
|
+
child: DirectoryChild | undefined,
|
|
59
|
+
childIndex: number
|
|
60
|
+
): boolean => {
|
|
61
|
+
if (!childReference || childReference.childIndex !== childIndex) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (childReference.childId && childReference.childId !== child?.id) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return true;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const resolveDirectoryChildFromReference = (
|
|
73
|
+
directoryChildren: DirectoryChild[],
|
|
74
|
+
childReference: DirectoryChildReference | undefined
|
|
75
|
+
): DirectoryChild | undefined => {
|
|
76
|
+
if (!childReference) {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const childAtIndex = directoryChildren[childReference.childIndex];
|
|
81
|
+
if (
|
|
82
|
+
matchesDirectoryChildReference(
|
|
83
|
+
childReference,
|
|
84
|
+
childAtIndex,
|
|
85
|
+
childReference.childIndex
|
|
86
|
+
)
|
|
87
|
+
) {
|
|
88
|
+
return childAtIndex;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (childReference.childId) {
|
|
92
|
+
return directoryChildren.find(
|
|
93
|
+
(child) => child?.id === childReference.childId
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return childAtIndex;
|
|
98
|
+
};
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render, screen } from "@testing-library/react";
|
|
3
|
+
import { describe, expect, it, vi } from "vitest";
|
|
4
|
+
import { FilterModal } from "./Filters.tsx";
|
|
5
|
+
|
|
6
|
+
vi.mock("react-i18next", async () => {
|
|
7
|
+
const actual = await vi.importActual("react-i18next");
|
|
8
|
+
return {
|
|
9
|
+
...actual,
|
|
10
|
+
useTranslation: () => ({
|
|
11
|
+
t: (_key: string, defaultValue: string) => defaultValue,
|
|
12
|
+
i18n: { language: "fr" },
|
|
13
|
+
}),
|
|
14
|
+
};
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
vi.mock("@yext/search-headless-react", async () => {
|
|
18
|
+
const actual = await vi.importActual<
|
|
19
|
+
typeof import("@yext/search-headless-react")
|
|
20
|
+
>("@yext/search-headless-react");
|
|
21
|
+
return {
|
|
22
|
+
...actual,
|
|
23
|
+
useSearchState: (selector: (state: any) => unknown) =>
|
|
24
|
+
selector({
|
|
25
|
+
filters: {
|
|
26
|
+
facets: [
|
|
27
|
+
{
|
|
28
|
+
fieldId: "keywords",
|
|
29
|
+
options: [{ matcher: actual.Matcher.Equals, value: "retail" }],
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
fieldId: "services",
|
|
33
|
+
options: [{ matcher: actual.Matcher.Equals, value: "delivery" }],
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
fieldId: "languages",
|
|
37
|
+
options: [{ matcher: actual.Matcher.Equals, value: "French" }],
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
fieldId: "yearsOfExperience",
|
|
41
|
+
options: [
|
|
42
|
+
{
|
|
43
|
+
matcher: actual.Matcher.Between,
|
|
44
|
+
value: {
|
|
45
|
+
start: {
|
|
46
|
+
matcher: actual.Matcher.GreaterThanOrEqualTo,
|
|
47
|
+
value: 5,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
}),
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
vi.mock("@yext/search-ui-react", async () => {
|
|
60
|
+
const actual = await vi.importActual<typeof import("@yext/search-ui-react")>(
|
|
61
|
+
"@yext/search-ui-react"
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
...actual,
|
|
66
|
+
AppliedFilters: () => null,
|
|
67
|
+
Facets: ({ children }: React.PropsWithChildren) => <div>{children}</div>,
|
|
68
|
+
StandardFacet: ({
|
|
69
|
+
fieldId,
|
|
70
|
+
label,
|
|
71
|
+
}: {
|
|
72
|
+
fieldId: string;
|
|
73
|
+
label?: string;
|
|
74
|
+
}) => (
|
|
75
|
+
<div
|
|
76
|
+
data-testid={`facet-${fieldId}`}
|
|
77
|
+
data-label={label}
|
|
78
|
+
data-type="standard"
|
|
79
|
+
/>
|
|
80
|
+
),
|
|
81
|
+
NumericalFacet: ({
|
|
82
|
+
fieldId,
|
|
83
|
+
label,
|
|
84
|
+
}: {
|
|
85
|
+
fieldId: string;
|
|
86
|
+
label?: string;
|
|
87
|
+
}) => (
|
|
88
|
+
<div
|
|
89
|
+
data-testid={`facet-${fieldId}`}
|
|
90
|
+
data-label={label}
|
|
91
|
+
data-type="numerical"
|
|
92
|
+
/>
|
|
93
|
+
),
|
|
94
|
+
};
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
const renderFilterModal = (
|
|
98
|
+
keywordsDisplayName?: React.ComponentProps<
|
|
99
|
+
typeof FilterModal
|
|
100
|
+
>["keywordsDisplayName"]
|
|
101
|
+
) =>
|
|
102
|
+
render(
|
|
103
|
+
<FilterModal
|
|
104
|
+
showFilterModal={true}
|
|
105
|
+
showOpenNowOption={false}
|
|
106
|
+
isOpenNowSelected={false}
|
|
107
|
+
showDistanceOptions={false}
|
|
108
|
+
selectedDistanceOption={null}
|
|
109
|
+
handleCloseModalClick={vi.fn()}
|
|
110
|
+
handleOpenNowClick={vi.fn()}
|
|
111
|
+
handleDistanceClick={vi.fn()}
|
|
112
|
+
handleClearFiltersClick={vi.fn()}
|
|
113
|
+
accentColorCssValue="#000"
|
|
114
|
+
closeButtonRef={React.createRef<HTMLButtonElement>()}
|
|
115
|
+
keywordsDisplayName={keywordsDisplayName}
|
|
116
|
+
/>
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
describe("FilterModal", () => {
|
|
120
|
+
it("uses the current-locale display name only for the Keywords facet", () => {
|
|
121
|
+
renderFilterModal({
|
|
122
|
+
en: "Store Type",
|
|
123
|
+
fr: "Type de magasin",
|
|
124
|
+
hasLocalizedValue: "true",
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
expect(screen.getByTestId("facet-keywords").dataset.label).toBe(
|
|
128
|
+
"Type de magasin"
|
|
129
|
+
);
|
|
130
|
+
expect(screen.getByTestId("facet-services").dataset.label).toBeUndefined();
|
|
131
|
+
expect(screen.getByTestId("facet-languages").dataset.label).toBeUndefined();
|
|
132
|
+
expect(screen.getByTestId("facet-yearsOfExperience").dataset).toMatchObject(
|
|
133
|
+
{
|
|
134
|
+
type: "numerical",
|
|
135
|
+
}
|
|
136
|
+
);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("leaves the Keywords label undefined when the current locale is missing", () => {
|
|
140
|
+
renderFilterModal({
|
|
141
|
+
en: "Store Type",
|
|
142
|
+
hasLocalizedValue: "true",
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
expect(screen.getByTestId("facet-keywords").dataset.label).toBeUndefined();
|
|
146
|
+
});
|
|
147
|
+
});
|