mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-12 04:23:04 +00:00
[DURACOM-191] fix: section-license unit-tests
This commit is contained in:
@@ -41,8 +41,6 @@ import { provideMockStore } from '@ngrx/store/testing';
|
|||||||
import { DsDynamicTypeBindRelationService } from 'src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-type-bind-relation.service';
|
import { DsDynamicTypeBindRelationService } from 'src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-type-bind-relation.service';
|
||||||
import { APP_CONFIG } from 'src/config/app-config.interface';
|
import { APP_CONFIG } from 'src/config/app-config.interface';
|
||||||
import { environment } from 'src/environments/environment.test';
|
import { environment } from 'src/environments/environment.test';
|
||||||
import { getMockFormBuilderService } from 'src/app/shared/mocks/form-builder-service.mock';
|
|
||||||
import { SECTION_LICENSE_FORM_MODEL } from './section-license.model';
|
|
||||||
|
|
||||||
function getMockDsDynamicTypeBindRelationService(): DsDynamicTypeBindRelationService {
|
function getMockDsDynamicTypeBindRelationService(): DsDynamicTypeBindRelationService {
|
||||||
return jasmine.createSpyObj('DsDynamicTypeBindRelationService', {
|
return jasmine.createSpyObj('DsDynamicTypeBindRelationService', {
|
||||||
@@ -75,17 +73,6 @@ function getMockSubmissionFormsConfigService(): SubmissionFormsConfigDataService
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const formBuilderServiceStub = {
|
|
||||||
findById: jasmine.createSpy('findById'),
|
|
||||||
fromJSON: jasmine.createSpy('fromJSON'),
|
|
||||||
createFormGroup: () => {
|
|
||||||
return {
|
|
||||||
patchValue: () => { },
|
|
||||||
reset(_value?: any, _options?: { onlySelf?: boolean; emitEvent?: boolean; }): void { },
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const sectionObject: SectionDataObject = {
|
const sectionObject: SectionDataObject = {
|
||||||
config: 'https://dspace7.4science.it/or2018/api/config/submissionforms/license',
|
config: 'https://dspace7.4science.it/or2018/api/config/submissionforms/license',
|
||||||
mandatory: true,
|
mandatory: true,
|
||||||
@@ -110,7 +97,7 @@ const dynamicFormControlEvent: DynamicFormControlEvent = {
|
|||||||
type: DynamicFormControlEventType.Change
|
type: DynamicFormControlEventType.Change
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('SubmissionSectionLicenseComponent test suite', () => {
|
fdescribe('SubmissionSectionLicenseComponent test suite', () => {
|
||||||
|
|
||||||
let comp: SubmissionSectionLicenseComponent;
|
let comp: SubmissionSectionLicenseComponent;
|
||||||
let compAsAny: any;
|
let compAsAny: any;
|
||||||
@@ -134,9 +121,17 @@ describe('SubmissionSectionLicenseComponent test suite', () => {
|
|||||||
findById: jasmine.createSpy('findById'),
|
findById: jasmine.createSpy('findById'),
|
||||||
findByHref: jasmine.createSpy('findByHref')
|
findByHref: jasmine.createSpy('findByHref')
|
||||||
});
|
});
|
||||||
|
const initialState: any = {
|
||||||
|
core: {
|
||||||
|
'cache/object': {},
|
||||||
|
'cache/syncbuffer': {},
|
||||||
|
'cache/object-updates': {},
|
||||||
|
'data/request': {},
|
||||||
|
'index': {},
|
||||||
|
}
|
||||||
|
};
|
||||||
beforeEach(waitForAsync(() => {
|
beforeEach(waitForAsync(() => {
|
||||||
TestBed.configureTestingModule({
|
void TestBed.configureTestingModule({
|
||||||
imports: [
|
imports: [
|
||||||
CommonModule,
|
CommonModule,
|
||||||
FormsModule,
|
FormsModule,
|
||||||
@@ -159,9 +154,9 @@ describe('SubmissionSectionLicenseComponent test suite', () => {
|
|||||||
{ provide: 'sectionDataProvider', useValue: Object.assign({}, sectionObject) },
|
{ provide: 'sectionDataProvider', useValue: Object.assign({}, sectionObject) },
|
||||||
{ provide: 'submissionIdProvider', useValue: submissionId },
|
{ provide: 'submissionIdProvider', useValue: submissionId },
|
||||||
ChangeDetectorRef,
|
ChangeDetectorRef,
|
||||||
provideMockStore({}),
|
provideMockStore({initialState}),
|
||||||
{ provide: FormBuilderService, useValue: getMockFormBuilderService() },
|
FormBuilderService,
|
||||||
{ provide:DsDynamicTypeBindRelationService, useValue: getMockDsDynamicTypeBindRelationService() },
|
{ provide: DsDynamicTypeBindRelationService, useValue: getMockDsDynamicTypeBindRelationService() },
|
||||||
{ provide: APP_CONFIG, useValue: environment },
|
{ provide: APP_CONFIG, useValue: environment },
|
||||||
SubmissionSectionLicenseComponent
|
SubmissionSectionLicenseComponent
|
||||||
],
|
],
|
||||||
@@ -222,16 +217,11 @@ describe('SubmissionSectionLicenseComponent test suite', () => {
|
|||||||
mockCollectionDataService.findById.and.returnValue(createSuccessfulRemoteDataObject$(mockCollection));
|
mockCollectionDataService.findById.and.returnValue(createSuccessfulRemoteDataObject$(mockCollection));
|
||||||
sectionsServiceStub.getSectionErrors.and.returnValue(observableOf([]));
|
sectionsServiceStub.getSectionErrors.and.returnValue(observableOf([]));
|
||||||
sectionsServiceStub.isSectionReadOnly.and.returnValue(observableOf(false));
|
sectionsServiceStub.isSectionReadOnly.and.returnValue(observableOf(false));
|
||||||
(formBuilderService.findById as jasmine.Spy).and.returnValue(new DynamicCheckboxModel({ id: 'granted'}));
|
spyOn(formBuilderService, 'findById').and.returnValue(new DynamicCheckboxModel({ id: 'granted' }));
|
||||||
(formBuilderService.fromJSON as jasmine.Spy).and.returnValue(SECTION_LICENSE_FORM_MODEL);
|
|
||||||
// formBuilderServiceStub.findById.and.returnValue(new DynamicCheckboxModel({ id: 'granted'}));
|
|
||||||
// formBuilderServiceStub.fromJSON.and.returnValue(SECTION_LICENSE_FORM_MODEL);
|
|
||||||
comp.onSectionInit();
|
|
||||||
fixture.detectChanges();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should init section properly', () => {
|
it('should init section properly', () => {
|
||||||
|
fixture.detectChanges();
|
||||||
spyOn(compAsAny, 'getSectionStatus');
|
spyOn(compAsAny, 'getSectionStatus');
|
||||||
|
|
||||||
const model = formBuilderService.findById('granted', comp.formModel);
|
const model = formBuilderService.findById('granted', comp.formModel);
|
||||||
@@ -251,11 +241,8 @@ describe('SubmissionSectionLicenseComponent test suite', () => {
|
|||||||
acceptanceDate: Date.now(),
|
acceptanceDate: Date.now(),
|
||||||
granted: true
|
granted: true
|
||||||
} as any;
|
} as any;
|
||||||
|
fixture.detectChanges();
|
||||||
spyOn(compAsAny, 'getSectionStatus');
|
|
||||||
|
|
||||||
const model = formBuilderService.findById('granted', comp.formModel);
|
const model = formBuilderService.findById('granted', comp.formModel);
|
||||||
|
|
||||||
expect(compAsAny.subs.length).toBe(2);
|
expect(compAsAny.subs.length).toBe(2);
|
||||||
expect(comp.formModel).toBeDefined();
|
expect(comp.formModel).toBeDefined();
|
||||||
expect(model.value).toBeTruthy();
|
expect(model.value).toBeTruthy();
|
||||||
@@ -265,19 +252,21 @@ describe('SubmissionSectionLicenseComponent test suite', () => {
|
|||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
fit('should have status true when checkbox is selected', () => {
|
it('should have status true when checkbox is selected', (done) => {
|
||||||
const model = formBuilderService.findById('granted', comp.formModel);
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
const model = formBuilderService.findById('granted', comp.formModel);
|
||||||
(model as DynamicCheckboxModel).value = true;
|
(model as DynamicCheckboxModel).value = true;
|
||||||
|
|
||||||
compAsAny.getSectionStatus().subscribe((status) => {
|
compAsAny.getSectionStatus().subscribe((status) => {
|
||||||
expect(status).toBeTruthy();
|
expect(status).toBeTruthy();
|
||||||
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should have status false when checkbox is not selected', () => {
|
it('should have status false when checkbox is not selected', () => {
|
||||||
|
fixture.detectChanges();
|
||||||
const model = formBuilderService.findById('granted', comp.formModel);
|
const model = formBuilderService.findById('granted', comp.formModel);
|
||||||
|
|
||||||
compAsAny.getSectionStatus().subscribe((status) => {
|
compAsAny.getSectionStatus().subscribe((status) => {
|
||||||
expect(status).toBeFalsy();
|
expect(status).toBeFalsy();
|
||||||
});
|
});
|
||||||
@@ -295,7 +284,7 @@ describe('SubmissionSectionLicenseComponent test suite', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should set section errors properly', () => {
|
it('should set section errors properly', () => {
|
||||||
comp.onSectionInit();
|
fixture.detectChanges();
|
||||||
const expectedErrors = mockLicenseParsedErrors.license;
|
const expectedErrors = mockLicenseParsedErrors.license;
|
||||||
|
|
||||||
expect(sectionsServiceStub.checkSectionErrors).toHaveBeenCalled();
|
expect(sectionsServiceStub.checkSectionErrors).toHaveBeenCalled();
|
||||||
@@ -310,7 +299,7 @@ describe('SubmissionSectionLicenseComponent test suite', () => {
|
|||||||
granted: true
|
granted: true
|
||||||
} as any;
|
} as any;
|
||||||
|
|
||||||
comp.onSectionInit();
|
fixture.detectChanges();
|
||||||
|
|
||||||
expect(sectionsServiceStub.dispatchRemoveSectionErrors).toHaveBeenCalled();
|
expect(sectionsServiceStub.dispatchRemoveSectionErrors).toHaveBeenCalled();
|
||||||
|
|
||||||
@@ -352,8 +341,10 @@ describe('SubmissionSectionLicenseComponent test suite', () => {
|
|||||||
template: ``,
|
template: ``,
|
||||||
standalone: true,
|
standalone: true,
|
||||||
imports: [
|
imports: [
|
||||||
|
SubmissionSectionLicenseComponent,
|
||||||
CommonModule,
|
CommonModule,
|
||||||
FormsModule,
|
FormsModule,
|
||||||
|
FormComponent,
|
||||||
ReactiveFormsModule
|
ReactiveFormsModule
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { ChangeDetectorRef, Component, Inject, ViewChild } from '@angular/core';
|
import { AfterViewChecked, ChangeDetectorRef, Component, Inject, ViewChild } from '@angular/core';
|
||||||
import {
|
import {
|
||||||
DynamicCheckboxModel,
|
DynamicCheckboxModel,
|
||||||
DynamicFormControlEvent,
|
DynamicFormControlEvent,
|
||||||
@@ -39,15 +39,16 @@ import { AsyncPipe, NgIf } from '@angular/common';
|
|||||||
selector: 'ds-submission-section-license',
|
selector: 'ds-submission-section-license',
|
||||||
styleUrls: ['./section-license.component.scss'],
|
styleUrls: ['./section-license.component.scss'],
|
||||||
templateUrl: './section-license.component.html',
|
templateUrl: './section-license.component.html',
|
||||||
|
providers: [],
|
||||||
imports: [
|
imports: [
|
||||||
FormComponent,
|
FormComponent,
|
||||||
NgIf,
|
NgIf,
|
||||||
AsyncPipe
|
AsyncPipe,
|
||||||
],
|
],
|
||||||
standalone: true
|
standalone: true
|
||||||
})
|
})
|
||||||
@renderSectionFor(SectionsType.License)
|
@renderSectionFor(SectionsType.License)
|
||||||
export class SubmissionSectionLicenseComponent extends SectionModelComponent {
|
export class SubmissionSectionLicenseComponent extends SectionModelComponent implements AfterViewChecked {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The form id
|
* The form id
|
||||||
@@ -190,11 +191,14 @@ export class SubmissionSectionLicenseComponent extends SectionModelComponent {
|
|||||||
// Remove any section's errors
|
// Remove any section's errors
|
||||||
this.sectionService.dispatchRemoveSectionErrors(this.submissionId, this.sectionData.id);
|
this.sectionService.dispatchRemoveSectionErrors(this.submissionId, this.sectionData.id);
|
||||||
}
|
}
|
||||||
this.changeDetectorRef.detectChanges();
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngAfterViewChecked(): void {
|
||||||
|
this.changeDetectorRef.detectChanges();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get section status
|
* Get section status
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user