listable-object-component-loader.component.spec.ts (dspace-angular-dspace-7.0) | : | listable-object-component-loader.component.spec.ts (dspace-angular-dspace-7.1) | ||
---|---|---|---|---|
skipping to change at line 14 | skipping to change at line 14 | |||
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' ; | |||
import { Context } from '../../../../core/shared/context.model'; | import { Context } from '../../../../core/shared/context.model'; | |||
import { ViewMode } from '../../../../core/shared/view-mode.model'; | import { ViewMode } from '../../../../core/shared/view-mode.model'; | |||
import { ItemListElementComponent } from '../../../object-list/item-list-element /item-types/item/item-list-element.component'; | import { ItemListElementComponent } from '../../../object-list/item-list-element /item-types/item/item-list-element.component'; | |||
import { ListableObjectDirective } from './listable-object.directive'; | import { ListableObjectDirective } from './listable-object.directive'; | |||
import { TranslateModule } from '@ngx-translate/core'; | import { TranslateModule } from '@ngx-translate/core'; | |||
import { By } from '@angular/platform-browser'; | import { By } from '@angular/platform-browser'; | |||
import { Item } from '../../../../core/shared/item.model'; | import { Item } from '../../../../core/shared/item.model'; | |||
import { provideMockStore } from '@ngrx/store/testing'; | import { provideMockStore } from '@ngrx/store/testing'; | |||
import { ThemeService } from '../../../theme-support/theme.service'; | ||||
const testType = 'TestType'; | const testType = 'TestType'; | |||
const testContext = Context.Search; | const testContext = Context.Search; | |||
const testViewMode = ViewMode.StandalonePage; | const testViewMode = ViewMode.StandalonePage; | |||
class TestType extends ListableObject { | class TestType extends ListableObject { | |||
getRenderTypes(): (string | GenericConstructor<ListableObject>)[] { | getRenderTypes(): (string | GenericConstructor<ListableObject>)[] { | |||
return [testType]; | return [testType]; | |||
} | } | |||
} | } | |||
describe('ListableObjectComponentLoaderComponent', () => { | describe('ListableObjectComponentLoaderComponent', () => { | |||
let comp: ListableObjectComponentLoaderComponent; | let comp: ListableObjectComponentLoaderComponent; | |||
let fixture: ComponentFixture<ListableObjectComponentLoaderComponent>; | let fixture: ComponentFixture<ListableObjectComponentLoaderComponent>; | |||
let themeService: ThemeService; | ||||
beforeEach(waitForAsync(() => { | beforeEach(waitForAsync(() => { | |||
themeService = jasmine.createSpyObj('themeService', { | ||||
getThemeName: 'dspace', | ||||
}); | ||||
TestBed.configureTestingModule({ | TestBed.configureTestingModule({ | |||
imports: [TranslateModule.forRoot()], | imports: [TranslateModule.forRoot()], | |||
declarations: [ListableObjectComponentLoaderComponent, ItemListElementComp onent, ListableObjectDirective], | declarations: [ListableObjectComponentLoaderComponent, ItemListElementComp onent, ListableObjectDirective], | |||
schemas: [NO_ERRORS_SCHEMA], | schemas: [NO_ERRORS_SCHEMA], | |||
providers: [provideMockStore({})] | providers: [ | |||
provideMockStore({}), | ||||
{ provide: ThemeService, useValue: themeService }, | ||||
] | ||||
}).overrideComponent(ListableObjectComponentLoaderComponent, { | }).overrideComponent(ListableObjectComponentLoaderComponent, { | |||
set: { | set: { | |||
changeDetection: ChangeDetectionStrategy.Default, | changeDetection: ChangeDetectionStrategy.Default, | |||
entryComponents: [ItemListElementComponent] | entryComponents: [ItemListElementComponent] | |||
} | } | |||
}).compileComponents(); | }).compileComponents(); | |||
})); | })); | |||
beforeEach(waitForAsync(() => { | beforeEach(waitForAsync(() => { | |||
fixture = TestBed.createComponent(ListableObjectComponentLoaderComponent); | fixture = TestBed.createComponent(ListableObjectComponentLoaderComponent); | |||
comp = fixture.componentInstance; | comp = fixture.componentInstance; | |||
comp.object = new TestType(); | comp.object = new TestType(); | |||
comp.viewMode = testViewMode; | comp.viewMode = testViewMode; | |||
comp.context = testContext; | comp.context = testContext; | |||
spyOn(comp, 'getComponent').and.returnValue(ItemListElementComponent as any) ; | spyOn(comp, 'getComponent').and.returnValue(ItemListElementComponent as any) ; | |||
spyOn(comp as any, 'connectInputsAndOutputs').and.callThrough(); | ||||
fixture.detectChanges(); | fixture.detectChanges(); | |||
})); | })); | |||
describe('When the component is rendered', () => { | describe('When the component is rendered', () => { | |||
it('should call the getListableObjectComponent function with the right types , view mode and context', () => { | it('should call the getListableObjectComponent function with the right types , view mode and context', () => { | |||
expect(comp.getComponent).toHaveBeenCalledWith([testType], testViewMode, t estContext); | expect(comp.getComponent).toHaveBeenCalledWith([testType], testViewMode, t estContext); | |||
}); | }); | |||
it('should connectInputsAndOutputs of loaded component', () => { | ||||
expect((comp as any).connectInputsAndOutputs).toHaveBeenCalled(); | ||||
}); | ||||
}); | }); | |||
describe('when the object is an item and viewMode is a list', () => { | describe('when the object is an item and viewMode is a list', () => { | |||
beforeEach(() => { | beforeEach(() => { | |||
comp.object = Object.assign(new Item()); | comp.object = Object.assign(new Item()); | |||
comp.viewMode = ViewMode.ListElement; | comp.viewMode = ViewMode.ListElement; | |||
}); | }); | |||
describe('when the item is not withdrawn', () => { | describe('when the item is not withdrawn', () => { | |||
beforeEach(() => { | beforeEach(() => { | |||
skipping to change at line 124 | skipping to change at line 138 | |||
expect(badge).not.toBeNull(); | expect(badge).not.toBeNull(); | |||
}); | }); | |||
}); | }); | |||
}); | }); | |||
describe('When a reloadedObject is emitted', () => { | describe('When a reloadedObject is emitted', () => { | |||
let listableComponent; | let listableComponent; | |||
let reloadedObject: any; | let reloadedObject: any; | |||
beforeEach(() => { | beforeEach(() => { | |||
spyOn((comp as any), 'connectInputsAndOutputs').and.returnValue(null); | spyOn((comp as any), 'instantiateComponent').and.returnValue(null); | |||
spyOn((comp as any).contentChange, 'emit').and.returnValue(null); | spyOn((comp as any).contentChange, 'emit').and.returnValue(null); | |||
listableComponent = fixture.debugElement.query(By.css('ds-item-list-elemen t')).componentInstance; | listableComponent = fixture.debugElement.query(By.css('ds-item-list-elemen t')).componentInstance; | |||
reloadedObject = 'object'; | reloadedObject = 'object'; | |||
}); | }); | |||
it('should pass it on connectInputsAndOutputs', fakeAsync(() => { | it('should re-instantiate the listable component', fakeAsync(() => { | |||
expect((comp as any).connectInputsAndOutputs).not.toHaveBeenCalled(); | expect((comp as any).instantiateComponent).not.toHaveBeenCalled(); | |||
(listableComponent as any).reloadedObject.emit(reloadedObject); | (listableComponent as any).reloadedObject.emit(reloadedObject); | |||
tick(); | tick(); | |||
expect((comp as any).connectInputsAndOutputs).toHaveBeenCalled(); | expect((comp as any).instantiateComponent).toHaveBeenCalledWith(reloadedOb ject); | |||
})); | })); | |||
it('should re-emit it as a contentChange', fakeAsync(() => { | it('should re-emit it as a contentChange', fakeAsync(() => { | |||
expect((comp as any).contentChange.emit).not.toHaveBeenCalled(); | expect((comp as any).contentChange.emit).not.toHaveBeenCalled(); | |||
(listableComponent as any).reloadedObject.emit(reloadedObject); | (listableComponent as any).reloadedObject.emit(reloadedObject); | |||
tick(); | tick(); | |||
expect((comp as any).contentChange.emit).toHaveBeenCalledWith(reloadedObje ct); | expect((comp as any).contentChange.emit).toHaveBeenCalledWith(reloadedObje ct); | |||
})); | })); | |||
End of changes. 9 change blocks. | ||||
5 lines changed or deleted | 19 lines changed or added |