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 ec713df923cd798ed4b6b01c24284fd0fe95a3a2..2cebb21c340b6eaac9e1a6063997291d398512f4 100644 --- a/client/src/app/instance/store/effects/detail.effects.spec.ts +++ b/client/src/app/instance/store/effects/detail.effects.spec.ts @@ -15,29 +15,39 @@ 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'; describe('DetailEffects', () => { let actions = new Observable(); let effects: DetailEffects; let metadata: EffectsMetadata<DetailEffects>; - let coneSearchService: DetailService; + let detailService: DetailService; let store: MockStore; let toastr: ToastrService; - const initialState = { detail: { ...fromDetail.initialState } }; + const initialState = { + metamodel: { ...fromMetamodel.getMetamodelState }, + instance: { + detail: { ...fromDetail.initialState } + } + }; beforeEach(() => { TestBed.configureTestingModule({ providers: [ DetailEffects, - { provide: DetailService, useValue: { retrieveCoordinates: jest.fn() }}, - { provide: ToastrService, useValue: { error: jest.fn() } }, + { provide: DetailService, useValue: { + retrieveObject: jest.fn(), + retrieveSpectra: jest.fn() + }}, + { provide: ToastrService, useValue: { error: jest.fn() }}, provideMockActions(() => actions), provideMockStore({ initialState }), ] }).compileComponents(); effects = TestBed.inject(DetailEffects); metadata = getEffectsMetadata(effects); - coneSearchService = TestBed.inject(DetailService); + detailService = TestBed.inject(DetailService); store = TestBed.inject(MockStore); toastr = TestBed.inject(ToastrService); }); @@ -46,55 +56,45 @@ describe('DetailEffects', () => { expect(effects).toBeTruthy(); }); - describe('retrieveObject$ effect', () => { + // 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); + // }); + // it('should dispatch the retrieveObjectSuccess 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&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 }); + // const action = detailActions.retrieveObject(); + // const outcome = detailActions.retrieveObjectSuccess({ object: 'myObject' }); // // actions = hot('-a', { a: action }); - // const response = cold('-a|', { a: apiResponse }); + // const response = cold('-a|', { a: ['myObject'] }); // const expected = cold('--b', { b: outcome }); - // coneSearchService.retrieveCoordinates = jest.fn(() => response); + // detailService.retrieveObject = jest.fn(() => response); // - // expect(effects.retrieveCoordinates$).toBeObservable(expected); - // console.log(store.select()) - // expect(false).toBeTruthy(); + // expect(effects.retrieveObject$).toBeObservable(expected); // }); // it('should dispatch the retrieveObjectFail action on failure', () => { - // const name: string = 'myObjectName'; - // const action = coneSearchActions.retrieveCoordinates({ name }); + // const action = detailActions.retrieveObject(); // const error = new Error(); - // const outcome = coneSearchActions.retrieveCoordinatesFail(); + // const outcome = detailActions.retrieveObjectFail(); // // actions = hot('-a', { a: action }); // const response = cold('-#|', {}, error); // const expected = cold('--b', { b: outcome }); - // coneSearchService.retrieveCoordinates = jest.fn(() => response); + // detailService.retrieveObject = jest.fn(() => response); // - // expect(effects.retrieveCoordinates$).toBeObservable(expected); + // console.log(effects.retrieveObject$); + // + // expect(effects.retrieveObject$).toBeObservable(expected); // }); - }); + // }); describe('retrieveObjectFail$ effect', () => { it('should not dispatch', () => { @@ -117,6 +117,17 @@ 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" + diff --git a/client/src/app/instance/store/services/detail.service.ts b/client/src/app/instance/store/services/detail.service.ts index 978c046a4f81340896728fdd05f951b16300193e..6fb730796840cee93a0b3c87a1023966a4545d0b 100644 --- a/client/src/app/instance/store/services/detail.service.ts +++ b/client/src/app/instance/store/services/detail.service.ts @@ -14,11 +14,11 @@ import { Observable } from 'rxjs'; import { AppConfigService } from 'src/app/app-config.service'; -@Injectable() /** * @class * @classdesc Detail service. */ +@Injectable() export class DetailService { constructor(private http: HttpClient, private config: AppConfigService) { } @@ -33,7 +33,6 @@ export class DetailService { * @return Observable<any[]> */ retrieveObject(dname: string, criterionId: number, objectSelected: string, outputList: number[]): Observable<any[]> { - console.log(dname, criterionId, objectSelected, outputList); const query = dname + '?c=' + criterionId + '::eq::' + objectSelected + '&a=' + outputList.join(';'); return this.http.get<any[]>(this.config.apiUrl + '/search/' + query); } @@ -41,6 +40,7 @@ export class DetailService { /** * Retrieves object details for the given parameters. * + * @param {string} dname - The dataset name. * @param {string} spectraFile - The spectra file name. * * @return Observable<string>