diff --git a/src/glue.spec.ts b/src/glue.spec.ts index f5ee1d2f46b0321c522dab6f574b6fcd6edc378f..e3b6d940d851d5dad9e0e5b6da28c044c05e9abc 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 7be1c6b576e6cd9fa9df0354567110892428b251..696129f96f5558c4e0c36cd3ce5523c7059bc53b 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 4b6ef2f0d3cc71ef3677c946ff34e390e3052dc4..09218b04f306b7584e57d8342c106100ea372432 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'