Skip to content
This repository has been archived by the owner on Jun 10, 2022. It is now read-only.

Commit

Permalink
Add reparenting functional test (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
eanders-ms authored Feb 4, 2019
1 parent 9490392 commit 8f403a2
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 36 deletions.
72 changes: 36 additions & 36 deletions packages/functional-tests/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import InterpolationTest from './tests/interpolation-test';
import LookAtTest from './tests/look-at-test';
import MutableAssetTest from './tests/mutable-asset-test';
import PrimitivesTest from './tests/primitives-test';
import ReparentTest from './tests/reparent-test';
import RigidBodyTest from './tests/rigid-body-test';
import Test from './tests/test';
import TextTest from './tests/text-test';
Expand Down Expand Up @@ -53,6 +54,7 @@ export default class App {
'look-at-test': (user: MRESDK.User): Test => new LookAtTest(this, this.baseUrl, user),
'mutable-asset-test': (user: MRESDK.User): Test => new MutableAssetTest(this, this.baseUrl, user),
'primitives-test': (): Test => new PrimitivesTest(this, this.baseUrl),
'reparent-test': (): Test => new ReparentTest(this),
'rigid-body-test': (): Test => new RigidBodyTest(this),
'text-test': (): Test => new TextTest(this),
'user-test': (user: MRESDK.User): Test => new UserTest(this, this.baseUrl, user),
Expand Down Expand Up @@ -148,44 +150,42 @@ export default class App {
private async displayFunctionalTestChoices(rootActor: MRESDK.ActorLike): Promise<string> {
return new Promise<string>((resolve) => {
let y = 0.3;
for (const key in this.testFactories) {
if (this.testFactories.hasOwnProperty(key)) {
const button = MRESDK.Actor.CreatePrimitive(this.context, {
definition: {
shape: MRESDK.PrimitiveShape.Box,
dimensions: { x: 0.3, y: 0.3, z: 0.01 }
},
addCollider: true,
actor: {
name: key,
parentId: rootActor.id,
transform: {
position: { x: 0, y, z: 0 }
}
for (const key of Object.keys(this.testFactories).sort().reverse()) {
const button = MRESDK.Actor.CreatePrimitive(this.context, {
definition: {
shape: MRESDK.PrimitiveShape.Box,
dimensions: { x: 0.3, y: 0.3, z: 0.01 }
},
addCollider: true,
actor: {
name: key,
parentId: rootActor.id,
transform: {
position: { x: 0, y, z: 0 }
}
});

const buttonBehavior = button.value.setBehavior(MRESDK.ButtonBehavior);
buttonBehavior.onClick('released', (userId: string) => {
resolve(button.value.name);
});

MRESDK.Actor.CreateEmpty(this.context, {
actor: {
name: 'label',
parentId: rootActor.id,
text: {
contents: key,
height: 0.5,
anchor: MRESDK.TextAnchorLocation.MiddleLeft
},
transform: {
position: { x: 0.5, y, z: 0 }
}
}
});

const buttonBehavior = button.value.setBehavior(MRESDK.ButtonBehavior);
buttonBehavior.onClick('released', (userId: string) => {
resolve(button.value.name);
});

MRESDK.Actor.CreateEmpty(this.context, {
actor: {
name: 'label',
parentId: rootActor.id,
text: {
contents: key,
height: 0.5,
anchor: MRESDK.TextAnchorLocation.MiddleLeft
},
transform: {
position: { x: 0.5, y, z: 0 }
}
});
y = y + 0.5;
}
}
});
y = y + 0.5;
}
});
}
Expand Down
1 change: 1 addition & 0 deletions packages/functional-tests/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import App from './app';
process.on('uncaughtException', (err) => console.log('uncaughtException', err));
process.on('unhandledRejection', (reason) => console.log('unhandledRejection', reason));

log.enable('app');
// log.enable('network');

// Start listening for connections, and serve static files
Expand Down
91 changes: 91 additions & 0 deletions packages/functional-tests/src/tests/reparent-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*!
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/

import * as MRESDK from '@microsoft/mixed-reality-extension-sdk';
import App from '../app';
import delay from '../utils/delay';
import destroyActors from '../utils/destroyActors';
import Test from './test';

export default class ReparentTest extends Test {
private sceneRoot: MRESDK.Actor;
private running = true;

constructor(app: App) {
super(app);
}

public async run(): Promise<boolean> {
this.sceneRoot = MRESDK.Actor.CreateEmpty(this.app.context).value;
const runningTestPromise = this.runTest();
const timeout = setTimeout(() => this.running = false, 60000);
await runningTestPromise;
clearTimeout(timeout);
destroyActors(this.sceneRoot);
return true;
}

private async runTest() {
MRESDK.Actor.CreateEmpty(this.app.context, {
actor: {
parentId: this.sceneRoot.id,
transform: {
position: { y: 3 }
},
text: {
contents:
'Reparenting Test\n' +
'Sphere should be jumping left and right\n' +
'Click to exit (or wait a minute)',
anchor: MRESDK.TextAnchorLocation.TopCenter,
justify: MRESDK.TextJustify.Center,
height: 0.4,
color: MRESDK.Color3.Yellow()
}
}
});
const leftParent = MRESDK.Actor.CreateEmpty(this.app.context, {
actor: {
parentId: this.sceneRoot.id,
transform: {
position: { x: -1, y: 1 }
}
}
}).value;
const rightParent = MRESDK.Actor.CreateEmpty(this.app.context, {
actor: {
parentId: this.sceneRoot.id,
transform: {
position: { x: 1, y: 1 }
}
}
}).value;

const sphere = MRESDK.Actor.CreatePrimitive(this.app.context, {
definition: {
shape: MRESDK.PrimitiveShape.Sphere,
radius: 0.25
},
addCollider: true,
actor: {
parentId: leftParent.id
}
}).value;

let currParent = 0;
const parentIds = [leftParent.id, rightParent.id];

const buttonBehavior = sphere.setBehavior(MRESDK.ButtonBehavior);
buttonBehavior.onClick('released', () => this.running = false);

while (this.running) {
for (let i = 0; i < 10 && this.running; ++i) {
await delay(100);
}
currParent = 1 - currParent;
sphere.parentId = parentIds[currParent];
}
}
}

0 comments on commit 8f403a2

Please sign in to comment.