@exdst-sitecore-content-sdk/astro 0.0.23 → 0.0.25
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 +9 -14
- package/src/client/sitecore-astro-client.ts +0 -45
- package/src/context.ts +14 -16
- package/src/env.d.ts +1 -1
- package/src/sharedTypes/component-props.ts +0 -10
- package/src/tools/generate-map.ts +9 -21
- package/src/client/sitecore-astro-client.test.ts +0 -292
- package/src/components/AstroImage.astro.test.ts +0 -541
- package/src/components/Date.astro.test.ts +0 -197
- package/src/components/EditingScripts.astro.test.ts +0 -267
- package/src/components/ErrorBoundary.astro.test.ts +0 -252
- package/src/components/ErrorComponent.astro.test.ts +0 -31
- package/src/components/FieldMetadata.astro.test.ts +0 -40
- package/src/components/File.astro.test.ts +0 -68
- package/src/components/HiddenRendering.astro.test.ts +0 -36
- package/src/components/Image.astro.test.ts +0 -438
- package/src/components/Link.astro.test.ts +0 -261
- package/src/components/MissingComponent.astro.test.ts +0 -21
- package/src/components/Placeholder/Placeholder.astro.test.ts +0 -1088
- package/src/components/Placeholder/PlaceholderMetadata.astro.test.ts +0 -228
- package/src/components/Placeholder/PlaceholderUtils.astro.test.ts +0 -149
- package/src/components/Placeholder/placeholder-utils.test.ts +0 -309
- package/src/components/RichText.astro.test.ts +0 -205
- package/src/components/Text.astro.test.ts +0 -273
- package/src/config/define-config.test.ts +0 -526
- package/src/config-cli/define-cli-config.test.ts +0 -88
- package/src/editing/editing-config-middleware.test.ts +0 -164
- package/src/editing/editing-render-middleware.test.ts +0 -1143
- package/src/editing/render-middleware.test.ts +0 -57
- package/src/editing/utils.test.ts +0 -1212
- package/src/enhancers/WithEmptyFieldEditingComponent.astro.test.ts +0 -380
- package/src/enhancers/WithFieldMetadata.astro.test.ts +0 -113
- package/src/middleware/middleware.test.ts +0 -520
- package/src/middleware/multisite-middleware.test.ts +0 -667
- package/src/middleware/robots-middleware.test.ts +0 -129
- package/src/middleware/sitemap-middleware.test.ts +0 -184
- package/src/services/component-props-service.ts +0 -183
- package/src/tests/astro-helpers.ts +0 -61
- package/src/tests/helpers.ts +0 -46
- package/src/tests/personalizeData.ts +0 -63
- package/src/tests/test-components/CustomErrorComponent.astro +0 -3
- package/src/tests/test-components/CustomHiddenRendering.astro +0 -10
- package/src/tests/test-components/CustomMissingComponent.astro +0 -9
- package/src/tests/test-components/DownloadCallout.astro +0 -12
- package/src/tests/test-components/EmptyFieldEditingComponent.astro +0 -5
- package/src/tests/test-components/ErrorBoundaryWithError.astro +0 -10
- package/src/tests/test-components/Home.astro +0 -12
- package/src/tests/test-components/SxaRichText.astro +0 -23
- package/src/tests/test-components/SxaRichTextDefault.astro +0 -7
- package/src/tests/test-components/SxaRichTextWithTitle.astro +0 -8
- package/src/tests/test-components/TestComponent.astro +0 -9
- package/src/tests/test-components/TestComponentWithError.astro +0 -4
- package/src/tests/test-components/TestComponentWithField.astro +0 -17
- package/src/tests/test-components/TestHeader.astro +0 -8
- package/src/tests/test-components/TestLogo.astro +0 -5
- package/src/tests/test-components/TestParentWrapperComponent.astro +0 -5
- package/src/tests/test-components/TestWrapperComponent.astro +0 -5
- package/src/tests/test-components/map-components/Bar.astro +0 -0
- package/src/tests/test-components/map-components/Baz.astro +0 -0
- package/src/tests/test-components/map-components/Foo.astro +0 -0
- package/src/tests/test-components/map-components/Hero.variant.astro +0 -0
- package/src/tests/test-components/map-components/NotComponent.bsx +0 -0
- package/src/tests/test-components/map-components/Qux.astro +0 -0
- package/src/tests/test-components/map-components/folded/Folded.astro +0 -0
- package/src/tests/test-components/map-components/folded/random-file-2.docx +0 -0
- package/src/tests/test-components/map-components/random-file.txt +0 -0
- package/src/tests/test-data/metadata-data.ts +0 -86
- package/src/tests/test-data/normal-mode-data.ts +0 -466
- package/src/tests/vitest.setup.ts +0 -4
- package/src/tools/templating/components.test.ts +0 -318
- package/src/tools/templating/default-component.test.ts +0 -31
- package/src/utils/utils.test.ts +0 -48
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exdst-sitecore-content-sdk/astro",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.25",
|
|
4
|
+
"description": "Astro Content SDK for Sitecore AI (XM Cloud)",
|
|
4
5
|
"type": "module",
|
|
5
6
|
"sideEffects": false,
|
|
6
7
|
"publishConfig": {
|
|
@@ -9,13 +10,13 @@
|
|
|
9
10
|
},
|
|
10
11
|
"scripts": {
|
|
11
12
|
"typecheck": "tsc -p tsconfig.json",
|
|
13
|
+
"build:types": "tsc -p tsconfig.build.json",
|
|
12
14
|
"lint": "eslint \"./src/**/*.ts\"",
|
|
13
|
-
"test": "npm run test:unit
|
|
15
|
+
"test": "npm run test:unit && npm run test:components",
|
|
14
16
|
"test:unit": "mocha \"./src/**/*.test.ts\" --ignore \"src/**/*.astro.test.ts\"",
|
|
15
17
|
"test:components": "vitest run --config ./vitest.config.ts",
|
|
16
18
|
"coverage": "nyc npm test",
|
|
17
|
-
"
|
|
18
|
-
"api-extractor": "npm run build && api-extractor run --local --verbose",
|
|
19
|
+
"api-extractor": "api-extractor run --local --verbose",
|
|
19
20
|
"api-extractor:verify": "api-extractor run"
|
|
20
21
|
},
|
|
21
22
|
"engines": {
|
|
@@ -49,7 +50,7 @@
|
|
|
49
50
|
"@types/sinon-chai": "^4.0.0",
|
|
50
51
|
"@typescript-eslint/eslint-plugin": "8.39.0",
|
|
51
52
|
"@typescript-eslint/parser": "8.39.0",
|
|
52
|
-
"astro": "^6.1.
|
|
53
|
+
"astro": "^6.1.3",
|
|
53
54
|
"chai": "^4.4.1",
|
|
54
55
|
"chai-spies": "^1.1.0",
|
|
55
56
|
"chai-string": "^1.6.0",
|
|
@@ -58,7 +59,6 @@
|
|
|
58
59
|
"eslint-plugin-import": "2.32.0",
|
|
59
60
|
"eslint-plugin-jsdoc": "52.0.3",
|
|
60
61
|
"eslint-plugin-prettier": "^4.0.0",
|
|
61
|
-
"glob": "^11.0.2",
|
|
62
62
|
"happy-dom": "^16.7.3",
|
|
63
63
|
"mocha": "^11.2.2",
|
|
64
64
|
"nyc": "^17.1.0",
|
|
@@ -72,7 +72,8 @@
|
|
|
72
72
|
},
|
|
73
73
|
"peerDependencies": {
|
|
74
74
|
"@sitecore-content-sdk/analytics-core": "^2.0.1",
|
|
75
|
-
"@sitecore-content-sdk/events": "^2.0.1"
|
|
75
|
+
"@sitecore-content-sdk/events": "^2.0.1",
|
|
76
|
+
"astro": "^6.0.0"
|
|
76
77
|
},
|
|
77
78
|
"dependencies": {
|
|
78
79
|
"@sitecore-content-sdk/content": "^2.0.1",
|
|
@@ -96,11 +97,5 @@
|
|
|
96
97
|
"./tools": "./src/tools/index.ts",
|
|
97
98
|
"./utils": "./src/utils/index.ts",
|
|
98
99
|
"./components/Placeholder": "./src/components/Placeholder/index.ts"
|
|
99
|
-
}
|
|
100
|
-
"description": "",
|
|
101
|
-
"files": [
|
|
102
|
-
"src",
|
|
103
|
-
"index.ts",
|
|
104
|
-
"readme.md"
|
|
105
|
-
]
|
|
100
|
+
}
|
|
106
101
|
}
|
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
SitecoreClientInit,
|
|
8
8
|
} from '@sitecore-content-sdk/content/client';
|
|
9
9
|
import { PreviewData } from '../sharedTypes/component-props';
|
|
10
|
-
import { ComponentPropsService } from '../services/component-props-service';
|
|
11
10
|
import { EditingPreviewData } from '@sitecore-content-sdk/content/editing';
|
|
12
11
|
import { getSiteRewriteData, normalizeSiteRewrite } from '@sitecore-content-sdk/content/site';
|
|
13
12
|
import {
|
|
@@ -27,10 +26,8 @@ export type SitecoreAstroClientInit = SitecoreClientInit & Pick<SitecoreConfig,
|
|
|
27
26
|
* @public
|
|
28
27
|
*/
|
|
29
28
|
export class SitecoreAstroClient extends SitecoreClient {
|
|
30
|
-
protected componentPropsService: ComponentPropsService;
|
|
31
29
|
constructor(protected initOptions: SitecoreAstroClientInit) {
|
|
32
30
|
super(initOptions);
|
|
33
|
-
this.componentPropsService = this.getComponentPropsService();
|
|
34
31
|
}
|
|
35
32
|
|
|
36
33
|
/**
|
|
@@ -109,46 +106,4 @@ export class SitecoreAstroClient extends SitecoreClient {
|
|
|
109
106
|
|
|
110
107
|
return staticPaths;
|
|
111
108
|
}
|
|
112
|
-
|
|
113
|
-
// /**
|
|
114
|
-
// * Parses components from component map and layoutData, executes getServerProps/getStaticProps methods
|
|
115
|
-
// * and returns resulting props from components
|
|
116
|
-
// * @param {LayoutServiceData} layoutData layout data to parse compnents from
|
|
117
|
-
// * @param {ComponentMap<AstroContentSdkComponent>} components component map to get props for
|
|
118
|
-
// * @returns {ComponentPropsCollection} component props
|
|
119
|
-
// */
|
|
120
|
-
// async getComponentData(
|
|
121
|
-
// layoutData: LayoutServiceData,
|
|
122
|
-
// // context: GetServerSidePropsContext | GetStaticPropsContext,
|
|
123
|
-
// components: ComponentMap<AstroContentSdkComponent>
|
|
124
|
-
// ): Promise<ComponentPropsCollection> {
|
|
125
|
-
// let componentProps: ComponentPropsCollection = {};
|
|
126
|
-
// if (!layoutData.sitecore.route) return componentProps;
|
|
127
|
-
// // Retrieve component props using side-effects defined on components level
|
|
128
|
-
// componentProps = await this.componentPropsService.fetchComponentProps({
|
|
129
|
-
// layoutData: layoutData,
|
|
130
|
-
// // context,
|
|
131
|
-
// components,
|
|
132
|
-
// });
|
|
133
|
-
|
|
134
|
-
// const errors = Object.keys(componentProps)
|
|
135
|
-
// .map((id) => {
|
|
136
|
-
// const component = componentProps[id] as ComponentPropsError;
|
|
137
|
-
|
|
138
|
-
// return component.error
|
|
139
|
-
// ? `\nUnable to get component props for ${component.componentName} (${id}): ${component.error}`
|
|
140
|
-
// : '';
|
|
141
|
-
// })
|
|
142
|
-
// .join('');
|
|
143
|
-
|
|
144
|
-
// if (errors.length) {
|
|
145
|
-
// throw new Error(errors);
|
|
146
|
-
// }
|
|
147
|
-
|
|
148
|
-
// return componentProps;
|
|
149
|
-
// }
|
|
150
|
-
|
|
151
|
-
protected getComponentPropsService(): ComponentPropsService {
|
|
152
|
-
return new ComponentPropsService();
|
|
153
|
-
}
|
|
154
109
|
}
|
package/src/context.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { map } from 'nanostores';
|
|
|
2
2
|
import { ComponentMap } from './sharedTypes/component-props';
|
|
3
3
|
import { Page } from '@sitecore-content-sdk/content/client';
|
|
4
4
|
import { SitecoreConfig } from '@sitecore-content-sdk/content/config';
|
|
5
|
-
import { DictionaryPhrases } from '@sitecore-content-sdk/content/
|
|
5
|
+
import { DictionaryPhrases } from '@sitecore-content-sdk/content/i18n';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Nanostore map holding Sitecore page, API config, component map, and dictionary for the current request or app scope.
|
|
@@ -12,7 +12,7 @@ export const SitecoreContext: any = map({});
|
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Shape of values passed when updating {@link SitecoreContext} (page, API, and optional component map).
|
|
15
|
-
* @
|
|
15
|
+
* @public
|
|
16
16
|
*/
|
|
17
17
|
export interface SitecoreContextProps {
|
|
18
18
|
/**
|
|
@@ -31,9 +31,9 @@ export interface SitecoreContextProps {
|
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* Shape of values passed when updating dictionary phrases on {@link SitecoreContext}.
|
|
34
|
-
* @
|
|
34
|
+
* @public
|
|
35
35
|
*/
|
|
36
|
-
export interface
|
|
36
|
+
export interface SitecoreDictionaryProps {
|
|
37
37
|
/**
|
|
38
38
|
* The dictionary data.
|
|
39
39
|
*/
|
|
@@ -42,10 +42,8 @@ export interface SitecoreDictionarytProps {
|
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
44
|
* Writes page data, API config, and optional component map into {@link SitecoreContext}.
|
|
45
|
-
* @param {
|
|
46
|
-
* @
|
|
47
|
-
* @param {ComponentMap} [props.componentMap] - Component map.
|
|
48
|
-
* @internal
|
|
45
|
+
* @param {SitecoreContextProps} props - Page, API, and optional component map.
|
|
46
|
+
* @public
|
|
49
47
|
*/
|
|
50
48
|
export const updateSitecoreContext = ({ page, api, componentMap }: SitecoreContextProps) => {
|
|
51
49
|
SitecoreContext.setKey('page', page);
|
|
@@ -55,11 +53,10 @@ export const updateSitecoreContext = ({ page, api, componentMap }: SitecoreConte
|
|
|
55
53
|
|
|
56
54
|
/**
|
|
57
55
|
* Writes dictionary phrases into {@link SitecoreContext} for {@link useDictionary}.
|
|
58
|
-
* @param {
|
|
59
|
-
* @
|
|
60
|
-
* @internal
|
|
56
|
+
* @param {DictionaryPhrases} dictionary - The dictionary data.
|
|
57
|
+
* @public
|
|
61
58
|
*/
|
|
62
|
-
export const updateSitecoreDictionary = ({ dictionary }:
|
|
59
|
+
export const updateSitecoreDictionary = ({ dictionary }: SitecoreDictionaryProps) => {
|
|
63
60
|
SitecoreContext.setKey('dictionary', dictionary);
|
|
64
61
|
};
|
|
65
62
|
|
|
@@ -68,9 +65,10 @@ export const updateSitecoreDictionary = ({ dictionary }: SitecoreDictionarytProp
|
|
|
68
65
|
* @public
|
|
69
66
|
*/
|
|
70
67
|
export const useSitecore = (): SitecoreContextProps => {
|
|
68
|
+
const context = SitecoreContext.get();
|
|
71
69
|
return {
|
|
72
|
-
page:
|
|
73
|
-
api:
|
|
70
|
+
page: context.page,
|
|
71
|
+
api: context.api,
|
|
74
72
|
};
|
|
75
73
|
};
|
|
76
74
|
|
|
@@ -79,7 +77,7 @@ export const useSitecore = (): SitecoreContextProps => {
|
|
|
79
77
|
* @public
|
|
80
78
|
*/
|
|
81
79
|
export const useComponentMap = (): ComponentMap => {
|
|
82
|
-
return SitecoreContext.get()
|
|
80
|
+
return SitecoreContext.get().componentMap;
|
|
83
81
|
};
|
|
84
82
|
|
|
85
83
|
/**
|
|
@@ -88,7 +86,7 @@ export const useComponentMap = (): ComponentMap => {
|
|
|
88
86
|
*/
|
|
89
87
|
export const useDictionary = () => {
|
|
90
88
|
const t = (key: string): string => {
|
|
91
|
-
const dictionary = SitecoreContext.get()
|
|
89
|
+
const dictionary = SitecoreContext.get().dictionary;
|
|
92
90
|
if (!dictionary) {
|
|
93
91
|
return key;
|
|
94
92
|
}
|
package/src/env.d.ts
CHANGED
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
export type ComponentPropsError = { error: string; componentName: string };
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Shape of component props storage
|
|
5
|
-
* @public
|
|
6
|
-
*/
|
|
7
|
-
export type ComponentPropsCollection = {
|
|
8
|
-
[componentUid: string]: unknown | ComponentPropsError;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
1
|
/**
|
|
12
2
|
* Represents an Astro component import
|
|
13
3
|
* @public
|
|
@@ -36,40 +36,28 @@ export const generateMap: GenerateMapFunction = ({
|
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
const buildAstroMapContent: ComponentMapTemplate = (components, componentImports): string => {
|
|
39
|
-
const
|
|
40
|
-
const namedImports: string[] = [];
|
|
41
|
-
|
|
39
|
+
const componentImportsList: string[] = [];
|
|
42
40
|
const componentMapEntries: string[] = [];
|
|
43
41
|
|
|
44
42
|
components.forEach((component) => {
|
|
45
|
-
|
|
43
|
+
componentImportsList.push(
|
|
44
|
+
`import ${component.moduleName} from '${component.importPath}.astro';`
|
|
45
|
+
);
|
|
46
46
|
componentMapEntries.push(`['${component.moduleName}', ${component.moduleName}]`);
|
|
47
47
|
});
|
|
48
48
|
|
|
49
49
|
componentImports?.forEach((packageEntry) => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}.astro';`
|
|
55
|
-
);
|
|
56
|
-
packageEntry.importInfo.namedImports.forEach((importName) => {
|
|
57
|
-
componentMapEntries.push(`['${importName}', ${importName}]`);
|
|
58
|
-
});
|
|
59
|
-
} else {
|
|
60
|
-
wildcardImports.push(
|
|
61
|
-
`import ${packageEntry.importName} from '${packageEntry.importInfo.importFrom}';`
|
|
62
|
-
);
|
|
63
|
-
componentMapEntries.push(`['${packageEntry.importName}', ${packageEntry.importName}]`);
|
|
64
|
-
}
|
|
50
|
+
componentImportsList.push(
|
|
51
|
+
`import ${packageEntry.importName} from '${packageEntry.importInfo.importFrom}';`
|
|
52
|
+
);
|
|
53
|
+
componentMapEntries.push(`['${packageEntry.importName}', ${packageEntry.importName}]`);
|
|
65
54
|
});
|
|
66
55
|
|
|
67
56
|
return `
|
|
68
57
|
import type { AstroContentSdkComponent } from '@exdst-sitecore-content-sdk/astro';
|
|
69
58
|
|
|
70
59
|
// Components imported from the app itself
|
|
71
|
-
${
|
|
72
|
-
${namedImports.join('\n')}
|
|
60
|
+
${componentImportsList.join('\n')}
|
|
73
61
|
|
|
74
62
|
// Components must be registered within the map to match the string key with component name in Sitecore
|
|
75
63
|
export const componentMap = new Map<string, AstroContentSdkComponent>([
|
|
@@ -1,292 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-unused-vars */
|
|
2
|
-
/* eslint-disable no-unused-expressions, @typescript-eslint/no-unused-expressions */
|
|
3
|
-
import { expect } from 'chai';
|
|
4
|
-
import * as chai from 'chai';
|
|
5
|
-
import sinon from 'sinon';
|
|
6
|
-
import sinonChai from 'sinon-chai';
|
|
7
|
-
import { SitecoreAstroClient } from './sitecore-astro-client';
|
|
8
|
-
import { DefaultRetryStrategy } from '@sitecore-content-sdk/core';
|
|
9
|
-
import { SITE_PREFIX } from '@sitecore-content-sdk/content/site';
|
|
10
|
-
import { layoutData, componentsWithExperiencesArray } from '../tests/personalizeData';
|
|
11
|
-
import { VARIANT_PREFIX } from '@sitecore-content-sdk/content/personalize';
|
|
12
|
-
|
|
13
|
-
chai.use(sinonChai);
|
|
14
|
-
|
|
15
|
-
describe('SitecoreClient', () => {
|
|
16
|
-
const sandbox = sinon.createSandbox();
|
|
17
|
-
const defaultInitOptions = {
|
|
18
|
-
api: {
|
|
19
|
-
edge: {
|
|
20
|
-
contextId: 'test-context-id',
|
|
21
|
-
clientContextId: 'client-context-id',
|
|
22
|
-
edgeUrl: 'https://edge.example.com',
|
|
23
|
-
},
|
|
24
|
-
local: {
|
|
25
|
-
apiHost: 'http://local.example.com',
|
|
26
|
-
apiKey: 'test-api-key',
|
|
27
|
-
path: '/api/graph/test',
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
editingSecret: '********-****',
|
|
31
|
-
retries: {
|
|
32
|
-
count: 3,
|
|
33
|
-
retryStrategy: sinon.createStubInstance(DefaultRetryStrategy),
|
|
34
|
-
},
|
|
35
|
-
defaultSite: 'default-site',
|
|
36
|
-
defaultLanguage: 'en',
|
|
37
|
-
layout: { formatLayoutQuery: sandbox.stub() },
|
|
38
|
-
dictionary: { caching: { enabled: true, timeout: 60000 } },
|
|
39
|
-
disableCodeGeneration: false,
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
let sitecoreClient = new SitecoreAstroClient(defaultInitOptions);
|
|
43
|
-
|
|
44
|
-
let layoutServiceStub = {
|
|
45
|
-
fetchLayoutData: sandbox.stub(),
|
|
46
|
-
};
|
|
47
|
-
let dictionaryServiceStub = {
|
|
48
|
-
fetchDictionaryData: sandbox.stub(),
|
|
49
|
-
};
|
|
50
|
-
let errorPagesServiceStub = {
|
|
51
|
-
fetchErrorPages: sandbox.stub(),
|
|
52
|
-
};
|
|
53
|
-
let editingServiceStub = {
|
|
54
|
-
fetchEditingData: sandbox.stub(),
|
|
55
|
-
fetchDictionaryData: sandbox.stub(),
|
|
56
|
-
};
|
|
57
|
-
let restComponentServiceStub = {
|
|
58
|
-
fetchComponentData: sandbox.stub(),
|
|
59
|
-
};
|
|
60
|
-
let sitePathServiceStub = {
|
|
61
|
-
fetchSiteRoutes: sandbox.stub(),
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
beforeEach(() => {
|
|
65
|
-
layoutServiceStub = {
|
|
66
|
-
fetchLayoutData: sandbox.stub(),
|
|
67
|
-
};
|
|
68
|
-
dictionaryServiceStub = {
|
|
69
|
-
fetchDictionaryData: sandbox.stub(),
|
|
70
|
-
};
|
|
71
|
-
errorPagesServiceStub = {
|
|
72
|
-
fetchErrorPages: sandbox.stub(),
|
|
73
|
-
};
|
|
74
|
-
editingServiceStub = {
|
|
75
|
-
fetchEditingData: sandbox.stub(),
|
|
76
|
-
fetchDictionaryData: sandbox.stub(),
|
|
77
|
-
};
|
|
78
|
-
restComponentServiceStub = {
|
|
79
|
-
fetchComponentData: sandbox.stub(),
|
|
80
|
-
};
|
|
81
|
-
sitePathServiceStub = {
|
|
82
|
-
fetchSiteRoutes: sandbox.stub(),
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
sitecoreClient = new SitecoreAstroClient(defaultInitOptions);
|
|
86
|
-
|
|
87
|
-
(sitecoreClient as any).layoutService = layoutServiceStub;
|
|
88
|
-
(sitecoreClient as any).dictionaryService = dictionaryServiceStub;
|
|
89
|
-
(sitecoreClient as any).errorPagesService = errorPagesServiceStub;
|
|
90
|
-
(sitecoreClient as any).editingService = editingServiceStub;
|
|
91
|
-
(sitecoreClient as any).componentService = restComponentServiceStub;
|
|
92
|
-
(sitecoreClient as any).sitePathService = sitePathServiceStub;
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
describe('getPage', () => {
|
|
96
|
-
it('should personalize page layout when variants present in path', async () => {
|
|
97
|
-
const path = `${VARIANT_PREFIX}variant1/${VARIANT_PREFIX}mountain_bike_audience/test/path`;
|
|
98
|
-
const locale = 'en-US';
|
|
99
|
-
const testLayoutData = structuredClone(layoutData);
|
|
100
|
-
|
|
101
|
-
const siteInfo = {
|
|
102
|
-
name: 'default-site',
|
|
103
|
-
hostName: 'example.com',
|
|
104
|
-
language: 'en',
|
|
105
|
-
};
|
|
106
|
-
layoutServiceStub.fetchLayoutData.returns(testLayoutData);
|
|
107
|
-
sandbox.stub(sitecoreClient, 'getHeadLinks').returns([]);
|
|
108
|
-
|
|
109
|
-
const result = await sitecoreClient.getPage(path, { locale });
|
|
110
|
-
|
|
111
|
-
expect(result?.layout.sitecore.route?.placeholders).to.deep.equal({
|
|
112
|
-
'content-sdk-main': [...componentsWithExperiencesArray],
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('should use personalize details passed in page options over variants present in path', async () => {
|
|
117
|
-
const path = `${VARIANT_PREFIX}variant1/${VARIANT_PREFIX}sand_bike_audience/test/path`;
|
|
118
|
-
const locale = 'en-US';
|
|
119
|
-
const testLayoutData = structuredClone(layoutData);
|
|
120
|
-
|
|
121
|
-
const siteInfo = {
|
|
122
|
-
name: 'default-site',
|
|
123
|
-
hostName: 'example.com',
|
|
124
|
-
language: 'en',
|
|
125
|
-
};
|
|
126
|
-
layoutServiceStub.fetchLayoutData.returns(testLayoutData);
|
|
127
|
-
sandbox.stub(sitecoreClient, 'getHeadLinks').returns([]);
|
|
128
|
-
|
|
129
|
-
const result = await sitecoreClient.getPage(path, {
|
|
130
|
-
locale,
|
|
131
|
-
personalize: {
|
|
132
|
-
variantId: 'variant2',
|
|
133
|
-
componentVariantIds: ['mountain_bike_audience'],
|
|
134
|
-
},
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
expect(result?.layout.sitecore.route?.placeholders).to.deep.equal({
|
|
138
|
-
'content-sdk-main': [...componentsWithExperiencesArray],
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it('should pass site from path to base getPage method', async () => {
|
|
143
|
-
const path = `${SITE_PREFIX}mysite/test/path`;
|
|
144
|
-
const locale = 'en-US';
|
|
145
|
-
const testLayoutData = structuredClone(layoutData);
|
|
146
|
-
|
|
147
|
-
sandbox.stub(sitecoreClient, 'parsePath').returns('/test/path');
|
|
148
|
-
layoutServiceStub.fetchLayoutData.returns(testLayoutData);
|
|
149
|
-
|
|
150
|
-
await sitecoreClient.getPage(path, {
|
|
151
|
-
locale,
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
expect(layoutServiceStub.fetchLayoutData).to.be.calledWithMatch('/test/path', {
|
|
155
|
-
locale,
|
|
156
|
-
site: 'mysite',
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
it('should use site passed in page options over site parsed from path', async () => {
|
|
161
|
-
const path = `${SITE_PREFIX}mysite/test/path`;
|
|
162
|
-
const locale = 'en-US';
|
|
163
|
-
const testLayoutData = structuredClone(layoutData);
|
|
164
|
-
|
|
165
|
-
sandbox.stub(sitecoreClient, 'parsePath').returns('/test/path');
|
|
166
|
-
|
|
167
|
-
layoutServiceStub.fetchLayoutData.returns(testLayoutData);
|
|
168
|
-
|
|
169
|
-
await sitecoreClient.getPage(path, {
|
|
170
|
-
locale,
|
|
171
|
-
site: 'other-site',
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
expect(layoutServiceStub.fetchLayoutData).to.be.calledWithMatch('/test/path', {
|
|
175
|
-
locale,
|
|
176
|
-
site: 'other-site',
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
describe('getSiteNameFromPath', () => {
|
|
182
|
-
it('should get site name correctly with string path', () => {
|
|
183
|
-
const path = '/some/path';
|
|
184
|
-
const siteInfo = { name: 'default-site', hostName: '*', language: 'en' };
|
|
185
|
-
|
|
186
|
-
const result = sitecoreClient.getSiteNameFromPath(path);
|
|
187
|
-
|
|
188
|
-
expect(result).to.equal(siteInfo.name);
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
it('should get site name correctly with array path', () => {
|
|
192
|
-
const path = [`${SITE_PREFIX}other-site`, '/some', 'path'];
|
|
193
|
-
const siteInfo = { name: 'other-site', hostName: '*', language: 'en' };
|
|
194
|
-
|
|
195
|
-
const result = sitecoreClient.getSiteNameFromPath(path);
|
|
196
|
-
|
|
197
|
-
expect(result).to.equal(siteInfo.name);
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
it('should get default site name when site not found', () => {
|
|
201
|
-
const path = ['wrong-path-yet-anoother-site', '/some', 'path'];
|
|
202
|
-
|
|
203
|
-
const result = sitecoreClient.getSiteNameFromPath(path);
|
|
204
|
-
|
|
205
|
-
expect(result).to.equal('default-site');
|
|
206
|
-
});
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
describe('parsePath', () => {
|
|
210
|
-
it('should return string path when accepting string[] path', () => {
|
|
211
|
-
const path = ['/some', 'path'];
|
|
212
|
-
const expectedPath = '/some/path';
|
|
213
|
-
|
|
214
|
-
const result = sitecoreClient.parsePath(path);
|
|
215
|
-
|
|
216
|
-
expect(result).to.equal(expectedPath);
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
it('should strip site and variant prefixes from path', () => {
|
|
220
|
-
const path = `/${SITE_PREFIX}site1/${VARIANT_PREFIX}variant1/some/path`;
|
|
221
|
-
const expectedPath = '/some/path';
|
|
222
|
-
|
|
223
|
-
const result = sitecoreClient.parsePath(path);
|
|
224
|
-
|
|
225
|
-
expect(result).to.equal(expectedPath);
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
describe('getPagePaths', () => {
|
|
230
|
-
it('should return static paths without site prefixes', async () => {
|
|
231
|
-
const paths = [
|
|
232
|
-
{ params: { path: ['_site_site-one', 'home'] }, locale: 'en' },
|
|
233
|
-
{ params: { path: ['_site_site-one', 'about'] }, locale: 'en' },
|
|
234
|
-
{ params: { path: ['_site_site-two', 'home'] }, locale: 'de-DE' },
|
|
235
|
-
];
|
|
236
|
-
|
|
237
|
-
const expectedPaths = [
|
|
238
|
-
{ params: { path: ['home'] }, locale: 'en' },
|
|
239
|
-
{ params: { path: ['about'] }, locale: 'en' },
|
|
240
|
-
{ params: { path: ['home'] }, locale: 'de-DE' },
|
|
241
|
-
];
|
|
242
|
-
|
|
243
|
-
sitePathServiceStub.fetchSiteRoutes.resolves(structuredClone(paths));
|
|
244
|
-
|
|
245
|
-
const result = await sitecoreClient.getPagePaths(['site-one'], ['en'], undefined);
|
|
246
|
-
|
|
247
|
-
expect(result).to.deep.equal(expectedPaths);
|
|
248
|
-
});
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
/*
|
|
252
|
-
describe('getComponentData', () => {
|
|
253
|
-
it('should return componentData when component has getComponentsProps method', async () => {
|
|
254
|
-
const context = {
|
|
255
|
-
params: { path: ['test', 'path'] },
|
|
256
|
-
query: {},
|
|
257
|
-
req: {},
|
|
258
|
-
res: {},
|
|
259
|
-
resolvedUrl: '/test/path',
|
|
260
|
-
} as unknown as GetServerSidePropsContext;
|
|
261
|
-
const layoutData = {
|
|
262
|
-
sitecore: {
|
|
263
|
-
context,
|
|
264
|
-
route: {
|
|
265
|
-
name: 'test',
|
|
266
|
-
placeholders: {
|
|
267
|
-
main: [
|
|
268
|
-
{
|
|
269
|
-
componentName: 'TestComponent',
|
|
270
|
-
uid: 'test-uid',
|
|
271
|
-
},
|
|
272
|
-
],
|
|
273
|
-
},
|
|
274
|
-
},
|
|
275
|
-
},
|
|
276
|
-
};
|
|
277
|
-
|
|
278
|
-
const mockComponent = {
|
|
279
|
-
getComponentServerProps: sandbox.stub().resolves({ props: { data: 'test-data' } }),
|
|
280
|
-
};
|
|
281
|
-
|
|
282
|
-
const componentMap = new Map([['TestComponent', mockComponent]]);
|
|
283
|
-
|
|
284
|
-
const result = await sitecoreClient.getComponentData(layoutData, context, componentMap);
|
|
285
|
-
|
|
286
|
-
expect(result).to.deep.equal({
|
|
287
|
-
'test-uid': { props: { data: 'test-data' } },
|
|
288
|
-
});
|
|
289
|
-
expect(mockComponent.getComponentServerProps.calledOnce).to.be.true;
|
|
290
|
-
});
|
|
291
|
-
});*/
|
|
292
|
-
});
|