Skip to content
This repository was archived by the owner on Aug 21, 2024. It is now read-only.
Open
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
c941edc
doc: Fix license plate formatting on `FogSettingsComponent.test.tsx`
heysokam Aug 1, 2024
250766a
tst: Sketch for `FogSettingsComponent` Unit Tests
heysokam Aug 1, 2024
10800e6
tst: Sketch for `FogShaders.ts` Unit Tests
heysokam Aug 1, 2024
c23deb3
tst: Sketch for `GroupComponent.tsx` Unit Tests
heysokam Aug 1, 2024
3d74e1f
tst: Sketch for `HighlightComponent.ts` Unit Tests
heysokam Aug 1, 2024
29db8b4
tst: Sketch for `InfiniteGridHelper.ts` Unit Tests
heysokam Aug 1, 2024
9fee81f
tst: Sketch for `LineSegmentComponent.ts` Unit Tests
heysokam Aug 1, 2024
74865be
fix: Standarize the name property of `MeshComponent`
heysokam Aug 1, 2024
990b08b
tst: Sketch for `MeshComponent.tsx` Unit Tests
heysokam Aug 1, 2024
0676e89
tst: Sketch for `Object3DComponent.ts` Unit Tests
heysokam Aug 1, 2024
8a6bf35
tst: Sketch for `ObjectLayerComponent.tsx` Unit Tests
heysokam Aug 1, 2024
47f9628
tst: Sketch for `PostProcessingComponent.tsx` Unit Tests
heysokam Aug 1, 2024
922b682
tst: Sketch for `VisibleComponent.ts` Unit Tests
heysokam Aug 1, 2024
bf3e6ca
tst: Sketch for `SceneComponent.tsx` Unit Tests
heysokam Aug 1, 2024
e6b942a
Merge branch 'dev' into IR-3459-unit-test-spatial-renderer-components…
heysokam Aug 1, 2024
31cf776
Merge branch 'dev' into IR-3459-unit-test-spatial-renderer-components…
heysokam Aug 6, 2024
f43da08
fix: Standarize the name property of `InfiniteGridComponent`
heysokam Aug 6, 2024
dc70992
tst: Unit Tests for `FogSettingsComponent`
heysokam Aug 6, 2024
12b96e7
tst: Unit Tests for `FogShaders.ts`
heysokam Aug 6, 2024
1f403f4
tst: Unit Tests for `VisibleComponent.ts`
heysokam Aug 6, 2024
bd8164b
tst: Unit Tests for `PostProcessingComponent.tsx`
heysokam Aug 6, 2024
7d03349
Merge branch 'dev' into IR-3459-unit-test-spatial-renderer-components…
heysokam Aug 6, 2024
f5f3c3b
fix: Standarize the name property of `Object3DComponent`
heysokam Aug 6, 2024
0a4b114
tst: Unit Tests for `Object3DComponent.ts`
heysokam Aug 7, 2024
8e28e55
Merge branch 'dev' into IR-3459-unit-test-spatial-renderer-components…
heysokam Aug 7, 2024
d60f2d7
tst: Move the `OutlineEffect` test to `HighlightCompoment.test.tsx`
heysokam Aug 7, 2024
1d07548
tst: UnitTests for `HighlightComponent.ts` (phase 1)
heysokam Aug 7, 2024
f2abe2d
tst: UnitTests for `SceneComponent.tsx`
heysokam Aug 7, 2024
9ed3fc2
Merge branch 'dev' into IR-3459-unit-test-spatial-renderer-components…
heysokam Aug 8, 2024
dadff69
doc: Improve `EntityTree.traverseEntityNode` documentation comments
heysokam Aug 8, 2024
53786d2
tst: UnitTests for `HighlightComponent.ts` (phase 2)
heysokam Aug 8, 2024
0e6c276
Merge branch 'dev' into IR-3459-unit-test-spatial-renderer-components…
heysokam Aug 8, 2024
a76c233
tst: UnitTests for `LineSegmentComponent.tsx`
heysokam Aug 9, 2024
5ad0cae
Merge branch 'dev' into IR-3459-unit-test-spatial-renderer-components…
heysokam Aug 9, 2024
7b2e504
tst: UnitTests for `InfiniteGridHelper.ts` (phase 1)
heysokam Aug 9, 2024
9a97528
Merge branch 'dev' into IR-3459-unit-test-spatial-renderer-components…
heysokam Aug 9, 2024
c740165
tst: New assertion helper functions for matrices
heysokam Aug 13, 2024
a46d92f
tst: UnitTests for `GroupComponent.tsx` (phase 1)
heysokam Aug 13, 2024
1db8ebd
Merge branch 'dev' into IR-3459-unit-test-spatial-renderer-components…
heysokam Aug 13, 2024
3a8eefa
tst: UnitTests for `MeshComponent.ts` (phase 1)
heysokam Aug 13, 2024
566647e
doc: Improve doc-comments for `ObjectLayerMaskComponent.onSet`
heysokam Aug 13, 2024
9223d94
tst: UnitTests for `ObjectLayerComponent.ts` (phase 1)
heysokam Aug 13, 2024
46f71c4
Merge branch 'dev' into IR-3459-unit-test-spatial-renderer-components…
heysokam Aug 13, 2024
54b1c22
tst: UnitTests for `ObjectLayerComponent.ts` (phase 2)
heysokam Aug 14, 2024
8900ca7
Merge branch 'dev' into IR-3459-unit-test-spatial-renderer-components…
heysokam Aug 14, 2024
c1fa591
tst: UnitTests for `GroupComponent.tsx` (phase 2)
heysokam Aug 15, 2024
5547db7
tst: UnitTests for `InfiniteGridHelper.ts` (phase 2)
heysokam Aug 15, 2024
8a8d826
tst: UnitTests for `ObjectLayerComponent.ts` (phase 3)
heysokam Aug 15, 2024
9ae468f
Merge branch 'dev' into IR-3459-unit-test-spatial-renderer-components…
heysokam Aug 15, 2024
e70c6e5
tst: UnitTests for `MeshComponent.ts` (phase 2)
heysokam Aug 16, 2024
0ce66c4
Merge branch 'dev' into IR-3459-unit-test-spatial-renderer-components…
heysokam Aug 16, 2024
624d4b0
tst: UnitTests for `ObjectLayerComponent.ts` (phase 4)
heysokam Aug 16, 2024
8cd34d9
tst: UnitTests for `HighlightComponent.ts` (phase 3)
heysokam Aug 16, 2024
60a4df9
Merge branch 'dev' into IR-3459-unit-test-spatial-renderer-components…
heysokam Aug 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
tst: UnitTests for ObjectLayerComponent.ts (phase 3)
  • Loading branch information
