mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-13 13:03:04 +00:00
80195: Fix unit tests
This commit is contained in:
@@ -60,7 +60,10 @@ describe('ItemMoveComponent', () => {
|
|||||||
const routeStub = {
|
const routeStub = {
|
||||||
data: observableOf({
|
data: observableOf({
|
||||||
dso: createSuccessfulRemoteDataObject(Object.assign(new Item(), {
|
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', () => {
|
describe('populating listEntries', () => {
|
||||||
it('should not be empty', () => {
|
it('should not be empty', (done) => {
|
||||||
expect(component.listEntries.length).toBeGreaterThan(0);
|
component.listEntries$.subscribe((listEntries) => {
|
||||||
|
expect(listEntries.length).toBeGreaterThan(0);
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should contain a combination of the current DSO and first page results', () => {
|
it('should contain a combination of the current DSO and first page results', (done) => {
|
||||||
expect(component.listEntries).toEqual([searchResult, ...firstPageResults]);
|
component.listEntries$.subscribe((listEntries) => {
|
||||||
|
expect(listEntries).toEqual([searchResult, ...firstPageResults]);
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when current page increases', () => {
|
describe('when current page increases', () => {
|
||||||
@@ -105,8 +111,11 @@ describe('DSOSelectorComponent', () => {
|
|||||||
component.currentPage$.next(2);
|
component.currentPage$.next(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should contain a combination of the current DSO, as well as first and second page results', () => {
|
it('should contain a combination of the current DSO, as well as first and second page results', (done) => {
|
||||||
expect(component.listEntries).toEqual([searchResult, ...firstPageResults, ...nextPageResults]);
|
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 { ComponentFixture, fakeAsync, TestBed, tick, waitForAsync } from '@angular/core/testing';
|
||||||
import { ChangeDetectionStrategy, ComponentFactoryResolver, NO_ERRORS_SCHEMA } from '@angular/core';
|
import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||||
import { ListableObjectComponentLoaderComponent } from './listable-object-component-loader.component';
|
import { ListableObjectComponentLoaderComponent } from './listable-object-component-loader.component';
|
||||||
import { ListableObject } from '../listable-object.model';
|
import { ListableObject } from '../listable-object.model';
|
||||||
import { GenericConstructor } from '../../../../core/shared/generic-constructor';
|
import { GenericConstructor } from '../../../../core/shared/generic-constructor';
|
||||||
@@ -117,17 +117,33 @@ describe('ListableObjectComponentLoaderComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('When a reloadedObject is emitted', () => {
|
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);
|
(listableComponent as any).reloadedObject.emit(reloadedObject);
|
||||||
tick();
|
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