mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
80195: Fix unit tests
This commit is contained in:
@@ -60,7 +60,10 @@ describe('ItemMoveComponent', () => {
|
||||
const routeStub = {
|
||||
data: observableOf({
|
||||
dso: createSuccessfulRemoteDataObject(Object.assign(new Item(), {
|
||||
id: 'item1'
|
||||
id: 'item1',
|
||||
owningCollection: createSuccessfulRemoteDataObject$(Object.assign(new Collection(), {
|
||||
id: 'originalOwningCollection',
|
||||
}))
|
||||
}))
|
||||
})
|
||||
};
|
||||
|
@@ -92,12 +92,18 @@ describe('DSOSelectorComponent', () => {
|
||||
});
|
||||
|
||||
describe('populating listEntries', () => {
|
||||
it('should not be empty', () => {
|
||||
expect(component.listEntries.length).toBeGreaterThan(0);
|
||||
it('should not be empty', (done) => {
|
||||
component.listEntries$.subscribe((listEntries) => {
|
||||
expect(listEntries.length).toBeGreaterThan(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should contain a combination of the current DSO and first page results', () => {
|
||||
expect(component.listEntries).toEqual([searchResult, ...firstPageResults]);
|
||||
it('should contain a combination of the current DSO and first page results', (done) => {
|
||||
component.listEntries$.subscribe((listEntries) => {
|
||||
expect(listEntries).toEqual([searchResult, ...firstPageResults]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when current page increases', () => {
|
||||
@@ -105,8 +111,11 @@ describe('DSOSelectorComponent', () => {
|
||||
component.currentPage$.next(2);
|
||||
});
|
||||
|
||||
it('should contain a combination of the current DSO, as well as first and second page results', () => {
|
||||
expect(component.listEntries).toEqual([searchResult, ...firstPageResults, ...nextPageResults]);
|
||||
it('should contain a combination of the current DSO, as well as first and second page results', (done) => {
|
||||
component.listEntries$.subscribe((listEntries) => {
|
||||
expect(listEntries).toEqual([searchResult, ...firstPageResults, ...nextPageResults]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { waitForAsync, ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
|
||||
import { ChangeDetectionStrategy, ComponentFactoryResolver, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { ComponentFixture, fakeAsync, TestBed, tick, waitForAsync } from '@angular/core/testing';
|
||||
import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { ListableObjectComponentLoaderComponent } from './listable-object-component-loader.component';
|
||||
import { ListableObject } from '../listable-object.model';
|
||||
import { GenericConstructor } from '../../../../core/shared/generic-constructor';
|
||||
@@ -117,17 +117,33 @@ describe('ListableObjectComponentLoaderComponent', () => {
|
||||
});
|
||||
|
||||
describe('When a reloadedObject is emitted', () => {
|
||||
let listableComponent;
|
||||
let reloadedObject: any;
|
||||
|
||||
it('should re-instantiate the listable component ', fakeAsync(() => {
|
||||
beforeEach(() => {
|
||||
spyOn((comp as any), 'connectInputsAndOutputs').and.returnValue(null);
|
||||
spyOn((comp as any).contentChange, 'emit').and.returnValue(null);
|
||||
|
||||
spyOn((comp as any), 'instantiateComponent').and.returnValue(null);
|
||||
listableComponent = fixture.debugElement.query(By.css('ds-item-list-element')).componentInstance;
|
||||
reloadedObject = 'object';
|
||||
});
|
||||
|
||||
it('should pass it on connectInputsAndOutputs', fakeAsync(() => {
|
||||
expect((comp as any).connectInputsAndOutputs).not.toHaveBeenCalled();
|
||||
|
||||
const listableComponent = fixture.debugElement.query(By.css('ds-item-list-element')).componentInstance;
|
||||
const reloadedObject: any = 'object';
|
||||
(listableComponent as any).reloadedObject.emit(reloadedObject);
|
||||
tick();
|
||||
|
||||
expect((comp as any).instantiateComponent).toHaveBeenCalledWith(reloadedObject);
|
||||
expect((comp as any).connectInputsAndOutputs).toHaveBeenCalled();
|
||||
}));
|
||||
|
||||
it('should re-emit it as a contentChange', fakeAsync(() => {
|
||||
expect((comp as any).contentChange.emit).not.toHaveBeenCalled();
|
||||
|
||||
(listableComponent as any).reloadedObject.emit(reloadedObject);
|
||||
tick();
|
||||
|
||||
expect((comp as any).contentChange.emit).toHaveBeenCalledWith(reloadedObject);
|
||||
}));
|
||||
|
||||
});
|
||||
|
Reference in New Issue
Block a user