From d576296c4a6e7111a60775b52e5a9ed77690f6eb Mon Sep 17 00:00:00 2001 From: Xiao Gui <xgui3783@gmail.com> Date: Thu, 7 Oct 2021 16:10:52 +0200 Subject: [PATCH] fix tests --- .../nehubaViewerGlue.component.spec.ts | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/viewerModule/nehuba/nehubaViewerGlue/nehubaViewerGlue.component.spec.ts b/src/viewerModule/nehuba/nehubaViewerGlue/nehubaViewerGlue.component.spec.ts index 4e8ae0680..4b081a97a 100644 --- a/src/viewerModule/nehuba/nehubaViewerGlue/nehubaViewerGlue.component.spec.ts +++ b/src/viewerModule/nehuba/nehubaViewerGlue/nehubaViewerGlue.component.spec.ts @@ -25,8 +25,7 @@ import { selectorAuxMeshes } from "../store" import { TouchSideClass } from "../touchSideClass.directive" import { NehubaGlueCmp } from "./nehubaViewerGlue.component" import { HarnessLoader } from "@angular/cdk/testing" -import { NehubaModule } from "../module" -import { NEHUBA_VIEWER_FEATURE_KEY } from "../constants" +import { AtlasWorkerService } from "src/atlasViewer/atlasViewer.workerService.service" @Component({ @@ -116,6 +115,18 @@ describe('> nehubaViewerGlue.component.ts', () => { useValue: { loadMeshes$: new Subject() } + }, { + provide: AtlasWorkerService, + useValue: { + sendMessage: async () => { + return { + result: { + meta: {}, + buffer: null + } + } + } + } } ] }).compileComponents() @@ -230,6 +241,7 @@ describe('> nehubaViewerGlue.component.ts', () => { describe('> handleFileDrop', () => { let addNgLayerSpy: jasmine.Spy let removeNgLayersSpy: jasmine.Spy + let workerSendMessageSpy: jasmine.Spy let dummyFile1: File let dummyFile2: File let input: File[] @@ -258,10 +270,19 @@ describe('> nehubaViewerGlue.component.ts', () => { removeNgLayersSpy = spyOn(fixture.componentInstance['layerCtrlService'], 'removeNgLayers').and.callFake(() => { }) + + workerSendMessageSpy = spyOn(fixture.componentInstance['worker'], 'sendMessage').and.callFake(async () => { + return { + result: { + meta: {}, buffer: null + } + } + }) }) afterEach(() => { addNgLayerSpy.calls.reset() removeNgLayersSpy.calls.reset() + workerSendMessageSpy.calls.reset() }) describe('> malformed input', () => { @@ -305,11 +326,11 @@ describe('> nehubaViewerGlue.component.ts', () => { }) describe('> correct input', () => { - beforeEach(() => { + beforeEach(async () => { input = [dummyFile1] const cmp = fixture.componentInstance - cmp.handleFileDrop(input) + await cmp.handleFileDrop(input) }) afterEach(() => { @@ -321,9 +342,9 @@ describe('> nehubaViewerGlue.component.ts', () => { expect(removeNgLayersSpy).not.toHaveBeenCalled() expect(addNgLayerSpy).toHaveBeenCalledTimes(1) }) - it('> on repeated input, both remove nglayer and remove ng layer called', () => { + it('> on repeated input, both remove nglayer and remove ng layer called', async () => { const cmp = fixture.componentInstance - cmp.handleFileDrop(input) + await cmp.handleFileDrop(input) expect(removeNgLayersSpy).toHaveBeenCalledTimes(1) expect(addNgLayerSpy).toHaveBeenCalledTimes(2) -- GitLab