@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,438 @@
|
|
|
1
|
+
import { describe, test, expect } from 'vitest';
|
|
2
|
+
import { renderAstroComponent } from '../tests/astro-helpers';
|
|
3
|
+
import Image, { ImageField } from './Image.astro';
|
|
4
|
+
import DefaultEmptyFieldEditingComponentImage from './DefaultEmptyFieldEditingComponentImage.astro';
|
|
5
|
+
import EmptyFieldEditingComponent from '../tests/test-components/EmptyFieldEditingComponent.astro';
|
|
6
|
+
|
|
7
|
+
describe('<Image />', () => {
|
|
8
|
+
describe('with direct image object, no value', async () => {
|
|
9
|
+
const props = {
|
|
10
|
+
field: {
|
|
11
|
+
src: '/assets/img/test0.png',
|
|
12
|
+
width: '8',
|
|
13
|
+
height: '10',
|
|
14
|
+
},
|
|
15
|
+
id: 'some-id',
|
|
16
|
+
style: {
|
|
17
|
+
width: '100%',
|
|
18
|
+
},
|
|
19
|
+
className: 'the-dude-abides',
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const rendered = (
|
|
23
|
+
await renderAstroComponent(Image, {
|
|
24
|
+
props: { ...props },
|
|
25
|
+
})
|
|
26
|
+
).querySelectorAll('img');
|
|
27
|
+
|
|
28
|
+
test('should render <img /> with url', async () => {
|
|
29
|
+
expect(rendered).to.have.length(1);
|
|
30
|
+
expect(rendered[0]?.getAttribute('src')).to.equal(props.field.src);
|
|
31
|
+
expect(rendered[0]?.getAttribute('width')).to.equal(props.field.width);
|
|
32
|
+
expect(rendered[0]?.getAttribute('height')).to.equal(props.field.height);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('should render <img /> with non-media props', async () => {
|
|
36
|
+
expect(rendered[0]?.getAttribute('id')).to.equal(props.id);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('should render <img /> with style and className props', async () => {
|
|
40
|
+
expect(rendered[0]?.getAttribute('style')).to.eql('width:100%');
|
|
41
|
+
expect(rendered[0]?.getAttribute('class')).to.eql(props.className);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe('with responsive image object', async () => {
|
|
46
|
+
const props = {
|
|
47
|
+
field: {
|
|
48
|
+
src: '/assets/img/test0.png',
|
|
49
|
+
},
|
|
50
|
+
srcSet: [{ mw: 100 }, { mw: 300 }],
|
|
51
|
+
sizes: '(min-width: 960px) 300px, 100px',
|
|
52
|
+
id: 'some-id',
|
|
53
|
+
className: 'the-dude-abides',
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const rendered = (
|
|
57
|
+
await renderAstroComponent(Image, {
|
|
58
|
+
props: { ...props },
|
|
59
|
+
})
|
|
60
|
+
).querySelectorAll('img');
|
|
61
|
+
|
|
62
|
+
test('should render <img /> with needed img tags', async () => {
|
|
63
|
+
expect(rendered).to.have.length(1);
|
|
64
|
+
expect(rendered[0]?.getAttribute('src')).to.equal(props.field.src);
|
|
65
|
+
expect(rendered[0]?.getAttribute('srcSet')).to.equal(
|
|
66
|
+
'/assets/img/test0.png?mw=100 100w, /assets/img/test0.png?mw=300 300w'
|
|
67
|
+
);
|
|
68
|
+
expect(rendered[0]?.getAttribute('sizes')).to.equal('(min-width: 960px) 300px, 100px');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('should render <img /> with non-media props', async () => {
|
|
72
|
+
expect(rendered[0]?.getAttribute('id')).to.equal(props.id);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test('should render <img /> with style and className props', async () => {
|
|
76
|
+
expect(rendered[0]?.getAttribute('class')).to.eql(props.className);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe('with "value" property value', async () => {
|
|
81
|
+
const props = {
|
|
82
|
+
field: { value: { src: '/assets/img/test0.png', alt: 'my image' } },
|
|
83
|
+
id: 'some-id',
|
|
84
|
+
style: { width: '100%' },
|
|
85
|
+
className: 'the-dude-abides',
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const rendered = (
|
|
89
|
+
await renderAstroComponent(Image, {
|
|
90
|
+
props: { ...props },
|
|
91
|
+
})
|
|
92
|
+
).querySelectorAll('img');
|
|
93
|
+
|
|
94
|
+
test('should render <img /> component with "value" properties', async () => {
|
|
95
|
+
expect(rendered).to.have.length(1);
|
|
96
|
+
expect(rendered[0]?.getAttribute('src')).to.eql(props.field.value.src);
|
|
97
|
+
expect(rendered[0]?.getAttribute('alt')).to.eql(props.field.value.alt);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test('should render <img /> with non-media props', async () => {
|
|
101
|
+
expect(rendered[0]?.getAttribute('id')).to.equal(props.id);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test('should render <img /> with style and className props', async () => {
|
|
105
|
+
expect(rendered[0]?.getAttribute('style')).to.eql('width:100%');
|
|
106
|
+
expect(rendered[0]?.getAttribute('class')).to.eql(props.className);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
describe('with "class" and "className" property set', async () => {
|
|
111
|
+
const props = {
|
|
112
|
+
field: { value: { src: '/assets/img/test0.png', alt: 'my image' } },
|
|
113
|
+
editable: false,
|
|
114
|
+
style: { width: '100%' },
|
|
115
|
+
className: 'the-dude',
|
|
116
|
+
class: 'abides',
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const rendered = (
|
|
120
|
+
await renderAstroComponent(Image, {
|
|
121
|
+
props: { ...props },
|
|
122
|
+
})
|
|
123
|
+
).querySelector('img');
|
|
124
|
+
|
|
125
|
+
test('should attach "class" value at the end of class attribute', async () => {
|
|
126
|
+
expect(rendered?.getAttribute('class')).to.eql(`${props.className} ${props.class}`);
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
describe('with "mediaUrlPrefix" property', async () => {
|
|
131
|
+
test('should transform url with "value" property value', async () => {
|
|
132
|
+
const props = {
|
|
133
|
+
field: { value: { src: '/~assets/img/test0.png', alt: 'my image' } },
|
|
134
|
+
id: 'some-id',
|
|
135
|
+
style: { width: '100%' },
|
|
136
|
+
className: 'the-dude-abides',
|
|
137
|
+
imageParams: { foo: 'bar' },
|
|
138
|
+
mediaUrlPrefix: /\/([-~]{1})assets\//i,
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
let rendered = await renderAstroComponent(Image, {
|
|
142
|
+
props: { ...props },
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
expect(rendered.querySelector('img')?.getAttribute('src')).to.equal(
|
|
146
|
+
'/~/jssmedia/img/test0.png?foo=bar'
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
const newProps = {
|
|
150
|
+
...props,
|
|
151
|
+
field: { value: { src: '/-assets/img/test0.png', alt: 'my image' } },
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
rendered = await renderAstroComponent(Image, {
|
|
155
|
+
props: { ...newProps },
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
expect(rendered.querySelector('img')?.getAttribute('src')).to.equal(
|
|
159
|
+
'/-/jssmedia/img/test0.png?foo=bar'
|
|
160
|
+
);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
test('should transform url with direct image object, no value', async () => {
|
|
164
|
+
const props = {
|
|
165
|
+
field: {
|
|
166
|
+
src: '/~assets/img/test0.png',
|
|
167
|
+
width: 8,
|
|
168
|
+
height: 10,
|
|
169
|
+
},
|
|
170
|
+
id: 'some-id',
|
|
171
|
+
style: {
|
|
172
|
+
width: '100%',
|
|
173
|
+
},
|
|
174
|
+
className: 'the-dude-abides',
|
|
175
|
+
imageParams: { foo: 'bar' },
|
|
176
|
+
mediaUrlPrefix: /\/([-~]{1})assets\//i,
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
let rendered = await renderAstroComponent(Image, {
|
|
180
|
+
props: { ...props },
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
expect(rendered.querySelector('img')?.getAttribute('src')).to.equal(
|
|
184
|
+
'/~/jssmedia/img/test0.png?foo=bar'
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
const newProps = {
|
|
188
|
+
...props,
|
|
189
|
+
field: {
|
|
190
|
+
src: '/-assets/img/test0.png',
|
|
191
|
+
width: 8,
|
|
192
|
+
height: 10,
|
|
193
|
+
},
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
rendered = await renderAstroComponent(Image, {
|
|
197
|
+
props: { ...newProps },
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
expect(rendered.querySelector('img')?.getAttribute('src')).to.equal(
|
|
201
|
+
'/-/jssmedia/img/test0.png?foo=bar'
|
|
202
|
+
);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
test('should transform url with responsive image object', async () => {
|
|
206
|
+
const props = {
|
|
207
|
+
field: {
|
|
208
|
+
src: '/~assets/img/test0.png',
|
|
209
|
+
},
|
|
210
|
+
srcSet: [{ mw: 100 }, { mw: 300 }],
|
|
211
|
+
sizes: '(min-width: 960px) 300px, 100px',
|
|
212
|
+
id: 'some-id',
|
|
213
|
+
className: 'the-dude-abides',
|
|
214
|
+
mediaUrlPrefix: /\/([-~]{1})assets\//i,
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
let rendered = await renderAstroComponent(Image, {
|
|
218
|
+
props: { ...props },
|
|
219
|
+
});
|
|
220
|
+
expect(rendered.querySelector('img')?.getAttribute('src')).to.equal('/~assets/img/test0.png');
|
|
221
|
+
expect(rendered.querySelector('img')?.getAttribute('srcSet')).to.equal(
|
|
222
|
+
'/~/jssmedia/img/test0.png?mw=100 100w, /~/jssmedia/img/test0.png?mw=300 300w'
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
const newProps = {
|
|
226
|
+
...props,
|
|
227
|
+
field: {
|
|
228
|
+
src: '/-assets/img/test0.png',
|
|
229
|
+
width: 8,
|
|
230
|
+
height: 10,
|
|
231
|
+
},
|
|
232
|
+
imageParams: { foo: 'bar' },
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
rendered = await renderAstroComponent(Image, {
|
|
236
|
+
props: { ...newProps },
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
expect(rendered.querySelector('img')?.getAttribute('src')).to.equal(
|
|
240
|
+
'/-/jssmedia/img/test0.png?foo=bar'
|
|
241
|
+
);
|
|
242
|
+
expect(rendered.querySelector('img')?.getAttribute('srcSet')).to.equal(
|
|
243
|
+
'/-/jssmedia/img/test0.png?foo=bar&mw=100 100w, /-/jssmedia/img/test0.png?foo=bar&mw=300 300w'
|
|
244
|
+
);
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
test('should render no <img /> when media prop is empty', async () => {
|
|
249
|
+
const imgField = '' as ImageField;
|
|
250
|
+
|
|
251
|
+
const rendered = await renderAstroComponent(Image, {
|
|
252
|
+
props: { field: imgField },
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
expect(rendered.querySelectorAll('img')).to.have.length(0);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
test('should render when field prop is used instead of media prop', async () => {
|
|
259
|
+
const imgField = {
|
|
260
|
+
src: '/assets/img/test0.png',
|
|
261
|
+
width: 8,
|
|
262
|
+
height: 10,
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
const rendered = await renderAstroComponent(Image, {
|
|
266
|
+
props: { field: imgField },
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
expect(rendered.querySelectorAll('img')).to.have.length(1);
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
describe('edit mode', async () => {
|
|
273
|
+
const testMetadata = {
|
|
274
|
+
contextItem: {
|
|
275
|
+
id: '{09A07660-6834-476C-B93B-584248D3003B}',
|
|
276
|
+
language: 'en',
|
|
277
|
+
revision: 'a0b36ce0a7db49418edf90eb9621e145',
|
|
278
|
+
version: 1,
|
|
279
|
+
},
|
|
280
|
+
fieldId: '{414061F4-FBB1-4591-BC37-BFFA67F745EB}',
|
|
281
|
+
fieldType: 'image',
|
|
282
|
+
rawValue: 'Test1',
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
test('should render field metadata component when metadata property is present', async () => {
|
|
286
|
+
const imgField = {
|
|
287
|
+
src: '/assets/img/test0.png',
|
|
288
|
+
width: 8,
|
|
289
|
+
height: 10,
|
|
290
|
+
metadata: testMetadata,
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
const rendered = await renderAstroComponent(Image, {
|
|
294
|
+
props: { field: imgField },
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
expect(rendered.innerHTML).to.equal(
|
|
298
|
+
[
|
|
299
|
+
`<code type="text/sitecore" chrometype="field" class="scpm" kind="open">${JSON.stringify(
|
|
300
|
+
testMetadata
|
|
301
|
+
)}</code>`,
|
|
302
|
+
'<img width="8" height="10" src="/assets/img/test0.png">',
|
|
303
|
+
'<code type="text/sitecore" chrometype="field" class="scpm" kind="close"></code>',
|
|
304
|
+
].join('')
|
|
305
|
+
);
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
test('should render default empty field component for Image when field value src is not present', async () => {
|
|
309
|
+
const imgField = {
|
|
310
|
+
value: { src: undefined },
|
|
311
|
+
metadata: testMetadata,
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
const rendered = await renderAstroComponent(Image, {
|
|
315
|
+
props: { field: imgField },
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
const defaultEmptyImagePlaceholder = await renderAstroComponent(
|
|
319
|
+
DefaultEmptyFieldEditingComponentImage
|
|
320
|
+
);
|
|
321
|
+
|
|
322
|
+
expect(rendered.innerHTML).to.equal(
|
|
323
|
+
[
|
|
324
|
+
`<code type="text/sitecore" chrometype="field" class="scpm" kind="open">${JSON.stringify(
|
|
325
|
+
testMetadata
|
|
326
|
+
)}</code>`,
|
|
327
|
+
defaultEmptyImagePlaceholder.innerHTML,
|
|
328
|
+
'<code type="text/sitecore" chrometype="field" class="scpm" kind="close"></code>',
|
|
329
|
+
].join('')
|
|
330
|
+
);
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
test('should render default empty field component for Image when field src is not present', async () => {
|
|
334
|
+
const imgField = {
|
|
335
|
+
src: undefined,
|
|
336
|
+
metadata: testMetadata,
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
const rendered = await renderAstroComponent(Image, {
|
|
340
|
+
props: { field: imgField, className: 'custom-class' },
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
const defaultEmptyImagePlaceholder = await renderAstroComponent(
|
|
344
|
+
DefaultEmptyFieldEditingComponentImage,
|
|
345
|
+
{
|
|
346
|
+
props: { className: 'custom-class' },
|
|
347
|
+
}
|
|
348
|
+
);
|
|
349
|
+
|
|
350
|
+
expect(rendered.innerHTML).to.equal(
|
|
351
|
+
[
|
|
352
|
+
`<code type="text/sitecore" chrometype="field" class="scpm" kind="open">${JSON.stringify(
|
|
353
|
+
testMetadata
|
|
354
|
+
)}</code>`,
|
|
355
|
+
defaultEmptyImagePlaceholder.innerHTML,
|
|
356
|
+
'<code type="text/sitecore" chrometype="field" class="scpm" kind="close"></code>',
|
|
357
|
+
].join('')
|
|
358
|
+
);
|
|
359
|
+
|
|
360
|
+
expect(rendered.innerHTML).to.contain('custom-class');
|
|
361
|
+
expect(rendered.innerHTML).to.contain('scEmptyImage');
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
test('should render custom empty field component when provided, when field value src is not present', async () => {
|
|
365
|
+
const imgField = {
|
|
366
|
+
value: { src: undefined },
|
|
367
|
+
metadata: testMetadata,
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
const rendered = await renderAstroComponent(Image, {
|
|
371
|
+
props: {
|
|
372
|
+
field: imgField,
|
|
373
|
+
emptyFieldEditingComponent: EmptyFieldEditingComponent,
|
|
374
|
+
},
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
expect(rendered.innerHTML).to.equal(
|
|
378
|
+
[
|
|
379
|
+
`<code type="text/sitecore" chrometype="field" class="scpm" kind="open">${JSON.stringify(
|
|
380
|
+
testMetadata
|
|
381
|
+
)}</code>`,
|
|
382
|
+
'<span class="empty-field-value-placeholder">Custom Empty field value</span>',
|
|
383
|
+
'<code type="text/sitecore" chrometype="field" class="scpm" kind="close"></code>',
|
|
384
|
+
].join('')
|
|
385
|
+
);
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
test('should render custom empty field component when provided, when field src is not present', async () => {
|
|
389
|
+
const imgField = {
|
|
390
|
+
src: undefined,
|
|
391
|
+
metadata: testMetadata,
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
const rendered = await renderAstroComponent(Image, {
|
|
395
|
+
props: {
|
|
396
|
+
field: imgField,
|
|
397
|
+
emptyFieldEditingComponent: EmptyFieldEditingComponent,
|
|
398
|
+
},
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
expect(rendered.innerHTML).to.equal(
|
|
402
|
+
[
|
|
403
|
+
`<code type="text/sitecore" chrometype="field" class="scpm" kind="open">${JSON.stringify(
|
|
404
|
+
testMetadata
|
|
405
|
+
)}</code>`,
|
|
406
|
+
'<span class="empty-field-value-placeholder">Custom Empty field value</span>',
|
|
407
|
+
'<code type="text/sitecore" chrometype="field" class="scpm" kind="close"></code>',
|
|
408
|
+
].join('')
|
|
409
|
+
);
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
test('should render nothing when field value src is not present, when editing is explicitly disabled', async () => {
|
|
413
|
+
const imgField = {
|
|
414
|
+
value: { src: undefined },
|
|
415
|
+
metadata: testMetadata,
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
const rendered = await renderAstroComponent(Image, {
|
|
419
|
+
props: { field: imgField, editable: false },
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
expect(rendered.innerHTML).to.equal('');
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
test('should render nothing when field src is not present, when editing is explicitly disabled', async () => {
|
|
426
|
+
const imgField = {
|
|
427
|
+
src: undefined,
|
|
428
|
+
metadata: testMetadata,
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
const rendered = await renderAstroComponent(Image, {
|
|
432
|
+
props: { field: imgField, editable: false },
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
expect(rendered.innerHTML).to.equal('');
|
|
436
|
+
});
|
|
437
|
+
});
|
|
438
|
+
});
|
|
@@ -2,12 +2,16 @@
|
|
|
2
2
|
import {
|
|
3
3
|
FieldMetadata,
|
|
4
4
|
isFieldValueEmpty,
|
|
5
|
-
} from '@sitecore-content-sdk/
|
|
5
|
+
} from '@sitecore-content-sdk/content/layout';
|
|
6
6
|
import { EditableFieldProps } from './sharedTypes';
|
|
7
7
|
import WithFieldMetadata from '../enhancers/WithFieldMetadata.astro';
|
|
8
8
|
import WithEmptyFieldEditingComponent from '../enhancers/WithEmptyFieldEditingComponent.astro';
|
|
9
9
|
import DefaultEmptyFieldEditingComponentText from './DefaultEmptyFieldEditingComponentText.astro';
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* The interface for the Link field value.
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
11
15
|
export interface LinkFieldValue {
|
|
12
16
|
[attributeName: string]: unknown;
|
|
13
17
|
href?: string;
|
|
@@ -20,10 +24,18 @@ export interface LinkFieldValue {
|
|
|
20
24
|
linktype?: string;
|
|
21
25
|
}
|
|
22
26
|
|
|
27
|
+
/**
|
|
28
|
+
* The interface for the Link field.
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
23
31
|
export interface LinkField {
|
|
24
32
|
value: LinkFieldValue;
|
|
25
33
|
}
|
|
26
34
|
|
|
35
|
+
/**
|
|
36
|
+
* The interface for the Link component props.
|
|
37
|
+
* @public
|
|
38
|
+
*/
|
|
27
39
|
export interface LinkProps extends EditableFieldProps {
|
|
28
40
|
[htmlAttributes: string]: unknown;
|
|
29
41
|
/** The link field data. */
|