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 { Collection } from '../../../core/shared/collection.model';
import { createTestComponent } from '../../../shared/testing/utils';
import { cold } from 'jasmine-marbles';
const subcommunities = [Object.assign(new Community(), {
name: 'SubCommunity 1',
@@ -288,11 +289,15 @@ describe('SubmissionFormCollectionComponent Component', () => {
currentCollectionId: new SimpleChange(null, collectionId, true)
});
comp.searchListCollection$.pipe(
filter(() => !comp.disabled$.getValue())
).subscribe((list) => {
expect(list).toEqual(mockCollectionList);
})
expect(comp.searchListCollection$).toBeObservable(cold('(ab)', {
a: [],
b: mockCollectionList
}));
expect(comp.selectedCollectionName$).toBeObservable(cold('(ab|)', {
a: '',
b: 'Community 1-Collection 1'
}));
});
it('should show only the searched collection', () => {
@@ -306,7 +311,8 @@ describe('SubmissionFormCollectionComponent Component', () => {
filter(() => !comp.disabled$.getValue())
).subscribe((list) => {
expect(list).toEqual([mockCollectionList[3]]);
})
});
});
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(submissionServiceStub.changeSubmissionCollection).toHaveBeenCalled();
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 searchListCollection$: Observable<CollectionListEntry[]>;
public selectedCollectionId: string;
public selectedCollectionName: string;
public selectedCollectionName$: Observable<string>;
protected pathCombiner: JsonPatchOperationPathCombiner;
@@ -114,8 +113,8 @@ export class SubmissionFormCollectionComponent implements OnChanges, OnInit {
mergeMap((collections: RemoteData<PaginatedList<Collection>>) => collections.payload.page),
filter((collectionData: Collection) => isNotEmpty(collectionData)),
map((collectionData: Collection) => ({
communities: [{id: communityData.id, name: communityData.name}],
collection: {id: collectionData.id, name: collectionData.name}
communities: [{ id: communityData.id, name: communityData.name }],
collection: { id: collectionData.id, name: collectionData.name }
}))
);
}),
@@ -173,7 +172,6 @@ export class SubmissionFormCollectionComponent implements OnChanges, OnInit {
'collection')
.subscribe((submissionObject: SubmissionObject[]) => {
this.selectedCollectionId = event.collection.id;
this.selectedCollectionName = event.collection.name;
this.selectedCollectionName$ = observableOf(event.collection.name);
this.collectionChange.emit(submissionObject[0]);
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 { License } from '../../../core/shared/license.model';
import { FormFieldMetadataValueObject } from '../../../shared/form/builder/models/form-field-metadata-value.model';
import { cold } from 'jasmine-marbles';
function getMockSubmissionFormsConfigService(): SubmissionFormsConfigService {
return jasmine.createSpyObj('FormOperationsService', {
@@ -205,7 +206,10 @@ describe('LicenseSectionComponent test suite', () => {
expect(compAsAny.subs.length).toBe(2);
expect(comp.formModel).toBeDefined();
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', () => {
@@ -228,7 +232,10 @@ describe('LicenseSectionComponent test suite', () => {
expect(compAsAny.subs.length).toBe(2);
expect(comp.formModel).toBeDefined();
expect(model.value).toBeTruthy();
expect(comp.licenseText).toBe(licenseText);
expect(comp.licenseText$).toBeObservable(cold('(ab|)', {
a: '',
b: licenseText
}));
});
it('should set section errors properly', () => {