@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.
Files changed (72) hide show
  1. package/package.json +9 -14
  2. package/src/client/sitecore-astro-client.ts +0 -45
  3. package/src/context.ts +14 -16
  4. package/src/env.d.ts +1 -1
  5. package/src/sharedTypes/component-props.ts +0 -10
  6. package/src/tools/generate-map.ts +9 -21
  7. package/src/client/sitecore-astro-client.test.ts +0 -292
  8. package/src/components/AstroImage.astro.test.ts +0 -541
  9. package/src/components/Date.astro.test.ts +0 -197
  10. package/src/components/EditingScripts.astro.test.ts +0 -267
  11. package/src/components/ErrorBoundary.astro.test.ts +0 -252
  12. package/src/components/ErrorComponent.astro.test.ts +0 -31
  13. package/src/components/FieldMetadata.astro.test.ts +0 -40
  14. package/src/components/File.astro.test.ts +0 -68
  15. package/src/components/HiddenRendering.astro.test.ts +0 -36
  16. package/src/components/Image.astro.test.ts +0 -438
  17. package/src/components/Link.astro.test.ts +0 -261
  18. package/src/components/MissingComponent.astro.test.ts +0 -21
  19. package/src/components/Placeholder/Placeholder.astro.test.ts +0 -1088
  20. package/src/components/Placeholder/PlaceholderMetadata.astro.test.ts +0 -228
  21. package/src/components/Placeholder/PlaceholderUtils.astro.test.ts +0 -149
  22. package/src/components/Placeholder/placeholder-utils.test.ts +0 -309
  23. package/src/components/RichText.astro.test.ts +0 -205
  24. package/src/components/Text.astro.test.ts +0 -273
  25. package/src/config/define-config.test.ts +0 -526
  26. package/src/config-cli/define-cli-config.test.ts +0 -88
  27. package/src/editing/editing-config-middleware.test.ts +0 -164
  28. package/src/editing/editing-render-middleware.test.ts +0 -1143
  29. package/src/editing/render-middleware.test.ts +0 -57
  30. package/src/editing/utils.test.ts +0 -1212
  31. package/src/enhancers/WithEmptyFieldEditingComponent.astro.test.ts +0 -380
  32. package/src/enhancers/WithFieldMetadata.astro.test.ts +0 -113
  33. package/src/middleware/middleware.test.ts +0 -520
  34. package/src/middleware/multisite-middleware.test.ts +0 -667
  35. package/src/middleware/robots-middleware.test.ts +0 -129
  36. package/src/middleware/sitemap-middleware.test.ts +0 -184
  37. package/src/services/component-props-service.ts +0 -183
  38. package/src/tests/astro-helpers.ts +0 -61
  39. package/src/tests/helpers.ts +0 -46
  40. package/src/tests/personalizeData.ts +0 -63
  41. package/src/tests/test-components/CustomErrorComponent.astro +0 -3
  42. package/src/tests/test-components/CustomHiddenRendering.astro +0 -10
  43. package/src/tests/test-components/CustomMissingComponent.astro +0 -9
  44. package/src/tests/test-components/DownloadCallout.astro +0 -12
  45. package/src/tests/test-components/EmptyFieldEditingComponent.astro +0 -5
  46. package/src/tests/test-components/ErrorBoundaryWithError.astro +0 -10
  47. package/src/tests/test-components/Home.astro +0 -12
  48. package/src/tests/test-components/SxaRichText.astro +0 -23
  49. package/src/tests/test-components/SxaRichTextDefault.astro +0 -7
  50. package/src/tests/test-components/SxaRichTextWithTitle.astro +0 -8
  51. package/src/tests/test-components/TestComponent.astro +0 -9
  52. package/src/tests/test-components/TestComponentWithError.astro +0 -4
  53. package/src/tests/test-components/TestComponentWithField.astro +0 -17
  54. package/src/tests/test-components/TestHeader.astro +0 -8
  55. package/src/tests/test-components/TestLogo.astro +0 -5
  56. package/src/tests/test-components/TestParentWrapperComponent.astro +0 -5
  57. package/src/tests/test-components/TestWrapperComponent.astro +0 -5
  58. package/src/tests/test-components/map-components/Bar.astro +0 -0
  59. package/src/tests/test-components/map-components/Baz.astro +0 -0
  60. package/src/tests/test-components/map-components/Foo.astro +0 -0
  61. package/src/tests/test-components/map-components/Hero.variant.astro +0 -0
  62. package/src/tests/test-components/map-components/NotComponent.bsx +0 -0
  63. package/src/tests/test-components/map-components/Qux.astro +0 -0
  64. package/src/tests/test-components/map-components/folded/Folded.astro +0 -0
  65. package/src/tests/test-components/map-components/folded/random-file-2.docx +0 -0
  66. package/src/tests/test-components/map-components/random-file.txt +0 -0
  67. package/src/tests/test-data/metadata-data.ts +0 -86
  68. package/src/tests/test-data/normal-mode-data.ts +0 -466
  69. package/src/tests/vitest.setup.ts +0 -4
  70. package/src/tools/templating/components.test.ts +0 -318
  71. package/src/tools/templating/default-component.test.ts +0 -31
  72. package/src/utils/utils.test.ts +0 -48
