From 37386c870d5bd9123ac4d6323c09427d6bc6707d Mon Sep 17 00:00:00 2001 From: Tifenn Guillas <tifenn.guillas@gmail.com> Date: Mon, 30 Aug 2021 12:45:03 +0200 Subject: [PATCH] WIP: tests on detail effect... --- .../store/effects/detail.effects.spec.ts | 72 +++++++++++++------ 1 file changed, 50 insertions(+), 22 deletions(-) diff --git a/client/src/app/instance/store/effects/detail.effects.spec.ts b/client/src/app/instance/store/effects/detail.effects.spec.ts index 2cebb21c..7e09d59d 100644 --- a/client/src/app/instance/store/effects/detail.effects.spec.ts +++ b/client/src/app/instance/store/effects/detail.effects.spec.ts @@ -17,6 +17,8 @@ import * as datasetSelector from 'src/app/metamodel/selectors/dataset.selector'; import * as fromDetail from '../reducers/detail.reducer'; import * as fromMetamodel from '../../../metamodel/metamodel.reducer'; import { HttpClient } from '@angular/common/http'; +import { MemoizedSelector } from '@ngrx/store'; +import { Attribute, Dataset, Option, RendererConfig } from '../../../metamodel/models'; describe('DetailEffects', () => { let actions = new Observable(); @@ -25,6 +27,9 @@ describe('DetailEffects', () => { let detailService: DetailService; let store: MockStore; let toastr: ToastrService; + let mockDatasetSelectorSelectDatasetNameByRoute; + let mockAttributeSelectorSelectAllAttributes; + let mockDetailSelectorSelectIdByRoute; const initialState = { metamodel: { ...fromMetamodel.getMetamodelState }, instance: { @@ -50,23 +55,46 @@ describe('DetailEffects', () => { detailService = TestBed.inject(DetailService); store = TestBed.inject(MockStore); toastr = TestBed.inject(ToastrService); + mockDatasetSelectorSelectDatasetNameByRoute = store.overrideSelector( + datasetSelector.selectDatasetNameByRoute, + 'myDatasetName' + ); + mockAttributeSelectorSelectAllAttributes = store.overrideSelector( + attributeSelector.selectAllAttributes, + [{ + id: 1, + name: 'myFirstAttribute', + label: 'My First Attribute', + form_label: 'My First Attribute', + output_display: 1, + criteria_display: 1, + type: 'type', + display_detail: 1 + }] as Attribute[] + ); + mockDetailSelectorSelectIdByRoute = store.overrideSelector( + detailSelector.selectIdByRoute, + 1 + ); }); it('should be created', () => { expect(effects).toBeTruthy(); }); - // describe('retrieveObject$ effect', () => { - // it('should call retrieveObject method of service', () => { - // console.log(store); - // - // const action = detailActions.retrieveObject(); - // jest.spyOn(detailService, 'retrieveObject'); - // actions = hot('a', { a: action }); - // const expected = cold('a', { a: action }); - // - // expect(effects.retrieveObject$).toBeObservable(expected); - // }); + describe('retrieveObject$ effect', () => { + it('should call retrieveObject method of service', () => { + const action = detailActions.retrieveObject(); + jest.spyOn(detailService, 'retrieveObject'); + actions = hot('a', { a: action }); + const outcome = detailActions.retrieveObjectSuccess({ object: 'myObject' }); + const expected = cold('--b', { b: outcome }); + + // TODO: logger les params envoyé au service mocké. + + expect(effects.retrieveObject$).toBeObservable(expected); + // expect(true).toBeTruthy(); + }); // it('should dispatch the retrieveObjectSuccess action on success', () => { // const action = detailActions.retrieveObject(); @@ -94,7 +122,7 @@ describe('DetailEffects', () => { // // expect(effects.retrieveObject$).toBeObservable(expected); // }); - // }); + }); describe('retrieveObjectFail$ effect', () => { it('should not dispatch', () => { @@ -117,16 +145,16 @@ describe('DetailEffects', () => { }); describe('retrieveSpectra$ effect', () => { - it('should call retrieveSpectra method of service', () => { - console.log(store); - - const action = detailActions.retrieveSpectra({ filename: 'mySpectra' }); - jest.spyOn(detailService, 'retrieveSpectra'); - actions = hot('a', { a: action }); - const expected = cold('a', { a: action }); - - expect(effects.retrieveSpectra$).toBeObservable(expected); - }); + // it('should call retrieveSpectra method of service', () => { + // console.log(store); + // + // const action = detailActions.retrieveSpectra({ filename: 'mySpectra' }); + // jest.spyOn(detailService, 'retrieveSpectra'); + // actions = hot('a', { a: action }); + // const expected = cold('a', { a: action }); + // + // expect(effects.retrieveSpectra$).toBeObservable(expected); + // }); // it('should dispatch the retrieveSpectraSuccess action on success', () => { // const name: string = 'myObjectName'; -- GitLab