@@ -26,7 +26,9 @@ describe('Text component', function() {
2626 const d3 = require ( 'd3' )
2727 const init_variable = sinon . spy ( )
2828 const set_variable = sinon . spy ( )
29- const state_handler = { init_variable, set_variable }
29+ const get_state = sinon . stub ( ) . returns ( args . state || { } )
30+ const subscribe = sinon . spy ( )
31+ const state_handler = { init_variable, set_variable, get_state, subscribe }
3032 const component_args = Object . assign ( args . args , {
3133 state_handler
3234 } )
@@ -139,5 +141,17 @@ describe('Text component', function() {
139141 set_variable . should . be . calledWith ( 'my_var' , 'baz' )
140142 } )
141143
144+ it ( 'correct value should be selected based on state' , ( ) => {
145+ const d3 = require ( 'd3' )
146+ const { set_variable } = call_render_with ( {
147+ 'args' : { 'variable' : 'my_var' , 'default' : '0' } ,
148+ 'state' : { 'my_var' : 1 } ,
149+ 'data' : [
150+ { 'text' : 'foo' , 'value' : '0' } ,
151+ { 'text' : 'bar' , 'value' : '1' } ,
152+ ] } )
153+ assert . equal ( d3 . select ( 'select' ) . node ( ) . value , '1' )
154+ } )
155+
142156} )
143157
0 commit comments