From 7f82c351c9331b8677dd19e7e3560452114b44f0 Mon Sep 17 00:00:00 2001 From: Brian Zinn Date: Fri, 6 Aug 2021 11:56:43 -0700 Subject: [PATCH] add: GlowLayer declarative inclusion list test --- test/hostConfig.spec.ts | 6 +++--- test/render.spec.tsx | 41 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/test/hostConfig.spec.ts b/test/hostConfig.spec.ts index 4ad061c8..63db5ad3 100644 --- a/test/hostConfig.spec.ts +++ b/test/hostConfig.spec.ts @@ -5,7 +5,7 @@ import { CreatedInstance } from '../src/CreatedInstance'; import { CustomProps } from '../src/CustomProps'; import renderer, { Container } from '../src/ReactBabylonJSHostConfig'; import { Engine, FreeCamera, Mesh, NullEngine, PBRMaterial, Scene, StandardMaterial, Vector3 } from '@babylonjs/core'; -import { CameraLifecycleListener, FallbackLifecycleListener, NodeLifecycleListener } from '../src/customHosts'; +import { AbstractMeshLifecycleListener, CameraLifecycleListener, FallbackLifecycleListener } from '../src/customHosts'; import { PBRClearCoatConfiguration } from '@babylonjs/core/Materials/PBR/pbrClearCoatConfiguration'; describe(' > Reconciler tests', function testSuite() { @@ -78,7 +78,7 @@ describe(' > Reconciler tests', function testSuite() { assert.ok(logger.notCalled, 'console.warn should not be called.'); }); - it('Create box (Mesh) should be assigned NodeLifecycleListener', async function test() { + it('Create box (Mesh) should be assigned AbstractMeshLifecycleListener', async function test() { const container = getRootContainerInstance(); const createdInstance: CreatedInstance | undefined = renderer.createInstance('box', { @@ -88,7 +88,7 @@ describe(' > Reconciler tests', function testSuite() { assert.notStrictEqual(createdInstance, undefined); assert.notStrictEqual(createdInstance!.lifecycleListener, undefined); - assert.ok(createdInstance?.lifecycleListener instanceof NodeLifecycleListener, `expecting node lifecycle listener: ${createdInstance?.lifecycleListener}`); + assert.ok(createdInstance?.lifecycleListener instanceof AbstractMeshLifecycleListener, `expecting node lifecycle listener: ${createdInstance?.lifecycleListener}`); }); it('Create "assignFrom" should defer construction and included delayed creation props', async function test() { diff --git a/test/render.spec.tsx b/test/render.spec.tsx index 7f4e6404..89a5ee91 100644 --- a/test/render.spec.tsx +++ b/test/render.spec.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { AbstractMesh, ArcRotateCamera, Camera, Color4, Engine, NullEngine, Scene, Vector3 } from "@babylonjs/core"; +import { AbstractMesh, ArcRotateCamera, Camera, EffectLayer, Engine, GlowLayer, NullEngine, Scene, Vector3 } from "@babylonjs/core"; import sinon from "sinon"; import assert from 'assert'; @@ -142,4 +142,43 @@ describe(' > Reconciler/Render tests', function testSuite() { assert.ok(camera instanceof ArcRotateCamera, 'Should be ArcRotateCamera'); assert.ok(Vector3.Up().equals(camera.target), 'should be the same as Vector3.Up'); }) + + it('GlowLayer should include children to inclusion list (when configured).', async function test() { + const container: Container = getRootContainerInstance(); + const reconciler: ReconcilerInstance = createReconciler({}); + + + const sceneGraph = ( + + + + + + + + + + + ) + reconciler.render(sceneGraph, container, () => { /* empty for now */ }, null) + + const box: AbstractMesh | undefined = container.scene.meshes.find(m => m.name === 'box'); + assert.ok(box !== undefined) + + const effectLayers: EffectLayer[] = container.scene.effectLayers; + assert.strictEqual(1, effectLayers.length, 'glow layer should be part of scene'); + assert.ok(effectLayers[0] instanceof GlowLayer); + + const glowLayer: GlowLayer = effectLayers[0] as GlowLayer; + assert.ok(glowLayer.hasMesh(box)); + assert.strictEqual((glowLayer as any)._includedOnlyMeshes.length, 1); + assert.strictEqual((glowLayer as any)._includedOnlyMeshes[0], box.uniqueId); + }) }) \ No newline at end of file