From 916ecadc03a631e609ff806f11c746c6d8526016 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandru=20V=C4=83leanu?= Date: Sun, 17 Oct 2021 00:19:49 +0100 Subject: [PATCH] Add unit test --- .../window/window.component.spec.ts | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/packages/altair-app/src/app/modules/altair/containers/window/window.component.spec.ts b/packages/altair-app/src/app/modules/altair/containers/window/window.component.spec.ts index 3d6e86c2d3..272584fbd5 100644 --- a/packages/altair-app/src/app/modules/altair/containers/window/window.component.spec.ts +++ b/packages/altair-app/src/app/modules/altair/containers/window/window.component.spec.ts @@ -1,29 +1,38 @@ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; import { NO_ERRORS_SCHEMA } from '@angular/core'; -import { Store } from '@ngrx/store'; +import { Store, combineReducers } from '@ngrx/store'; import * as services from './../../services'; import { WindowComponent } from './window.component'; import { mock, anyFn, mockStoreFactory } from '../../../../../testing'; import { TranslateModule } from '@ngx-translate/core'; -import { of } from 'rxjs'; import { RootState } from 'altair-graphql-core/build/types/state/state.interfaces'; - -let mockStore: Store; +import { ClearResultAction } from '../../store/query/query.action'; +import { getInitWindowState } from '../../store/windows/windows.reducer'; +import { getPerWindowReducer } from '../../store'; +import * as windowsMetaReducer from '../../store/windows-meta/windows-meta.reducer'; describe('WindowComponent', () => { let component: WindowComponent; let fixture: ComponentFixture; + let mockStore: Store; beforeEach(waitForAsync(() => { - const store = of(); - mockStore = mock>(store as any); + mockStore = mockStoreFactory({ + windows: { + 'abc-123': getInitWindowState(combineReducers(getPerWindowReducer())), + }, + windowsMeta: { + ...windowsMetaReducer.getInitialState(), + activeWindowId: 'abc-123', + } + }); const providers = [ { provide: Store, - useValue: mockStoreFactory({}), + useValue: mockStore, }, { provide: services.GqlService, @@ -65,10 +74,21 @@ describe('WindowComponent', () => { beforeEach(() => { fixture = TestBed.createComponent(WindowComponent); component = fixture.componentInstance; + component.ngOnInit = () => {}; fixture.detectChanges(); }); it('should create', () => { expect(component).toBeTruthy(); }); + + describe('clearResult', () => { + it('should dispatch ClearResultAction', () => { + component.clearResult(); + + const expectedAction = new ClearResultAction(component.windowId) + + expect(mockStore.dispatch).toHaveBeenCalledWith(expectedAction); + }) + }); });