forked from hazza/dspace-angular
Merge remote-tracking branch 'templates/dspace-7.4' into issue-1671_fix-relationships-not-updating-view-on-submission-form_contribute-7.4
# Conflicts: # src/app/submission/sections/form/section-form.component.spec.ts # src/app/submission/sections/form/section-form.component.ts
This commit is contained in:
@@ -19,13 +19,11 @@ import { getMockFormOperationsService } from '../../../shared/mocks/form-operati
|
||||
import { SectionFormOperationsService } from './section-form-operations.service';
|
||||
import { getMockFormService } from '../../../shared/mocks/form-service.mock';
|
||||
import { FormService } from '../../../shared/form/form.service';
|
||||
import { SubmissionFormsConfigService } from '../../../core/config/submission-forms-config.service';
|
||||
import { SubmissionFormsConfigDataService } from '../../../core/config/submission-forms-config-data.service';
|
||||
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';
|
||||
@@ -35,7 +33,6 @@ import { FormFieldModel } from '../../../shared/form/builder/models/form-field.m
|
||||
import { FormFieldMetadataValueObject } from '../../../shared/form/builder/models/form-field-metadata-value.model';
|
||||
import { DynamicRowGroupModel } from '../../../shared/form/builder/ds-dynamic-form-ui/models/ds-dynamic-row-group-model';
|
||||
import { DsDynamicInputModel } from '../../../shared/form/builder/ds-dynamic-form-ui/models/ds-dynamic-input.model';
|
||||
import { SubmissionSectionError } from '../../objects/submission-objects.reducer';
|
||||
import { DynamicFormControlEvent, DynamicFormControlEventType } from '@ng-dynamic-forms/core';
|
||||
import { JsonPatchOperationPathCombiner } from '../../../core/json-patch/builder/json-patch-operation-path-combiner';
|
||||
import { FormRowModel } from '../../../core/config/models/config-submission-form.model';
|
||||
@@ -45,8 +42,10 @@ 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';
|
||||
import { SubmissionSectionError } from '../../objects/submission-section-error.model';
|
||||
|
||||
function getMockSubmissionFormsConfigService(): SubmissionFormsConfigService {
|
||||
function getMockSubmissionFormsConfigService(): SubmissionFormsConfigDataService {
|
||||
return jasmine.createSpyObj('FormOperationsService', {
|
||||
getConfigAll: jasmine.createSpy('getConfigAll'),
|
||||
getConfigByHref: jasmine.createSpy('getConfigByHref'),
|
||||
@@ -174,7 +173,7 @@ describe('SubmissionSectionFormComponent test suite', () => {
|
||||
{ provide: FormBuilderService, useValue: getMockFormBuilderService() },
|
||||
{ provide: SectionFormOperationsService, useValue: getMockFormOperationsService() },
|
||||
{ provide: FormService, useValue: formService },
|
||||
{ provide: SubmissionFormsConfigService, useValue: formConfigService },
|
||||
{ provide: SubmissionFormsConfigDataService, useValue: formConfigService },
|
||||
{ provide: NotificationsService, useClass: NotificationsServiceStub },
|
||||
{ provide: SectionsService, useValue: sectionsServiceStub },
|
||||
{ provide: SubmissionService, useClass: SubmissionServiceStub },
|
||||
@@ -298,8 +297,10 @@ describe('SubmissionSectionFormComponent test suite', () => {
|
||||
compAsAny.sectionData.data = {
|
||||
'dc.title': [new FormFieldMetadataValueObject('test')]
|
||||
};
|
||||
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', () => {
|
||||
@@ -307,8 +308,13 @@ describe('SubmissionSectionFormComponent test suite', () => {
|
||||
'dc.title': [new FormFieldMetadataValueObject('test')]
|
||||
};
|
||||
compAsAny.formData = newSectionData;
|
||||
compAsAny.sectionMetadata = ['dc.title'];
|
||||
compAsAny.sectionData.data = {
|
||||
'dc.title': [new FormFieldMetadataValueObject('test')]
|
||||
};
|
||||
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', () => {
|
||||
@@ -320,6 +326,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.submissionObject = { type: WorkspaceItem.type.value };
|
||||
});
|
||||
|
||||
it('should return true for unscoped fields', () => {
|
||||
expect((comp as any).inCurrentSubmissionScope('dc.title')).toBe(true);
|
||||
});
|
||||
|
||||
it('should return true for fields scoped to workspace', () => {
|
||||
expect((comp as any).inCurrentSubmissionScope('scoped.workspace')).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false for fields scoped to workflow', () => {
|
||||
expect((comp as any).inCurrentSubmissionScope('scoped.workflow')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('in workflow scope', () => {
|
||||
beforeEach(() => {
|
||||
// @ts-ignore
|
||||
comp.submissionObject = { type: WorkflowItem.type.value };
|
||||
});
|
||||
|
||||
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');
|
||||
|
Reference in New Issue
Block a user