@exdst-sitecore-content-sdk/astro 0.0.16 → 0.0.19
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/README.md +3 -3
- package/package.json +41 -42
- package/src/client/index.ts +1 -1
- package/src/client/sitecore-astro-client.test.ts +41 -20
- package/src/client/sitecore-astro-client.ts +74 -57
- package/src/components/AstroImage.astro +2 -2
- package/src/components/AstroImage.astro.test.ts +542 -0
- package/src/components/Date.astro +5 -1
- package/src/components/Date.astro.test.ts +197 -0
- package/src/components/DefaultEmptyFieldEditingComponentImage.astro +4 -0
- package/src/components/DefaultEmptyFieldEditingComponentText.astro +4 -0
- package/src/components/EditingScripts.astro +2 -2
- package/src/components/EditingScripts.astro.test.ts +267 -0
- package/src/components/ErrorBoundary.astro +8 -9
- package/src/components/ErrorBoundary.astro.test.ts +252 -0
- package/src/components/ErrorComponent.astro +16 -0
- package/src/components/ErrorComponent.astro.test.ts +31 -0
- package/src/components/FieldMetadata.astro +1 -1
- package/src/components/FieldMetadata.astro.test.ts +40 -0
- package/src/components/File.astro +5 -1
- package/src/components/File.astro.test.ts +68 -0
- package/src/components/HiddenRendering.astro.test.ts +36 -0
- package/src/components/Image.astro +18 -4
- package/src/components/Image.astro.test.ts +438 -0
- package/src/components/Link.astro +13 -1
- package/src/components/Link.astro.test.ts +261 -0
- package/src/components/MissingComponent.astro.test.ts +21 -0
- package/src/components/Placeholder/Placeholder.astro +18 -23
- package/src/components/Placeholder/Placeholder.astro.test.ts +1088 -0
- package/src/components/Placeholder/PlaceholderMetadata.astro +24 -18
- package/src/components/Placeholder/PlaceholderMetadata.astro.test.ts +228 -0
- package/src/components/Placeholder/PlaceholderUtils.astro +21 -40
- package/src/components/Placeholder/PlaceholderUtils.astro.test.ts +149 -0
- package/src/components/Placeholder/models.ts +26 -17
- package/src/components/Placeholder/placeholder-utils.test.ts +153 -6
- package/src/components/Placeholder/placeholder-utils.ts +33 -11
- package/src/components/RichText.astro +9 -1
- package/src/components/RichText.astro.test.ts +205 -0
- package/src/components/Text.astro +15 -3
- package/src/components/Text.astro.test.ts +273 -0
- package/src/config/define-config.test.ts +5 -5
- package/src/config/define-config.ts +22 -42
- package/src/config-cli/define-cli-config.test.ts +5 -12
- package/src/config-cli/define-cli-config.ts +4 -8
- package/src/context.ts +42 -11
- package/src/debug.ts +13 -0
- package/src/editing/editing-config-middleware.test.ts +5 -7
- package/src/editing/editing-config-middleware.ts +11 -7
- package/src/editing/editing-render-middleware.test.ts +366 -24
- package/src/editing/editing-render-middleware.ts +34 -12
- package/src/editing/index.ts +2 -0
- package/src/editing/render-middleware.test.ts +1 -1
- package/src/editing/render-middleware.ts +1 -1
- package/src/editing/types.ts +39 -0
- package/src/editing/utils.test.ts +364 -4
- package/src/editing/utils.ts +82 -24
- package/src/enhancers/WithEmptyFieldEditingComponent.astro +1 -1
- package/src/enhancers/WithEmptyFieldEditingComponent.astro.test.ts +380 -0
- package/src/enhancers/WithFieldMetadata.astro.test.ts +113 -0
- package/src/index.ts +10 -7
- package/src/middleware/index.ts +4 -12
- package/src/middleware/middleware.test.ts +13 -0
- package/src/middleware/middleware.ts +12 -3
- package/src/middleware/multisite-middleware.test.ts +45 -50
- package/src/middleware/multisite-middleware.ts +33 -6
- package/src/middleware/robots-middleware.test.ts +20 -4
- package/src/middleware/robots-middleware.ts +10 -3
- package/src/middleware/sitemap-middleware.test.ts +35 -3
- package/src/middleware/sitemap-middleware.ts +7 -6
- package/src/services/component-props-service.ts +7 -6
- package/src/sharedTypes/component-props.ts +15 -4
- package/src/site/index.ts +1 -1
- package/src/tests/astro-helpers.ts +61 -0
- package/src/tests/test-components/CustomErrorComponent.astro +3 -0
- package/src/tests/test-components/CustomHiddenRendering.astro +10 -0
- package/src/tests/test-components/CustomMissingComponent.astro +9 -0
- package/src/tests/test-components/DownloadCallout.astro +12 -0
- package/src/tests/test-components/EmptyFieldEditingComponent.astro +5 -0
- package/src/tests/test-components/ErrorBoundaryWithError.astro +10 -0
- package/src/tests/test-components/Home.astro +12 -0
- package/src/tests/test-components/SxaRichText.astro +23 -0
- package/src/tests/test-components/SxaRichTextDefault.astro +7 -0
- package/src/tests/test-components/SxaRichTextWithTitle.astro +8 -0
- package/src/tests/test-components/TestComponent.astro +9 -0
- package/src/tests/test-components/TestComponentWithError.astro +4 -0
- package/src/tests/test-components/TestComponentWithField.astro +17 -0
- package/src/tests/test-components/TestHeader.astro +8 -0
- package/src/tests/test-components/TestLogo.astro +5 -0
- package/src/tests/test-components/TestParentWrapperComponent.astro +5 -0
- package/src/tests/test-components/TestWrapperComponent.astro +5 -0
- package/src/tests/test-data/metadata-data.ts +86 -0
- package/src/tests/test-data/normal-mode-data.ts +466 -0
- package/src/tests/vitest.setup.ts +4 -0
- package/src/tools/generate-map.ts +4 -3
- package/src/tools/index.ts +2 -4
- package/src/tools/templating/components.test.ts +100 -87
- package/src/tools/templating/components.ts +2 -1
- package/src/tools/templating/default-component.ts +3 -8
- package/src/utils/utils.ts +20 -2
- /package/src/{test-data → tests}/helpers.ts +0 -0
- /package/src/{test-data → tests}/personalizeData.ts +0 -0
- /package/src/{test-data/components → tests/test-components/map-components}/Bar.astro +0 -0
- /package/src/{test-data/components → tests/test-components/map-components}/Baz.astro +0 -0
- /package/src/{test-data/components → tests/test-components/map-components}/Foo.astro +0 -0
- /package/src/{test-data/components → tests/test-components/map-components}/Hero.variant.astro +0 -0
- /package/src/{test-data/components → tests/test-components/map-components}/NotComponent.bsx +0 -0
- /package/src/{test-data/components → tests/test-components/map-components}/Qux.astro +0 -0
- /package/src/{test-data/components → tests/test-components/map-components}/folded/Folded.astro +0 -0
- /package/src/{test-data/components → tests/test-components/map-components}/folded/random-file-2.docx +0 -0
- /package/src/{test-data/components → tests/test-components/map-components}/random-file.txt +0 -0
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import { describe, test, expect } from 'vitest';
|
|
2
|
+
import { renderAstroComponent } from '../tests/astro-helpers';
|
|
3
|
+
import WithEmptyFieldEditingComponent from './WithEmptyFieldEditingComponent.astro';
|
|
4
|
+
import DefaultEmptyFieldEditingComponentText from '../components/DefaultEmptyFieldEditingComponentText.astro';
|
|
5
|
+
import { EMPTY_DATE_FIELD_VALUE } from '@sitecore-content-sdk/content/layout';
|
|
6
|
+
import TestComponent from '../tests/test-components/TestComponent.astro';
|
|
7
|
+
import EmptyFieldEditingComponent from '../tests/test-components/EmptyFieldEditingComponent.astro';
|
|
8
|
+
|
|
9
|
+
describe('WithEmptyFieldEditingComponent', () => {
|
|
10
|
+
describe('Metadata', () => {
|
|
11
|
+
const testMetadata = {
|
|
12
|
+
contextItem: {
|
|
13
|
+
id: '{09A07660-6834-476C-B93B-584248D3003B}',
|
|
14
|
+
language: 'en',
|
|
15
|
+
revision: 'a0b36ce0a7db49418edf90eb9621e145',
|
|
16
|
+
version: 1,
|
|
17
|
+
},
|
|
18
|
+
fieldId: '{414061F4-FBB1-4591-BC37-BFFA67F745EB}',
|
|
19
|
+
fieldType: 'single-line',
|
|
20
|
+
rawValue: 'Test1',
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
test('Should render provided default empty value component component if field value is not provided', async () => {
|
|
24
|
+
const props = {
|
|
25
|
+
tag: 'h1',
|
|
26
|
+
field: {
|
|
27
|
+
value: '',
|
|
28
|
+
metadata: testMetadata,
|
|
29
|
+
},
|
|
30
|
+
defaultEmptyFieldEditingComponent: DefaultEmptyFieldEditingComponentText,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const testComponent = (await renderAstroComponent(TestComponent)).innerHTML;
|
|
34
|
+
|
|
35
|
+
const rendered = await renderAstroComponent(WithEmptyFieldEditingComponent, {
|
|
36
|
+
props: props,
|
|
37
|
+
slots: {
|
|
38
|
+
default: testComponent,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
expect(rendered.innerHTML).to.equal('<h1 tag="h1">[No text in field]</h1>');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('Should render custom empty value component if provided via props if field value is not provided', async () => {
|
|
46
|
+
const props = {
|
|
47
|
+
field: {
|
|
48
|
+
value: '',
|
|
49
|
+
metadata: testMetadata,
|
|
50
|
+
},
|
|
51
|
+
emptyFieldEditingComponent: EmptyFieldEditingComponent,
|
|
52
|
+
defaultEmptyFieldEditingComponent: DefaultEmptyFieldEditingComponentText,
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const testComponent = (await renderAstroComponent(TestComponent)).innerHTML;
|
|
56
|
+
|
|
57
|
+
const rendered = await renderAstroComponent(WithEmptyFieldEditingComponent, {
|
|
58
|
+
props: props,
|
|
59
|
+
slots: {
|
|
60
|
+
default: testComponent,
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const expected = await renderAstroComponent(EmptyFieldEditingComponent);
|
|
65
|
+
|
|
66
|
+
expect(rendered.innerHTML).to.equal(expected.innerHTML);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test('Should render component if field value is provided', async () => {
|
|
70
|
+
const props = {
|
|
71
|
+
field: {
|
|
72
|
+
value: 'field value',
|
|
73
|
+
metadata: testMetadata,
|
|
74
|
+
},
|
|
75
|
+
defaultEmptyFieldEditingComponent: DefaultEmptyFieldEditingComponentText,
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const testComponent = (await renderAstroComponent(TestComponent)).innerHTML;
|
|
79
|
+
|
|
80
|
+
const rendered = await renderAstroComponent(WithEmptyFieldEditingComponent, {
|
|
81
|
+
props: props,
|
|
82
|
+
slots: {
|
|
83
|
+
default: testComponent,
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
expect(rendered.innerHTML).to.equal('<div><h1>hi</h1><h2>foo</h2><p>bar</p></div>');
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test('Should render component if component is explicitly not editable if value is empty', async () => {
|
|
91
|
+
const props = {
|
|
92
|
+
field: {
|
|
93
|
+
value: '',
|
|
94
|
+
metadata: testMetadata,
|
|
95
|
+
},
|
|
96
|
+
editable: false,
|
|
97
|
+
defaultEmptyFieldEditingComponent: DefaultEmptyFieldEditingComponentText,
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const testComponent = (await renderAstroComponent(TestComponent)).innerHTML;
|
|
101
|
+
|
|
102
|
+
const rendered = await renderAstroComponent(WithEmptyFieldEditingComponent, {
|
|
103
|
+
props: props,
|
|
104
|
+
slots: {
|
|
105
|
+
default: testComponent,
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
expect(rendered.innerHTML).to.equal('<div><h1>hi</h1><h2>foo</h2><p>bar</p></div>');
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test('Should render component if metadata is not provided', async () => {
|
|
113
|
+
const props = {
|
|
114
|
+
field: {
|
|
115
|
+
value: '',
|
|
116
|
+
},
|
|
117
|
+
defaultEmptyFieldEditingComponent: DefaultEmptyFieldEditingComponentText,
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const testComponent = (await renderAstroComponent(TestComponent)).innerHTML;
|
|
121
|
+
|
|
122
|
+
const rendered = await renderAstroComponent(WithEmptyFieldEditingComponent, {
|
|
123
|
+
props: props,
|
|
124
|
+
slots: {
|
|
125
|
+
default: testComponent,
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
expect(rendered.innerHTML).to.equal('<div><h1>hi</h1><h2>foo</h2><p>bar</p></div>');
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
describe('Date', () => {
|
|
133
|
+
test('Should render component if field value is provided', async () => {
|
|
134
|
+
const props = {
|
|
135
|
+
field: {
|
|
136
|
+
metadata: testMetadata,
|
|
137
|
+
value: '2024-01-01T00:00:00Z',
|
|
138
|
+
},
|
|
139
|
+
defaultEmptyFieldEditingComponent: DefaultEmptyFieldEditingComponentText,
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const testComponent = (await renderAstroComponent(TestComponent)).innerHTML;
|
|
143
|
+
|
|
144
|
+
const rendered = await renderAstroComponent(WithEmptyFieldEditingComponent, {
|
|
145
|
+
props: props,
|
|
146
|
+
slots: {
|
|
147
|
+
default: testComponent,
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
expect(rendered.innerHTML).to.equal('<div><h1>hi</h1><h2>foo</h2><p>bar</p></div>');
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test('Should render default empty component if field value is empty', async () => {
|
|
155
|
+
const props = {
|
|
156
|
+
field: {
|
|
157
|
+
value: EMPTY_DATE_FIELD_VALUE,
|
|
158
|
+
metadata: testMetadata,
|
|
159
|
+
},
|
|
160
|
+
defaultEmptyFieldEditingComponent: DefaultEmptyFieldEditingComponentText,
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const testComponent = (await renderAstroComponent(TestComponent)).innerHTML;
|
|
164
|
+
|
|
165
|
+
const rendered = await renderAstroComponent(WithEmptyFieldEditingComponent, {
|
|
166
|
+
props: props,
|
|
167
|
+
slots: {
|
|
168
|
+
default: testComponent,
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
const expected = await renderAstroComponent(DefaultEmptyFieldEditingComponentText);
|
|
173
|
+
|
|
174
|
+
expect(rendered.innerHTML).to.equal(expected.innerHTML);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test('Should render custom empty component if field value is empty', async () => {
|
|
178
|
+
const props = {
|
|
179
|
+
field: {
|
|
180
|
+
value: EMPTY_DATE_FIELD_VALUE,
|
|
181
|
+
metadata: testMetadata,
|
|
182
|
+
},
|
|
183
|
+
emptyFieldEditingComponent: EmptyFieldEditingComponent,
|
|
184
|
+
defaultEmptyFieldEditingComponent: DefaultEmptyFieldEditingComponentText,
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
const testComponent = (await renderAstroComponent(TestComponent)).innerHTML;
|
|
188
|
+
|
|
189
|
+
const rendered = await renderAstroComponent(WithEmptyFieldEditingComponent, {
|
|
190
|
+
props: props,
|
|
191
|
+
slots: {
|
|
192
|
+
default: testComponent,
|
|
193
|
+
},
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
const expected = await renderAstroComponent(EmptyFieldEditingComponent);
|
|
197
|
+
|
|
198
|
+
expect(rendered.innerHTML).to.equal(expected.innerHTML);
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
describe('Image', () => {
|
|
203
|
+
test('Should render component if field src is provided', async () => {
|
|
204
|
+
const props = {
|
|
205
|
+
field: {
|
|
206
|
+
metadata: testMetadata,
|
|
207
|
+
src: 'img src',
|
|
208
|
+
},
|
|
209
|
+
defaultEmptyFieldEditingComponent: DefaultEmptyFieldEditingComponentText,
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
const testComponent = (await renderAstroComponent(TestComponent)).innerHTML;
|
|
213
|
+
|
|
214
|
+
const rendered = await renderAstroComponent(WithEmptyFieldEditingComponent, {
|
|
215
|
+
props: props,
|
|
216
|
+
slots: {
|
|
217
|
+
default: testComponent,
|
|
218
|
+
},
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
expect(rendered.innerHTML).to.equal('<div><h1>hi</h1><h2>foo</h2><p>bar</p></div>');
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
test('Should render component if field value src is provided', async () => {
|
|
225
|
+
const props = {
|
|
226
|
+
field: {
|
|
227
|
+
metadata: testMetadata,
|
|
228
|
+
value: { src: 'img src' },
|
|
229
|
+
},
|
|
230
|
+
defaultEmptyFieldEditingComponent: DefaultEmptyFieldEditingComponentText,
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
const testComponent = (await renderAstroComponent(TestComponent)).innerHTML;
|
|
234
|
+
|
|
235
|
+
const rendered = await renderAstroComponent(WithEmptyFieldEditingComponent, {
|
|
236
|
+
props: props,
|
|
237
|
+
slots: {
|
|
238
|
+
default: testComponent,
|
|
239
|
+
},
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
expect(rendered.innerHTML).to.equal('<div><h1>hi</h1><h2>foo</h2><p>bar</p></div>');
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
test('Should render provided default empty value component component if field value src is not provided', async () => {
|
|
246
|
+
const props = {
|
|
247
|
+
field: {
|
|
248
|
+
value: { src: undefined },
|
|
249
|
+
metadata: testMetadata,
|
|
250
|
+
},
|
|
251
|
+
defaultEmptyFieldEditingComponent: DefaultEmptyFieldEditingComponentText,
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
const testComponent = (await renderAstroComponent(TestComponent)).innerHTML;
|
|
255
|
+
|
|
256
|
+
const rendered = await renderAstroComponent(WithEmptyFieldEditingComponent, {
|
|
257
|
+
props: props,
|
|
258
|
+
slots: {
|
|
259
|
+
default: testComponent,
|
|
260
|
+
},
|
|
261
|
+
});
|
|
262
|
+
const expected = await renderAstroComponent(DefaultEmptyFieldEditingComponentText);
|
|
263
|
+
|
|
264
|
+
expect(rendered.innerHTML).to.equal(expected.innerHTML);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
test('Should render custom empty value component if provided via props if field src is not provided', async () => {
|
|
268
|
+
const props = {
|
|
269
|
+
field: {
|
|
270
|
+
src: undefined,
|
|
271
|
+
metadata: testMetadata,
|
|
272
|
+
},
|
|
273
|
+
defaultEmptyFieldEditingComponent: DefaultEmptyFieldEditingComponentText,
|
|
274
|
+
emptyFieldEditingComponent: EmptyFieldEditingComponent,
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
const testComponent = (await renderAstroComponent(TestComponent)).innerHTML;
|
|
278
|
+
|
|
279
|
+
const rendered = await renderAstroComponent(WithEmptyFieldEditingComponent, {
|
|
280
|
+
props: props,
|
|
281
|
+
slots: {
|
|
282
|
+
default: testComponent,
|
|
283
|
+
},
|
|
284
|
+
});
|
|
285
|
+
const expected = await renderAstroComponent(EmptyFieldEditingComponent);
|
|
286
|
+
|
|
287
|
+
expect(rendered.innerHTML).to.equal(expected.innerHTML);
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
describe('Link', () => {
|
|
292
|
+
test('Should render component if field href is provided', async () => {
|
|
293
|
+
const props = {
|
|
294
|
+
field: {
|
|
295
|
+
metadata: testMetadata,
|
|
296
|
+
href: 'img src',
|
|
297
|
+
},
|
|
298
|
+
defaultEmptyFieldEditingComponent: DefaultEmptyFieldEditingComponentText,
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
const testComponent = (await renderAstroComponent(TestComponent)).innerHTML;
|
|
302
|
+
|
|
303
|
+
const rendered = await renderAstroComponent(WithEmptyFieldEditingComponent, {
|
|
304
|
+
props: props,
|
|
305
|
+
slots: {
|
|
306
|
+
default: testComponent,
|
|
307
|
+
},
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
expect(rendered.innerHTML).to.equal('<div><h1>hi</h1><h2>foo</h2><p>bar</p></div>');
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
test('Should render component if field value href is provided', async () => {
|
|
314
|
+
const props = {
|
|
315
|
+
field: {
|
|
316
|
+
metadata: testMetadata,
|
|
317
|
+
value: { href: 'img src' },
|
|
318
|
+
},
|
|
319
|
+
defaultEmptyFieldEditingComponent: DefaultEmptyFieldEditingComponentText,
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
const testComponent = (await renderAstroComponent(TestComponent)).innerHTML;
|
|
323
|
+
|
|
324
|
+
const rendered = await renderAstroComponent(WithEmptyFieldEditingComponent, {
|
|
325
|
+
props: props,
|
|
326
|
+
slots: {
|
|
327
|
+
default: testComponent,
|
|
328
|
+
},
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
expect(rendered.innerHTML).to.equal('<div><h1>hi</h1><h2>foo</h2><p>bar</p></div>');
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
test('Should render provided default empty value component component if field value href is not provided', async () => {
|
|
335
|
+
const props = {
|
|
336
|
+
field: {
|
|
337
|
+
value: { href: undefined },
|
|
338
|
+
metadata: testMetadata,
|
|
339
|
+
},
|
|
340
|
+
defaultEmptyFieldEditingComponent: DefaultEmptyFieldEditingComponentText,
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
const testComponent = (await renderAstroComponent(TestComponent)).innerHTML;
|
|
344
|
+
|
|
345
|
+
const rendered = await renderAstroComponent(WithEmptyFieldEditingComponent, {
|
|
346
|
+
props: props,
|
|
347
|
+
slots: {
|
|
348
|
+
default: testComponent,
|
|
349
|
+
},
|
|
350
|
+
});
|
|
351
|
+
const expected = await renderAstroComponent(DefaultEmptyFieldEditingComponentText);
|
|
352
|
+
|
|
353
|
+
expect(rendered.innerHTML).to.equal(expected.innerHTML);
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
test('Should render custom empty value component if provided via props if field href is not provided', async () => {
|
|
357
|
+
const props = {
|
|
358
|
+
field: {
|
|
359
|
+
href: undefined,
|
|
360
|
+
metadata: testMetadata,
|
|
361
|
+
},
|
|
362
|
+
defaultEmptyFieldEditingComponent: DefaultEmptyFieldEditingComponentText,
|
|
363
|
+
emptyFieldEditingComponent: EmptyFieldEditingComponent,
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
const testComponent = (await renderAstroComponent(TestComponent)).innerHTML;
|
|
367
|
+
|
|
368
|
+
const rendered = await renderAstroComponent(WithEmptyFieldEditingComponent, {
|
|
369
|
+
props: props,
|
|
370
|
+
slots: {
|
|
371
|
+
default: testComponent,
|
|
372
|
+
},
|
|
373
|
+
});
|
|
374
|
+
const expected = await renderAstroComponent(EmptyFieldEditingComponent);
|
|
375
|
+
|
|
376
|
+
expect(rendered.innerHTML).to.equal(expected.innerHTML);
|
|
377
|
+
});
|
|
378
|
+
});
|
|
379
|
+
});
|
|
380
|
+
});
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { describe, test, expect } from 'vitest';
|
|
2
|
+
import { renderAstroComponent } from '../tests/astro-helpers';
|
|
3
|
+
import WithFieldMetadata from './WithFieldMetadata.astro';
|
|
4
|
+
import TestComponentWithField from '../tests/test-components/TestComponentWithField.astro';
|
|
5
|
+
|
|
6
|
+
describe('WithFieldMetadata', () => {
|
|
7
|
+
const testMetadata = {
|
|
8
|
+
contextItem: {
|
|
9
|
+
id: '{09A07660-6834-476C-B93B-584248D3003B}',
|
|
10
|
+
language: 'en',
|
|
11
|
+
revision: 'a0b36ce0a7db49418edf90eb9621e145',
|
|
12
|
+
version: 1,
|
|
13
|
+
},
|
|
14
|
+
fieldId: '{414061F4-FBB1-4591-BC37-BFFA67F745EB}',
|
|
15
|
+
fieldType: 'single-line',
|
|
16
|
+
rawValue: 'Test1',
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
test('should return component if field is empty', async () => {
|
|
20
|
+
const props = {
|
|
21
|
+
editable: true,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const testComponent = (await renderAstroComponent(TestComponentWithField, { props: props }))
|
|
25
|
+
.innerHTML;
|
|
26
|
+
|
|
27
|
+
const rendered = await renderAstroComponent(WithFieldMetadata, {
|
|
28
|
+
props: props,
|
|
29
|
+
slots: {
|
|
30
|
+
default: testComponent,
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
expect(rendered.innerHTML).to.equal('<div><h1></h1><h2>foo</h2><p>bar</p></div>');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('should render unwrapped component if metadata field is not provided', async () => {
|
|
38
|
+
const props = {
|
|
39
|
+
field: {
|
|
40
|
+
value: 'test',
|
|
41
|
+
},
|
|
42
|
+
editable: true,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const testComponent = (await renderAstroComponent(TestComponentWithField, { props: props }))
|
|
46
|
+
.innerHTML;
|
|
47
|
+
|
|
48
|
+
const rendered = await renderAstroComponent(WithFieldMetadata, {
|
|
49
|
+
props: props,
|
|
50
|
+
slots: {
|
|
51
|
+
default: testComponent,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
expect(rendered.innerHTML).to.equal('<div><h1>test</h1><h2>foo</h2><p>bar</p></div>');
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('should render unwrapped component if metadata is provided but field is not editable', async () => {
|
|
59
|
+
const props = {
|
|
60
|
+
field: {
|
|
61
|
+
value: 'test',
|
|
62
|
+
metadata: testMetadata,
|
|
63
|
+
},
|
|
64
|
+
editable: false,
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const testComponent = (await renderAstroComponent(TestComponentWithField, { props: props }))
|
|
68
|
+
.innerHTML;
|
|
69
|
+
|
|
70
|
+
const rendered = await renderAstroComponent(WithFieldMetadata, {
|
|
71
|
+
props: props,
|
|
72
|
+
slots: {
|
|
73
|
+
default: testComponent,
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
expect(rendered.innerHTML).to.equal('<div><h1>test</h1><h2>foo</h2><p>bar</p></div>');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('should wrap field with provided metadata', async () => {
|
|
81
|
+
const props = {
|
|
82
|
+
field: {
|
|
83
|
+
value: 'car',
|
|
84
|
+
metadata: testMetadata,
|
|
85
|
+
},
|
|
86
|
+
editable: true,
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const testComponent = (await renderAstroComponent(TestComponentWithField, { props: props }))
|
|
90
|
+
.innerHTML;
|
|
91
|
+
|
|
92
|
+
const rendered = await renderAstroComponent(WithFieldMetadata, {
|
|
93
|
+
props: props,
|
|
94
|
+
slots: {
|
|
95
|
+
default: testComponent,
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
expect(rendered.innerHTML).to.equal(
|
|
100
|
+
[
|
|
101
|
+
`<code type="text/sitecore" chrometype="field" class="scpm" kind="open">${JSON.stringify(
|
|
102
|
+
testMetadata
|
|
103
|
+
)}</code>`,
|
|
104
|
+
'<div>',
|
|
105
|
+
'<h1>car</h1>',
|
|
106
|
+
'<h2>foo</h2>',
|
|
107
|
+
'<p>bar</p>',
|
|
108
|
+
'</div>',
|
|
109
|
+
'<code type="text/sitecore" chrometype="field" class="scpm" kind="close"></code>',
|
|
110
|
+
].join('')
|
|
111
|
+
);
|
|
112
|
+
});
|
|
113
|
+
});
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { default as debug } from './debug';
|
|
2
|
+
|
|
3
|
+
export { initContentSdk } from '@sitecore-content-sdk/core';
|
|
4
|
+
|
|
5
|
+
export { PageMode, ErrorPage, Page } from '@sitecore-content-sdk/content/client';
|
|
6
|
+
|
|
7
|
+
export { HTMLLink, StaticPath } from '@sitecore-content-sdk/content';
|
|
2
8
|
|
|
3
9
|
export {
|
|
4
10
|
Field,
|
|
@@ -6,11 +12,8 @@ export {
|
|
|
6
12
|
ComponentRendering,
|
|
7
13
|
ComponentFields,
|
|
8
14
|
ComponentParams,
|
|
9
|
-
} from '@sitecore-content-sdk/
|
|
15
|
+
} from '@sitecore-content-sdk/content/layout';
|
|
10
16
|
|
|
11
|
-
export {
|
|
12
|
-
AstroContentSdkComponent,
|
|
13
|
-
ComponentMap,
|
|
14
|
-
} from './sharedTypes/component-props';
|
|
17
|
+
export { CdpHelper } from '@sitecore-content-sdk/content/personalize';
|
|
15
18
|
|
|
16
|
-
export {
|
|
19
|
+
export { AstroContentSdkComponent, ComponentMap } from './sharedTypes/component-props';
|
package/src/middleware/index.ts
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
MiddlewareBase,
|
|
4
|
-
MiddlewareBaseConfig,
|
|
5
|
-
Middleware,
|
|
6
|
-
} from './middleware';
|
|
1
|
+
export { MiddlewareBase, MiddlewareBaseConfig, Middleware } from './middleware';
|
|
7
2
|
export { RobotsMiddleware } from './robots-middleware';
|
|
8
3
|
export { SitemapMiddleware } from './sitemap-middleware';
|
|
9
4
|
export {
|
|
10
5
|
PersonalizeService,
|
|
11
6
|
PersonalizeServiceConfig,
|
|
12
|
-
} from '@sitecore-content-sdk/
|
|
13
|
-
export {
|
|
14
|
-
MultisiteMiddleware,
|
|
15
|
-
MultisiteMiddlewareConfig,
|
|
16
|
-
} from './multisite-middleware';
|
|
7
|
+
} from '@sitecore-content-sdk/content/personalize';
|
|
8
|
+
export { MultisiteMiddleware, MultisiteMiddlewareConfig } from './multisite-middleware';
|
|
17
9
|
export {
|
|
18
10
|
RedirectsService,
|
|
19
11
|
RedirectsServiceConfig,
|
|
@@ -21,4 +13,4 @@ export {
|
|
|
21
13
|
REDIRECT_TYPE_302,
|
|
22
14
|
REDIRECT_TYPE_SERVER_TRANSFER,
|
|
23
15
|
RedirectInfo,
|
|
24
|
-
} from '@sitecore-content-sdk/
|
|
16
|
+
} from '@sitecore-content-sdk/content/site';
|
|
@@ -343,6 +343,19 @@ describe('MiddlewareBase', () => {
|
|
|
343
343
|
|
|
344
344
|
expect(middleware['getHostHeader'](context)).to.equal('bar.net');
|
|
345
345
|
});
|
|
346
|
+
|
|
347
|
+
it('should return x-forwarded-host header when present', () => {
|
|
348
|
+
const middleware = new SampleMiddleware({ sites: [] });
|
|
349
|
+
|
|
350
|
+
const context = createContext({
|
|
351
|
+
headerValues: {
|
|
352
|
+
'x-forwarded-host': 'proxy.forwarded.com',
|
|
353
|
+
host: 'localhost:3000',
|
|
354
|
+
},
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
expect(middleware['getHostHeader'](context)).to.equal('proxy.forwarded.com');
|
|
358
|
+
});
|
|
346
359
|
});
|
|
347
360
|
|
|
348
361
|
describe('getLanguage', () => {
|
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
import { SITE_KEY, SiteInfo, SiteResolver } from '@sitecore-content-sdk/
|
|
1
|
+
import { SITE_KEY, SiteInfo, SiteResolver } from '@sitecore-content-sdk/content/site';
|
|
2
2
|
import { GraphQLRequestClientFactory } from '@sitecore-content-sdk/core';
|
|
3
3
|
import {
|
|
4
4
|
createGraphQLClientFactory,
|
|
5
5
|
GraphQLClientOptions,
|
|
6
|
-
} from '@sitecore-content-sdk/
|
|
6
|
+
} from '@sitecore-content-sdk/content/client';
|
|
7
7
|
import { PreviewCookies } from '../editing';
|
|
8
8
|
import { APIContext, MiddlewareHandler, MiddlewareNext } from 'astro';
|
|
9
9
|
import * as cookie from 'cookie';
|
|
10
10
|
|
|
11
11
|
export const REWRITE_HEADER_NAME = 'x-sc-rewrite';
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* The interface for the Middleware configuration.
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
13
17
|
export type MiddlewareBaseConfig = {
|
|
14
18
|
/**
|
|
15
19
|
* function, determines if middleware execution should be skipped, based on cookie, header, or other considerations
|
|
@@ -34,6 +38,7 @@ export type MiddlewareBaseConfig = {
|
|
|
34
38
|
|
|
35
39
|
/**
|
|
36
40
|
* Middleware class to be extended by all middleware implementations
|
|
41
|
+
* @public
|
|
37
42
|
*/
|
|
38
43
|
export abstract class Middleware {
|
|
39
44
|
/**
|
|
@@ -45,6 +50,7 @@ export abstract class Middleware {
|
|
|
45
50
|
|
|
46
51
|
/**
|
|
47
52
|
* Base middleware class with common methods
|
|
53
|
+
* @public
|
|
48
54
|
*/
|
|
49
55
|
export abstract class MiddlewareBase extends Middleware {
|
|
50
56
|
protected defaultHostname: string;
|
|
@@ -105,7 +111,10 @@ export abstract class MiddlewareBase extends Middleware {
|
|
|
105
111
|
* @param {APIContext} context Astro context
|
|
106
112
|
*/
|
|
107
113
|
protected getHostHeader(context: APIContext) {
|
|
108
|
-
return
|
|
114
|
+
return (
|
|
115
|
+
context.request.headers.get('x-forwarded-host') ||
|
|
116
|
+
context.request.headers.get('host')?.split(':')[0]
|
|
117
|
+
);
|
|
109
118
|
}
|
|
110
119
|
|
|
111
120
|
/**
|