Skip to content

Commit

Permalink
fix(scene): fix Scene Hierarchy Tree item for node with no components
Browse files Browse the repository at this point in the history
  • Loading branch information
haweston committed Mar 6, 2024
1 parent 00c1707 commit e341fa5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test.describe('scene-composer--local-scene', () => {

test('get object by name', async ({ page }) => {
const state = new PlaywrightHelper(page, localScene);
const palletJack = await state.getObjecByName('PalletJack');
const palletJack = await state.getObjectByName('PalletJack');

// assert expected values on object
expect(palletJack.isObject3D).toBeTruthy();
Expand All @@ -30,7 +30,7 @@ test.describe('scene-composer--local-scene', () => {

test('validate hierarchy interaction', async ({ page }) => {
const state = new PlaywrightHelper(page, localScene);
const palletJack = await state.getObjecByName('PalletJack');
const palletJack = await state.getObjectByName('PalletJack');
// select object in hierarchy
await page.getByTestId(palletJack.userData.componentRef).click();

Expand Down
12 changes: 6 additions & 6 deletions packages/scene-composer/e2e/tests/utils/sceneHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ export class PlaywrightHelper {
this.localScene = localScene;
}

async goto(localScene: string) {
async goto(localScene: string): Promise<void> {
await this.page.goto(localScene);
}

async getFrame(localFrame: string) {
async getFrame(localFrame: string): Promise<Locator> {
return this.page.locator(localFrame);
}

async getSceneId(frame: Locator) {
async getSceneId(frame: Locator): Promise<string> {
const sceneId: string = await frame.evaluate(async () => {
return await new Promise((res, rej) => {
const timer = setTimeout(
Expand All @@ -64,14 +64,14 @@ export class PlaywrightHelper {
return sceneId;
}

async tmScene(frame: Locator, sceneId: string) {
async tmScene(frame: Locator, sceneId: string): Promise<Scene> {
const sceneResult = await frame.evaluate((_element: HTMLElement, sceneId: string) => {
return Promise.resolve<Scene>(window['__twinmaker_tests'][sceneId].scene);
}, sceneId);
return sceneResult;
}

async getScene() {
async getScene(): Promise<{ frame: Locator; sceneId: string; scene: Scene }> {
await this.page.goto(this.localScene);
const frame = this.page.locator('#root');
const sceneId = await this.getSceneId(frame);
Expand Down Expand Up @@ -107,7 +107,7 @@ export class PlaywrightHelper {
}

// map harness functions here
async getObjecByName(name: string) {
async getObjectByName(name: string) {
return await this.playwrightState('getObjecByName', name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const SceneHierarchyTreeItem: FC<SceneHierarchyTreeItemProps> = ({
key={key}
labelNode={
<SceneNodeLabel
dataTestid={node?.components[0].ref}
dataTestid={node?.components && node.components.length > 0 ? node?.components[0].ref : undefined}
objectRef={key}
labelText={labelText}
componentTypes={componentTypes}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ export const SceneNodeInspectorPanel: React.FC = () => {
>
<FormField label={intl.formatMessage({ defaultMessage: 'Name', description: 'Form field label' })}>
<TextInput
data-testid={`ip-${selectedSceneNode.components[0].ref}`}
data-testid={
selectedSceneNode.components.length > 0 ? `ip-${selectedSceneNode.components[0].ref}` : undefined
}
value={selectedSceneNode.name}
setValue={(e) => handleInputChanges({ name: e?.toString() })}
/>
Expand Down

0 comments on commit e341fa5

Please sign in to comment.