Skip to content

Commit

Permalink
feat(scene composer): adding data-testid to improve e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
mumanity committed Feb 13, 2024
1 parent 3db0c9b commit 1e5ab86
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ test.describe('scene-composer--local-scene', () => {

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

// assert expected values on object
Expand All @@ -29,18 +28,13 @@ test.describe('scene-composer--local-scene', () => {
expect(palletJack.visible).toBeTruthy();
});

test('select object', async ({ page }) => {
test('validate hierarchy interaction', async ({ page }) => {
const state = new PlaywrightHelper(page, localScene);
// find object named 'PalletJack'
const palletJack = await state.getObjecByName('PalletJack');

// select object in hierarchy
const formattedName = palletJack.name.replace(/([A-Z])/g, ' $1').trim();
const handle = await page.$(`text=${formattedName}`);
await handle?.hover();
await handle?.click();
await page.getByTestId(palletJack.userData.componentRef).click();

// assert that the associated selectedSceneNode.ref was selected in the Inspector Panel
expect(page.getByTestId('cb85148b-00ca-4006-8b0f-600890eaee46')).toBeDefined();
// assert that the correct obj is displayed in the Inspector Panel
expect(page.getByTestId(`ip-${palletJack.userData.componentRef}`)).toBeDefined();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,14 @@ const SceneHierarchyTreeItem: FC<SceneHierarchyTreeItemProps> = ({
return (
<EnhancedTreeItem
key={key}
labelNode={<SceneNodeLabel objectRef={key} labelText={labelText} componentTypes={componentTypes} />}
labelNode={
<SceneNodeLabel
dataTestid={node?.components[0].ref}
objectRef={key}
labelText={labelText}
componentTypes={componentTypes}
/>
}
labelText={labelText}
onExpand={onExpandNode}
expanded={expanded}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import { useSceneHierarchyData } from '../../SceneHierarchyDataProvider';
import ComponentTypeIcon from './ComponentTypeIcon';

export interface SceneNodeLabelProps {
dataTestid: string | undefined;
objectRef: string;
labelText: string;
componentTypes?: string[];
}

const SceneNodeLabel: FC<SceneNodeLabelProps> = ({ objectRef, labelText, componentTypes }) => {
const SceneNodeLabel: FC<SceneNodeLabelProps> = ({ dataTestid, objectRef, labelText, componentTypes }) => {
const { toggleObjectVisibility, remove, validationErrors } = useSceneHierarchyData();
const [visible, setVisible] = useState(true);
const error = validationErrors[objectRef];
Expand All @@ -37,7 +38,7 @@ const SceneNodeLabel: FC<SceneNodeLabelProps> = ({ objectRef, labelText, compone
}, [objectRef]);

return (
<span className={`tm-scene-node-label ${error ? 'error' : ''}`.trim()} title={error}>
<span data-testid={dataTestid} className={`tm-scene-node-label ${error ? 'error' : ''}`.trim()} title={error}>
{componentTypeIcons}
<p className='tm-scene-node-label-inner'>{labelText}</p>
<span className='actions'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ describe('SceneNodeLabel', () => {
});

const defaultParams: SceneNodeLabelProps = {
dataTestid: 'testid',
objectRef: '123',
labelText: 'Text',
componentTypes: [KnownComponentType.ModelRef],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ exports[`SceneNodeLabel should allow deleting node if there's errors 1`] = `
<div>
<span
class="tm-scene-node-label error"
data-testid="testid"
title="There is an error"
>
<componenttypeicon
Expand Down Expand Up @@ -32,6 +33,7 @@ exports[`SceneNodeLabel should not render an icon if there is no matching type 1
<div>
<span
class="tm-scene-node-label"
data-testid="testid"
>
<p
class="tm-scene-node-label-inner"
Expand All @@ -51,6 +53,7 @@ exports[`SceneNodeLabel should render with no errors 1`] = `
<div>
<span
class="tm-scene-node-label"
data-testid="testid"
>
<componenttypeicon
type="ModelRef"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export const SceneNodeInspectorPanel: React.FC = () => {
>
<FormField label={intl.formatMessage({ defaultMessage: 'Name', description: 'Form field label' })}>
<TextInput
data-test-id={selectedSceneNode.ref}
data-testid={`ip-${selectedSceneNode.components[0].ref}`}
value={selectedSceneNode.name}
setValue={(e) => handleInputChanges({ name: e?.toString() })}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ exports[`SceneNodeInspectorPanel returns expected elements. SceneNode panel cont
>
<div
data-mocked="Input"
data-test-id="node-ref"
data-testid="ip-undefined"
value="node-name"
/>
</div>
Expand Down Expand Up @@ -648,7 +648,7 @@ exports[`SceneNodeInspectorPanel returns expected elements. disable rotation, hi
>
<div
data-mocked="Input"
data-test-id="node-ref"
data-testid="ip-undefined"
value="node-name"
/>
</div>
Expand Down Expand Up @@ -1057,7 +1057,7 @@ exports[`SceneNodeInspectorPanel returns expected elements. disable rotation, hi
>
<div
data-mocked="Input"
data-test-id="node-ref"
data-testid="ip-undefined"
value="node-name"
/>
</div>
Expand Down Expand Up @@ -1433,7 +1433,7 @@ exports[`SceneNodeInspectorPanel returns expected elements. disable scale and ro
>
<div
data-mocked="Input"
data-test-id="node-ref"
data-testid="ip-undefined"
value="node-name"
/>
</div>
Expand Down Expand Up @@ -1916,7 +1916,7 @@ exports[`SceneNodeInspectorPanel returns expected elements. disable y scale when
>
<div
data-mocked="Input"
data-test-id="node-ref"
data-testid="ip-undefined"
value="node-name"
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ const EntityGroup = ({ node }: IEntityGroupProps): JSX.Element => {
onClick={onClick}
onPointerEnter={onPointerEnter}
onPointerLeave={onPointerLeave}
userData={{ nodeRef, componentTypes }}
userData={{ nodeRef, componentTypes, dataTestId: object3dRef?.current?.uuid }}
>
<ComponentGroup node={node} components={node.components} />
<ChildGroup node={node} />
Expand Down

0 comments on commit 1e5ab86

Please sign in to comment.