@@ -3,9 +3,18 @@ import { mount } from "enzyme";
3
3
import React from "react" ;
4
4
5
5
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" ;
7
8
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
+ } ) ) ;
9
18
10
19
test ( "toggleInteractive" , ( ) => {
11
20
const container = createElement ( "div" , ELEMENT_PROPERTIES ) ;
@@ -46,3 +55,46 @@ test("toggleView", () => {
46
55
// assert toggle axes button is visible
47
56
expect ( wrapper . find ( SELECTORS . toggleAxesRoundIconButton ) . exists ( ) ) . toBe ( true ) ;
48
57
} ) ;
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
+ } ) ;
0 commit comments