mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-16 14:33:03 +00:00
[CST-4505] Fixed canChangeDiscoverable managment and unit testing
This commit is contained in:
@@ -19,6 +19,9 @@ export class SubmissionAccessModel extends ConfigObject {
|
|||||||
@autoserialize
|
@autoserialize
|
||||||
discoverable: boolean;
|
discoverable: boolean;
|
||||||
|
|
||||||
|
@autoserialize
|
||||||
|
canChangeDiscoverable: boolean;
|
||||||
|
|
||||||
@deserialize
|
@deserialize
|
||||||
_links: {
|
_links: {
|
||||||
self: HALLink
|
self: HALLink
|
||||||
|
@@ -37,8 +37,51 @@ const configRes = Object.assign(new SubmissionFormsModel(), {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
const configResNotChangeDiscoverable = Object.assign(new SubmissionFormsModel(), {
|
||||||
|
'id': 'AccessConditionDefaultConfiguration',
|
||||||
|
'canChangeDiscoverable': false,
|
||||||
|
'accessConditionOptions': [
|
||||||
|
{
|
||||||
|
'name': 'openaccess',
|
||||||
|
'hasStartDate': false,
|
||||||
|
'hasEndDate': false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'name': 'lease',
|
||||||
|
'hasStartDate': false,
|
||||||
|
'hasEndDate': true,
|
||||||
|
'maxEndDate': '2022-06-20T12:17:44.420+00:00'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'name': 'embargo',
|
||||||
|
'hasStartDate': true,
|
||||||
|
'hasEndDate': false,
|
||||||
|
'maxStartDate': '2024-12-20T12:17:44.420+00:00'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'name': 'administrator',
|
||||||
|
'hasStartDate': false,
|
||||||
|
'hasEndDate': false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
'type': 'submissionaccessoption',
|
||||||
|
'_links': {
|
||||||
|
'self': {
|
||||||
|
'href': 'http://localhost:8080/server/api/config/submissionaccessoptions/AccessConditionDefaultConfiguration'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
export function getSubmissionAccessesConfigService(): SubmissionFormsConfigService {
|
export function getSubmissionAccessesConfigService(): SubmissionFormsConfigService {
|
||||||
return jasmine.createSpyObj('SubmissionAccessesConfigService', {
|
return jasmine.createSpyObj('SubmissionAccessesConfigService', {
|
||||||
findByHref: createSuccessfulRemoteDataObject$(configRes),
|
findByHref: createSuccessfulRemoteDataObject$(configRes),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export function getSubmissionAccessesConfigNotChangeDiscoverableService(): SubmissionFormsConfigService {
|
||||||
|
return jasmine.createSpyObj('SubmissionAccessesConfigService', {
|
||||||
|
findByHref: createSuccessfulRemoteDataObject$(configResNotChangeDiscoverable),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
@@ -8,7 +8,7 @@ import { SectionsServiceStub } from '../../../shared/testing/sections-service.st
|
|||||||
import { FormBuilderService } from '../../../shared/form/builder/form-builder.service';
|
import { FormBuilderService } from '../../../shared/form/builder/form-builder.service';
|
||||||
import { getMockFormBuilderService } from '../../../shared/mocks/form-builder-service.mock';
|
import { getMockFormBuilderService } from '../../../shared/mocks/form-builder-service.mock';
|
||||||
import { SubmissionAccessesConfigService } from '../../../core/config/submission-accesses-config.service';
|
import { SubmissionAccessesConfigService } from '../../../core/config/submission-accesses-config.service';
|
||||||
import { getSubmissionAccessesConfigService } from '../../../shared/mocks/section-accesses-config.service.mock';
|
import { getSubmissionAccessesConfigService, getSubmissionAccessesConfigNotChangeDiscoverableService } from '../../../shared/mocks/section-accesses-config.service.mock';
|
||||||
import { SectionAccessesService } from './section-accesses.service';
|
import { SectionAccessesService } from './section-accesses.service';
|
||||||
import { SectionFormOperationsService } from '../form/section-form-operations.service';
|
import { SectionFormOperationsService } from '../form/section-form-operations.service';
|
||||||
import { JsonPatchOperationsBuilder } from '../../../core/json-patch/builder/json-patch-operations-builder';
|
import { JsonPatchOperationsBuilder } from '../../../core/json-patch/builder/json-patch-operations-builder';
|
||||||
@@ -72,7 +72,7 @@ describe('SubmissionSectionAccessesComponent', () => {
|
|||||||
isValid: true
|
isValid: true
|
||||||
};
|
};
|
||||||
|
|
||||||
|
describe('First with canChangeDiscoverable true', () => {
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await TestBed.configureTestingModule({
|
await TestBed.configureTestingModule({
|
||||||
@@ -109,6 +109,7 @@ describe('SubmissionSectionAccessesComponent', () => {
|
|||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
it('should create', () => {
|
it('should create', () => {
|
||||||
expect(component).toBeTruthy();
|
expect(component).toBeTruthy();
|
||||||
});
|
});
|
||||||
@@ -146,4 +147,55 @@ describe('SubmissionSectionAccessesComponent', () => {
|
|||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(operationsBuilder.add).toHaveBeenCalled();
|
expect(operationsBuilder.add).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when canDescoverable is false', () => {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
imports: [
|
||||||
|
BrowserModule,
|
||||||
|
TranslateModule.forRoot()
|
||||||
|
],
|
||||||
|
declarations: [SubmissionSectionAccessesComponent, FormComponent],
|
||||||
|
providers: [
|
||||||
|
{ provide: SectionsService, useValue: sectionsServiceStub },
|
||||||
|
{ provide: FormBuilderService, useValue: builderService },
|
||||||
|
{ provide: SubmissionAccessesConfigService, useValue: getSubmissionAccessesConfigNotChangeDiscoverableService() },
|
||||||
|
{ provide: SectionAccessesService, useValue: sectionAccessesService },
|
||||||
|
{ provide: SectionFormOperationsService, useValue: sectionFormOperationsService },
|
||||||
|
{ provide: JsonPatchOperationsBuilder, useValue: operationsBuilder },
|
||||||
|
{ provide: TranslateService, useValue: getMockTranslateService() },
|
||||||
|
{ provide: FormService, useValue: getMockFormService() },
|
||||||
|
{ provide: Store, useValue: storeStub },
|
||||||
|
{ provide: SubmissionJsonPatchOperationsService, useValue: SubmissionJsonPatchOperationsServiceStub },
|
||||||
|
{ provide: 'sectionDataProvider', useValue: sectionData },
|
||||||
|
{ provide: 'submissionIdProvider', useValue: '1508' },
|
||||||
|
]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(inject([Store], (store: Store<AppState>) => {
|
||||||
|
fixture = TestBed.createComponent(SubmissionSectionAccessesComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
formService = TestBed.inject(FormService);
|
||||||
|
formService.validateAllFormFields.and.callFake(() => null);
|
||||||
|
formService.isValid.and.returnValue(observableOf(true));
|
||||||
|
formService.getFormData.and.returnValue(observableOf(mockAccessesFormData));
|
||||||
|
fixture.detectChanges();
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
it('should have formModel length should be 1', () => {
|
||||||
|
expect(component.formModel.length).toEqual(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('formModel should have only 1 model type array', () => {
|
||||||
|
expect(component.formModel[0] instanceof DynamicFormArrayModel).toBeTrue();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -113,6 +113,12 @@ export class SubmissionSectionAccessesComponent extends SectionModelComponent {
|
|||||||
*/
|
*/
|
||||||
protected fieldsOnTheirWayToBeRemoved: Map<string, number[]> = new Map();
|
protected fieldsOnTheirWayToBeRemoved: Map<string, number[]> = new Map();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines if the access discoverable property can be managed
|
||||||
|
*/
|
||||||
|
public canChangeDiscoverable: boolean;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize instance variables
|
* Initialize instance variables
|
||||||
*
|
*
|
||||||
@@ -282,6 +288,7 @@ export class SubmissionSectionAccessesComponent extends SectionModelComponent {
|
|||||||
|
|
||||||
combineLatest(config$, accessData$).subscribe(([config, accessData]) => {
|
combineLatest(config$, accessData$).subscribe(([config, accessData]) => {
|
||||||
this.availableAccessConditionOptions = isNotEmpty(config.accessConditionOptions) ? config.accessConditionOptions : [];
|
this.availableAccessConditionOptions = isNotEmpty(config.accessConditionOptions) ? config.accessConditionOptions : [];
|
||||||
|
this.canChangeDiscoverable = !!config.canChangeDiscoverable;
|
||||||
this.accessesData = accessData;
|
this.accessesData = accessData;
|
||||||
this.formModel = this.buildFileEditForm();
|
this.formModel = this.buildFileEditForm();
|
||||||
});
|
});
|
||||||
@@ -305,6 +312,7 @@ export class SubmissionSectionAccessesComponent extends SectionModelComponent {
|
|||||||
protected buildFileEditForm() {
|
protected buildFileEditForm() {
|
||||||
|
|
||||||
const formModel: DynamicFormControlModel[] = [];
|
const formModel: DynamicFormControlModel[] = [];
|
||||||
|
if (this.canChangeDiscoverable) {
|
||||||
formModel.push(
|
formModel.push(
|
||||||
new DynamicCheckboxModel({
|
new DynamicCheckboxModel({
|
||||||
id: 'discoverable',
|
id: 'discoverable',
|
||||||
@@ -313,6 +321,8 @@ export class SubmissionSectionAccessesComponent extends SectionModelComponent {
|
|||||||
value: this.accessesData.discoverable
|
value: this.accessesData.discoverable
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const accessConditionTypeModelConfig = Object.assign({}, FORM_ACCESS_CONDITION_TYPE_CONFIG);
|
const accessConditionTypeModelConfig = Object.assign({}, FORM_ACCESS_CONDITION_TYPE_CONFIG);
|
||||||
const accessConditionsArrayConfig = Object.assign({}, ACCESS_CONDITIONS_FORM_ARRAY_CONFIG);
|
const accessConditionsArrayConfig = Object.assign({}, ACCESS_CONDITIONS_FORM_ARRAY_CONFIG);
|
||||||
|
Reference in New Issue
Block a user