64574: Test fixes

This commit is contained in:
Kristof De Langhe
2019-08-28 12:01:24 +02:00
parent 713c40451f
commit 76636933e4
2 changed files with 9 additions and 123 deletions

View File

@@ -317,115 +317,4 @@ describe('ItemComponent', () => {
}); });
}); });
describe('when calling buildRepresentations', () => {
let comp: ItemComponent;
let fixture: ComponentFixture<ItemComponent>;
const metadataField = 'dc.contributor.author';
const relatedItem = Object.assign(new Item(), {
id: '2',
metadata: Object.assign(new MetadataMap(), {
'dc.title': [
{
language: 'en_US',
value: 'related item'
}
]
})
});
const mockItem = Object.assign(new Item(), {
id: '1',
uuid: '1',
metadata: new MetadataMap()
});
mockItem.relationships = createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), [
Object.assign(new Relationship(), {
uuid: '123',
id: '123',
leftItem: createSuccessfulRemoteDataObject$(mockItem),
rightItem: createSuccessfulRemoteDataObject$(relatedItem),
relationshipType: createSuccessfulRemoteDataObject$(new RelationshipType())
})
]));
mockItem.metadata[metadataField] = [
{
value: 'Second value',
place: 1
},
{
value: 'Third value',
place: 2,
authority: 'virtual::123'
},
{
value: 'First value',
place: 0
},
{
value: 'Fourth value',
place: 3,
authority: '123'
}
] as MetadataValue[];
const mockItemDataService = Object.assign({
findById: (id) => {
if (id === relatedItem.id) {
return createSuccessfulRemoteDataObject$(relatedItem)
}
}
}) as ItemDataService;
let representations: Observable<MetadataRepresentation[]>;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useClass: MockTranslateLoader
}
}), BrowserAnimationsModule],
declarations: [ItemComponent, VarDirective],
providers: [
{provide: ITEM, useValue: mockItem}
],
schemas: [NO_ERRORS_SCHEMA]
}).overrideComponent(ItemComponent, {
set: {changeDetection: ChangeDetectionStrategy.Default}
}).compileComponents();
}));
beforeEach(async(() => {
fixture = TestBed.createComponent(ItemComponent);
comp = fixture.componentInstance;
fixture.detectChanges();
representations = comp.buildRepresentations('bogus', metadataField);
}));
it('should contain exactly 4 metadata-representations', () => {
representations.subscribe((reps: MetadataRepresentation[]) => {
expect(reps.length).toEqual(4);
});
});
it('should have all the representations in the correct order', () => {
representations.subscribe((reps: MetadataRepresentation[]) => {
expect(reps[0].getValue()).toEqual('First value');
expect(reps[1].getValue()).toEqual('Second value');
expect(reps[2].getValue()).toEqual('related item');
expect(reps[3].getValue()).toEqual('Fourth value');
});
});
it('should have created the correct MetadatumRepresentation and ItemMetadataRepresentation objects for the correct Metadata', () => {
representations.subscribe((reps: MetadataRepresentation[]) => {
expect(reps[0] instanceof MetadatumRepresentation).toEqual(true);
expect(reps[1] instanceof MetadatumRepresentation).toEqual(true);
expect(reps[2] instanceof ItemMetadataRepresentation).toEqual(true);
expect(reps[3] instanceof MetadatumRepresentation).toEqual(true);
});
});
})
}); });

View File

@@ -79,11 +79,16 @@ describe('RelationshipService', () => {
function initTestService() { function initTestService() {
return new RelationshipService( return new RelationshipService(
requestService,
halService,
rdbService,
itemService, itemService,
objectCache requestService,
rdbService,
null,
null,
halService,
objectCache,
null,
null,
null
); );
} }
@@ -142,14 +147,6 @@ describe('RelationshipService', () => {
}); });
}); });
describe('getRelatedItemsByLabel', () => {
it('should return the related items by label', () => {
service.getRelatedItemsByLabel(item, relationshipType.rightLabel).subscribe((result) => {
expect(result).toEqual(relatedItems);
});
});
})
}); });
function getRemotedataObservable(obj: any): Observable<RemoteData<any>> { function getRemotedataObservable(obj: any): Observable<RemoteData<any>> {