Fixed tests

This commit is contained in:
Giuseppe Digilio
2019-02-18 17:40:23 +01:00
parent 9c2b51fb19
commit 024e5688a1
3 changed files with 26 additions and 13 deletions

View File

@@ -24,6 +24,7 @@ import { PaginatedList } from '../../../core/data/paginated-list';
import { PageInfo } from '../../../core/shared/page-info.model'; import { PageInfo } from '../../../core/shared/page-info.model';
import { Collection } from '../../../core/shared/collection.model'; import { Collection } from '../../../core/shared/collection.model';
import { createTestComponent } from '../../../shared/testing/utils'; import { createTestComponent } from '../../../shared/testing/utils';
import { cold } from 'jasmine-marbles';
const subcommunities = [Object.assign(new Community(), { const subcommunities = [Object.assign(new Community(), {
name: 'SubCommunity 1', name: 'SubCommunity 1',
@@ -288,11 +289,15 @@ describe('SubmissionFormCollectionComponent Component', () => {
currentCollectionId: new SimpleChange(null, collectionId, true) currentCollectionId: new SimpleChange(null, collectionId, true)
}); });
comp.searchListCollection$.pipe( expect(comp.searchListCollection$).toBeObservable(cold('(ab)', {
filter(() => !comp.disabled$.getValue()) a: [],
).subscribe((list) => { b: mockCollectionList
expect(list).toEqual(mockCollectionList); }));
})
expect(comp.selectedCollectionName$).toBeObservable(cold('(ab|)', {
a: '',
b: 'Community 1-Collection 1'
}));
}); });
it('should show only the searched collection', () => { it('should show only the searched collection', () => {
@@ -306,7 +311,8 @@ describe('SubmissionFormCollectionComponent Component', () => {
filter(() => !comp.disabled$.getValue()) filter(() => !comp.disabled$.getValue())
).subscribe((list) => { ).subscribe((list) => {
expect(list).toEqual([mockCollectionList[3]]); expect(list).toEqual([mockCollectionList[3]]);
}) });
}); });
it('should emit collectionChange event when selecting a new collection', () => { it('should emit collectionChange event when selecting a new collection', () => {
@@ -321,7 +327,9 @@ describe('SubmissionFormCollectionComponent Component', () => {
expect(comp.collectionChange.emit).toHaveBeenCalledWith(submissionRestResponse[0]); expect(comp.collectionChange.emit).toHaveBeenCalledWith(submissionRestResponse[0]);
expect(submissionServiceStub.changeSubmissionCollection).toHaveBeenCalled(); expect(submissionServiceStub.changeSubmissionCollection).toHaveBeenCalled();
expect(comp.selectedCollectionId).toBe(mockCollectionList[1].collection.id); expect(comp.selectedCollectionId).toBe(mockCollectionList[1].collection.id);
expect(comp.selectedCollectionName).toBe(mockCollectionList[1].collection.name); expect(comp.selectedCollectionName$).toBeObservable(cold('(a|)', {
a: mockCollectionList[1].collection.name
}));
}); });

View File

@@ -67,7 +67,6 @@ export class SubmissionFormCollectionComponent implements OnChanges, OnInit {
public searchField: FormControl = new FormControl(); public searchField: FormControl = new FormControl();
public searchListCollection$: Observable<CollectionListEntry[]>; public searchListCollection$: Observable<CollectionListEntry[]>;
public selectedCollectionId: string; public selectedCollectionId: string;
public selectedCollectionName: string;
public selectedCollectionName$: Observable<string>; public selectedCollectionName$: Observable<string>;
protected pathCombiner: JsonPatchOperationPathCombiner; protected pathCombiner: JsonPatchOperationPathCombiner;
@@ -114,8 +113,8 @@ export class SubmissionFormCollectionComponent implements OnChanges, OnInit {
mergeMap((collections: RemoteData<PaginatedList<Collection>>) => collections.payload.page), mergeMap((collections: RemoteData<PaginatedList<Collection>>) => collections.payload.page),
filter((collectionData: Collection) => isNotEmpty(collectionData)), filter((collectionData: Collection) => isNotEmpty(collectionData)),
map((collectionData: Collection) => ({ map((collectionData: Collection) => ({
communities: [{id: communityData.id, name: communityData.name}], communities: [{ id: communityData.id, name: communityData.name }],
collection: {id: collectionData.id, name: collectionData.name} collection: { id: collectionData.id, name: collectionData.name }
})) }))
); );
}), }),
@@ -173,7 +172,6 @@ export class SubmissionFormCollectionComponent implements OnChanges, OnInit {
'collection') 'collection')
.subscribe((submissionObject: SubmissionObject[]) => { .subscribe((submissionObject: SubmissionObject[]) => {
this.selectedCollectionId = event.collection.id; this.selectedCollectionId = event.collection.id;
this.selectedCollectionName = event.collection.name;
this.selectedCollectionName$ = observableOf(event.collection.name); this.selectedCollectionName$ = observableOf(event.collection.name);
this.collectionChange.emit(submissionObject[0]); this.collectionChange.emit(submissionObject[0]);
this.submissionService.changeSubmissionCollection(this.submissionId, event.collection.id); this.submissionService.changeSubmissionCollection(this.submissionId, event.collection.id);

View File

@@ -37,6 +37,7 @@ import { Collection } from '../../../core/shared/collection.model';
import { RemoteData } from '../../../core/data/remote-data'; import { RemoteData } from '../../../core/data/remote-data';
import { License } from '../../../core/shared/license.model'; import { License } from '../../../core/shared/license.model';
import { FormFieldMetadataValueObject } from '../../../shared/form/builder/models/form-field-metadata-value.model'; import { FormFieldMetadataValueObject } from '../../../shared/form/builder/models/form-field-metadata-value.model';
import { cold } from 'jasmine-marbles';
function getMockSubmissionFormsConfigService(): SubmissionFormsConfigService { function getMockSubmissionFormsConfigService(): SubmissionFormsConfigService {
return jasmine.createSpyObj('FormOperationsService', { return jasmine.createSpyObj('FormOperationsService', {
@@ -205,7 +206,10 @@ describe('LicenseSectionComponent test suite', () => {
expect(compAsAny.subs.length).toBe(2); expect(compAsAny.subs.length).toBe(2);
expect(comp.formModel).toBeDefined(); expect(comp.formModel).toBeDefined();
expect(model.value).toBeFalsy(); expect(model.value).toBeFalsy();
expect(comp.licenseText).toBe(licenseText); expect(comp.licenseText$).toBeObservable(cold('(ab|)', {
a: '',
b: licenseText
}));
}); });
it('should set checkbox value to true', () => { it('should set checkbox value to true', () => {
@@ -228,7 +232,10 @@ describe('LicenseSectionComponent test suite', () => {
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();
expect(comp.licenseText).toBe(licenseText); expect(comp.licenseText$).toBeObservable(cold('(ab|)', {
a: '',
b: licenseText
}));
}); });
it('should set section errors properly', () => { it('should set section errors properly', () => {