From 6a1e8f63c914125a3b8c89e0722e3abe7e5e0420 Mon Sep 17 00:00:00 2001 From: Felix Frank Date: Mon, 17 Jun 2024 08:51:59 +0200 Subject: [PATCH] Fixed tests after changes. --- src/light/__test__/AmbientLight.test.ts | 16 +++++++++++---- src/light/__test__/PointLight.test.ts | 27 ++++++++++++++++++------- src/light/__test__/SceneLight.test.ts | 14 +++++++++---- 3 files changed, 42 insertions(+), 15 deletions(-) diff --git a/src/light/__test__/AmbientLight.test.ts b/src/light/__test__/AmbientLight.test.ts index 030182b4..511af03a 100644 --- a/src/light/__test__/AmbientLight.test.ts +++ b/src/light/__test__/AmbientLight.test.ts @@ -1,4 +1,4 @@ -import { Color } from 'three'; +import { AmbientLight, Color, Object3D } from 'three'; import DIVEAmbientLight from '../AmbientLight'; jest.mock('three', () => { @@ -12,6 +12,14 @@ jest.mock('three', () => { this.layers = { mask: 0, }; + this.removeFromParent = jest.fn(); + return this; + }), + Object3D: jest.fn(function () { + this.children = []; + this.add = (obj: Object3D) => { + this.children.push(obj); + }; return this; }), } @@ -27,18 +35,18 @@ describe('dive/light/DIVEAmbientLight', () => { it('should set intensity', () => { const testLight = new DIVEAmbientLight(); testLight.SetIntensity(1.0); - expect(testLight.intensity).toBe(1.0); + expect((testLight.children[0] as AmbientLight).intensity).toBe(1.0); }); it('should set color', () => { const testLight = new DIVEAmbientLight(); testLight.SetColor({ test: true } as unknown as Color); - expect(testLight.color).toEqual({ test: true }); + expect((testLight.children[0] as AmbientLight).color).toEqual({ test: true }); }); it('should set enabled', () => { const testLight = new DIVEAmbientLight(); testLight.SetEnabled(false); - expect(testLight.visible).toBe(false); + expect(testLight.children[0].visible).toBe(false); }); }); \ No newline at end of file diff --git a/src/light/__test__/PointLight.test.ts b/src/light/__test__/PointLight.test.ts index 9ca9a5c1..07277d33 100644 --- a/src/light/__test__/PointLight.test.ts +++ b/src/light/__test__/PointLight.test.ts @@ -1,6 +1,6 @@ import DIVEPointLight from '../PointLight.ts'; import DIVECommunication from '../../com/Communication.ts'; -import { Color } from 'three'; +import { Color, MeshBasicMaterial, Object3D, PointLight } from 'three'; const mockAdd = jest.fn(); @@ -10,6 +10,7 @@ jest.mock('three', () => { return {}; }), PointLight: jest.fn(function () { + this.visible = true; this.color = {}; this.intensity = 0; this.layers = { @@ -31,19 +32,30 @@ jest.mock('three', () => { color: {}, }, }]; - this.userData = {}; return this; }), SphereGeometry: jest.fn(function () { return this; }), MeshBasicMaterial: jest.fn(function () { + this.opacity = 1.0; + this.color = new Color(); return this; }), Mesh: jest.fn(function () { this.layers = { mask: 0, }; + this.visible = true; + this.material = new MeshBasicMaterial(); + return this; + }), + Object3D: jest.fn(function () { + this.children = []; + this.add = (obj: Object3D) => { + this.children.push(obj); + }; + this.userData = {}; return this; }), } @@ -64,27 +76,28 @@ describe('dive/light/DIVEPointLight', () => { const testLight = new DIVEPointLight(); testLight.userData.id = 'something'; expect(testLight).toBeDefined(); - expect(mockAdd).toHaveBeenCalledTimes(1); + expect(testLight.userData.id).toBe('something'); + expect(testLight.children).toHaveLength(2); }); it('should set intensity', () => { const testLight = new DIVEPointLight(); testLight.SetIntensity(1.0); - expect(testLight.intensity).toBe(1.0); + expect((testLight.children[0] as PointLight).intensity).toBe(1.0); testLight.SetIntensity(0.6); - expect(testLight.intensity).toBe(0.6); + expect((testLight.children[0] as PointLight).intensity).toBe(0.6); }); it('should set color', () => { const testLight = new DIVEPointLight(); testLight.SetColor({ test: true } as unknown as Color); - expect(testLight.color).toEqual({ test: true }); + expect((testLight.children[0] as PointLight).color).toEqual({ test: true }); }); it('should set enabled', () => { const testLight = new DIVEPointLight(); testLight.SetEnabled(false); - expect(testLight.visible).toBe(false); + expect(testLight.children[0].visible).toBe(false); }); it('should onMove', () => { diff --git a/src/light/__test__/SceneLight.test.ts b/src/light/__test__/SceneLight.test.ts index f8f3938c..66a19867 100644 --- a/src/light/__test__/SceneLight.test.ts +++ b/src/light/__test__/SceneLight.test.ts @@ -1,6 +1,6 @@ import DIVESceneLight from '../SceneLight'; import DIVECommunication from '../../com/Communication'; -import { Color } from 'three'; +import { Color, HemisphereLight as THREEHemisphereLight, DirectionalLight as THREEDirectionalLight, Object3D } from 'three'; jest.mock('../../com/Communication.ts', () => { return { @@ -57,10 +57,14 @@ jest.mock('three', () => { return this; }), Object3D: jest.fn(function () { - this.add = mockAdd; + this.children = []; + this.add = (obj: Object3D) => { + this.children.push(obj); + }; return this; }), HemisphereLight: jest.fn(function () { + this.visible = true; this.layers = { mask: 0, }; @@ -71,6 +75,7 @@ jest.mock('three', () => { return this; }), DirectionalLight: jest.fn(function () { + this.visible = true; this.layers = { mask: 0, }; @@ -100,7 +105,7 @@ describe('dive/light/DIVESceneLight', () => { it('should instantiate', () => { const testLight = new DIVESceneLight(); expect(testLight).toBeDefined(); - expect(mockAdd).toHaveBeenCalledTimes(2); + expect(testLight.children).toHaveLength(2); }); it('should set intensity', () => { @@ -117,6 +122,7 @@ describe('dive/light/DIVESceneLight', () => { it('should set enabled', () => { const testLight = new DIVESceneLight(); testLight.SetEnabled(false); - expect(testLight.visible).toBe(false); + expect(testLight.children[0].visible).toBe(false); + expect(testLight.children[1].visible).toBe(false); }); }); \ No newline at end of file