import { RealtimeStatsComponent } from "./realtime-stats.component" ; import { async , ComponentFixture , TestBed } from '@angular/core/testing' ; import { NO_ERRORS_SCHEMA } from '@angular/core' ; import { provideMockStore , MockStore } from '@ngrx/store/testing' ; import { AppState } from '../../../store' ; import { SystemStats } from 'shared-library/shared/model' ; import { Store } from '@ngrx/store' ; import { DashboardState , dashboardState } from '../../store' ; import { testData } from 'test/data' ; import * as StatActions from '../../store/actions' ; describe ( 'RealtimeStatsComponent' , ( ) => { let component ; let fixture ; let systemStat ; let spy ; let mockStore ; beforeEach ( async ( ( ) => { TestBed . configureTestingModule ( { declarations : [ RealtimeStatsComponent ] , schemas : [ NO_ERRORS_SCHEMA ] , providers : [ provideMockStore ( { initialState : { } , selectors : [ { selector : dashboardState , value : { } } ] } ) ] } ) ; } ) ) ; beforeEach ( ( ) => { fixture = TestBed . createComponent ( RealtimeStatsComponent ) ; mockStore = TestBed . get ( Store ) ; spy = spyOn ( mockStore , 'dispatch' ) ; fixture = TestBed . createComponent ( RealtimeStatsComponent ) ; component = fixture . componentInstance ; fixture . detectChanges ( ) ; } ) ; it ( 'should create' , ( ) => { expect ( component ) . toBeTruthy ( ) ; } ) ; it ( 'Verify that the laod system stat action is dispached' , async ( ) => { mockStore . overrideSelector < AppState , Partial < DashboardState > > ( dashboardState , { } ) ; mockStore . refreshState ( ) ; fixture . detectChanges ( ) ; expect ( spy ) . toHaveBeenCalledWith ( new StatActions . LoadSystemStat ( ) ) ; } ) ; it ( 'Verify the data for systemStat' , ( ) => { systemStat = { ... testData . realTimeStats } ; mockStore . overrideSelector < AppState , Partial < DashboardState > > ( dashboardState , { systemStat : systemStat } ) ; mockStore . refreshState ( ) ; fixture . detectChanges ( ) ; expect ( component . systemStats ) . toEqual ( systemStat ) ; } ) ; it ( 'Verify the systemStat is null initially' , ( ) => { expect ( component . systemStats ) . toBe ( undefined ) ; } ) ; afterEach ( ( ) => { fixture . destroy ( ) ; } ) ; } ) ;