From 9eb2a3f1614e1538ac1197b26d223a0de73110b2 Mon Sep 17 00:00:00 2001 From: Xiao Gui <xgui3783@gmail.com> Date: Fri, 19 Jun 2020 18:47:00 +0200 Subject: [PATCH] chore: added unit tests for glue chore: handling ie syntax error --- src/glue.spec.ts | 51 +++++++++++++++++++++++++++++++-- src/glue.ts | 9 ------ third_party/catchSyntaxError.js | 6 ++-- 3 files changed, 51 insertions(+), 15 deletions(-) diff --git a/src/glue.spec.ts b/src/glue.spec.ts index f5ee1d2f4..e3b6d940d 100644 --- a/src/glue.spec.ts +++ b/src/glue.spec.ts @@ -5,11 +5,12 @@ import { provideMockStore, MockStore } from "@ngrx/store/testing" import { getRandomHex } from 'common/util' import { EnumWidgetTypes, TypeOpenedWidget, uiActionSetPreviewingDatasetFiles } from "./services/state/uiState.store.helper" import { hot } from "jasmine-marbles" -import * as DATABROWSER_MODULE_EXPORTS from 'src/ui/databrowserModule' import { HttpClientTestingModule, HttpTestingController } from "@angular/common/http/testing" import { glueActionToggleDatasetPreview } from './glue' import { getIdObj } from 'common/util' import { DS_PREVIEW_URL } from 'src/util/constants' +import { NgLayersService } from "./ui/layerbrowser/ngLayerService.service" +import { EnumColorMapName } from "./util/colorMaps" const mockActionOnSpyReturnVal0 = { id: getRandomHex(), @@ -32,7 +33,14 @@ let actionOnWidgetSpy const nifti = { mimetype: "application/nifti", url: "http://abc.xyz", - referenceSpaces: [] + referenceSpaces: [], + volumeMetadata: { + min: 0.1, + max: 0.45, + colormap: 'viridis' + }, + name: 'helloworld', + filename: 'foobar' } const chart = { @@ -88,7 +96,8 @@ describe('> glue.ts', () => { { provide: ACTION_TO_WIDGET_TOKEN, useValue: actionOnWidgetSpy - } + }, + NgLayersService ] }) }) @@ -247,6 +256,42 @@ describe('> glue.ts', () => { const req = ctrl.expectOne(`${DS_PREVIEW_URL}/${datasetId}/${encodeURIComponent(filename)}`) req.flush(nifti) })) + + it('> on previewing nifti, thresholds, colormap and remove bg flag set properly', fakeAsync(() => { + const store = TestBed.inject(MockStore) + const ctrl = TestBed.inject(HttpTestingController) + + const layerService = TestBed.inject(NgLayersService) + + const highThresholdMapSpy = spyOn(layerService.highThresholdMap, 'set').and.callThrough() + const lowThresholdMapSpy = spyOn(layerService.lowThresholdMap, 'set').and.callThrough() + const colorMapMapSpy = spyOn(layerService.colorMapMap, 'set').and.callThrough() + const bgFlagSpy = spyOn(layerService.removeBgMap, 'set').and.callThrough() + + const glue = TestBed.inject(DatasetPreviewGlue) + + + + store.setState({ + uiState: { + previewingDatasetFiles: [ file1 ] + } + }) + + const { datasetId, filename } = file1 + // debounce at 100ms + tick(200) + + const req = ctrl.expectOne(`${DS_PREVIEW_URL}/${datasetId}/${encodeURIComponent(filename)}`) + req.flush(nifti) + + const { name, volumeMetadata } = nifti + const { min, max } = volumeMetadata + expect(highThresholdMapSpy).toHaveBeenCalledWith(name, max) + expect(lowThresholdMapSpy).toHaveBeenCalledWith(name, min) + expect(colorMapMapSpy).toHaveBeenCalledWith(name, EnumColorMapName.VIRIDIS) + expect(bgFlagSpy).toHaveBeenCalledWith(name, true) + })) }) describe('> #actionOnWidget', () => { diff --git a/src/glue.ts b/src/glue.ts index 7be1c6b57..696129f96 100644 --- a/src/glue.ts +++ b/src/glue.ts @@ -449,15 +449,6 @@ export const SAVE_USER_DATA = new InjectionToken<TypeSaveUserData>('SAVE_USER_DA type TypeSaveUserData = (key: string, value: string) => void - -@Injectable({ - providedIn: 'root' -}) - -export class DatasetUserGlue { - -} - export const gluActionFavDataset = createAction( '[glue] favDataset', props<{dataentry: Partial<IKgDataEntry>}>() diff --git a/third_party/catchSyntaxError.js b/third_party/catchSyntaxError.js index 4b6ef2f0d..09218b04f 100644 --- a/third_party/catchSyntaxError.js +++ b/third_party/catchSyntaxError.js @@ -1,6 +1,6 @@ -(() => { - window.onerror = e => { - if (/^SyntaxError/.test(e)) { +(function(){ + window.onerror = function(e) { + if (/^SyntaxError/.test(e) || /^Syntax\serror/.test(e)) { console.log('Caught SyntaxError') const warning = 'Your browser cannot display the interactive viewer. Please use either Chrome >= 56 and/or Firefox >= 51' -- GitLab