import { configureTestBed } from '../../../../testing/unit-test-helper';
import { ComponentsModule } from '../../../shared/components/components.module';
+import { ViewCacheStatus } from '../../../shared/enum/view-cache-status.enum';
+import { SummaryService } from '../../../shared/services/summary.service';
import { SharedModule } from '../../../shared/shared.module';
import { RbdDetailsComponent } from '../rbd-details/rbd-details.component';
import { RbdSnapshotListComponent } from '../rbd-snapshot-list/rbd-snapshot-list.component';
let component: RbdListComponent;
let fixture: ComponentFixture<RbdListComponent>;
+ class SummaryServiceMock extends SummaryService {
+ data: any;
+
+ raiseError() {
+ this.summaryDataSource.error(undefined);
+ }
+
+ refresh() {
+ this.summaryDataSource.next(this.data);
+ }
+ }
+
configureTestBed({
imports: [
SharedModule,
RouterTestingModule,
HttpClientTestingModule
],
- declarations: [RbdListComponent, RbdDetailsComponent, RbdSnapshotListComponent]
+ declarations: [RbdListComponent, RbdDetailsComponent, RbdSnapshotListComponent],
+ providers: [{ provide: SummaryService, useClass: SummaryServiceMock }]
});
beforeEach(() => {
fixture = TestBed.createComponent(RbdListComponent);
component = fixture.componentInstance;
- fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
+
+ describe('after ngOnInit', () => {
+ let summaryService: SummaryServiceMock;
+
+ beforeEach(() => {
+ summaryService = TestBed.get(SummaryService);
+ summaryService.data = undefined;
+ fixture.detectChanges();
+ });
+
+ it('should load images on init', () => {
+ spyOn(component, 'loadImages');
+ summaryService.data = {};
+ summaryService.refresh();
+ expect(component.loadImages).toHaveBeenCalled();
+ });
+
+ it('should not load images on init because no data', () => {
+ spyOn(component, 'loadImages');
+ summaryService.refresh();
+ expect(component.loadImages).not.toHaveBeenCalled();
+ });
+
+ it('should call error function on init when summary service fails', () => {
+ spyOn(component.table, 'reset');
+ summaryService.raiseError();
+ expect(component.table.reset).toHaveBeenCalled();
+ expect(component.viewCacheStatusList).toEqual([{ status: ViewCacheStatus.ValueException }]);
+ });
+ });
});
* which is updated once every 5 seconds or when a new task is created.
*
* @param {(summary: any) => void} call
+ * @param {(error: any) => void} error
* @returns {Subscription}
* @memberof SummaryService
*/
- subscribe(call: (summary: any) => void): Subscription {
- return this.summaryData$.subscribe(call);
+ subscribe(call: (summary: any) => void, error?: (error: any) => void): Subscription {
+ return this.summaryData$.subscribe(call, error);
}
/**