Skip to content

Commit f160ca6

Browse files
authored
Merge pull request #95 from Exabyte-io/test/SOF-6005
SOF-6005
2 parents 1f9465c + 33392b3 commit f160ca6

File tree

6 files changed

+151
-93
lines changed

6 files changed

+151
-93
lines changed

package-lock.json

Lines changed: 89 additions & 89 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading

tests/__tests__/components/ThreeDEditor.jsx

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,18 @@ import { mount } from "enzyme";
33
import React from "react";
44

55
import { ThreeDEditor } from "../../../src/components/ThreeDEditor";
6-
import { ELEMENT_PROPERTIES, MATERIAL_CONFIG } from "../../enums";
6+
import { ThreejsEditorModal } from "../../../src/components/ThreejsEditorModal";
7+
import { ELEMENT_PROPERTIES, getWaveInstance, MATERIAL_CONFIG, WAVE_SETTINGS } from "../../enums";
78
import { SELECTORS } from "../../selectors";
8-
import { createElement } from "../../utils";
9+
import { createElement, takeSnapshotAndAssertEqualityAsync } from "../../utils";
10+
import { WaveComponent } from "../../../src/components/WaveComponent";
11+
12+
jest.mock("../../../src/components/ThreejsEditorModal", () => ({
13+
__esModule: true,
14+
ThreejsEditorModal: () => {
15+
return <div data-name="threejs-editor-modal-content" />;
16+
},
17+
}));
918

1019
test("toggleInteractive", () => {
1120
const container = createElement("div", ELEMENT_PROPERTIES);
@@ -46,3 +55,46 @@ test("toggleView", () => {
4655
// assert toggle axes button is visible
4756
expect(wrapper.find(SELECTORS.toggleAxesRoundIconButton).exists()).toBe(true);
4857
});
58+
59+
test("preserve three.js editor changes", async () => {
60+
const container = createElement("div", ELEMENT_PROPERTIES);
61+
const wrapper = mount(<ThreeDEditor material={new Made.Material(MATERIAL_CONFIG)} editable />, {
62+
attachTo: container,
63+
});
64+
65+
// Click on "interactive" button
66+
const interactiveButton = wrapper.find(`${SELECTORS.interactiveIconToolbar} button`);
67+
interactiveButton.prop("onClick")();
68+
wrapper.update();
69+
70+
expect(wrapper.find(SELECTORS.threeDEditorIconToolbar).exists()).toBe(true);
71+
72+
// Click on "Editor" button
73+
const threeDEditorButton = wrapper.find(`${SELECTORS.threeDEditorIconToolbar} button`);
74+
threeDEditorButton.prop("onClick")();
75+
wrapper.update();
76+
77+
// Simulate modifying materials in the editor
78+
const modifiedMaterial = new Made.Material({
79+
...MATERIAL_CONFIG,
80+
basis: {
81+
...MATERIAL_CONFIG.basis,
82+
coordinates: MATERIAL_CONFIG.basis.coordinates.map((coordinate) => ({
83+
...coordinate,
84+
value: coordinate.value.map((axisValue) => axisValue + 0.5),
85+
})),
86+
},
87+
});
88+
const threeJsEditorModal = wrapper.find(ThreejsEditorModal);
89+
threeJsEditorModal.prop("onHide")(modifiedMaterial);
90+
wrapper.update();
91+
92+
// Get updated instance of wave and compare it with snapshot
93+
const { wave } = wrapper.find(WaveComponent).instance();
94+
const waveInstance = getWaveInstance(WAVE_SETTINGS, wave.structure);
95+
96+
return takeSnapshotAndAssertEqualityAsync(
97+
waveInstance.renderer.context,
98+
"preserveThreeJsEditorChanges",
99+
);
100+
});

tests/enums.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ export const WAVE_SETTINGS = {
2424
repetitions: 1,
2525
};
2626

27-
export function getWaveInstance(settings) {
28-
const material = new Made.Material(MATERIAL_CONFIG);
27+
export function getWaveInstance(settings, material = new Made.Material(MATERIAL_CONFIG)) {
2928
return new Wave({
3029
DOMElement: createElement("div", ELEMENT_PROPERTIES),
3130
structure: material,

tests/selectors.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ export const SELECTORS = {
33
exportIconToolbar: '[data-name="Export"]',
44
interactiveIconToolbar: '[data-name="Interactive"]',
55
toggleAxesRoundIconButton: 'button[aria-label="toggle axes"]',
6+
threeDEditorIconToolbar: '[data-name="3DEdit"]',
67
};

0 commit comments

Comments
 (0)