mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
[DURACOM-291] back porting of fix submission section visibility in order to rely on the configured section scope
This commit is contained in:
@@ -4,14 +4,7 @@ import { typedObject } from '../../cache/builders/build-decorators';
|
||||
import { HALLink } from '../../shared/hal-link.model';
|
||||
import { ConfigObject } from './config.model';
|
||||
import { SUBMISSION_SECTION_TYPE } from './config-type';
|
||||
|
||||
/**
|
||||
* An interface that define section visibility and its properties.
|
||||
*/
|
||||
export interface SubmissionSectionVisibility {
|
||||
main: any;
|
||||
other: any;
|
||||
}
|
||||
import { SectionScope, SectionVisibility } from '../../../submission/objects/section-visibility.model';
|
||||
|
||||
@typedObject
|
||||
@inheritSerialization(ConfigObject)
|
||||
@@ -30,6 +23,12 @@ export class SubmissionSectionModel extends ConfigObject {
|
||||
@autoserialize
|
||||
mandatory: boolean;
|
||||
|
||||
/**
|
||||
* The submission scope for this section
|
||||
*/
|
||||
@autoserialize
|
||||
scope: SectionScope;
|
||||
|
||||
/**
|
||||
* A string representing the kind of section object
|
||||
*/
|
||||
@@ -37,10 +36,10 @@ export class SubmissionSectionModel extends ConfigObject {
|
||||
sectionType: SectionsType;
|
||||
|
||||
/**
|
||||
* The [SubmissionSectionVisibility] object for this section
|
||||
* The [SectionVisibility] object for this section
|
||||
*/
|
||||
@autoserialize
|
||||
visibility: SubmissionSectionVisibility;
|
||||
visibility: SectionVisibility;
|
||||
|
||||
/**
|
||||
* The {@link HALLink}s for this SubmissionSectionModel
|
||||
|
@@ -18,10 +18,10 @@ import { Item } from '../../core/shared/item.model';
|
||||
import { SectionsType } from '../sections/sections-type';
|
||||
import { SectionsService } from '../sections/sections.service';
|
||||
import { SubmissionError } from '../objects/submission-error.model';
|
||||
import { SubmissionSectionVisibility } from './../../core/config/models/config-submission-section.model';
|
||||
import { SubmissionSectionModel } from './../../core/config/models/config-submission-section.model';
|
||||
import { VisibilityType } from '../sections/visibility-type';
|
||||
import isEqual from 'lodash/isEqual';
|
||||
import { SectionVisibility } from '../objects/section-visibility.model';
|
||||
|
||||
/**
|
||||
* This component represents the submission form.
|
||||
@@ -196,7 +196,7 @@ export class SubmissionFormComponent implements OnChanges, OnDestroy {
|
||||
/**
|
||||
* Returns the visibility object of the collection section
|
||||
*/
|
||||
private getCollectionVisibility(): SubmissionSectionVisibility {
|
||||
private getCollectionVisibility(): SectionVisibility {
|
||||
const submissionSectionModel: SubmissionSectionModel =
|
||||
this.submissionDefinition.sections.page.find(
|
||||
(section) => isEqual(section.sectionType, SectionsType.Collection)
|
||||
|
@@ -5,3 +5,9 @@ export interface SectionVisibility {
|
||||
main: any;
|
||||
other: any;
|
||||
}
|
||||
|
||||
|
||||
export enum SectionScope {
|
||||
Submission = 'SUBMISSION',
|
||||
Workflow = 'WORKFLOW',
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@ import { SubmissionObject } from '../../core/submission/models/submission-object
|
||||
import { SubmissionDefinitionsModel } from '../../core/config/models/config-submission-definitions.model';
|
||||
import { SectionsType } from '../sections/sections-type';
|
||||
import { Item } from '../../core/shared/item.model';
|
||||
import { SectionVisibility } from './section-visibility.model';
|
||||
import { SectionScope, SectionVisibility } from './section-visibility.model';
|
||||
import { SubmissionError } from './submission-error.model';
|
||||
import { SubmissionSectionError } from './submission-section-error.model';
|
||||
|
||||
@@ -116,6 +116,7 @@ export class InitSectionAction implements Action {
|
||||
header: string;
|
||||
config: string;
|
||||
mandatory: boolean;
|
||||
scope: SectionScope;
|
||||
sectionType: SectionsType;
|
||||
visibility: SectionVisibility;
|
||||
enabled: boolean;
|
||||
@@ -136,6 +137,8 @@ export class InitSectionAction implements Action {
|
||||
* the section's config
|
||||
* @param mandatory
|
||||
* the section's mandatory
|
||||
* @param scope
|
||||
* the section's scope
|
||||
* @param sectionType
|
||||
* the section's type
|
||||
* @param visibility
|
||||
@@ -152,12 +155,13 @@ export class InitSectionAction implements Action {
|
||||
header: string,
|
||||
config: string,
|
||||
mandatory: boolean,
|
||||
scope: SectionScope,
|
||||
sectionType: SectionsType,
|
||||
visibility: SectionVisibility,
|
||||
enabled: boolean,
|
||||
data: WorkspaceitemSectionDataType,
|
||||
errors: SubmissionSectionError[]) {
|
||||
this.payload = { submissionId, sectionId, header, config, mandatory, sectionType, visibility, enabled, data, errors };
|
||||
this.payload = { submissionId, sectionId, header, config, mandatory, scope, sectionType, visibility, enabled, data, errors };
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -151,6 +151,7 @@ describe('SubmissionObjectEffects test suite', () => {
|
||||
sectionDefinition.header,
|
||||
config,
|
||||
sectionDefinition.mandatory,
|
||||
sectionDefinition.scope,
|
||||
sectionDefinition.sectionType,
|
||||
sectionDefinition.visibility,
|
||||
enabled,
|
||||
|
@@ -87,6 +87,7 @@ export class SubmissionObjectEffects {
|
||||
sectionDefinition.header,
|
||||
config,
|
||||
sectionDefinition.mandatory,
|
||||
sectionDefinition.scope,
|
||||
sectionDefinition.sectionType,
|
||||
sectionDefinition.visibility,
|
||||
enabled,
|
||||
|
@@ -233,6 +233,7 @@ describe('submissionReducer test suite', () => {
|
||||
header: 'submit.progressbar.describe.stepone',
|
||||
config: 'https://rest.api/dspace-spring-rest/api/config/submissionforms/traditionalpageone',
|
||||
mandatory: true,
|
||||
scope: null,
|
||||
sectionType: 'submission-form',
|
||||
visibility: undefined,
|
||||
collapsed: false,
|
||||
@@ -253,6 +254,7 @@ describe('submissionReducer test suite', () => {
|
||||
'submit.progressbar.describe.stepone',
|
||||
'https://rest.api/dspace-spring-rest/api/config/submissionforms/traditionalpageone',
|
||||
true,
|
||||
null,
|
||||
SectionsType.SubmissionForm,
|
||||
undefined,
|
||||
true,
|
||||
|
@@ -548,6 +548,7 @@ function initSection(state: SubmissionObjectState, action: InitSectionAction): S
|
||||
header: action.payload.header,
|
||||
config: action.payload.config,
|
||||
mandatory: action.payload.mandatory,
|
||||
scope: action.payload.scope,
|
||||
sectionType: action.payload.sectionType,
|
||||
visibility: action.payload.visibility,
|
||||
collapsed: false,
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { SectionsType } from '../sections/sections-type';
|
||||
import { SectionVisibility } from './section-visibility.model';
|
||||
import { SectionScope, SectionVisibility } from './section-visibility.model';
|
||||
import { WorkspaceitemSectionDataType } from '../../core/submission/models/workspaceitem-sections.model';
|
||||
import { SubmissionSectionError } from './submission-section-error.model';
|
||||
|
||||
@@ -22,6 +22,11 @@ export interface SubmissionSectionObject {
|
||||
*/
|
||||
mandatory: boolean;
|
||||
|
||||
/**
|
||||
* The submission scope for this section
|
||||
*/
|
||||
scope: SectionScope;
|
||||
|
||||
/**
|
||||
* The section type
|
||||
*/
|
||||
|
@@ -37,6 +37,7 @@ import { SectionsType } from './sections-type';
|
||||
import { FormService } from '../../shared/form/form.service';
|
||||
import { getMockFormService } from '../../shared/mocks/form-service.mock';
|
||||
import { SubmissionSectionError } from '../objects/submission-section-error.model';
|
||||
import { SectionScope } from '../objects/section-visibility.model';
|
||||
|
||||
describe('SectionsService test suite', () => {
|
||||
let notificationsServiceStub: NotificationsServiceStub;
|
||||
@@ -253,46 +254,282 @@ describe('SectionsService test suite', () => {
|
||||
});
|
||||
|
||||
describe('isSectionReadOnly', () => {
|
||||
it('should return an observable of true when it\'s a readonly section and scope is not workspace', () => {
|
||||
store.select.and.returnValue(observableOf({
|
||||
visibility: {
|
||||
main: null,
|
||||
describe('when submission scope is workspace', () => {
|
||||
describe('and section scope is workspace', () => {
|
||||
it('should return an observable of true when visibility main is READONLY and visibility other is null', () => {
|
||||
store.select.and.returnValue(observableOf({
|
||||
scope: SectionScope.Submission,
|
||||
visibility: {
|
||||
main: 'READONLY',
|
||||
other: null,
|
||||
},
|
||||
}));
|
||||
|
||||
const expected = cold('(b|)', {
|
||||
b: true,
|
||||
});
|
||||
|
||||
expect(service.isSectionReadOnly(submissionId, sectionId, SubmissionScopeType.WorkspaceItem)).toBeObservable(expected);
|
||||
});
|
||||
it('should return an observable of true when both visibility main and other are READONLY', () => {
|
||||
store.select.and.returnValue(observableOf({
|
||||
scope: SectionScope.Submission,
|
||||
visibility: {
|
||||
main: 'READONLY',
|
||||
other: 'READONLY',
|
||||
},
|
||||
}));
|
||||
|
||||
const expected = cold('(b|)', {
|
||||
b: true,
|
||||
});
|
||||
|
||||
expect(service.isSectionReadOnly(submissionId, sectionId, SubmissionScopeType.WorkspaceItem)).toBeObservable(expected);
|
||||
});
|
||||
it('should return an observable of false when visibility main is null and visibility other is READONLY', () => {
|
||||
store.select.and.returnValue(observableOf({
|
||||
scope: SectionScope.Submission,
|
||||
visibility: {
|
||||
main: null,
|
||||
other: 'READONLY',
|
||||
},
|
||||
}));
|
||||
|
||||
const expected = cold('(b|)', {
|
||||
b: false,
|
||||
});
|
||||
|
||||
expect(service.isSectionReadOnly(submissionId, sectionId, SubmissionScopeType.WorkspaceItem)).toBeObservable(expected);
|
||||
});
|
||||
it('should return an observable of false when visibility is null', () => {
|
||||
store.select.and.returnValue(observableOf({
|
||||
scope: SectionScope.Submission,
|
||||
visibility: null,
|
||||
}));
|
||||
|
||||
const expected = cold('(b|)', {
|
||||
b: false,
|
||||
});
|
||||
|
||||
expect(service.isSectionReadOnly(submissionId, sectionId, SubmissionScopeType.WorkspaceItem)).toBeObservable(expected);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('and section scope is workflow', () => {
|
||||
it('should return an observable of false when visibility main is READONLY and visibility other is null', () => {
|
||||
store.select.and.returnValue(observableOf({
|
||||
scope: SectionScope.Workflow,
|
||||
visibility: {
|
||||
main: 'READONLY',
|
||||
other: null,
|
||||
},
|
||||
}));
|
||||
|
||||
const expected = cold('(b|)', {
|
||||
b: false,
|
||||
});
|
||||
|
||||
expect(service.isSectionReadOnly(submissionId, sectionId, SubmissionScopeType.WorkspaceItem)).toBeObservable(expected);
|
||||
});
|
||||
it('should return an observable of true when both visibility main and other are READONLY', () => {
|
||||
store.select.and.returnValue(observableOf({
|
||||
scope: SectionScope.Workflow,
|
||||
visibility: {
|
||||
main: 'READONLY',
|
||||
other: 'READONLY',
|
||||
},
|
||||
}));
|
||||
|
||||
const expected = cold('(b|)', {
|
||||
b: true,
|
||||
});
|
||||
|
||||
expect(service.isSectionReadOnly(submissionId, sectionId, SubmissionScopeType.WorkspaceItem)).toBeObservable(expected);
|
||||
});
|
||||
it('should return an observable of true when visibility main is null and visibility other is READONLY', () => {
|
||||
store.select.and.returnValue(observableOf({
|
||||
scope: SectionScope.Workflow,
|
||||
visibility: {
|
||||
main: null,
|
||||
other: 'READONLY'
|
||||
}
|
||||
}));
|
||||
}));
|
||||
|
||||
const expected = cold('(b|)', {
|
||||
const expected = cold('(b|)', {
|
||||
b: true
|
||||
});
|
||||
|
||||
expect(service.isSectionReadOnly(submissionId, sectionId, SubmissionScopeType.WorkspaceItem)).toBeObservable(expected);
|
||||
});
|
||||
it('should return an observable of false when visibility is null', () => {
|
||||
store.select.and.returnValue(observableOf({
|
||||
scope: SectionScope.Workflow,
|
||||
visibility: null,
|
||||
}));
|
||||
|
||||
const expected = cold('(b|)', {
|
||||
b: false,
|
||||
});
|
||||
|
||||
expect(service.isSectionReadOnly(submissionId, sectionId, SubmissionScopeType.WorkspaceItem)).toBeObservable(expected);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
expect(service.isSectionReadOnly(submissionId, sectionId, SubmissionScopeType.WorkflowItem)).toBeObservable(expected);
|
||||
describe('and section scope is null', () => {
|
||||
it('should return an observable of false', () => {
|
||||
store.select.and.returnValue(observableOf({
|
||||
scope: null,
|
||||
visibility: null,
|
||||
}));
|
||||
|
||||
const expected = cold('(b|)', {
|
||||
b: false,
|
||||
});
|
||||
|
||||
expect(service.isSectionReadOnly(submissionId, sectionId, SubmissionScopeType.WorkspaceItem)).toBeObservable(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an observable of false when it\'s a readonly section and scope is workspace', () => {
|
||||
store.select.and.returnValue(observableOf({
|
||||
visibility: {
|
||||
main: null,
|
||||
describe('when submission scope is workflow', () => {
|
||||
describe('and section scope is workspace', () => {
|
||||
it('should return an observable of false when visibility main is READONLY and visibility other is null', () => {
|
||||
store.select.and.returnValue(observableOf({
|
||||
scope: SectionScope.Submission,
|
||||
visibility: {
|
||||
main: 'READONLY',
|
||||
other: null,
|
||||
},
|
||||
}));
|
||||
|
||||
const expected = cold('(b|)', {
|
||||
b: false,
|
||||
});
|
||||
|
||||
expect(service.isSectionReadOnly(submissionId, sectionId, SubmissionScopeType.WorkflowItem)).toBeObservable(expected);
|
||||
});
|
||||
it('should return an observable of true when both visibility main and other are READONLY', () => {
|
||||
store.select.and.returnValue(observableOf({
|
||||
scope: SectionScope.Submission,
|
||||
visibility: {
|
||||
main: 'READONLY',
|
||||
other: 'READONLY',
|
||||
},
|
||||
}));
|
||||
|
||||
const expected = cold('(b|)', {
|
||||
b: true,
|
||||
});
|
||||
|
||||
expect(service.isSectionReadOnly(submissionId, sectionId, SubmissionScopeType.WorkflowItem)).toBeObservable(expected);
|
||||
});
|
||||
it('should return an observable of true when visibility main is null and visibility other is READONLY', () => {
|
||||
store.select.and.returnValue(observableOf({
|
||||
scope: SectionScope.Submission,
|
||||
visibility: {
|
||||
main: null,
|
||||
other: 'READONLY'
|
||||
}
|
||||
}));
|
||||
}));
|
||||
|
||||
const expected = cold('(b|)', {
|
||||
const expected = cold('(b|)', {
|
||||
b: true,
|
||||
});
|
||||
|
||||
expect(service.isSectionReadOnly(submissionId, sectionId, SubmissionScopeType.WorkflowItem)).toBeObservable(expected);
|
||||
});
|
||||
it('should return an observable of false when visibility is null', () => {
|
||||
store.select.and.returnValue(observableOf({
|
||||
scope: SectionScope.Submission,
|
||||
visibility: null,
|
||||
}));
|
||||
|
||||
const expected = cold('(b|)', {
|
||||
b: false
|
||||
});
|
||||
|
||||
expect(service.isSectionReadOnly(submissionId, sectionId, SubmissionScopeType.WorkflowItem)).toBeObservable(expected);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
expect(service.isSectionReadOnly(submissionId, sectionId, SubmissionScopeType.WorkspaceItem)).toBeObservable(expected);
|
||||
});
|
||||
describe('and section scope is workflow', () => {
|
||||
it('should return an observable of true when visibility main is READONLY and visibility other is null', () => {
|
||||
store.select.and.returnValue(observableOf({
|
||||
scope: SectionScope.Workflow,
|
||||
visibility: {
|
||||
main: 'READONLY',
|
||||
other: null,
|
||||
},
|
||||
}));
|
||||
|
||||
it('should return an observable of false when it\'s not a readonly section', () => {
|
||||
store.select.and.returnValue(observableOf({
|
||||
visibility: null
|
||||
}));
|
||||
const expected = cold('(b|)', {
|
||||
b: true,
|
||||
});
|
||||
|
||||
expect(service.isSectionReadOnly(submissionId, sectionId, SubmissionScopeType.WorkflowItem)).toBeObservable(expected);
|
||||
});
|
||||
it('should return an observable of true when both visibility main and other is READONLY', () => {
|
||||
store.select.and.returnValue(observableOf({
|
||||
scope: SectionScope.Workflow,
|
||||
visibility: {
|
||||
main: 'READONLY',
|
||||
other: 'READONLY',
|
||||
},
|
||||
}));
|
||||
|
||||
const expected = cold('(b|)', {
|
||||
b: true,
|
||||
});
|
||||
|
||||
expect(service.isSectionReadOnly(submissionId, sectionId, SubmissionScopeType.WorkflowItem)).toBeObservable(expected);
|
||||
});
|
||||
it('should return an observable of false when visibility main is null and visibility other is READONLY', () => {
|
||||
store.select.and.returnValue(observableOf({
|
||||
scope: SectionScope.Workflow,
|
||||
visibility: {
|
||||
main: null,
|
||||
other: 'READONLY',
|
||||
},
|
||||
}));
|
||||
|
||||
const expected = cold('(b|)', {
|
||||
b: false,
|
||||
});
|
||||
|
||||
expect(service.isSectionReadOnly(submissionId, sectionId, SubmissionScopeType.WorkflowItem)).toBeObservable(expected);
|
||||
});
|
||||
it('should return an observable of false when visibility is null', () => {
|
||||
store.select.and.returnValue(observableOf({
|
||||
scope: SectionScope.Workflow,
|
||||
visibility: null,
|
||||
}));
|
||||
|
||||
const expected = cold('(b|)', {
|
||||
b: false,
|
||||
});
|
||||
|
||||
expect(service.isSectionReadOnly(submissionId, sectionId, SubmissionScopeType.WorkflowItem)).toBeObservable(expected);
|
||||
});
|
||||
|
||||
const expected = cold('(b|)', {
|
||||
b: false
|
||||
});
|
||||
|
||||
expect(service.isSectionReadOnly(submissionId, sectionId, SubmissionScopeType.WorkflowItem)).toBeObservable(expected);
|
||||
describe('and section scope is null', () => {
|
||||
it('should return an observable of false', () => {
|
||||
store.select.and.returnValue(observableOf({
|
||||
scope: null,
|
||||
visibility: null,
|
||||
}));
|
||||
|
||||
const expected = cold('(b|)', {
|
||||
b: false
|
||||
});
|
||||
|
||||
expect(service.isSectionReadOnly(submissionId, sectionId, SubmissionScopeType.WorkflowItem)).toBeObservable(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
@@ -45,6 +45,7 @@ import { JsonPatchOperationPathCombiner } from '../../core/json-patch/builder/js
|
||||
import { FormError } from '../../shared/form/form.reducer';
|
||||
import { SubmissionSectionObject } from '../objects/submission-section-object.model';
|
||||
import { SubmissionSectionError } from '../objects/submission-section-error.model';
|
||||
import { SectionScope } from '../objects/section-visibility.model';
|
||||
|
||||
/**
|
||||
* A service that provides methods used in submission process.
|
||||
@@ -333,10 +334,14 @@ export class SectionsService {
|
||||
return this.store.select(submissionSectionFromIdSelector(submissionId, sectionId)).pipe(
|
||||
filter((sectionObj) => hasValue(sectionObj)),
|
||||
map((sectionObj: SubmissionSectionObject) => {
|
||||
return isNotEmpty(sectionObj.visibility)
|
||||
&& ((sectionObj.visibility.other === 'READONLY' && submissionScope !== SubmissionScopeType.WorkspaceItem)
|
||||
|| (sectionObj.visibility.main === 'READONLY' && submissionScope === SubmissionScopeType.WorkspaceItem)
|
||||
);
|
||||
if (isEmpty(submissionScope) || isEmpty(sectionObj.visibility) || isEmpty(sectionObj.scope)) {
|
||||
return false;
|
||||
}
|
||||
const convertedSubmissionScope: SectionScope = submissionScope.valueOf() === SubmissionScopeType.WorkspaceItem.valueOf() ?
|
||||
SectionScope.Submission : SectionScope.Workflow;
|
||||
const visibility = convertedSubmissionScope.valueOf() === sectionObj.scope.valueOf() ?
|
||||
sectionObj.visibility.main : sectionObj.visibility.other;
|
||||
return visibility === 'READONLY';
|
||||
}),
|
||||
distinctUntilChanged());
|
||||
}
|
||||
|
@@ -42,6 +42,7 @@ import { storeModuleConfig } from '../app.reducer';
|
||||
import { environment } from '../../environments/environment';
|
||||
import { SubmissionJsonPatchOperationsService } from '../core/submission/submission-json-patch-operations.service';
|
||||
import { SubmissionJsonPatchOperationsServiceStub } from '../shared/testing/submission-json-patch-operations-service.stub';
|
||||
import { SectionScope } from './objects/section-visibility.model';
|
||||
|
||||
describe('SubmissionService test suite', () => {
|
||||
const collectionId = '43fe1f8c-09a6-4fcf-9c78-5d4fed8f2c8f';
|
||||
@@ -58,6 +59,7 @@ describe('SubmissionService test suite', () => {
|
||||
extraction: {
|
||||
config: '',
|
||||
mandatory: true,
|
||||
scope: SectionScope.Submission,
|
||||
sectionType: 'utils',
|
||||
visibility: {
|
||||
main: 'HIDDEN',
|
||||
@@ -74,6 +76,7 @@ describe('SubmissionService test suite', () => {
|
||||
collection: {
|
||||
config: '',
|
||||
mandatory: true,
|
||||
scope: SectionScope.Submission,
|
||||
sectionType: 'collection',
|
||||
visibility: {
|
||||
main: 'HIDDEN',
|
||||
@@ -213,6 +216,7 @@ describe('SubmissionService test suite', () => {
|
||||
extraction: {
|
||||
config: '',
|
||||
mandatory: true,
|
||||
scope: SectionScope.Submission,
|
||||
sectionType: 'utils',
|
||||
visibility: {
|
||||
main: 'HIDDEN',
|
||||
@@ -229,6 +233,7 @@ describe('SubmissionService test suite', () => {
|
||||
collection: {
|
||||
config: '',
|
||||
mandatory: true,
|
||||
scope: SectionScope.Submission,
|
||||
sectionType: 'collection',
|
||||
visibility: {
|
||||
main: 'HIDDEN',
|
||||
@@ -566,6 +571,7 @@ describe('SubmissionService test suite', () => {
|
||||
|
||||
describe('getSubmissionSections', () => {
|
||||
it('should return submission form sections', () => {
|
||||
spyOn(service, 'getSubmissionScope').and.returnValue(SubmissionScopeType.WorkspaceItem);
|
||||
spyOn((service as any).store, 'select').and.returnValue(hot('a|', {
|
||||
a: subState.objects[826]
|
||||
}));
|
||||
@@ -735,6 +741,7 @@ describe('SubmissionService test suite', () => {
|
||||
|
||||
describe('getSubmissionStatus', () => {
|
||||
it('should return properly submission status', () => {
|
||||
spyOn(service, 'getSubmissionScope').and.returnValue(SubmissionScopeType.WorkspaceItem);
|
||||
spyOn((service as any).store, 'select').and.returnValue(hot('-a-b', {
|
||||
a: subState,
|
||||
b: validSubState
|
||||
@@ -794,41 +801,207 @@ describe('SubmissionService test suite', () => {
|
||||
});
|
||||
|
||||
describe('isSectionHidden', () => {
|
||||
it('should return true/false when section is hidden/visible', () => {
|
||||
let section: any = {
|
||||
config: '',
|
||||
header: '',
|
||||
mandatory: true,
|
||||
sectionType: 'collection' as any,
|
||||
visibility: {
|
||||
main: 'HIDDEN',
|
||||
other: 'HIDDEN'
|
||||
},
|
||||
collapsed: false,
|
||||
enabled: true,
|
||||
data: {},
|
||||
errorsToShow: [],
|
||||
serverValidationErrors: [],
|
||||
isLoading: false,
|
||||
isValid: false
|
||||
};
|
||||
expect(service.isSectionHidden(section)).toBeTruthy();
|
||||
describe('when submission scope is workspace', () => {
|
||||
beforeEach(() => {
|
||||
spyOn(service, 'getSubmissionScope').and.returnValue(SubmissionScopeType.WorkspaceItem);
|
||||
});
|
||||
|
||||
describe('and section scope is workspace', () => {
|
||||
it('should return true when visibility main is HIDDEN and visibility other is null', () => {
|
||||
let section: any = {
|
||||
scope: SectionScope.Submission,
|
||||
visibility: {
|
||||
main: 'HIDDEN',
|
||||
other: null,
|
||||
},
|
||||
};
|
||||
expect(service.isSectionHidden(section)).toBeTrue();
|
||||
});
|
||||
it('should return true when both visibility main and other are HIDDEN', () => {
|
||||
let section: any = {
|
||||
scope: SectionScope.Submission,
|
||||
visibility: {
|
||||
main: 'HIDDEN',
|
||||
other: 'HIDDEN'
|
||||
},
|
||||
};
|
||||
expect(service.isSectionHidden(section)).toBeTrue();
|
||||
});
|
||||
it('should return false when visibility main is null and visibility other is HIDDEN', () => {
|
||||
let section: any = {
|
||||
scope: SectionScope.Submission,
|
||||
visibility: {
|
||||
main: null,
|
||||
other: 'HIDDEN',
|
||||
},
|
||||
};
|
||||
expect(service.isSectionHidden(section)).toBeFalse();
|
||||
});
|
||||
it('should return false when visibility is null', () => {
|
||||
let section: any = {
|
||||
scope: SectionScope.Submission,
|
||||
visibility: null,
|
||||
};
|
||||
expect(service.isSectionHidden(section)).toBeFalse();
|
||||
});
|
||||
});
|
||||
|
||||
describe('and section scope is workflow', () => {
|
||||
it('should return false when visibility main is HIDDEN and visibility other is null', () => {
|
||||
let section: any = {
|
||||
scope: SectionScope.Workflow,
|
||||
visibility: {
|
||||
main: 'HIDDEN',
|
||||
other: null,
|
||||
},
|
||||
};
|
||||
expect(service.isSectionHidden(section)).toBeFalse();
|
||||
});
|
||||
it('should return true when both visibility main and other are HIDDEN', () => {
|
||||
let section: any = {
|
||||
scope: SectionScope.Workflow,
|
||||
visibility: {
|
||||
main: 'HIDDEN',
|
||||
other: 'HIDDEN',
|
||||
},
|
||||
};
|
||||
expect(service.isSectionHidden(section)).toBeTrue();
|
||||
});
|
||||
it('should return true when visibility main is null and visibility other is HIDDEN', () => {
|
||||
let section: any = {
|
||||
scope: SectionScope.Workflow,
|
||||
visibility: {
|
||||
main: null,
|
||||
other: 'HIDDEN',
|
||||
},
|
||||
};
|
||||
expect(service.isSectionHidden(section)).toBeTrue();
|
||||
});
|
||||
it('should return false when visibility is null', () => {
|
||||
let section: any = {
|
||||
scope: SectionScope.Workflow,
|
||||
visibility: null,
|
||||
};
|
||||
expect(service.isSectionHidden(section)).toBeFalse();
|
||||
});
|
||||
});
|
||||
|
||||
describe('and section scope is null', () => {
|
||||
it('should return false', () => {
|
||||
let section: any = {
|
||||
scope: null,
|
||||
visibility: {
|
||||
main: 'HIDDEN',
|
||||
other: null,
|
||||
},
|
||||
};
|
||||
expect(service.isSectionHidden(section)).toBeFalse();
|
||||
});
|
||||
});
|
||||
|
||||
section = {
|
||||
header: 'submit.progressbar.describe.keyinformation',
|
||||
config: 'https://rest.api/dspace-spring-rest/api/config/submissionforms/keyinformation',
|
||||
mandatory: true,
|
||||
sectionType: 'submission-form',
|
||||
collapsed: false,
|
||||
enabled: true,
|
||||
data: {},
|
||||
errorsToShow: [],
|
||||
serverValidationErrors: [],
|
||||
isLoading: false,
|
||||
isValid: false
|
||||
};
|
||||
expect(service.isSectionHidden(section)).toBeFalsy();
|
||||
});
|
||||
|
||||
describe('when submission scope is workflow', () => {
|
||||
beforeEach(() => {
|
||||
spyOn(service, 'getSubmissionScope').and.returnValue(SubmissionScopeType.WorkflowItem);
|
||||
});
|
||||
|
||||
describe('and section scope is workspace', () => {
|
||||
it('should return false when visibility main is HIDDEN and visibility other is null', () => {
|
||||
let section: any = {
|
||||
scope: SectionScope.Submission,
|
||||
visibility: {
|
||||
main: 'HIDDEN',
|
||||
other: null,
|
||||
},
|
||||
};
|
||||
expect(service.isSectionHidden(section)).toBeFalse();
|
||||
});
|
||||
it('should return true when both visibility main and other are HIDDEN', () => {
|
||||
let section: any = {
|
||||
scope: SectionScope.Submission,
|
||||
visibility: {
|
||||
main: 'HIDDEN',
|
||||
other: 'HIDDEN',
|
||||
},
|
||||
};
|
||||
expect(service.isSectionHidden(section)).toBeTrue();
|
||||
});
|
||||
it('should return true when visibility main is null and visibility other is HIDDEN', () => {
|
||||
let section: any = {
|
||||
scope: SectionScope.Submission,
|
||||
visibility: {
|
||||
main: null,
|
||||
other: 'HIDDEN',
|
||||
},
|
||||
};
|
||||
expect(service.isSectionHidden(section)).toBeTrue();
|
||||
});
|
||||
it('should return false when visibility is null', () => {
|
||||
let section: any = {
|
||||
scope: SectionScope.Submission,
|
||||
visibility: null,
|
||||
};
|
||||
expect(service.isSectionHidden(section)).toBeFalse();
|
||||
});
|
||||
});
|
||||
|
||||
describe('and section scope is workflow', () => {
|
||||
it('should return true when visibility main is HIDDEN and visibility other is null', () => {
|
||||
let section: any = {
|
||||
scope: SectionScope.Workflow,
|
||||
visibility: {
|
||||
main: 'HIDDEN',
|
||||
other: null,
|
||||
},
|
||||
};
|
||||
expect(service.isSectionHidden(section)).toBeTrue();
|
||||
});
|
||||
it('should return true when both visibility main and other are HIDDEN', () => {
|
||||
let section: any = {
|
||||
scope: SectionScope.Workflow,
|
||||
visibility: {
|
||||
main: 'HIDDEN',
|
||||
other: 'HIDDEN',
|
||||
},
|
||||
};
|
||||
expect(service.isSectionHidden(section)).toBeTrue();
|
||||
});
|
||||
it('should return false when visibility main is null and visibility other is HIDDEN', () => {
|
||||
let section: any = {
|
||||
scope: SectionScope.Workflow,
|
||||
visibility: {
|
||||
main: null,
|
||||
other: 'HIDDEN',
|
||||
},
|
||||
};
|
||||
expect(service.isSectionHidden(section)).toBeFalse();
|
||||
});
|
||||
it('should return false when visibility is null', () => {
|
||||
let section: any = {
|
||||
scope: SectionScope.Workflow,
|
||||
visibility: null,
|
||||
};
|
||||
expect(service.isSectionHidden(section)).toBeFalse();
|
||||
});
|
||||
});
|
||||
|
||||
describe('and section scope is null', () => {
|
||||
it('should return false', () => {
|
||||
let section: any = {
|
||||
scope: null,
|
||||
visibility: {
|
||||
main: 'HIDDEN',
|
||||
other: null,
|
||||
},
|
||||
};
|
||||
expect(service.isSectionHidden(section)).toBeFalse();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
describe('isSubmissionLoading', () => {
|
||||
|
@@ -46,6 +46,7 @@ import { environment } from '../../environments/environment';
|
||||
import { SubmissionJsonPatchOperationsService } from '../core/submission/submission-json-patch-operations.service';
|
||||
import { SubmissionSectionObject } from './objects/submission-section-object.model';
|
||||
import { SubmissionError } from './objects/submission-error.model';
|
||||
import { SectionScope } from './objects/section-visibility.model';
|
||||
|
||||
function getSubmissionSelector(submissionId: string): MemoizedSelector<SubmissionState, SubmissionObjectEntry> {
|
||||
return createSelector(
|
||||
@@ -475,9 +476,15 @@ export class SubmissionService {
|
||||
* true if section is hidden, false otherwise
|
||||
*/
|
||||
isSectionHidden(sectionData: SubmissionSectionObject): boolean {
|
||||
return (isNotUndefined(sectionData.visibility)
|
||||
&& sectionData.visibility.main === 'HIDDEN'
|
||||
&& sectionData.visibility.other === 'HIDDEN');
|
||||
const submissionScope: SubmissionScopeType = this.getSubmissionScope();
|
||||
if (isEmpty(submissionScope) || isEmpty(sectionData.visibility) || isEmpty(sectionData.scope)) {
|
||||
return false;
|
||||
}
|
||||
const convertedSubmissionScope: SectionScope = submissionScope.valueOf() === SubmissionScopeType.WorkspaceItem.valueOf() ?
|
||||
SectionScope.Submission : SectionScope.Workflow;
|
||||
const visibility = convertedSubmissionScope.valueOf() === sectionData.scope.valueOf() ?
|
||||
sectionData.visibility.main : sectionData.visibility.other;
|
||||
return visibility === 'HIDDEN';
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user