Skip to content
Snippets Groups Projects
Commit d04d8568 authored by Tifenn Guillas's avatar Tifenn Guillas
Browse files

Tests on detail effects => DONE

parent b6e94dd8
No related branches found
No related tags found
2 merge requests!29Develop,!8Resolve "Add tests for instance store module"
......@@ -2,6 +2,7 @@ import { TestBed } from '@angular/core/testing';
import { provideMockActions } from '@ngrx/effects/testing';
import { EffectsMetadata, getEffectsMetadata } from '@ngrx/effects';
import { MockStore, provideMockStore } from '@ngrx/store/testing';
import { Observable } from 'rxjs';
import { cold, hot } from 'jasmine-marbles';
import { ToastrService } from 'ngx-toastr';
......@@ -9,16 +10,11 @@ import { ToastrService } from 'ngx-toastr';
import { DetailEffects } from './detail.effects';
import { DetailService } from '../services/detail.service';
import * as detailActions from '../actions/detail.actions';
import { Resolver } from '../models';
import { MockStore, provideMockStore } from '@ngrx/store/testing';
import * as detailSelector from '../selectors/detail.selector';
import * as attributeSelector from 'src/app/metamodel/selectors/attribute.selector';
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();
......@@ -56,23 +52,10 @@ describe('DetailEffects', () => {
store = TestBed.inject(MockStore);
toastr = TestBed.inject(ToastrService);
mockDatasetSelectorSelectDatasetNameByRoute = store.overrideSelector(
datasetSelector.selectDatasetNameByRoute,
'myDatasetName'
datasetSelector.selectDatasetNameByRoute,''
);
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,
order_by: true,
detail: true
}] as Attribute[]
attributeSelector.selectAllAttributes,[]
);
mockDetailSelectorSelectIdByRoute = store.overrideSelector(
detailSelector.selectIdByRoute,1
......@@ -84,46 +67,72 @@ describe('DetailEffects', () => {
});
describe('retrieveObject$ effect', () => {
// it.only('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é.
// // console.log(myMock.mock.calls.length);
//
// expect(effects.retrieveObject$).toBeObservable(expected);
// // expect(true).toBeTruthy();
// });
// it('should dispatch the retrieveObjectSuccess action on success', () => {
// const action = detailActions.retrieveObject();
// const outcome = detailActions.retrieveObjectSuccess({ object: 'myObject' });
//
// actions = hot('-a', { a: action });
// const response = cold('-a|', { a: ['myObject'] });
// const expected = cold('--b', { b: outcome });
// detailService.retrieveObject = jest.fn(() => response);
//
// expect(effects.retrieveObject$).toBeObservable(expected);
// });
// it('should dispatch the retrieveObjectFail action on failure', () => {
// const action = detailActions.retrieveObject();
// const error = new Error();
// const outcome = detailActions.retrieveObjectFail();
//
// actions = hot('-a', { a: action });
// const response = cold('-#|', {}, error);
// const expected = cold('--b', { b: outcome });
// detailService.retrieveObject = jest.fn(() => response);
//
// console.log(effects.retrieveObject$);
//
// expect(effects.retrieveObject$).toBeObservable(expected);
// });
it('should dispatch the retrieveObjectSuccess action on success', () => {
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,
order_by: true,
detail: true
}]
);
mockDetailSelectorSelectIdByRoute = store.overrideSelector(
detailSelector.selectIdByRoute, 1
);
const action = detailActions.retrieveObject();
const outcome = detailActions.retrieveObjectSuccess({ object: 'myObject' });
actions = hot('-a', { a: action });
const response = cold('-b|', { b: ['myObject'] });
const expected = cold('--c', { c: outcome });
detailService.retrieveObject = jest.fn(() => response);
expect(effects.retrieveObject$).toBeObservable(expected);
});
it('should dispatch the retrieveObjectFail action on failure', () => {
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,
order_by: true,
detail: true
}]
);
mockDetailSelectorSelectIdByRoute = store.overrideSelector(
detailSelector.selectIdByRoute, 1
);
const action = detailActions.retrieveObject();
const error = new Error();
const outcome = detailActions.retrieveObjectFail();
actions = hot('-a', { a: action });
const response = cold('-#|', {}, error);
const expected = cold('--b', { b: outcome });
detailService.retrieveObject = jest.fn(() => response);
expect(effects.retrieveObject$).toBeObservable(expected);
});
});
describe('retrieveObjectFail$ effect', () => {
......@@ -147,64 +156,38 @@ 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 dispatch the retrieveSpectraSuccess action on success', () => {
// const name: string = 'myObjectName';
// const apiResponse = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
// "<Sesame xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
// " xsi:noNamespaceSchemaLocation=\"http://vizier.u-strasbg.fr/xml/sesame_4x.xsd\">\n" +
// "<Target option=\"NSV\">\n" +
// " <name>myObjectName</name>\n" +
// " <!-- Q1525761 #1 -->\n" +
// " <Resolver name=\"N=NED\"><!--delay: 989ms [2] -->\n" +
// " <otype>!*</otype>\n" +
// " <jpos>06:45:09.24 -16:42:47.3</jpos>\n" +
// " <jradeg>1</jradeg>\n" +
// " <jdedeg>2</jdedeg>\n" +
// " <refPos>2007A&amp;A...474..653V</refPos>\n" +
// " <errRAmas>50</errRAmas><errDEmas>500</errDEmas>\n" +
// " <oname>Sirius</oname>\n" +
// " </Resolver>\n" +
// "</Target>\n" +
// "</Sesame>\n" +
// "<!--- ====Done (2021-Aug-04,15:00:56z)==== -->\n";
// const resolver: Resolver = { name: 'myObjectName', ra: 1, dec: 2 };
// const action = coneSearchActions.retrieveCoordinates({ name });
// const outcome = coneSearchActions.retrieveCoordinatesSuccess({ resolver });
//
// actions = hot('-a', { a: action });
// const response = cold('-a|', { a: apiResponse });
// const expected = cold('--b', { b: outcome });
// coneSearchService.retrieveCoordinates = jest.fn(() => response);
//
// expect(effects.retrieveCoordinates$).toBeObservable(expected);
// console.log(store.select())
// expect(false).toBeTruthy();
// });
// it('should dispatch the retrieveSpectraFail action on failure', () => {
// const name: string = 'myObjectName';
// const action = coneSearchActions.retrieveCoordinates({ name });
// const error = new Error();
// const outcome = coneSearchActions.retrieveCoordinatesFail();
//
// actions = hot('-a', { a: action });
// const response = cold('-#|', {}, error);
// const expected = cold('--b', { b: outcome });
// coneSearchService.retrieveCoordinates = jest.fn(() => response);
//
// expect(effects.retrieveCoordinates$).toBeObservable(expected);
// });
it('should dispatch the retrieveSpectraSuccess action on success', () => {
mockDatasetSelectorSelectDatasetNameByRoute = store.overrideSelector(
datasetSelector.selectDatasetNameByRoute, 'myDatasetName'
);
const action = detailActions.retrieveSpectra({ filename: 'mySpectraFilename' });
const outcome = detailActions.retrieveSpectraSuccess({ spectraCSV: 'mySpectraFile' });
actions = hot('-a', { a: action });
const response = cold('-b|', { b: 'mySpectraFile' });
const expected = cold('--c', { c: outcome });
detailService.retrieveSpectra = jest.fn(() => response);
expect(effects.retrieveSpectra$).toBeObservable(expected);
});
it('should dispatch the retrieveSpectraFail action on failure', () => {
mockDatasetSelectorSelectDatasetNameByRoute = store.overrideSelector(
datasetSelector.selectDatasetNameByRoute, 'myDatasetName'
);
const action = detailActions.retrieveSpectra({ filename: 'mySpectraFilename' });
const error = new Error();
const outcome = detailActions.retrieveSpectraFail();
actions = hot('-a', { a: action });
const response = cold('-#|', {}, error);
const expected = cold('--b', { b: outcome });
detailService.retrieveSpectra = jest.fn(() => response);
expect(effects.retrieveSpectra$).toBeObservable(expected);
});
});
describe('retrieveSpectraFail$ effect', () => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment