@@ -4,7 +4,6 @@ import {expect} from 'chai';
44
55import Index from '/react/src/js/index' ;
66import VariableEditor from '/react/src/js/components/VariableEditor' ;
7- import ObjectAttributes from '/react/src/js/stores/ObjectAttributes' ;
87
98
109describe ( '<VariableEditor />' , function ( ) {
@@ -100,55 +99,101 @@ describe('<VariableEditor />', function () {
10099 } ) ;
101100
102101 it ( 'VariableEditor test textarea and submit icon' , function ( ) {
103- const wrapper = mount (
104- < Index
105- src = { { test :true } }
102+ const existing_value = 'existing_value' ;
103+ const new_value = 'new_value' ;
104+ const wrapper = shallow (
105+ < VariableEditor
106+ src = { { test :existing_value } }
106107 theme = 'rjv-default'
107- onEdit = { ( edit ) => { } }
108+ onEdit = { ( edit ) => {
109+ expect ( edit . updated_src . test ) . to . equal ( new_value ) ;
110+ } }
111+ namespace = { [ 'test' ] }
108112 rjvId = { rjvId }
113+ variable = { {
114+ name : 'test' ,
115+ value : existing_value ,
116+ type : 'string'
117+ } }
109118 />
110119 ) ;
120+
121+ //editMode defaluts to off
122+ expect (
123+ wrapper . state ( 'editMode' )
124+ ) . to . equal ( false )
125+ //click to open textarea
111126 wrapper . find ( '.click-to-edit-icon' ) . simulate ( 'click' ) ;
127+ //verify editMode is on
112128 expect (
113- wrapper . state ( 'onEdit' )
114- ) . to . not . equal ( false ) ;
129+ wrapper . state ( 'editMode' )
130+ ) . to . equal ( true )
131+ //make sure default textarea value is correct
115132 expect (
116- wrapper . find ( '.variable-editor' ) . length
117- ) . to . equal ( 1 ) ;
118- wrapper . find ( '.edit-check.string-value' ) . simulate ( 'click' ) ;
133+ wrapper . find ( '.variable-editor' ) . props ( ) . value
134+ ) . to . equal ( existing_value )
135+ //update edit value
136+ wrapper . setState ( { editValue : new_value } )
137+ //submit new value
138+ wrapper . find ( '.edit-check' ) . simulate ( 'click' ) ;
139+ //make sure editMode is off after submit
119140 expect (
120- wrapper . find ( '.variable-editor' ) . length
121- ) . to . equal ( 0 ) ;
141+ wrapper . state ( 'editMode' )
142+ ) . to . equal ( false )
122143 } ) ;
123144
124145 it ( 'VariableEditor edit after src change should respect current src' , function ( ) {
125- const oldSrc = { edited : true , other : 'old' } ;
126- const currentSrc = { edited : true , other : 'current' } ;
127-
128- const wrapper = mount (
129- < Index
130- src = { oldSrc }
131- theme = 'rjv-default'
132- onEdit = { ( edit ) => {
133- expect ( edit . updated_src . other ) . to . equal ( currentSrc . other ) ;
134- return true ;
135- } }
136- rjvId = { rjvId }
146+ const existing_value = 'existing_value' ;
147+ const new_value = 'new_value' ;
148+ const wrapper = shallow (
149+ < VariableEditor
150+ src = { { test :existing_value } }
151+ theme = 'rjv-default'
152+ onEdit = { ( edit ) => {
153+ expect ( edit . updated_src . test ) . to . equal ( new_value ) ;
154+ } }
155+ namespace = { [ 'test' ] }
156+ rjvId = { rjvId }
157+ variable = { {
158+ name : 'test' ,
159+ value : existing_value ,
160+ type : 'string'
161+ } }
137162 />
138163 ) ;
139- wrapper . setProps ( { src : currentSrc } ) ;
140164
141- wrapper . find ( '.click-to-edit-icon' ) . first ( ) . simulate ( 'click' ) ;
165+ //editMode defaluts to off
142166 expect (
143- wrapper . state ( 'onEdit' )
144- ) . to . not . equal ( false ) ;
167+ wrapper . state ( 'editMode' )
168+ ) . to . equal ( false )
169+ //click to open textarea
170+ wrapper . find ( '.click-to-edit-icon' ) . simulate ( 'click' ) ;
171+ //verify editMode is on
145172 expect (
146- wrapper . find ( '.variable-editor' ) . length
147- ) . to . equal ( 1 ) ;
148- wrapper . find ( '.edit-check.string-value' ) . simulate ( 'click' ) ;
173+ wrapper . state ( 'editMode' )
174+ ) . to . equal ( true )
175+ //make sure default textarea value is correct
176+ expect (
177+ wrapper . find ( '.variable-editor' ) . props ( ) . value
178+ ) . to . equal ( existing_value )
179+ //update edit value
180+ wrapper . setState ( { editValue : new_value } )
181+ //cancel update
182+ wrapper . find ( '.edit-cancel' ) . simulate ( 'click' ) ;
183+ //make sure editMode is off after cancel
149184 expect (
150- wrapper . find ( '.variable-editor' ) . length
151- ) . to . equal ( 0 ) ;
185+ wrapper . state ( 'editMode' )
186+ ) . to . equal ( false )
187+ //pop open textarea again
188+ wrapper . find ( '.click-to-edit-icon' ) . simulate ( 'click' ) ;
189+ //make sure editMode is on
190+ expect (
191+ wrapper . state ( 'editMode' )
192+ ) . to . equal ( true )
193+ //make sure that textarea still contains original value
194+ expect (
195+ wrapper . find ( '.variable-editor' ) . props ( ) . value
196+ ) . to . equal ( existing_value )
152197 } ) ;
153198
154199 it ( 'VariableEditor detected null' , function ( ) {
@@ -173,7 +218,7 @@ describe('<VariableEditor />', function () {
173218 wrapper . state ( 'editMode' )
174219 ) . to . equal ( true ) ;
175220 expect (
176- wrapper . find ( '.variable-editor textarea ' ) . props ( ) . value
221+ wrapper . find ( '.variable-editor' ) . props ( ) . value
177222 ) . to . equal ( 'null' ) ;
178223 } ) ;
179224
@@ -199,7 +244,7 @@ describe('<VariableEditor />', function () {
199244 wrapper . state ( 'editMode' )
200245 ) . to . equal ( true ) ;
201246 expect (
202- wrapper . find ( '.variable-editor textarea ' ) . props ( ) . value
247+ wrapper . find ( '.variable-editor' ) . props ( ) . value
203248 ) . to . equal ( 'undefined' ) ;
204249 } ) ;
205250
@@ -225,7 +270,7 @@ describe('<VariableEditor />', function () {
225270 wrapper . state ( 'editMode' )
226271 ) . to . equal ( true ) ;
227272 expect (
228- wrapper . find ( '.variable-editor textarea ' ) . props ( ) . value
273+ wrapper . find ( '.variable-editor' ) . props ( ) . value
229274 ) . to . equal ( 'NaN' ) ;
230275 } ) ;
231276
@@ -251,7 +296,7 @@ describe('<VariableEditor />', function () {
251296 wrapper . state ( 'editMode' )
252297 ) . to . equal ( true ) ;
253298 expect (
254- wrapper . find ( '.variable-editor textarea ' ) . props ( ) . value
299+ wrapper . find ( '.variable-editor' ) . props ( ) . value
255300 ) . to . equal ( 'test' ) ;
256301 } ) ;
257302
@@ -277,7 +322,7 @@ describe('<VariableEditor />', function () {
277322 wrapper . state ( 'editMode' )
278323 ) . to . equal ( true ) ;
279324 expect (
280- wrapper . find ( '.variable-editor textarea ' ) . props ( ) . value
325+ wrapper . find ( '.variable-editor' ) . props ( ) . value
281326 ) . to . equal ( 'function test() {}' ) ;
282327 } ) ;
283328
@@ -303,7 +348,7 @@ describe('<VariableEditor />', function () {
303348 wrapper . state ( 'editMode' )
304349 ) . to . equal ( true ) ;
305350 expect (
306- wrapper . find ( '.variable-editor textarea ' ) . props ( ) . value
351+ wrapper . find ( '.variable-editor' ) . props ( ) . value
307352 ) . to . equal ( '{}' ) ;
308353 } ) ;
309354
@@ -329,7 +374,7 @@ describe('<VariableEditor />', function () {
329374 wrapper . state ( 'editMode' )
330375 ) . to . equal ( true ) ;
331376 expect (
332- wrapper . find ( '.variable-editor textarea ' ) . props ( ) . value
377+ wrapper . find ( '.variable-editor' ) . props ( ) . value
333378 ) . to . equal ( '[1,2,3]' ) ;
334379 } ) ;
335380
@@ -355,7 +400,7 @@ describe('<VariableEditor />', function () {
355400 wrapper . state ( 'editMode' )
356401 ) . to . equal ( true ) ;
357402 expect (
358- wrapper . find ( '.variable-editor textarea ' ) . props ( ) . value
403+ wrapper . find ( '.variable-editor' ) . props ( ) . value
359404 ) . to . equal ( '-5.2' ) ;
360405 } ) ;
361406
@@ -381,7 +426,7 @@ describe('<VariableEditor />', function () {
381426 wrapper . state ( 'editMode' )
382427 ) . to . equal ( true ) ;
383428 expect (
384- wrapper . find ( '.variable-editor textarea ' ) . props ( ) . value
429+ wrapper . find ( '.variable-editor' ) . props ( ) . value
385430 ) . to . equal ( '5' ) ;
386431 } ) ;
387432
0 commit comments