heysokam committed Aug 15, 2024
commit 8a8d82626562a2da846614ff5423f53e925b0342
331 changes: 318 additions & 13 deletions packages/spatial/src/renderer/components/ObjectLayerComponent.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -588,20 +588,325 @@ describe('ObjectLayerComponents', () => {
})
}) //:: IDs

describe('onSet', () => {}) //:: onSet
describe('onRemove', () => {}) //:: onRemove
describe('onSet', () => {
let testEntity = UndefinedEntity

beforeEach(async () => {
createEngine()
testEntity = createEntity()
})

afterEach(() => {
removeEntity(testEntity)
return destroyEngine()
})

it('should activate the bit for the respective layer ID in ObjectLayerMaskComponent.mask[entity]', () => {
const Layer = 10
setComponent(testEntity, ObjectLayerComponents[Layer])
const hasLayer = Boolean(ObjectLayerMaskComponent.mask[testEntity] & (1 << Layer)) // true when mask contains the Layer bit
assert.equal(hasLayer, true)
})
}) //:: onSet

describe('onRemove', () => {
let testEntity = UndefinedEntity

beforeEach(async () => {
createEngine()
testEntity = createEntity()
})

afterEach(() => {
removeEntity(testEntity)
return destroyEngine()
})

it('should deactivate the bit for the respective layer ID in ObjectLayerMaskComponent.mask[entity]', () => {
const Layer = 10
setComponent(testEntity, ObjectLayerComponents[Layer])
const before = Boolean(ObjectLayerMaskComponent.mask[testEntity] & (1 << Layer)) // true when mask contains the Layer bit
assert.equal(before, true)
removeComponent(testEntity, ObjectLayerComponents[Layer])
const hasLayer = Boolean(ObjectLayerMaskComponent.mask[testEntity] & (1 << Layer)) // true when mask contains the Layer bit
assert.equal(hasLayer, false)
})
}) //:: onRemove
})

