@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
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import { describe, test, expect } from 'vitest';
|
|
2
|
-
import { renderAstroComponent } from '../tests/astro-helpers';
|
|
3
|
-
import Date from './Date.astro';
|
|
4
|
-
import EmptyFieldEditingComponent from '../tests/test-components/EmptyFieldEditingComponent.astro';
|
|
5
|
-
import { EMPTY_DATE_FIELD_VALUE } from '@sitecore-content-sdk/content/layout';
|
|
6
|
-
|
|
7
|
-
describe('<DateField />', () => {
|
|
8
|
-
test('should return null if no value', async () => {
|
|
9
|
-
const field = {};
|
|
10
|
-
|
|
11
|
-
const rendered = await renderAstroComponent(Date, {
|
|
12
|
-
props: { field: field },
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
expect(rendered.innerHTML).to.equal('');
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
test('should render value', async () => {
|
|
19
|
-
const field = {
|
|
20
|
-
value: '23-11-2001',
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const rendered = await renderAstroComponent(Date, {
|
|
24
|
-
props: { field: field },
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
expect(rendered.innerHTML).equal('23-11-2001');
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test('should render value using render prop function', async () => {
|
|
31
|
-
const renderDate = (date: Date | null) => `<p>${date ? date.toDateString() : ''}</p>`;
|
|
32
|
-
const field = {
|
|
33
|
-
value: '11-23-2001',
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const rendered = await renderAstroComponent(Date, {
|
|
37
|
-
props: { field: field, render: renderDate },
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
expect(rendered.innerHTML).equal('<p>Fri Nov 23 2001</p>');
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
test('should render value with provided tag', async () => {
|
|
44
|
-
const field = {
|
|
45
|
-
value: '11-23-2001',
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const rendered = await renderAstroComponent(Date, {
|
|
49
|
-
props: { field: field, tag: 'h3' },
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
expect(rendered.innerHTML).equal('<h3>11-23-2001</h3>');
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe('edit mode', () => {
|
|
56
|
-
const testMetadata = {
|
|
57
|
-
contextItem: {
|
|
58
|
-
id: '{09A07660-6834-476C-B93B-584248D3003B}',
|
|
59
|
-
language: 'en',
|
|
60
|
-
revision: 'a0b36ce0a7db49418edf90eb9621e145',
|
|
61
|
-
version: 1,
|
|
62
|
-
},
|
|
63
|
-
fieldId: '{414061F4-FBB1-4591-BC37-BFFA67F745EB}',
|
|
64
|
-
fieldType: 'date',
|
|
65
|
-
rawValue: 'Test1',
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
test('should render field metadata component when metadata property is present', async () => {
|
|
69
|
-
const field = {
|
|
70
|
-
value: '23-11-2001',
|
|
71
|
-
metadata: testMetadata,
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const rendered = await renderAstroComponent(Date, {
|
|
75
|
-
props: { field: field },
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
expect(rendered.innerHTML).to.equal(
|
|
79
|
-
[
|
|
80
|
-
`<code type="text/sitecore" chrometype="field" class="scpm" kind="open">${JSON.stringify(
|
|
81
|
-
testMetadata
|
|
82
|
-
)}</code>`,
|
|
83
|
-
'23-11-2001',
|
|
84
|
-
'<code type="text/sitecore" chrometype="field" class="scpm" kind="close"></code>',
|
|
85
|
-
].join('')
|
|
86
|
-
);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
describe('empty value', () => {
|
|
90
|
-
describe('Should render default component', () => {
|
|
91
|
-
test('field value is empty string', async () => {
|
|
92
|
-
const field = {
|
|
93
|
-
value: '',
|
|
94
|
-
metadata: testMetadata,
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const rendered = await renderAstroComponent(Date, {
|
|
98
|
-
props: { field: field },
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
expect(rendered.innerHTML).to.equal(
|
|
102
|
-
[
|
|
103
|
-
`<code type="text/sitecore" chrometype="field" class="scpm" kind="open">${JSON.stringify(
|
|
104
|
-
testMetadata
|
|
105
|
-
)}</code>`,
|
|
106
|
-
'<span>[No text in field]</span>',
|
|
107
|
-
'<code type="text/sitecore" chrometype="field" class="scpm" kind="close"></code>',
|
|
108
|
-
].join('')
|
|
109
|
-
);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
test('field value is default empty date value', async () => {
|
|
113
|
-
const field = {
|
|
114
|
-
value: EMPTY_DATE_FIELD_VALUE,
|
|
115
|
-
metadata: testMetadata,
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
const rendered = await renderAstroComponent(Date, {
|
|
119
|
-
props: { field: field },
|
|
120
|
-
});
|
|
121
|
-
expect(rendered.innerHTML).to.equal(
|
|
122
|
-
[
|
|
123
|
-
`<code type="text/sitecore" chrometype="field" class="scpm" kind="open">${JSON.stringify(
|
|
124
|
-
testMetadata
|
|
125
|
-
)}</code>`,
|
|
126
|
-
'<span>[No text in field]</span>',
|
|
127
|
-
'<code type="text/sitecore" chrometype="field" class="scpm" kind="close"></code>',
|
|
128
|
-
].join('')
|
|
129
|
-
);
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
describe('Should render custom component', () => {
|
|
134
|
-
test('field value is empty string', async () => {
|
|
135
|
-
const field = {
|
|
136
|
-
value: '',
|
|
137
|
-
metadata: testMetadata,
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
const rendered = await renderAstroComponent(Date, {
|
|
141
|
-
props: {
|
|
142
|
-
field: field,
|
|
143
|
-
emptyFieldEditingComponent: EmptyFieldEditingComponent,
|
|
144
|
-
},
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
expect(rendered.innerHTML).to.equal(
|
|
148
|
-
[
|
|
149
|
-
`<code type="text/sitecore" chrometype="field" class="scpm" kind="open">${JSON.stringify(
|
|
150
|
-
testMetadata
|
|
151
|
-
)}</code>`,
|
|
152
|
-
'<span class="empty-field-value-placeholder">Custom Empty field value</span>',
|
|
153
|
-
'<code type="text/sitecore" chrometype="field" class="scpm" kind="close"></code>',
|
|
154
|
-
].join('')
|
|
155
|
-
);
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
test('field value is defaule empty date value', async () => {
|
|
159
|
-
const field = {
|
|
160
|
-
value: EMPTY_DATE_FIELD_VALUE,
|
|
161
|
-
metadata: testMetadata,
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
const rendered = await renderAstroComponent(Date, {
|
|
165
|
-
props: {
|
|
166
|
-
field: field,
|
|
167
|
-
emptyFieldEditingComponent: EmptyFieldEditingComponent,
|
|
168
|
-
},
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
expect(rendered.innerHTML).to.equal(
|
|
172
|
-
[
|
|
173
|
-
`<code type="text/sitecore" chrometype="field" class="scpm" kind="open">${JSON.stringify(
|
|
174
|
-
testMetadata
|
|
175
|
-
)}</code>`,
|
|
176
|
-
'<span class="empty-field-value-placeholder">Custom Empty field value</span>',
|
|
177
|
-
'<code type="text/sitecore" chrometype="field" class="scpm" kind="close"></code>',
|
|
178
|
-
].join('')
|
|
179
|
-
);
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
test('should render nothing when field value is empty, when editing is explicitly disabled ', async () => {
|
|
185
|
-
const field = {
|
|
186
|
-
value: '',
|
|
187
|
-
metadata: testMetadata,
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
const rendered = await renderAstroComponent(Date, {
|
|
191
|
-
props: { field: field, editable: false },
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
expect(rendered.innerHTML).to.equal('');
|
|
195
|
-
});
|
|
196
|
-
});
|
|
197
|
-
});
|
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-unused-expressions */
|
|
2
|
-
import { describe, test, expect } from 'vitest';
|
|
3
|
-
import { mockSitecoreContext, renderAstroComponent } from '../tests/astro-helpers';
|
|
4
|
-
import {
|
|
5
|
-
LayoutServiceData,
|
|
6
|
-
LayoutServicePageState,
|
|
7
|
-
RenderingType,
|
|
8
|
-
} from '@sitecore-content-sdk/content/layout';
|
|
9
|
-
import EditingScripts from './EditingScripts.astro';
|
|
10
|
-
import {
|
|
11
|
-
getContentSdkPagesClientData,
|
|
12
|
-
getDesignLibraryScriptLink,
|
|
13
|
-
DesignLibraryMode,
|
|
14
|
-
} from '@sitecore-content-sdk/content/editing';
|
|
15
|
-
import { PageMode } from '@sitecore-content-sdk/content/client';
|
|
16
|
-
import sinon from 'sinon';
|
|
17
|
-
|
|
18
|
-
describe('<EditingScripts />', () => {
|
|
19
|
-
// @ts-ignore
|
|
20
|
-
const mode: PageMode = {
|
|
21
|
-
name: LayoutServicePageState.Edit,
|
|
22
|
-
isEditing: true,
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const getLayoutData = ({
|
|
26
|
-
pageState,
|
|
27
|
-
pageEditing,
|
|
28
|
-
clientData,
|
|
29
|
-
clientScripts,
|
|
30
|
-
renderingType,
|
|
31
|
-
}: {
|
|
32
|
-
pageEditing: boolean;
|
|
33
|
-
pageState?: LayoutServicePageState;
|
|
34
|
-
clientData?: Record<string, Record<string, unknown>>;
|
|
35
|
-
clientScripts?: string[];
|
|
36
|
-
renderingType?: RenderingType;
|
|
37
|
-
}): LayoutServiceData => ({
|
|
38
|
-
sitecore: {
|
|
39
|
-
context: {
|
|
40
|
-
pageState,
|
|
41
|
-
pageEditing,
|
|
42
|
-
renderingType,
|
|
43
|
-
site: {
|
|
44
|
-
name: 'ContentSdkTestWeb',
|
|
45
|
-
},
|
|
46
|
-
language: 'en',
|
|
47
|
-
clientData: clientData || {
|
|
48
|
-
foo: {
|
|
49
|
-
x: 1,
|
|
50
|
-
y: '1',
|
|
51
|
-
z: true,
|
|
52
|
-
},
|
|
53
|
-
bar: {
|
|
54
|
-
a: 2,
|
|
55
|
-
b: '2',
|
|
56
|
-
c: false,
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
clientScripts: clientScripts || [
|
|
60
|
-
'http://test.foo/script1.js',
|
|
61
|
-
'http://test.foo/script2.js',
|
|
62
|
-
],
|
|
63
|
-
},
|
|
64
|
-
route: null,
|
|
65
|
-
},
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
test('should render nothing when not in editing', async () => {
|
|
69
|
-
const mode: PageMode = {
|
|
70
|
-
name: LayoutServicePageState.Normal,
|
|
71
|
-
isNormal: true,
|
|
72
|
-
isPreview: false,
|
|
73
|
-
isEditing: false,
|
|
74
|
-
isDesignLibrary: false,
|
|
75
|
-
designLibrary: {
|
|
76
|
-
isVariantGeneration: false,
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
const page = {
|
|
81
|
-
locale: 'en',
|
|
82
|
-
layout: {
|
|
83
|
-
sitecore: {
|
|
84
|
-
context: {},
|
|
85
|
-
route: null,
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
mode,
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
mockSitecoreContext(page);
|
|
92
|
-
|
|
93
|
-
const component = await renderAstroComponent(EditingScripts);
|
|
94
|
-
|
|
95
|
-
expect(component.innerHTML).to.be.empty;
|
|
96
|
-
expect(component.querySelectorAll('script')).to.have.length(0);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
describe('should render Pages scripts when in Edit mode', () => {
|
|
100
|
-
test('should render scripts', async () => {
|
|
101
|
-
const layoutData = getLayoutData({
|
|
102
|
-
pageState: LayoutServicePageState.Edit,
|
|
103
|
-
pageEditing: true,
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
const page = {
|
|
107
|
-
locale: 'en',
|
|
108
|
-
layout: layoutData,
|
|
109
|
-
mode,
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
mockSitecoreContext(page);
|
|
113
|
-
|
|
114
|
-
const component = await renderAstroComponent(EditingScripts);
|
|
115
|
-
|
|
116
|
-
const scripts = component;
|
|
117
|
-
const contentSdkScriptsLength = Object.keys(getContentSdkPagesClientData()).length;
|
|
118
|
-
|
|
119
|
-
expect(scripts?.querySelectorAll('script')).to.have.length(4 + contentSdkScriptsLength);
|
|
120
|
-
|
|
121
|
-
const script1 = scripts?.querySelectorAll('script')[0];
|
|
122
|
-
expect(script1?.getAttribute('src')).to.equal('http://test.foo/script1.js');
|
|
123
|
-
|
|
124
|
-
const script2 = scripts?.querySelectorAll('script')[1];
|
|
125
|
-
expect(script2?.getAttribute('src')).to.equal('http://test.foo/script2.js');
|
|
126
|
-
|
|
127
|
-
const script3 = scripts?.querySelectorAll('script')[2];
|
|
128
|
-
expect(script3?.getAttribute('id')).to.equal('foo');
|
|
129
|
-
expect(script3?.getAttribute('type')).to.equal('application/json');
|
|
130
|
-
expect(script3?.outerHTML).to.equal(
|
|
131
|
-
'<script id="foo" type="application/json">{"x":1,"y":"1","z":true}</script>'
|
|
132
|
-
);
|
|
133
|
-
|
|
134
|
-
const script4 = scripts?.querySelectorAll('script')[3];
|
|
135
|
-
expect(script4?.getAttribute('id')).to.equal('bar');
|
|
136
|
-
expect(script4?.getAttribute('type')).to.equal('application/json');
|
|
137
|
-
expect(script4?.outerHTML).to.equal(
|
|
138
|
-
'<script id="bar" type="application/json">{"a":2,"b":"2","c":false}</script>'
|
|
139
|
-
);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
test('should render content sdk pages script elements when data is not provided', async () => {
|
|
143
|
-
const layoutData = getLayoutData({
|
|
144
|
-
pageState: LayoutServicePageState.Edit,
|
|
145
|
-
pageEditing: true,
|
|
146
|
-
clientData: {},
|
|
147
|
-
clientScripts: [],
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
const page = {
|
|
151
|
-
locale: 'en',
|
|
152
|
-
layout: layoutData,
|
|
153
|
-
mode,
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
mockSitecoreContext(page);
|
|
157
|
-
|
|
158
|
-
const component = await renderAstroComponent(EditingScripts);
|
|
159
|
-
|
|
160
|
-
const scripts = component;
|
|
161
|
-
const ids = Object.keys(getContentSdkPagesClientData());
|
|
162
|
-
ids.forEach((id) => {
|
|
163
|
-
expect(component.querySelector(`#${id}`)).to.not.be.null;
|
|
164
|
-
});
|
|
165
|
-
expect(scripts.querySelectorAll('script')).to.have.length(ids.length);
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
describe('Design Library scripts', () => {
|
|
170
|
-
// @ts-ignore
|
|
171
|
-
const mode: PageMode = {
|
|
172
|
-
name: DesignLibraryMode.Normal,
|
|
173
|
-
isDesignLibrary: true,
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
test('should render Design Library script when rendering type is component', async () => {
|
|
177
|
-
const layoutData = getLayoutData({
|
|
178
|
-
pageEditing: false,
|
|
179
|
-
pageState: LayoutServicePageState.Normal,
|
|
180
|
-
renderingType: RenderingType.Component,
|
|
181
|
-
clientData: {},
|
|
182
|
-
clientScripts: [],
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
const page = {
|
|
186
|
-
locale: 'en',
|
|
187
|
-
layout: layoutData,
|
|
188
|
-
mode,
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
mockSitecoreContext(page);
|
|
192
|
-
|
|
193
|
-
const component = await renderAstroComponent(EditingScripts);
|
|
194
|
-
|
|
195
|
-
const scripts = component;
|
|
196
|
-
expect(scripts.querySelectorAll('script')).to.have.length(1);
|
|
197
|
-
const script1 = scripts?.querySelectorAll('script')[0];
|
|
198
|
-
expect(script1.getAttribute('src')).to.contain(`${getDesignLibraryScriptLink()}?cb=`);
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
test('should render Design Library script with custom design library url when rendering type is component', async () => {
|
|
202
|
-
const layoutData = getLayoutData({
|
|
203
|
-
pageEditing: false,
|
|
204
|
-
pageState: LayoutServicePageState.Normal,
|
|
205
|
-
renderingType: RenderingType.Component,
|
|
206
|
-
clientData: {},
|
|
207
|
-
clientScripts: [],
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
const page = {
|
|
211
|
-
locale: 'en',
|
|
212
|
-
layout: layoutData,
|
|
213
|
-
mode,
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
const stagingEdgeUrl = 'http://edge-staging';
|
|
217
|
-
mockSitecoreContext(page, undefined, { edge: { edgeUrl: stagingEdgeUrl, contextId: 'id' } });
|
|
218
|
-
|
|
219
|
-
const component = await renderAstroComponent(EditingScripts);
|
|
220
|
-
|
|
221
|
-
const scripts = component;
|
|
222
|
-
expect(scripts.querySelectorAll('script')).to.have.length(1);
|
|
223
|
-
const script1 = scripts?.querySelectorAll('script')[0];
|
|
224
|
-
expect(script1.getAttribute('src')).to.contain(
|
|
225
|
-
`${getDesignLibraryScriptLink(stagingEdgeUrl)}?cb=`
|
|
226
|
-
);
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
test('should append UTC cache-buster in HH-DD-MM-YYYY format (zero-padded) across edge cases', async () => {
|
|
230
|
-
// Use sinon fake timers instead of overriding Date directly
|
|
231
|
-
|
|
232
|
-
const cases = [
|
|
233
|
-
{ date: '2024-01-02T03:04:05.000Z', expected: '03-02-01-2024' }, // single-digit month/day/hour
|
|
234
|
-
{ date: '2024-11-12T13:00:00.000Z', expected: '13-12-11-2024' }, // double-digit month/day/hour
|
|
235
|
-
{ date: '2024-12-31T23:59:59.000Z', expected: '23-31-12-2024' }, // end of year
|
|
236
|
-
{ date: '2025-01-01T00:00:00.000Z', expected: '00-01-01-2025' }, // start of year, hour 00
|
|
237
|
-
{ date: '2024-03-09T09:00:00.000Z', expected: '09-09-03-2024' }, // leading zero hour/day/month
|
|
238
|
-
];
|
|
239
|
-
|
|
240
|
-
for (const { date, expected } of cases) {
|
|
241
|
-
const clock = sinon.useFakeTimers(new Date(date).getTime());
|
|
242
|
-
try {
|
|
243
|
-
const layoutData = getLayoutData({
|
|
244
|
-
pageEditing: false,
|
|
245
|
-
pageState: LayoutServicePageState.Normal,
|
|
246
|
-
renderingType: RenderingType.Component,
|
|
247
|
-
clientData: {},
|
|
248
|
-
clientScripts: [],
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
const page = { locale: 'en', layout: layoutData, mode };
|
|
252
|
-
|
|
253
|
-
mockSitecoreContext(page);
|
|
254
|
-
|
|
255
|
-
const component = await renderAstroComponent(EditingScripts);
|
|
256
|
-
|
|
257
|
-
const script1 = component.querySelectorAll('script')[0];
|
|
258
|
-
const src = script1?.getAttribute('src') || '';
|
|
259
|
-
const cbValue = new URL(src).searchParams.get('cb');
|
|
260
|
-
expect(cbValue).to.equal(expected);
|
|
261
|
-
} finally {
|
|
262
|
-
clock.restore();
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
});
|
|
266
|
-
});
|
|
267
|
-
});
|