diff --git a/src/app/features/collections/components/add-to-collection/collection-metadata-step/collection-metadata-step.component.spec.ts b/src/app/features/collections/components/add-to-collection/collection-metadata-step/collection-metadata-step.component.spec.ts index 1984d047c..5cf55d01c 100644 --- a/src/app/features/collections/components/add-to-collection/collection-metadata-step/collection-metadata-step.component.spec.ts +++ b/src/app/features/collections/components/add-to-collection/collection-metadata-step/collection-metadata-step.component.spec.ts @@ -130,7 +130,7 @@ describe('CollectionMetadataStepComponent', () => { expect(component.cedarFormData()).toEqual({ field: 'value' }); }); - it('should load template and existing record metadata together when step opens', () => { + it('should load existing record metadata with the template and then on its own to keep checkbox answers when step opens', () => { const editor = {} as CedarEditorElement; setup({ cedarTemplate: mockCedarTemplate, @@ -139,11 +139,12 @@ describe('CollectionMetadataStepComponent', () => { editor, }); + expect(Object.keys(editor)).toEqual(['templateAndInstanceObject', 'instanceObject']); expect(editor.templateAndInstanceObject).toEqual({ templateObject: mockCedarTemplate.template, instanceObject: { field: 'value' }, }); - expect(editor.instanceObject).toBeUndefined(); + expect(editor.instanceObject).toEqual({ field: 'value' }); }); it('should load saved metadata together with template when step is reopened', () => { @@ -159,6 +160,7 @@ describe('CollectionMetadataStepComponent', () => { templateObject: mockCedarTemplate.template, instanceObject: { field: 'saved' }, }); + expect(editor.instanceObject).toEqual({ field: 'saved' }); }); it('should load existing record metadata together with template on discard', () => { @@ -172,6 +174,7 @@ describe('CollectionMetadataStepComponent', () => { templateObject: mockCedarTemplate.template, instanceObject: { field: 'value' }, }); + expect(editor.instanceObject).toEqual({ field: 'value' }); }); it('should populate cedarFormData from existingCedarRecord', () => { diff --git a/src/app/features/collections/components/add-to-collection/collection-metadata-step/collection-metadata-step.component.ts b/src/app/features/collections/components/add-to-collection/collection-metadata-step/collection-metadata-step.component.ts index 5736ae540..2bf9c4689 100644 --- a/src/app/features/collections/components/add-to-collection/collection-metadata-step/collection-metadata-step.component.ts +++ b/src/app/features/collections/components/add-to-collection/collection-metadata-step/collection-metadata-step.component.ts @@ -141,6 +141,7 @@ export class CollectionMetadataStepComponent { templateObject: template, instanceObject: untracked(() => this.cedarFormData()), }; + this.syncCedarInstance(editor); } } diff --git a/src/app/features/metadata/components/cedar-template-form/cedar-template-form.component.spec.ts b/src/app/features/metadata/components/cedar-template-form/cedar-template-form.component.spec.ts index 72965fa3a..76aaf0c01 100644 --- a/src/app/features/metadata/components/cedar-template-form/cedar-template-form.component.spec.ts +++ b/src/app/features/metadata/components/cedar-template-form/cedar-template-form.component.spec.ts @@ -104,18 +104,19 @@ describe('CedarTemplateFormComponent', () => { expect(component.formData()).toEqual(initialFormData); }); - it('should load template and record metadata together into the editor', () => { + it('should load record metadata with the template and then on its own to keep checkbox answers', () => { const editor = {} as CedarEditorElement; vi.spyOn(component, 'cedarEditor').mockReturnValue({ nativeElement: editor } as never); fixture.componentRef.setInput('existingRecord', mockRecord); fixture.detectChanges(); + expect(Object.keys(editor)).toEqual(['templateAndInstanceObject', 'instanceObject']); expect(editor.templateAndInstanceObject).toEqual({ templateObject: mockTemplate.template, instanceObject: mockRecord.metadata, }); - expect(editor.instanceObject).toBeUndefined(); + expect(editor.instanceObject).toEqual(mockRecord.metadata); }); it('should publish on submit when the editor report is valid', () => { diff --git a/src/app/features/metadata/components/cedar-template-form/cedar-template-form.component.ts b/src/app/features/metadata/components/cedar-template-form/cedar-template-form.component.ts index 9764a686f..b512087bc 100644 --- a/src/app/features/metadata/components/cedar-template-form/cedar-template-form.component.ts +++ b/src/app/features/metadata/components/cedar-template-form/cedar-template-form.component.ts @@ -114,7 +114,10 @@ export class CedarTemplateFormComponent { if (metadata) { const template = this.template()?.template; - if (editor && template) editor.templateAndInstanceObject = { templateObject: template, instanceObject: metadata }; + if (editor && template) { + editor.templateAndInstanceObject = { templateObject: template, instanceObject: metadata }; + editor.instanceObject = metadata; + } if (viewer) viewer.instanceObject = metadata; }