Skip to content

Commit

Permalink
Fixed tests after changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
ffrank913 committed Jun 17, 2024
1 parent 6343f5f commit 6a1e8f6
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 15 deletions.
16 changes: 12 additions & 4 deletions src/light/__test__/AmbientLight.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Color } from 'three';
import { AmbientLight, Color, Object3D } from 'three';
import DIVEAmbientLight from '../AmbientLight';

jest.mock('three', () => {
Expand All @@ -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;
}),
}
Expand All @@ -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);
});
});
27 changes: 20 additions & 7 deletions src/light/__test__/PointLight.test.ts
Original file line number Diff line number Diff line change
@@ -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();

Expand All @@ -10,6 +10,7 @@ jest.mock('three', () => {
return {};
}),
PointLight: jest.fn(function () {
this.visible = true;
this.color = {};
this.intensity = 0;
this.layers = {
Expand All @@ -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;
}),
}
Expand All @@ -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', () => {
Expand Down
14 changes: 10 additions & 4 deletions src/light/__test__/SceneLight.test.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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,
};
Expand All @@ -71,6 +75,7 @@ jest.mock('three', () => {
return this;
}),
DirectionalLight: jest.fn(function () {
this.visible = true;
this.layers = {
mask: 0,
};
Expand Down Expand Up @@ -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', () => {
Expand All @@ -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);
});
});

0 comments on commit 6a1e8f6

Please sign in to comment.