describe('Layer', () => {
describe('constructor', () => {}) //:: constructor
describe('get mask', () => {}) //:: get mask
describe('set mask', () => {}) //:: set mask
describe('set', () => {}) //:: set
describe('enable', () => {}) //:: enable
describe('enableAll', () => {}) //:: enableAll
describe('toggle', () => {}) //:: toggle
describe('disable', () => {}) //:: disable
describe('disableAll', () => {}) //:: disableAll
describe('test', () => {}) //:: test
describe('isEnabled', () => {}) //:: isEnabled
describe('constructor', () => {
let testEntity = UndefinedEntity

beforeEach(async () => {
createEngine()
testEntity = createEntity()
})

afterEach(() => {
removeEntity(testEntity)
return destroyEngine()
})

it("should add an ObjectLayerMaskComponent component to the entity if it doesn't have one", () => {
assert.equal(hasComponent(testEntity, ObjectLayerMaskComponent), false)
const result = new Layer(testEntity)
assert.equal(hasComponent(testEntity, ObjectLayerMaskComponent), true)
})
}) //:: constructor

describe('get mask', () => {
let testEntity = UndefinedEntity

beforeEach(async () => {
createEngine()
testEntity = createEntity()
})

afterEach(() => {
removeEntity(testEntity)
return destroyEngine()
})

it("should get the mask contained in the ObjectLayerMaskComponent.mask array, for the entity described in the class's data", () => {
const layer = new Layer(testEntity)
assert.equal(layer.mask, ObjectLayerMaskComponent.mask[testEntity])
})
}) //:: get mask

describe('set mask', () => {
let testEntity = UndefinedEntity

beforeEach(async () => {
createEngine()
testEntity = createEntity()
})

afterEach(() => {
removeEntity(testEntity)
return destroyEngine()
})

it("should set the mask contained in the ObjectLayerMaskComponent.mask array, for the entity described in the class's data, to the value given in the assignment statement", () => {
const Expected = 42
const layer = new Layer(testEntity)
assert.notEqual(ObjectLayerMaskComponent.mask[testEntity], Expected)
assert.equal(ObjectLayerMaskComponent.mask[testEntity], layer.mask)
layer.mask = Expected
assert.equal(ObjectLayerMaskComponent.mask[testEntity], Expected)
})
}) //:: set mask

describe('set', () => {
let testEntity = UndefinedEntity

beforeEach(async () => {
createEngine()
testEntity = createEntity()
})

afterEach(() => {
removeEntity(testEntity)
return destroyEngine()
})

it("should set the given `@param channel` layer into the ObjectLayerMaskComponent of the entity described by the class's data", () => {
const Expected = 10
const layer = new Layer(testEntity)
layer.set(Expected)
assert.equal(hasComponent(testEntity, ObjectLayerMaskComponent), true)
assert.equal(hasComponent(testEntity, ObjectLayerComponents[Expected]), true)
assert.equal(getComponent(testEntity, ObjectLayerMaskComponent), 1 << Expected)
})
}) //:: set

describe('enable', () => {
let testEntity = UndefinedEntity

beforeEach(async () => {
createEngine()
testEntity = createEntity()
})

afterEach(() => {
removeEntity(testEntity)
return destroyEngine()
})

it("should add the ObjectLayerComponent with ID `@param layer` to the entity and add an ObjectLayerMaskComponent to the entity if it doesn't have one", () => {
const ID = 10
assert.equal(hasComponent(testEntity, ObjectLayerComponents[ID]), false)
assert.equal(hasComponent(testEntity, ObjectLayerMaskComponent), false)
const layer = new Layer(testEntity)
layer.enable(ID)
assert.equal(hasComponent(testEntity, ObjectLayerComponents[ID]), true)
assert.equal(hasComponent(testEntity, ObjectLayerMaskComponent), true)
})
}) //:: enable

describe('enableAll', () => {
let testEntity = UndefinedEntity

beforeEach(async () => {
createEngine()
testEntity = createEntity()
})

afterEach(() => {
removeEntity(testEntity)
return destroyEngine()
})

it("should activate all ObjectLayers for the entity described in the class's data", () => {
for (const component of ObjectLayerComponents) assert.equal(hasComponent(testEntity, component), false)
const layer = new Layer(testEntity)
layer.enableAll()
for (const component of ObjectLayerComponents) assert.equal(hasComponent(testEntity, component), true)
})
}) //:: enableAll

describe('toggle', () => {
let testEntity = UndefinedEntity

beforeEach(async () => {
createEngine()
testEntity = createEntity()
})

afterEach(() => {
removeEntity(testEntity)
return destroyEngine()
})

it("should add the ObjectLayerComponent with ID `@param layer` to the entity if it doesn't have one", () => {
const ID = 10
assert.equal(hasComponent(testEntity, ObjectLayerComponents[ID]), false)
const layer = new Layer(testEntity)
layer.toggle(ID)
assert.equal(hasComponent(testEntity, ObjectLayerComponents[ID]), true)
})

/**
// @todo After the issues with testing toggleLayer removal are fixed in its unit test on this file
it("should remove the ObjectLayerComponent with ID `@param layer` to the entity if it already has it", () => {})
*/
}) //:: toggle

describe('disable', () => {
let testEntity = UndefinedEntity

beforeEach(async () => {
createEngine()
testEntity = createEntity()
})

afterEach(() => {
removeEntity(testEntity)
return destroyEngine()
})

it("should remove the ObjectLayerComponent with ID `@param layer` from the entity described in the class's data", () => {
const ID = 10
const layer = new Layer(testEntity)
setComponent(testEntity, ObjectLayerComponents[ID])
assert.equal(hasComponent(testEntity, ObjectLayerComponents[ID]), true)
layer.disable(ID)
assert.equal(hasComponent(testEntity, ObjectLayerComponents[ID]), false)
})
}) //:: disable

describe('disableAll', () => {
let testEntity = UndefinedEntity

beforeEach(async () => {
createEngine()
testEntity = createEntity()
})

afterEach(() => {
removeEntity(testEntity)
return destroyEngine()
})

it("should remove all ObjectLayers from the entity described in the class's data", () => {
for (const component of ObjectLayerComponents) assert.equal(hasComponent(testEntity, component), false)
const layer = new Layer(testEntity)
for (const component of ObjectLayerComponents) setComponent(testEntity, component)
layer.disableAll()
for (const component of ObjectLayerComponents) assert.equal(hasComponent(testEntity, component), false)
})
}) //:: disableAll

describe('test', () => {
let oneEntity = UndefinedEntity
let twoEntity = UndefinedEntity

beforeEach(async () => {
createEngine()
oneEntity = createEntity()
twoEntity = createEntity()
})

afterEach(() => {
removeEntity(oneEntity)
removeEntity(twoEntity)
return destroyEngine()
})

it("should return true when the entity's mask contains all layers of the `@param layers` mask", () => {
const Mask = (1 << 8) | (1 << 4) | (1 << 2)
const layerA = new Layer(oneEntity)
const layerB = new Layer(twoEntity)
layerA.set(Mask)
const before = layerA.test(layerB)
assert.equal(before, false)
layerB.set(Mask)
const result = layerA.test(layerB)
assert.equal(result, true)
})

it("should return false when the entity's mask does not contain all layers of the `@param layers` mask", () => {
const Mask1 = (1 << 8) | (1 << 4) | (1 << 2)
const Mask2 = (1 << 8) | (1 << 4)
const layerA = new Layer(oneEntity)
const layerB = new Layer(twoEntity)
layerA.set(Mask1)
const before = layerA.test(layerB)
assert.equal(before, false)
layerB.set(Mask2)
const result = layerA.test(layerB)
assert.equal(result, false)
})
}) //:: test

describe('isEnabled', () => {
let testEntity = UndefinedEntity

beforeEach(async () => {
createEngine()
testEntity = createEntity()
})

afterEach(() => {
removeEntity(testEntity)
return destroyEngine()
})

it("should return false when the entity's mask does not contain the `@param channel` layer", () => {
const ID = 10
const Other = 4
const layer = new Layer(testEntity)
assert.equal(layer.isEnabled(ID), false)
layer.enable(Other)
assert.equal(layer.isEnabled(ID), false)
})

it("should return true when the entity's mask contains the `@param channel` layer", () => {
const ID = 10
const layer = new Layer(testEntity)
assert.equal(layer.isEnabled(ID), false)
layer.enable(ID)
assert.equal(layer.isEnabled(ID), true)
})
}) //:: isEnabled
}) //:: Layer