Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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', () => {
Expand All @@ -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', () => {
Expand All @@ -172,6 +174,7 @@ describe('CollectionMetadataStepComponent', () => {
templateObject: mockCedarTemplate.template,
instanceObject: { field: 'value' },
});
expect(editor.instanceObject).toEqual({ field: 'value' });
});

it('should populate cedarFormData from existingCedarRecord', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export class CollectionMetadataStepComponent {
templateObject: template,
instanceObject: untracked(() => this.cedarFormData()),
};
this.syncCedarInstance(editor);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Loading