diff --git a/backend/src/Squidex.Web/Resources.cs b/backend/src/Squidex.Web/Resources.cs index 78cd1edc2..0bcf96f2f 100644 --- a/backend/src/Squidex.Web/Resources.cs +++ b/backend/src/Squidex.Web/Resources.cs @@ -179,7 +179,6 @@ namespace Squidex.Web public Resources(ApiController controller) { Controller = controller; - Context = controller.HttpContext.Context(); } diff --git a/frontend/src/app/shared/state/contents.forms.spec.ts b/frontend/src/app/shared/state/contents.forms.spec.ts index 10cde96d1..3a5468e23 100644 --- a/frontend/src/app/shared/state/contents.forms.spec.ts +++ b/frontend/src/app/shared/state/contents.forms.spec.ts @@ -559,6 +559,61 @@ describe('ContentForm', () => { }); }); + it('should add components with default values', () => { + const componentId = MathHelper.guid(); + const component = createSchema({ + id: 1, + fields: [ + createField({ + id: 11, + properties: createProperties('String', { + defaultValue: 'Initial', + }), + partitioning: 'invariant', + }), + createField({ + id: 12, + properties: createProperties('Number', { + defaultValue: 12, + }), + partitioning: 'invariant', + }), + ], + }); + + const contentForm = createForm([ + createField({ + id: 4, + properties: createProperties('Components'), + partitioning: 'invariant', + }), + ], [], { + [componentId]: component, + }); + + contentForm.load({}); + + // Should be undefined by default. + expect(contentForm.value).toEqual({ + field4: { + iv: undefined, + }, + }); + + (contentForm.get('field4')?.get('iv') as FieldArrayForm).addComponent(componentId); + + // Should add field from component. + expect(contentForm.value).toEqual({ + field4: { + iv: [{ + schemaId: componentId, + field11: 'Initial', + field12: 12, + }], + }, + }); + }); + it('should replace component with new fields', () => { const component1Id = MathHelper.guid(); const component1 = createSchema({ diff --git a/frontend/src/app/shared/state/contents.forms.ts b/frontend/src/app/shared/state/contents.forms.ts index 53dc3025e..746277343 100644 --- a/frontend/src/app/shared/state/contents.forms.ts +++ b/frontend/src/app/shared/state/contents.forms.ts @@ -351,7 +351,7 @@ export class FieldArrayForm extends AbstractContentForm