@@ -1,228 +0,0 @@
1
- import { describe, test, expect } from 'vitest';
2
- import { renderAstroComponent } from '../../tests/astro-helpers';
3
- import PlaceholderMetadata from './PlaceholderMetadata.astro';
4
-
5
- describe('PlaceholderMetadata', () => {
6
- test('renders rendering code blocks for metadataType rendering', async () => {
7
- const children = '<div class="richtext-class"></div>';
8
-
9
- const wrapper = await renderAstroComponent(PlaceholderMetadata, {
10
- props: { rendering: { uid: '123', componentName: 'RichText' } },
11
- slots: {
12
- default: children,
13
- },
14
- });
15
-
16
- expect(wrapper.innerHTML).to.equal(
17
- [
18
- '<code type="text/sitecore" chrometype="rendering" class="scpm" kind="open" id="123"></code>',
19
- '<div class="richtext-class"></div>',
20
- '<code type="text/sitecore" chrometype="rendering" class="scpm" kind="close"></code>',
21
- ].join('')
22
- );
23
- });
24
-
25
- test('renders placeholder code blocks when metadataType is placeholder', async () => {
26
- const children = '<div class="richtext-mock"></div>';
27
-
28
- const wrapper = await renderAstroComponent(PlaceholderMetadata, {
29
- props: {
30
- rendering: {
31
- uid: '123',
32
- componentName: 'RichText',
33
- placeholders: { main: [] },
34
- },
35
- placeholderName: 'main',
36
- },
37
- slots: {
38
- default: children,
39
- },
40
- });
41
-
42
- expect(wrapper.innerHTML).to.equal(
43
- [
44
- '<code type="text/sitecore" chrometype="placeholder" class="scpm" kind="open" id="main_123"></code>',
45
- '<div class="richtext-mock"></div>',
46
- '<code type="text/sitecore" chrometype="placeholder" class="scpm" kind="close"></code>',
47
- ].join('')
48
- );
49
- });
50
-
51
- test('renders placeholder code blocks with DEFAULT_PLACEHOLDER_UID value when metadataType is a placeholder(root) and uid is not present', async () => {
52
- const children = '<div class="richtext-mock"></div>';
53
-
54
- const wrapper = await renderAstroComponent(PlaceholderMetadata, {
55
- props: {
56
- rendering: {
57
- componentName: 'RichText',
58
- placeholders: { main: [] },
59
- },
60
- placeholderName: 'main',
61
- },
62
- slots: {
63
- default: children,
64
- },
65
- });
66
-
67
- expect(wrapper.innerHTML).to.equal(
68
- [
69
- '<code type="text/sitecore" chrometype="placeholder" class="scpm" kind="open" id="main_00000000-0000-0000-0000-000000000000"></code>',
70
- '<div class="richtext-mock"></div>',
71
- '<code type="text/sitecore" chrometype="placeholder" class="scpm" kind="close"></code>',
72
- ].join('')
73
- );
74
- });
75
-
76
- test('renders placeholder blocks with rendering uid when metadataType is dynamic placeholder', async () => {
77
- const children = '<div class="richtext-mock"></div>';
78
-
79
- const wrapper = await renderAstroComponent(PlaceholderMetadata, {
80
- props: {
81
- rendering: {
82
- uid: 'renderinguid',
83
- componentName: 'RichText',
84
- placeholders: { 'main-{*}': [] },
85
- },
86
- placeholderName: 'main-1',
87
- },
88
- slots: {
89
- default: children,
90
- },
91
- });
92
-
93
- expect(wrapper.innerHTML).to.equal(
94
- [
95
- '<code type="text/sitecore" chrometype="placeholder" class="scpm" kind="open" id="main-{*}_renderinguid"></code>',
96
- '<div class="richtext-mock"></div>',
97
- '<code type="text/sitecore" chrometype="placeholder" class="scpm" kind="close"></code>',
98
- ].join('')
99
- );
100
- });
101
-
102
- test('renders placeholder blocks with DEFAULT_PLACEHOLDER_UID value when metadataType is dynamic placeholder and uid is not present', async () => {
103
- const children = '<div class="richtext-mock"></div>';
104
-
105
- const wrapper = await renderAstroComponent(PlaceholderMetadata, {
106
- props: {
107
- rendering: {
108
- componentName: 'RichText',
109
- placeholders: { 'main-{*}': [] },
110
- },
111
- placeholderName: 'main-1',
112
- },
113
- slots: {
114
- default: children,
115
- },
116
- });
117
-
118
- expect(wrapper.innerHTML).to.equal(
119
- [
120
- '<code type="text/sitecore" chrometype="placeholder" class="scpm" kind="open" id="main-{*}_00000000-0000-0000-0000-000000000000"></code>',
121
- '<div class="richtext-mock"></div>',
122
- '<code type="text/sitecore" chrometype="placeholder" class="scpm" kind="close"></code>',
123
- ].join('')
124
- );
125
- });
126
-
127
- test('renders placeholder code blocks when metadataType is double digit dynamic placeholder', async () => {
128
- const children = '<div class="richtext-mock"></div>';
129
-
130
- const wrapper = await renderAstroComponent(PlaceholderMetadata, {
131
- props: {
132
- rendering: {
133
- uid: 'renderinguid',
134
- componentName: 'RichText',
135
- placeholders: { 'main-1-{*}': [] },
136
- },
137
- placeholderName: 'main-1-1',
138
- },
139
- slots: {
140
- default: children,
141
- },
142
- });
143
-
144
- expect(wrapper.innerHTML).to.equal(
145
- [
146
- '<code type="text/sitecore" chrometype="placeholder" class="scpm" kind="open" id="main-1-{*}_renderinguid"></code>',
147
- '<div class="richtext-mock"></div>',
148
- '<code type="text/sitecore" chrometype="placeholder" class="scpm" kind="close"></code>',
149
- ].join('')
150
- );
151
- });
152
-
153
- test('adds data-csdk-component-runtime attribute to rendering chrome', async () => {
154
- const children = '<div class="richtext-class"></div>';
155
-
156
- const wrapper = await renderAstroComponent(PlaceholderMetadata, {
157
- props: {
158
- rendering: {
159
- uid: '123',
160
- componentName: 'RichText',
161
- },
162
- componentRuntime: 'server',
163
- },
164
- slots: {
165
- default: children,
166
- },
167
- });
168
-
169
- expect(wrapper.innerHTML).to.equal(
170
- [
171
- '<code type="text/sitecore" chrometype="rendering" class="scpm" kind="open" id="123" data-csdk-component-runtime="server"></code>',
172
- '<div class="richtext-class"></div>',
173
- '<code type="text/sitecore" chrometype="rendering" class="scpm" kind="close"></code>',
174
- ].join('')
175
- );
176
- });
177
-
178
- test('does not add data-csdk-component-runtime attribute to placeholder chrome even when componentRuntime is provided', async () => {
179
- const children = '<div class="richtext-mock"></div>';
180
-
181
- const wrapper = await renderAstroComponent(PlaceholderMetadata, {
182
- props: {
183
- rendering: {
184
- uid: '123',
185
- componentName: 'RichText',
186
- placeholders: { main: [] },
187
- },
188
- componentRuntime: 'server',
189
- placeholderName: 'main',
190
- },
191
- slots: {
192
- default: children,
193
- },
194
- });
195
-
196
- expect(wrapper.innerHTML).to.equal(
197
- [
198
- '<code type="text/sitecore" chrometype="placeholder" class="scpm" kind="open" id="main_123"></code>',
199
- '<div class="richtext-mock"></div>',
200
- '<code type="text/sitecore" chrometype="placeholder" class="scpm" kind="close"></code>',
201
- ].join('')
202
- );
203
- });
204
-
205
- test('does not add data-csdk-component-runtime attribute when componentRuntime is not provided', async () => {
206
- const children = '<div class="richtext-class"></div>';
207
-
208
- const wrapper = await renderAstroComponent(PlaceholderMetadata, {
209
- props: {
210
- rendering: {
211
- uid: '123',
212
- componentName: 'RichText',
213
- },
214
- },
215
- slots: {
216
- default: children,
217
- },
218
- });
219
-
220
- expect(wrapper.innerHTML).to.equal(
221
- [
222
- '<code type="text/sitecore" chrometype="rendering" class="scpm" kind="open" id="123"></code>',
223
- '<div class="richtext-class"></div>',
224
- '<code type="text/sitecore" chrometype="rendering" class="scpm" kind="close"></code>',
225
- ].join('')
226
- );
227
- });
228
- });
@@ -1,149 +0,0 @@
1
- /* eslint-disable no-unused-expressions */
2
- import { describe, test, expect, beforeEach, afterEach } from 'vitest';
3
- import { ComponentRendering } from '@sitecore-content-sdk/content/layout';
4
- import { ComponentMap } from '../../sharedTypes/component-props';
5
- import { createSandbox } from 'sinon';
6
- import { getComponentForRendering } from './PlaceholderUtils.astro';
7
- import MissingComponent from '../MissingComponent.astro';
8
- import HiddenRendering from '../HiddenRendering.astro';
9
- import TestComponent from '../../tests/test-components/TestComponent.astro';
10
- import CustomMissingComponent from '../../tests/test-components/CustomMissingComponent.astro';
11
- import CustomHiddenRendering from '../../tests/test-components/CustomHiddenRendering.astro';
12
- import { HIDDEN_RENDERING_NAME } from '@sitecore-content-sdk/content';
13
-
14
- describe('placeholder-utils', () => {
15
- const sandbox = createSandbox();
16
- let consoleWarnStub: ReturnType<typeof sandbox.stub>;
17
-
18
- beforeEach(() => {
19
- consoleWarnStub = sandbox.stub(console, 'warn');
20
- sandbox.stub(console, 'error');
21
- });
22
-
23
- afterEach(() => {
24
- sandbox.restore();
25
- });
26
-
27
- describe('getComponentForRendering', () => {
28
- let componentMap: ComponentMap;
29
-
30
- beforeEach(() => {
31
- componentMap = new Map();
32
- });
33
-
34
- test('should return null when componentMap is empty', () => {
35
- const rendering: ComponentRendering = {
36
- componentName: 'TestComponent',
37
- uid: 'test-uid',
38
- };
39
-
40
- const result = getComponentForRendering(rendering, 'test-placeholder');
41
-
42
- expect(result?.component).to.equal(MissingComponent);
43
- expect(result?.isEmpty).to.be.true;
44
- expect(consoleWarnStub.calledOnce).to.be.true;
45
- });
46
-
47
- test('should return null when componentMap is not provided', () => {
48
- const rendering: ComponentRendering = {
49
- componentName: 'TestComponent',
50
- uid: 'test-uid',
51
- };
52
-
53
- const result = getComponentForRendering(rendering, 'test-placeholder', undefined);
54
-
55
- expect(result?.component).to.equal(MissingComponent);
56
- expect(result?.isEmpty).to.be.true;
57
- expect(consoleWarnStub.calledOnce).to.be.true;
58
- });
59
-
60
- test('should return component directly when it is not a module', () => {
61
- componentMap.set('TestComponent', TestComponent);
62
-
63
- const rendering: ComponentRendering = {
64
- componentName: 'TestComponent',
65
- uid: 'test-uid',
66
- };
67
-
68
- const result = getComponentForRendering(rendering, 'test-placeholder', componentMap);
69
-
70
- expect(result?.component).to.equal(TestComponent);
71
- });
72
-
73
- test('should return default missing component when component not found in component map', () => {
74
- // Add a dummy entry so componentMap is not empty
75
- componentMap.set('DummyComponent', TestComponent);
76
-
77
- const rendering: ComponentRendering = {
78
- componentName: 'NonExistentComponent',
79
- uid: 'test-uid',
80
- };
81
-
82
- const result = getComponentForRendering(rendering, 'test-placeholder', componentMap);
83
-
84
- expect(result?.component).to.equal(MissingComponent);
85
- expect(result?.isEmpty).to.be.true;
86
- });
87
-
88
- test('should return custom missing component when specified and component not found in component map', () => {
89
- // Add a dummy entry so componentMap is not empty
90
- componentMap.set('DummyComponent', TestComponent);
91
-
92
- const rendering: ComponentRendering = {
93
- componentName: 'NonExistentComponent',
94
- uid: 'test-uid',
95
- };
96
-
97
- const result = getComponentForRendering(
98
- rendering,
99
- 'test-placeholder',
100
- componentMap,
101
- undefined,
102
- CustomMissingComponent
103
- );
104
-
105
- expect(result?.component).to.equal(CustomMissingComponent);
106
- expect(result?.isEmpty).to.be.true;
107
- });
108
-
109
- test('should return hiddenRenderingComponent when component is hidden', () => {
110
- const rendering: ComponentRendering = {
111
- componentName: HIDDEN_RENDERING_NAME,
112
- uid: 'test-uid',
113
- };
114
-
115
- const result = getComponentForRendering(
116
- rendering,
117
- 'test-placeholder',
118
- componentMap,
119
- CustomHiddenRendering
120
- );
121
-
122
- expect(result?.component).to.equal(CustomHiddenRendering);
123
- expect(result?.isEmpty).to.be.true;
124
- });
125
-
126
- test('should return default HiddenRendering when component is hidden and no custom hidden component provided', () => {
127
- const rendering: ComponentRendering = {
128
- componentName: HIDDEN_RENDERING_NAME,
129
- uid: 'test-uid',
130
- };
131
-
132
- const result = getComponentForRendering(rendering, 'test-placeholder', componentMap);
133
-
134
- expect(result?.component).to.equal(HiddenRendering);
135
- expect(result?.isEmpty).to.be.true;
136
- });
137
-
138
- test('should handle rendering without componentName', () => {
139
- const rendering: ComponentRendering = {
140
- componentName: '',
141
- uid: 'test-uid',
142
- };
143
-
144
- const result = getComponentForRendering(rendering, 'test-placeholder', componentMap);
145
-
146
- expect(result?.isEmpty).to.be.true;
147
- });
148
- });
149
- });
@@ -1,309 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-unused-vars */
2
- /* eslint-disable no-unused-expressions */
3
- /* eslint-disable @typescript-eslint/no-explicit-any */
4
- import { expect } from 'chai';
5
- import { createSandbox } from 'sinon';
6
- import {
7
- getChildComponentProps,
8
- getPlaceholderRenderings,
9
- getSXAParams,
10
- } from './placeholder-utils';
11
- import { ComponentRendering } from '@sitecore-content-sdk/content/layout';
12
- import { PlaceholderProps } from './models';
13
-
14
- describe('placeholder-utils', () => {
15
- const sandbox = createSandbox();
16
- let consoleWarnStub: any;
17
-
18
- beforeEach(() => {
19
- consoleWarnStub = sandbox.stub(console, 'warn');
20
- });
21
-
22
- afterEach(() => {
23
- sandbox.restore();
24
- });
25
-
26
- describe('getPlaceholderRenderings', () => {
27
- it('should return null if rendering does not have placeholders', () => {
28
- const rendering: ComponentRendering = {
29
- componentName: 'TestComponent',
30
- uid: 'test-uid',
31
- };
32
-
33
- const result = getPlaceholderRenderings(rendering, 'test-placeholder', false);
34
-
35
- expect(result).to.deep.equal([]);
36
- expect(consoleWarnStub.calledOnce).to.be.true;
37
- expect(consoleWarnStub.firstCall.args[0]).to.include('test-placeholder');
38
- });
39
-
40
- it('should return renderings from placeholder by name', () => {
41
- const expectedRenderings = [
42
- {
43
- componentName: 'Component1',
44
- uid: 'comp1-uid',
45
- },
46
- {
47
- componentName: 'Component2',
48
- uid: 'comp2-uid',
49
- },
50
- ];
51
-
52
- const rendering: ComponentRendering = {
53
- componentName: 'TestComponent',
54
- uid: 'test-uid',
55
- placeholders: {
56
- 'test-placeholder': expectedRenderings,
57
- 'other-placeholder': [{ componentName: 'OtherComponent', uid: 'other-uid' }],
58
- },
59
- };
60
-
61
- const result = getPlaceholderRenderings(rendering, 'test-placeholder', false);
62
-
63
- expect(result).to.deep.equal(expectedRenderings);
64
- expect(consoleWarnStub.called).to.be.false;
65
- });
66
-
67
- it('should parse dynamic SXA placeholder names correctly', () => {
68
- const expectedRenderings = [
69
- {
70
- componentName: 'DynamicComponent',
71
- uid: 'dynamic-uid',
72
- },
73
- ];
74
-
75
- const rendering: ComponentRendering = {
76
- componentName: 'TestComponent',
77
- uid: 'test-uid',
78
- placeholders: {
79
- 'container-{*}': expectedRenderings,
80
- 'other-placeholder': [{ componentName: 'OtherComponent', uid: 'other-uid' }],
81
- },
82
- };
83
-
84
- // Test non-editing mode - should replace dynamic placeholder
85
- const result = getPlaceholderRenderings(rendering, 'container-1', false);
86
- expect(result).to.deep.equal(expectedRenderings);
87
- expect(rendering.placeholders?.['container-1']).to.deep.equal(expectedRenderings);
88
- expect(rendering.placeholders?.['container-{*}']).to.be.undefined;
89
-
90
- // Reset rendering for editing mode test
91
- rendering.placeholders = {
92
- 'container-{*}': expectedRenderings,
93
- 'other-placeholder': [{ componentName: 'OtherComponent', uid: 'other-uid' }],
94
- };
95
-
96
- // Test editing mode - should keep original placeholder name
97
- const editResult = getPlaceholderRenderings(rendering, 'container-1', true);
98
- expect(editResult).to.deep.equal(expectedRenderings);
99
- expect(rendering.placeholders['container-{*}']).to.deep.equal(expectedRenderings);
100
- });
101
- });
102
-
103
- describe('getSXAParams', () => {
104
- it('should return GridParameters and Styles when present', () => {
105
- const rendering: ComponentRendering = {
106
- componentName: 'TestComponent',
107
- uid: 'test-uid',
108
- params: {
109
- GridParameters: 'col-lg-6',
110
- Styles: 'custom-class',
111
- OtherParam: 'other-value',
112
- },
113
- };
114
-
115
- const result = getSXAParams(rendering);
116
-
117
- expect(result).to.deep.equal({
118
- styles: 'col-lg-6 custom-class',
119
- });
120
- });
121
-
122
- it('should return only GridParameters when Styles not present', () => {
123
- const rendering: ComponentRendering = {
124
- componentName: 'TestComponent',
125
- uid: 'test-uid',
126
- params: {
127
- GridParameters: 'col-lg-8',
128
- OtherParam: 'other-value',
129
- },
130
- };
131
-
132
- const result = getSXAParams(rendering);
133
-
134
- expect(result).to.deep.equal({
135
- styles: 'col-lg-8 ',
136
- });
137
- });
138
-
139
- it('should return only Styles when GridParameters not present', () => {
140
- const rendering: ComponentRendering = {
141
- componentName: 'TestComponent',
142
- uid: 'test-uid',
143
- params: {
144
- Styles: 'custom-styles',
145
- OtherParam: 'other-value',
146
- },
147
- };
148
-
149
- const result = getSXAParams(rendering);
150
-
151
- expect(result).to.deep.equal({
152
- styles: ' custom-styles',
153
- });
154
- });
155
-
156
- it('should return empty styles string when no params', () => {
157
- const rendering: ComponentRendering = {
158
- componentName: 'TestComponent',
159
- uid: 'test-uid',
160
- };
161
-
162
- const result = getSXAParams(rendering);
163
-
164
- expect(result).to.deep.equal({ styles: '' });
165
- });
166
- });
167
-
168
- describe('getChildComponentProps', () => {
169
- it('should merge placeholder and rendering fields', () => {
170
- const placeholderProps: PlaceholderProps = {
171
- name: 'test-placeholder',
172
- rendering: { componentName: 'Test', uid: 'test-uid' },
173
- page: {
174
- layout: {},
175
- locale: 'en',
176
- mode: {
177
- name: 'normal',
178
- isNormal: true,
179
- isPreview: false,
180
- isEditing: false,
181
- isDesignLibrary: false,
182
- designLibrary: { isVariantGeneration: false },
183
- },
184
- },
185
- fields: {
186
- placeholderField: { value: 'placeholder-value' },
187
- sharedField: { value: 'placeholder-shared-value' },
188
- },
189
- };
190
-
191
- const componentRendering: ComponentRendering = {
192
- componentName: 'TestComponent',
193
- uid: 'test-uid',
194
- fields: {
195
- renderingField: { value: 'rendering-value' },
196
- sharedField: { value: 'rendering-shared-value' },
197
- },
198
- };
199
-
200
- const result = getChildComponentProps(placeholderProps, componentRendering);
201
-
202
- expect(result.fields).to.deep.equal({
203
- placeholderField: { value: 'placeholder-value' },
204
- renderingField: { value: 'rendering-value' },
205
- sharedField: { value: 'rendering-shared-value' }, // rendering should override placeholder
206
- });
207
- expect(result.rendering).to.equal(componentRendering);
208
- });
209
-
210
- it('should merge placeholder and rendering params', () => {
211
- const placeholderProps: PlaceholderProps = {
212
- name: 'test-placeholder',
213
- rendering: { componentName: 'Test', uid: 'test-uid' },
214
- page: {
215
- layout: {},
216
- locale: 'en',
217
- mode: {
218
- name: 'normal',
219
- isNormal: true,
220
- isPreview: false,
221
- isEditing: false,
222
- isDesignLibrary: false,
223
- designLibrary: { isVariantGeneration: false },
224
- },
225
- },
226
- params: {
227
- placeholderParam: 'placeholder-param-value',
228
- sharedParam: 'placeholder-shared-param',
229
- },
230
- };
231
-
232
- const componentRendering: ComponentRendering = {
233
- componentName: 'TestComponent',
234
- uid: 'test-uid',
235
- params: {
236
- renderingParam: 'rendering-param-value',
237
- sharedParam: 'rendering-shared-param',
238
- GridParameters: 'col-lg-6',
239
- Styles: 'custom-class',
240
- },
241
- };
242
-
243
- const result = getChildComponentProps(placeholderProps, componentRendering);
244
-
245
- expect(result.params).to.deep.equal({
246
- placeholderParam: 'placeholder-param-value',
247
- renderingParam: 'rendering-param-value',
248
- sharedParam: 'rendering-shared-param', // rendering should override placeholder
249
- GridParameters: 'col-lg-6',
250
- Styles: 'custom-class',
251
- styles: 'col-lg-6 custom-class', // SXA styles should be added
252
- });
253
- expect(result.rendering).to.equal(componentRendering);
254
- });
255
-
256
- it('should return minimal child component props object', () => {
257
- const placeholderProps: PlaceholderProps = {
258
- name: 'test-placeholder',
259
- rendering: { componentName: 'Test', uid: 'test-uid' },
260
- page: {
261
- layout: {},
262
- locale: 'en',
263
- mode: {
264
- name: 'normal',
265
- isNormal: true,
266
- isPreview: false,
267
- isEditing: false,
268
- isDesignLibrary: false,
269
- designLibrary: { isVariantGeneration: false },
270
- },
271
- },
272
- componentMap: new Map(),
273
- customProp: 'custom-value',
274
- // missingComponentComponent: MissingComponent,
275
- // hiddenRenderingComponent: HiddenRendering,
276
- };
277
-
278
- const componentRendering: ComponentRendering = {
279
- componentName: 'TestComponent',
280
- uid: 'test-uid',
281
- fields: {
282
- testField: { value: 'test-value' },
283
- },
284
- params: {
285
- testParam: 'test-param',
286
- },
287
- };
288
-
289
- const result = getChildComponentProps(placeholderProps, componentRendering);
290
-
291
- // getChildComponentProps returns only fields, params, and rendering
292
- expect(result.rendering).to.equal(componentRendering);
293
- expect(result.fields).to.deep.equal({
294
- testField: { value: 'test-value' },
295
- });
296
- expect(result.params).to.deep.equal({
297
- testParam: 'test-param',
298
- });
299
-
300
- // getChildComponentProps does not include these props
301
- expect((result as any).key).to.be.undefined;
302
- expect((result as any).customProp).to.be.undefined;
303
- expect((result as any).componentMap).to.be.undefined;
304
- expect((result as any).missingComponentComponent).to.be.undefined;
305
- expect((result as any).hiddenRenderingComponent).to.be.undefined;
306
- expect((result as any).name).to.be.undefined;
307
- });
308
- });
309
- });