Skip to content
Snippets Groups Projects
Commit 9eb2a3f1 authored by Xiao Gui's avatar Xiao Gui
Browse files

chore: added unit tests for glue

chore: handling ie syntax error
parent d112bfc5
No related branches found
No related tags found
No related merge requests found
...@@ -5,11 +5,12 @@ import { provideMockStore, MockStore } from "@ngrx/store/testing" ...@@ -5,11 +5,12 @@ import { provideMockStore, MockStore } from "@ngrx/store/testing"
import { getRandomHex } from 'common/util' import { getRandomHex } from 'common/util'
import { EnumWidgetTypes, TypeOpenedWidget, uiActionSetPreviewingDatasetFiles } from "./services/state/uiState.store.helper" import { EnumWidgetTypes, TypeOpenedWidget, uiActionSetPreviewingDatasetFiles } from "./services/state/uiState.store.helper"
import { hot } from "jasmine-marbles" import { hot } from "jasmine-marbles"
import * as DATABROWSER_MODULE_EXPORTS from 'src/ui/databrowserModule'
import { HttpClientTestingModule, HttpTestingController } from "@angular/common/http/testing" import { HttpClientTestingModule, HttpTestingController } from "@angular/common/http/testing"
import { glueActionToggleDatasetPreview } from './glue' import { glueActionToggleDatasetPreview } from './glue'
import { getIdObj } from 'common/util' import { getIdObj } from 'common/util'
import { DS_PREVIEW_URL } from 'src/util/constants' import { DS_PREVIEW_URL } from 'src/util/constants'
import { NgLayersService } from "./ui/layerbrowser/ngLayerService.service"
import { EnumColorMapName } from "./util/colorMaps"
const mockActionOnSpyReturnVal0 = { const mockActionOnSpyReturnVal0 = {
id: getRandomHex(), id: getRandomHex(),
...@@ -32,7 +33,14 @@ let actionOnWidgetSpy ...@@ -32,7 +33,14 @@ let actionOnWidgetSpy
const nifti = { const nifti = {
mimetype: "application/nifti", mimetype: "application/nifti",
url: "http://abc.xyz", url: "http://abc.xyz",
referenceSpaces: [] referenceSpaces: [],
volumeMetadata: {
min: 0.1,
max: 0.45,
colormap: 'viridis'
},
name: 'helloworld',
filename: 'foobar'
} }
const chart = { const chart = {
...@@ -88,7 +96,8 @@ describe('> glue.ts', () => { ...@@ -88,7 +96,8 @@ describe('> glue.ts', () => {
{ {
provide: ACTION_TO_WIDGET_TOKEN, provide: ACTION_TO_WIDGET_TOKEN,
useValue: actionOnWidgetSpy useValue: actionOnWidgetSpy
} },
NgLayersService
] ]
}) })
}) })
...@@ -247,6 +256,42 @@ describe('> glue.ts', () => { ...@@ -247,6 +256,42 @@ describe('> glue.ts', () => {
const req = ctrl.expectOne(`${DS_PREVIEW_URL}/${datasetId}/${encodeURIComponent(filename)}`) const req = ctrl.expectOne(`${DS_PREVIEW_URL}/${datasetId}/${encodeURIComponent(filename)}`)
req.flush(nifti) 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', () => { describe('> #actionOnWidget', () => {
......
...@@ -449,15 +449,6 @@ export const SAVE_USER_DATA = new InjectionToken<TypeSaveUserData>('SAVE_USER_DA ...@@ -449,15 +449,6 @@ export const SAVE_USER_DATA = new InjectionToken<TypeSaveUserData>('SAVE_USER_DA
type TypeSaveUserData = (key: string, value: string) => void type TypeSaveUserData = (key: string, value: string) => void
@Injectable({
providedIn: 'root'
})
export class DatasetUserGlue {
}
export const gluActionFavDataset = createAction( export const gluActionFavDataset = createAction(
'[glue] favDataset', '[glue] favDataset',
props<{dataentry: Partial<IKgDataEntry>}>() props<{dataentry: Partial<IKgDataEntry>}>()
......
(() => { (function(){
window.onerror = e => { window.onerror = function(e) {
if (/^SyntaxError/.test(e)) { if (/^SyntaxError/.test(e) || /^Syntax\serror/.test(e)) {
console.log('Caught SyntaxError') console.log('Caught SyntaxError')
const warning = 'Your browser cannot display the interactive viewer. Please use either Chrome >= 56 and/or Firefox >= 51' const warning = 'Your browser cannot display the interactive viewer. Please use either Chrome >= 56 and/or Firefox >= 51'
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment