mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-17 23:13:04 +00:00
fixed tests after angular 10 upgrade
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||
import { SubmissionSectionCcLicensesComponent } from './submission-section-cc-licenses.component';
|
||||
import { SUBMISSION_CC_LICENSE } from '../../../core/submission/models/submission-cc-licence.resource-type';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
@@ -166,7 +166,7 @@ describe('SubmissionSectionCcLicensesComponent', () => {
|
||||
remove: undefined,
|
||||
});
|
||||
|
||||
beforeEach(async(() => {
|
||||
beforeEach(waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
SharedModule,
|
||||
@@ -181,7 +181,7 @@ describe('SubmissionSectionCcLicensesComponent', () => {
|
||||
{ provide: SectionsService, useValue: sectionService },
|
||||
{ provide: JsonPatchOperationsBuilder, useValue: operationsBuilder },
|
||||
{ provide: 'collectionIdProvider', useValue: 'test collection id' },
|
||||
{ provide: 'sectionDataProvider', useValue: sectionObject },
|
||||
{ provide: 'sectionDataProvider', useValue: Object.assign({}, sectionObject) },
|
||||
{ provide: 'submissionIdProvider', useValue: 'test submission id' },
|
||||
],
|
||||
})
|
||||
|
@@ -1,6 +1,6 @@
|
||||
// Load the implementations that should be tested
|
||||
import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
||||
import { async, ComponentFixture, inject, TestBed, } from '@angular/core/testing';
|
||||
import { ComponentFixture, inject, TestBed, waitForAsync, } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
|
||||
import { of as observableOf } from 'rxjs';
|
||||
@@ -47,23 +47,20 @@ describe('SubmissionSectionContainerComponent test suite', () => {
|
||||
let compAsAny: any;
|
||||
let fixture: ComponentFixture<SubmissionSectionContainerComponent>;
|
||||
|
||||
let submissionServiceStub: SubmissionServiceStub;
|
||||
let sectionsServiceStub: SectionsServiceStub;
|
||||
const submissionServiceStub: SubmissionServiceStub = new SubmissionServiceStub();
|
||||
const sectionsServiceStub: SectionsServiceStub = new SectionsServiceStub();
|
||||
|
||||
const submissionId = mockSubmissionId;
|
||||
const collectionId = mockSubmissionCollectionId;
|
||||
|
||||
function init() {
|
||||
sectionsServiceStub = TestBed.inject(SectionsService as any);
|
||||
submissionServiceStub = TestBed.inject(SubmissionService as any);
|
||||
|
||||
sectionsServiceStub.isSectionValid.and.returnValue(observableOf(true));
|
||||
sectionsServiceStub.getSectionState.and.returnValue(observableOf(sectionState));
|
||||
submissionServiceStub.getActiveSectionId.and.returnValue(observableOf('traditionalpageone'));
|
||||
}
|
||||
|
||||
// async beforeEach
|
||||
beforeEach(async(() => {
|
||||
beforeEach(waitForAsync(() => {
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
@@ -76,8 +73,8 @@ describe('SubmissionSectionContainerComponent test suite', () => {
|
||||
TestComponent,
|
||||
], // declare the test component
|
||||
providers: [
|
||||
{ provide: SectionsService, useClass: SectionsServiceStub },
|
||||
{ provide: SubmissionService, useClass: SubmissionServiceStub },
|
||||
{ provide: SectionsService, useValue: sectionsServiceStub },
|
||||
{ provide: SubmissionService, useValue: submissionServiceStub },
|
||||
SubmissionSectionContainerComponent
|
||||
],
|
||||
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
||||
@@ -92,14 +89,15 @@ describe('SubmissionSectionContainerComponent test suite', () => {
|
||||
|
||||
// synchronous beforeEach
|
||||
beforeEach(() => {
|
||||
init();
|
||||
html = `
|
||||
<ds-submission-section-container [collectionId]="collectionId"
|
||||
[submissionId]="submissionId"
|
||||
[sectionData]="object"></ds-submission-section-container>`;
|
||||
[submissionId]="submissionId"
|
||||
[sectionData]="object"></ds-submission-section-container>`;
|
||||
|
||||
testFixture = createTestComponent(html, TestComponent) as ComponentFixture<TestComponent>;
|
||||
testComp = testFixture.componentInstance;
|
||||
init();
|
||||
|
||||
});
|
||||
|
||||
it('should create SubmissionSectionContainerComponent', inject([SubmissionSectionContainerComponent], (app: SubmissionSectionContainerComponent) => {
|
||||
|
@@ -758,6 +758,6 @@ describe('SectionFormOperationsService test suite', () => {
|
||||
|
||||
expect(jsonPatchOpBuilder.remove).toHaveBeenCalledWith(pathCombiner.getPath('path'));
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
});
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { ChangeDetectorRef, Component, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { async, ComponentFixture, inject, TestBed } from '@angular/core/testing';
|
||||
import { ComponentFixture, inject, TestBed, waitForAsync } from '@angular/core/testing';
|
||||
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { TranslateModule, TranslateService } from '@ngx-translate/core';
|
||||
@@ -142,20 +142,21 @@ describe('SubmissionSectionformComponent test suite', () => {
|
||||
let compAsAny: any;
|
||||
let fixture: ComponentFixture<SubmissionSectionformComponent>;
|
||||
let submissionServiceStub: SubmissionServiceStub;
|
||||
let sectionsServiceStub: SectionsServiceStub;
|
||||
let notificationsServiceStub: NotificationsServiceStub;
|
||||
let formService: any;
|
||||
let formConfigService: any;
|
||||
let formService: any = getMockFormService();
|
||||
|
||||
let formOperationsService: any;
|
||||
let formBuilderService: any;
|
||||
let translateService: any;
|
||||
|
||||
const sectionsServiceStub: any = new SectionsServiceStub();
|
||||
const formConfigService: any = getMockSubmissionFormsConfigService();
|
||||
const submissionId = mockSubmissionId;
|
||||
const collectionId = mockSubmissionCollectionId;
|
||||
const parsedSectionErrors: any = mockUploadResponse1ParsedErrors.traditionalpageone;
|
||||
const formConfigData = new ConfigData(new PageInfo(), testFormConfiguration);
|
||||
|
||||
beforeEach(async(() => {
|
||||
beforeEach(waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
BrowserModule,
|
||||
@@ -172,16 +173,16 @@ describe('SubmissionSectionformComponent test suite', () => {
|
||||
providers: [
|
||||
{ provide: FormBuilderService, useValue: getMockFormBuilderService() },
|
||||
{ provide: SectionFormOperationsService, useValue: getMockFormOperationsService() },
|
||||
{ provide: FormService, useValue: getMockFormService() },
|
||||
{ provide: SubmissionFormsConfigService, useValue: getMockSubmissionFormsConfigService() },
|
||||
{ provide: FormService, useValue: formService },
|
||||
{ provide: SubmissionFormsConfigService, useValue: formConfigService },
|
||||
{ provide: NotificationsService, useClass: NotificationsServiceStub },
|
||||
{ provide: SectionsService, useClass: SectionsServiceStub },
|
||||
{ provide: SectionsService, useValue: sectionsServiceStub },
|
||||
{ provide: SubmissionService, useClass: SubmissionServiceStub },
|
||||
{ provide: TranslateService, useValue: getMockTranslateService() },
|
||||
{ provide: ObjectCacheService, useValue: { remove: () => {/*do nothing*/}, hasBySelfLinkObservable: () => observableOf(false) } },
|
||||
{ provide: RequestService, useValue: { removeByHrefSubstring: () => {/*do nothing*/}, hasByHrefObservable: () => observableOf(false) } },
|
||||
{ provide: 'collectionIdProvider', useValue: collectionId },
|
||||
{ provide: 'sectionDataProvider', useValue: sectionObject },
|
||||
{ provide: 'sectionDataProvider', useValue: Object.assign({}, sectionObject) },
|
||||
{ provide: 'submissionIdProvider', useValue: submissionId },
|
||||
{ provide: SubmissionObjectDataService, useValue: { getHrefByID: () => observableOf('testUrl'), findById: () => observableOf(new RemoteData(false, false, true, null, new WorkspaceItem())) } },
|
||||
ChangeDetectorRef,
|
||||
@@ -197,6 +198,11 @@ describe('SubmissionSectionformComponent test suite', () => {
|
||||
|
||||
// synchronous beforeEach
|
||||
beforeEach(() => {
|
||||
const sectionData = {};
|
||||
formService.isValid.and.returnValue(observableOf(true));
|
||||
formConfigService.getConfigByHref.and.returnValue(observableOf(formConfigData));
|
||||
sectionsServiceStub.getSectionData.and.returnValue(observableOf(sectionData));
|
||||
|
||||
const html = `
|
||||
<ds-submission-section-form></ds-submission-section-form>`;
|
||||
|
||||
@@ -221,9 +227,7 @@ describe('SubmissionSectionformComponent test suite', () => {
|
||||
comp = fixture.componentInstance;
|
||||
compAsAny = comp;
|
||||
submissionServiceStub = TestBed.inject(SubmissionService as any);
|
||||
sectionsServiceStub = TestBed.inject(SectionsService as any);
|
||||
formService = TestBed.inject(FormService);
|
||||
formConfigService = TestBed.inject(SubmissionFormsConfigService);
|
||||
formBuilderService = TestBed.inject(FormBuilderService);
|
||||
formOperationsService = TestBed.inject(SectionFormOperationsService);
|
||||
translateService = TestBed.inject(TranslateService);
|
||||
|
@@ -2,17 +2,13 @@ import { ChangeDetectorRef, Component, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { BrowserModule } from '@angular/platform-browser';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||
import { async, ComponentFixture, inject, TestBed } from '@angular/core/testing';
|
||||
import { ComponentFixture, inject, TestBed, waitForAsync } from '@angular/core/testing';
|
||||
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import {
|
||||
DynamicCheckboxModel,
|
||||
DynamicFormControlEvent,
|
||||
DynamicFormControlEventType
|
||||
} from '@ng-dynamic-forms/core';
|
||||
import { DynamicCheckboxModel, DynamicFormControlEvent, DynamicFormControlEventType } from '@ng-dynamic-forms/core';
|
||||
|
||||
import { createSuccessfulRemoteDataObject$} from '../../../shared/remote-data.utils';
|
||||
import { createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils';
|
||||
import { createTestComponent } from '../../../shared/testing/utils.test';
|
||||
import { NotificationsService } from '../../../shared/notifications/notifications.service';
|
||||
import { NotificationsServiceStub } from '../../../shared/testing/notifications-service.stub';
|
||||
@@ -39,11 +35,24 @@ import { CollectionDataService } from '../../../core/data/collection-data.servic
|
||||
import { JsonPatchOperationsBuilder } from '../../../core/json-patch/builder/json-patch-operations-builder';
|
||||
import { SectionFormOperationsService } from '../form/section-form-operations.service';
|
||||
import { Collection } from '../../../core/shared/collection.model';
|
||||
import { RemoteData } from '../../../core/data/remote-data';
|
||||
import { License } from '../../../core/shared/license.model';
|
||||
import { FormFieldMetadataValueObject } from '../../../shared/form/builder/models/form-field-metadata-value.model';
|
||||
import { cold } from 'jasmine-marbles';
|
||||
|
||||
const collectionId = mockSubmissionCollectionId;
|
||||
const licenseText = 'License text';
|
||||
const mockCollection = Object.assign(new Collection(), {
|
||||
name: 'Community 1-Collection 1',
|
||||
id: collectionId,
|
||||
metadata: [
|
||||
{
|
||||
key: 'dc.title',
|
||||
language: 'en_US',
|
||||
value: 'Community 1-Collection 1'
|
||||
}],
|
||||
license: createSuccessfulRemoteDataObject$(Object.assign(new License(), { text: licenseText }))
|
||||
});
|
||||
|
||||
function getMockSubmissionFormsConfigService(): SubmissionFormsConfigService {
|
||||
return jasmine.createSpyObj('FormOperationsService', {
|
||||
getConfigAll: jasmine.createSpy('getConfigAll'),
|
||||
@@ -53,13 +62,6 @@ function getMockSubmissionFormsConfigService(): SubmissionFormsConfigService {
|
||||
});
|
||||
}
|
||||
|
||||
function getMockCollectionDataService(): CollectionDataService {
|
||||
return jasmine.createSpyObj('CollectionDataService', {
|
||||
findById: jasmine.createSpy('findById'),
|
||||
findByHref: jasmine.createSpy('findByHref')
|
||||
});
|
||||
}
|
||||
|
||||
const sectionObject: SectionDataObject = {
|
||||
config: 'https://dspace7.4science.it/or2018/api/config/submissionforms/license',
|
||||
mandatory: true,
|
||||
@@ -89,14 +91,13 @@ describe('SubmissionSectionLicenseComponent test suite', () => {
|
||||
let compAsAny: any;
|
||||
let fixture: ComponentFixture<SubmissionSectionLicenseComponent>;
|
||||
let submissionServiceStub: SubmissionServiceStub;
|
||||
let sectionsServiceStub: SectionsServiceStub;
|
||||
let formService: any;
|
||||
let formOperationsService: any;
|
||||
let formBuilderService: any;
|
||||
let collectionDataService: any;
|
||||
|
||||
const sectionsServiceStub: any = new SectionsServiceStub();
|
||||
const submissionId = mockSubmissionId;
|
||||
const collectionId = mockSubmissionCollectionId;
|
||||
|
||||
const pathCombiner = new JsonPatchOperationPathCombiner('sections', sectionObject.id);
|
||||
const jsonPatchOpBuilder: any = jasmine.createSpyObj('jsonPatchOpBuilder', {
|
||||
add: jasmine.createSpy('add'),
|
||||
@@ -104,20 +105,12 @@ describe('SubmissionSectionLicenseComponent test suite', () => {
|
||||
remove: jasmine.createSpy('remove'),
|
||||
});
|
||||
|
||||
const licenseText = 'License text';
|
||||
const mockCollection = Object.assign(new Collection(), {
|
||||
name: 'Community 1-Collection 1',
|
||||
id: collectionId,
|
||||
metadata: [
|
||||
{
|
||||
key: 'dc.title',
|
||||
language: 'en_US',
|
||||
value: 'Community 1-Collection 1'
|
||||
}],
|
||||
license: createSuccessfulRemoteDataObject$(Object.assign(new License(), { text: licenseText }))
|
||||
const mockCollectionDataService = jasmine.createSpyObj('CollectionDataService', {
|
||||
findById: jasmine.createSpy('findById'),
|
||||
findByHref: jasmine.createSpy('findByHref')
|
||||
});
|
||||
|
||||
beforeEach(async(() => {
|
||||
beforeEach(waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
BrowserModule,
|
||||
@@ -132,16 +125,16 @@ describe('SubmissionSectionLicenseComponent test suite', () => {
|
||||
TestComponent
|
||||
],
|
||||
providers: [
|
||||
{ provide: CollectionDataService, useValue: getMockCollectionDataService() },
|
||||
{ provide: CollectionDataService, useValue: mockCollectionDataService },
|
||||
{ provide: SectionFormOperationsService, useValue: getMockFormOperationsService() },
|
||||
{ provide: FormService, useValue: getMockFormService() },
|
||||
{ provide: JsonPatchOperationsBuilder, useValue: jsonPatchOpBuilder },
|
||||
{ provide: SubmissionFormsConfigService, useValue: getMockSubmissionFormsConfigService() },
|
||||
{ provide: NotificationsService, useClass: NotificationsServiceStub },
|
||||
{ provide: SectionsService, useClass: SectionsServiceStub },
|
||||
{ provide: SectionsService, useValue: sectionsServiceStub },
|
||||
{ provide: SubmissionService, useClass: SubmissionServiceStub },
|
||||
{ provide: 'collectionIdProvider', useValue: collectionId },
|
||||
{ provide: 'sectionDataProvider', useValue: sectionObject },
|
||||
{ provide: 'sectionDataProvider', useValue: Object.assign({}, sectionObject) },
|
||||
{ provide: 'submissionIdProvider', useValue: submissionId },
|
||||
ChangeDetectorRef,
|
||||
FormBuilderService,
|
||||
@@ -157,6 +150,10 @@ describe('SubmissionSectionLicenseComponent test suite', () => {
|
||||
|
||||
// synchronous beforeEach
|
||||
beforeEach(() => {
|
||||
mockCollectionDataService.findById.and.returnValue(createSuccessfulRemoteDataObject$(mockCollection));
|
||||
sectionsServiceStub.isSectionReadOnly.and.returnValue(observableOf(false));
|
||||
sectionsServiceStub.getSectionErrors.and.returnValue(observableOf([]));
|
||||
|
||||
const html = `
|
||||
<ds-submission-section-license></ds-submission-section-license>`;
|
||||
|
||||
@@ -181,13 +178,12 @@ describe('SubmissionSectionLicenseComponent test suite', () => {
|
||||
comp = fixture.componentInstance;
|
||||
compAsAny = comp;
|
||||
submissionServiceStub = TestBed.inject(SubmissionService as any);
|
||||
sectionsServiceStub = TestBed.inject(SectionsService as any);
|
||||
formService = TestBed.inject(FormService);
|
||||
formBuilderService = TestBed.inject(FormBuilderService);
|
||||
formOperationsService = TestBed.inject(SectionFormOperationsService);
|
||||
collectionDataService = TestBed.inject(CollectionDataService);
|
||||
|
||||
compAsAny.pathCombiner = new JsonPatchOperationPathCombiner('sections', sectionObject.id);
|
||||
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -196,133 +192,132 @@ describe('SubmissionSectionLicenseComponent test suite', () => {
|
||||
compAsAny = null;
|
||||
});
|
||||
|
||||
it('should init section properly', () => {
|
||||
collectionDataService.findById.and.returnValue(createSuccessfulRemoteDataObject$(mockCollection));
|
||||
sectionsServiceStub.getSectionErrors.and.returnValue(observableOf([]));
|
||||
sectionsServiceStub.isSectionReadOnly.and.returnValue(observableOf(false));
|
||||
spyOn(compAsAny, 'getSectionStatus');
|
||||
describe('', () => {
|
||||
beforeEach(() => {
|
||||
mockCollectionDataService.findById.and.returnValue(createSuccessfulRemoteDataObject$(mockCollection));
|
||||
sectionsServiceStub.getSectionErrors.and.returnValue(observableOf([]));
|
||||
sectionsServiceStub.isSectionReadOnly.and.returnValue(observableOf(false));
|
||||
});
|
||||
|
||||
comp.onSectionInit();
|
||||
it('should init section properly', () => {
|
||||
|
||||
const model = formBuilderService.findById('granted', comp.formModel);
|
||||
spyOn(compAsAny, 'getSectionStatus');
|
||||
|
||||
expect(compAsAny.subs.length).toBe(2);
|
||||
expect(comp.formModel).toBeDefined();
|
||||
expect(model.value).toBeFalsy();
|
||||
expect(comp.licenseText$).toBeObservable(cold('(ab|)', {
|
||||
a: '',
|
||||
b: licenseText
|
||||
}));
|
||||
});
|
||||
comp.onSectionInit();
|
||||
|
||||
it('should set checkbox value to true', () => {
|
||||
comp.sectionData.data = {
|
||||
url: 'url',
|
||||
acceptanceDate: Date.now(),
|
||||
granted: true
|
||||
} as any;
|
||||
const model = formBuilderService.findById('granted', comp.formModel);
|
||||
|
||||
collectionDataService.findById.and.returnValue(createSuccessfulRemoteDataObject$(mockCollection));
|
||||
sectionsServiceStub.getSectionErrors.and.returnValue(observableOf([]));
|
||||
sectionsServiceStub.isSectionReadOnly.and.returnValue(observableOf(false));
|
||||
spyOn(compAsAny, 'getSectionStatus');
|
||||
expect(compAsAny.subs.length).toBe(2);
|
||||
expect(comp.formModel).toBeDefined();
|
||||
expect(model.value).toBeFalsy();
|
||||
expect(comp.licenseText$).toBeObservable(cold('(ab|)', {
|
||||
a: '',
|
||||
b: licenseText
|
||||
}));
|
||||
});
|
||||
|
||||
comp.onSectionInit();
|
||||
it('should set checkbox value to true', () => {
|
||||
comp.sectionData.data = {
|
||||
url: 'url',
|
||||
acceptanceDate: Date.now(),
|
||||
granted: true
|
||||
} as any;
|
||||
|
||||
const model = formBuilderService.findById('granted', comp.formModel);
|
||||
spyOn(compAsAny, 'getSectionStatus');
|
||||
|
||||
expect(compAsAny.subs.length).toBe(2);
|
||||
expect(comp.formModel).toBeDefined();
|
||||
expect(model.value).toBeTruthy();
|
||||
expect(comp.licenseText$).toBeObservable(cold('(ab|)', {
|
||||
a: '',
|
||||
b: licenseText
|
||||
}));
|
||||
});
|
||||
comp.onSectionInit();
|
||||
|
||||
it('should set section errors properly', () => {
|
||||
collectionDataService.findById.and.returnValue(createSuccessfulRemoteDataObject$(mockCollection));
|
||||
sectionsServiceStub.getSectionErrors.and.returnValue(observableOf(mockLicenseParsedErrors.license));
|
||||
sectionsServiceStub.isSectionReadOnly.and.returnValue(observableOf(false));
|
||||
const model = formBuilderService.findById('granted', comp.formModel);
|
||||
|
||||
comp.onSectionInit();
|
||||
const expectedErrors = mockLicenseParsedErrors.license;
|
||||
expect(compAsAny.subs.length).toBe(2);
|
||||
expect(comp.formModel).toBeDefined();
|
||||
expect(model.value).toBeTruthy();
|
||||
expect(comp.licenseText$).toBeObservable(cold('(ab|)', {
|
||||
a: '',
|
||||
b: licenseText
|
||||
}));
|
||||
});
|
||||
|
||||
expect(sectionsServiceStub.checkSectionErrors).toHaveBeenCalled();
|
||||
expect(comp.sectionData.errors).toEqual(expectedErrors);
|
||||
it('should have status true when checkbox is selected', () => {
|
||||
fixture.detectChanges();
|
||||
const model = formBuilderService.findById('granted', comp.formModel);
|
||||
|
||||
(model as DynamicCheckboxModel).value = true;
|
||||
|
||||
compAsAny.getSectionStatus().subscribe((status) => {
|
||||
expect(status).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
it('should have status false when checkbox is not selected', () => {
|
||||
fixture.detectChanges();
|
||||
const model = formBuilderService.findById('granted', comp.formModel);
|
||||
|
||||
compAsAny.getSectionStatus().subscribe((status) => {
|
||||
expect(status).toBeFalsy();
|
||||
});
|
||||
|
||||
(model as DynamicCheckboxModel).value = false;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('should remove any section\'s errors when checkbox is selected', () => {
|
||||
comp.sectionData.data = {
|
||||
url: 'url',
|
||||
acceptanceDate: Date.now(),
|
||||
granted: true
|
||||
} as any;
|
||||
describe('', () => {
|
||||
beforeEach(() => {
|
||||
mockCollectionDataService.findById.and.returnValue(createSuccessfulRemoteDataObject$(mockCollection));
|
||||
sectionsServiceStub.getSectionErrors.and.returnValue(observableOf(mockLicenseParsedErrors.license));
|
||||
sectionsServiceStub.isSectionReadOnly.and.returnValue(observableOf(false));
|
||||
});
|
||||
|
||||
collectionDataService.findById.and.returnValue(createSuccessfulRemoteDataObject$(mockCollection));
|
||||
sectionsServiceStub.getSectionErrors.and.returnValue(observableOf(mockLicenseParsedErrors.license));
|
||||
sectionsServiceStub.isSectionReadOnly.and.returnValue(observableOf(false));
|
||||
it('should set section errors properly', () => {
|
||||
comp.onSectionInit();
|
||||
const expectedErrors = mockLicenseParsedErrors.license;
|
||||
|
||||
comp.onSectionInit();
|
||||
expect(sectionsServiceStub.checkSectionErrors).toHaveBeenCalled();
|
||||
expect(comp.sectionData.errors).toEqual(expectedErrors);
|
||||
|
||||
expect(sectionsServiceStub.dispatchRemoveSectionErrors).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
});
|
||||
it('should remove any section\'s errors when checkbox is selected', () => {
|
||||
comp.sectionData.data = {
|
||||
url: 'url',
|
||||
acceptanceDate: Date.now(),
|
||||
granted: true
|
||||
} as any;
|
||||
|
||||
it('should have status true when checkbox is selected', () => {
|
||||
comp.onSectionInit();
|
||||
|
||||
collectionDataService.findById.and.returnValue(createSuccessfulRemoteDataObject$(mockCollection));
|
||||
sectionsServiceStub.getSectionErrors.and.returnValue(observableOf([]));
|
||||
sectionsServiceStub.isSectionReadOnly.and.returnValue(observableOf(false));
|
||||
expect(sectionsServiceStub.dispatchRemoveSectionErrors).toHaveBeenCalled();
|
||||
|
||||
fixture.detectChanges();
|
||||
const model = formBuilderService.findById('granted', comp.formModel);
|
||||
|
||||
(model as DynamicCheckboxModel).value = true;
|
||||
|
||||
compAsAny.getSectionStatus().subscribe((status) => {
|
||||
expect(status).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
it('should have status false when checkbox is not selected', () => {
|
||||
|
||||
collectionDataService.findById.and.returnValue(createSuccessfulRemoteDataObject$(mockCollection));
|
||||
sectionsServiceStub.getSectionErrors.and.returnValue(observableOf([]));
|
||||
sectionsServiceStub.isSectionReadOnly.and.returnValue(observableOf(false));
|
||||
|
||||
fixture.detectChanges();
|
||||
const model = formBuilderService.findById('granted', comp.formModel);
|
||||
|
||||
compAsAny.getSectionStatus().subscribe((status) => {
|
||||
expect(status).toBeFalsy();
|
||||
describe('', () => {
|
||||
let event;
|
||||
beforeEach(() => {
|
||||
event = dynamicFormControlEvent;
|
||||
formOperationsService.getFieldPathSegmentedFromChangeEvent.and.returnValue('granted');
|
||||
});
|
||||
|
||||
(model as DynamicCheckboxModel).value = false;
|
||||
it('should dispatch a json-path add operation when checkbox is selected', () => {
|
||||
|
||||
formOperationsService.getFieldValueFromChangeEvent.and.returnValue(new FormFieldMetadataValueObject(true));
|
||||
|
||||
comp.onChange(event);
|
||||
|
||||
expect(jsonPatchOpBuilder.add).toHaveBeenCalledWith(pathCombiner.getPath('granted'), 'true', false, true);
|
||||
expect(sectionsServiceStub.dispatchRemoveSectionErrors).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should dispatch a json-path remove operation when checkbox is not selected', () => {
|
||||
|
||||
formOperationsService.getFieldValueFromChangeEvent.and.returnValue(null);
|
||||
|
||||
comp.onChange(event);
|
||||
|
||||
expect(jsonPatchOpBuilder.remove).toHaveBeenCalledWith(pathCombiner.getPath('granted'));
|
||||
});
|
||||
});
|
||||
|
||||
it('should dispatch a json-path add operation when checkbox is selected', () => {
|
||||
const event = dynamicFormControlEvent;
|
||||
formOperationsService.getFieldPathSegmentedFromChangeEvent.and.returnValue('granted');
|
||||
formOperationsService.getFieldValueFromChangeEvent.and.returnValue(new FormFieldMetadataValueObject(true));
|
||||
|
||||
comp.onChange(event);
|
||||
|
||||
expect(jsonPatchOpBuilder.add).toHaveBeenCalledWith(pathCombiner.getPath('granted'), 'true', false, true);
|
||||
expect(sectionsServiceStub.dispatchRemoveSectionErrors).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should dispatch a json-path remove operation when checkbox is not selected', () => {
|
||||
const event = dynamicFormControlEvent;
|
||||
formOperationsService.getFieldPathSegmentedFromChangeEvent.and.returnValue('granted');
|
||||
formOperationsService.getFieldValueFromChangeEvent.and.returnValue(null);
|
||||
|
||||
comp.onChange(event);
|
||||
|
||||
expect(jsonPatchOpBuilder.remove).toHaveBeenCalledWith(pathCombiner.getPath('granted'));
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
@@ -233,7 +233,7 @@ describe('SubmissionSectionUploadFileComponent test suite', () => {
|
||||
|
||||
tick();
|
||||
|
||||
expect(fileService.downloadFile).toHaveBeenCalled()
|
||||
expect(fileService.downloadFile).toHaveBeenCalled();
|
||||
}));
|
||||
|
||||
it('should save Bitstream File data properly when form is valid', fakeAsync(() => {
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { Component, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { async, ComponentFixture, inject, TestBed } from '@angular/core/testing';
|
||||
import { ComponentFixture, inject, TestBed, waitForAsync } from '@angular/core/testing';
|
||||
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
@@ -18,7 +18,7 @@ describe('SubmissionSectionUploadFileViewComponent test suite', () => {
|
||||
|
||||
const fileData: any = mockUploadFiles[0];
|
||||
|
||||
beforeEach(async(() => {
|
||||
beforeEach(waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot()
|
||||
@@ -96,5 +96,5 @@ describe('SubmissionSectionUploadFileViewComponent test suite', () => {
|
||||
})
|
||||
class TestComponent {
|
||||
|
||||
fileData;
|
||||
fileData = mockUploadFiles[0];
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { ChangeDetectorRef, Component, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { async, ComponentFixture, inject, TestBed } from '@angular/core/testing';
|
||||
import { ComponentFixture, inject, TestBed, waitForAsync } from '@angular/core/testing';
|
||||
import { BrowserModule } from '@angular/platform-browser';
|
||||
import { CommonModule } from '@angular/common';
|
||||
|
||||
@@ -87,8 +87,9 @@ describe('SubmissionSectionUploadComponent test suite', () => {
|
||||
let submissionState: SubmissionObjectState;
|
||||
let mockCollection: Collection;
|
||||
let mockDefaultAccessCondition: ResourcePolicy;
|
||||
let prepareComp;
|
||||
|
||||
beforeEach(async(() => {
|
||||
beforeEach(waitForAsync(() => {
|
||||
sectionObject = {
|
||||
config: 'https://dspace7.4science.it/or2018/api/config/submissionforms/upload',
|
||||
mandatory: true,
|
||||
@@ -123,6 +124,38 @@ describe('SubmissionSectionUploadComponent test suite', () => {
|
||||
id: 20,
|
||||
uuid: 'resource-policy-20'
|
||||
});
|
||||
uploadsConfigService = getMockSubmissionUploadsConfigService();
|
||||
|
||||
submissionServiceStub = new SubmissionServiceStub();
|
||||
|
||||
collectionDataService = getMockCollectionDataService();
|
||||
|
||||
resourcePolicyService = getMockResourcePolicyService();
|
||||
|
||||
groupService = getMockGroupEpersonService();
|
||||
|
||||
bitstreamService = getMockSectionUploadService();
|
||||
|
||||
prepareComp = () => {
|
||||
submissionServiceStub.getSubmissionObject.and.returnValue(observableOf(submissionState));
|
||||
|
||||
collectionDataService.findById.and.returnValue(createSuccessfulRemoteDataObject$(Object.assign(new Collection(), mockCollection, {
|
||||
defaultAccessConditions: createSuccessfulRemoteDataObject$(mockDefaultAccessCondition)
|
||||
})));
|
||||
|
||||
resourcePolicyService.findByHref.and.returnValue(createSuccessfulRemoteDataObject$(mockDefaultAccessCondition));
|
||||
|
||||
uploadsConfigService.getConfigByHref.and.returnValue(observableOf(
|
||||
new ConfigData(new PageInfo(), mockUploadConfigResponse as any)
|
||||
));
|
||||
|
||||
groupService.findById.and.returnValues(
|
||||
createSuccessfulRemoteDataObject$(Object.assign(new Group(), mockGroup)),
|
||||
createSuccessfulRemoteDataObject$(Object.assign(new Group(), mockGroup))
|
||||
);
|
||||
|
||||
bitstreamService.getUploadedFileList.and.returnValue(observableOf([]));
|
||||
};
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
@@ -135,13 +168,13 @@ describe('SubmissionSectionUploadComponent test suite', () => {
|
||||
TestComponent
|
||||
],
|
||||
providers: [
|
||||
{ provide: CollectionDataService, useValue: getMockCollectionDataService() },
|
||||
{ provide: GroupDataService, useValue: getMockGroupEpersonService() },
|
||||
{ provide: ResourcePolicyService, useValue: getMockResourcePolicyService() },
|
||||
{ provide: SubmissionUploadsConfigService, useValue: getMockSubmissionUploadsConfigService() },
|
||||
{ provide: CollectionDataService, useValue: collectionDataService },
|
||||
{ provide: GroupDataService, useValue: groupService },
|
||||
{ provide: ResourcePolicyService, useValue: resourcePolicyService },
|
||||
{ provide: SubmissionUploadsConfigService, useValue: uploadsConfigService },
|
||||
{ provide: SectionsService, useClass: SectionsServiceStub },
|
||||
{ provide: SubmissionService, useClass: SubmissionServiceStub },
|
||||
{ provide: SectionUploadService, useValue: getMockSectionUploadService() },
|
||||
{ provide: SubmissionService, useValue: submissionServiceStub },
|
||||
{ provide: SectionUploadService, useValue: bitstreamService },
|
||||
{ provide: 'sectionDataProvider', useValue: sectionObject },
|
||||
{ provide: 'submissionIdProvider', useValue: submissionId },
|
||||
ChangeDetectorRef,
|
||||
@@ -157,6 +190,8 @@ describe('SubmissionSectionUploadComponent test suite', () => {
|
||||
|
||||
// synchronous beforeEach
|
||||
beforeEach(() => {
|
||||
prepareComp();
|
||||
|
||||
const html = `
|
||||
<ds-submission-section-upload></ds-submission-section-upload>`;
|
||||
|
||||
@@ -180,13 +215,7 @@ describe('SubmissionSectionUploadComponent test suite', () => {
|
||||
fixture = TestBed.createComponent(SubmissionSectionUploadComponent);
|
||||
comp = fixture.componentInstance;
|
||||
compAsAny = comp;
|
||||
submissionServiceStub = TestBed.inject(SubmissionService as any);
|
||||
sectionsServiceStub = TestBed.inject(SectionsService as any);
|
||||
collectionDataService = TestBed.inject(CollectionDataService);
|
||||
groupService = TestBed.inject(GroupDataService);
|
||||
resourcePolicyService = TestBed.inject(ResourcePolicyService);
|
||||
uploadsConfigService = TestBed.inject(SubmissionUploadsConfigService);
|
||||
bitstreamService = TestBed.inject(SectionUploadService);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -197,24 +226,7 @@ describe('SubmissionSectionUploadComponent test suite', () => {
|
||||
|
||||
it('should init component properly', () => {
|
||||
|
||||
submissionServiceStub.getSubmissionObject.and.returnValue(observableOf(submissionState));
|
||||
|
||||
collectionDataService.findById.and.returnValue(createSuccessfulRemoteDataObject$(Object.assign(new Collection(), mockCollection, {
|
||||
defaultAccessConditions: createSuccessfulRemoteDataObject$(mockDefaultAccessCondition)
|
||||
})));
|
||||
|
||||
resourcePolicyService.findByHref.and.returnValue(createSuccessfulRemoteDataObject$(mockDefaultAccessCondition));
|
||||
|
||||
uploadsConfigService.getConfigByHref.and.returnValue(observableOf(
|
||||
new ConfigData(new PageInfo(), mockUploadConfigResponse as any)
|
||||
));
|
||||
|
||||
groupService.findById.and.returnValues(
|
||||
createSuccessfulRemoteDataObject$(Object.assign(new Group(), mockGroup)),
|
||||
createSuccessfulRemoteDataObject$(Object.assign(new Group(), mockGroup))
|
||||
);
|
||||
|
||||
bitstreamService.getUploadedFileList.and.returnValue(observableOf([]));
|
||||
prepareComp();
|
||||
|
||||
comp.onSectionInit();
|
||||
|
||||
|
Reference in New Issue
Block a user