87242: Fix forced re-init due to out-of-scope fields

This commit is contained in:
Yura Bondarenko
2022-02-15 11:53:21 +01:00
parent 78c8c38ad4
commit f4b8d4fe41
2 changed files with 103 additions and 4 deletions

View File

@@ -23,9 +23,7 @@ import { SubmissionFormsConfigService } from '../../../core/config/submission-fo
import { SectionDataObject } from '../models/section-data.model';
import { SectionsType } from '../sections-type';
import {
mockSubmissionCollectionId,
mockSubmissionId,
mockUploadResponse1ParsedErrors
mockSubmissionCollectionId, mockSubmissionId, mockUploadResponse1ParsedErrors,
} from '../../../shared/mocks/submission.mock';
import { BrowserModule } from '@angular/platform-browser';
import { CommonModule } from '@angular/common';
@@ -45,6 +43,7 @@ import { ObjectCacheService } from '../../../core/cache/object-cache.service';
import { RequestService } from '../../../core/data/request.service';
import { createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils';
import { cold } from 'jasmine-marbles';
import { WorkflowItem } from '../../../core/submission/models/workflowitem.model';
function getMockSubmissionFormsConfigService(): SubmissionFormsConfigService {
return jasmine.createSpyObj('FormOperationsService', {
@@ -296,8 +295,10 @@ describe('SubmissionSectionFormComponent test suite', () => {
};
compAsAny.formData = {};
compAsAny.sectionMetadata = ['dc.title'];
spyOn(compAsAny, 'inCurrentSubmissionScope').and.callThrough();
expect(comp.hasMetadataEnrichment(newSectionData)).toBeTruthy();
expect(compAsAny.inCurrentSubmissionScope).toHaveBeenCalledWith('dc.title');
});
it('should return false when has not Metadata Enrichment', () => {
@@ -306,7 +307,10 @@ describe('SubmissionSectionFormComponent test suite', () => {
};
compAsAny.formData = newSectionData;
compAsAny.sectionMetadata = ['dc.title'];
spyOn(compAsAny, 'inCurrentSubmissionScope').and.callThrough();
expect(comp.hasMetadataEnrichment(newSectionData)).toBeFalsy();
expect(compAsAny.inCurrentSubmissionScope).toHaveBeenCalledWith('dc.title');
});
it('should return false when metadata has Metadata Enrichment but not belonging to sectionMetadata', () => {
@@ -318,6 +322,77 @@ describe('SubmissionSectionFormComponent test suite', () => {
expect(comp.hasMetadataEnrichment(newSectionData)).toBeFalsy();
});
describe('inCurrentSubmissionScope', () => {
beforeEach(() => {
// @ts-ignore
comp.formConfig = {
rows: [
{
fields: [
{
selectableMetadata: [{ metadata: 'scoped.workflow' }],
scope: 'WORKFLOW',
} as FormFieldModel
]
},
{
fields: [
{
selectableMetadata: [{ metadata: 'scoped.workspace' }],
scope: 'WORKSPACE',
} as FormFieldModel
]
},
{
fields: [
{
selectableMetadata: [{ metadata: 'dc.title' }],
} as FormFieldModel
]
}
]
};
});
describe('in workspace scope', () => {
beforeEach(() => {
// @ts-ignore
comp.workspaceItem = { type: WorkspaceItem.type };
});
it('should return true for unscoped fields', () => {
expect((comp as any).inCurrentSubmissionScope('dc.title')).toBe(true);
});
it('should return true for fields scoped to workflow', () => {
expect((comp as any).inCurrentSubmissionScope('scoped.workspace')).toBe(true);
});
it('should return false for fields scoped to workspace', () => {
expect((comp as any).inCurrentSubmissionScope('scoped.workflow')).toBe(false);
});
});
describe('in workflow scope', () => {
beforeEach(() => {
// @ts-ignore
comp.workspaceItem = { type: WorkflowItem.type };
});
it('should return true when field is unscoped', () => {
expect((comp as any).inCurrentSubmissionScope('dc.title')).toBe(true);
});
it('should return true for fields scoped to workflow', () => {
expect((comp as any).inCurrentSubmissionScope('scoped.workflow')).toBe(true);
});
it('should return false for fields scoped to workspace', () => {
expect((comp as any).inCurrentSubmissionScope('scoped.workspace')).toBe(false);
});
});
});
it('should update form properly', () => {
spyOn(comp, 'initForm');
spyOn(comp, 'checksForErrors');