3030 description : nil ,
3131 widget : nil ,
3232 }
33+ enum = {
34+ field : 'enum' ,
35+ type : 'Enum' ,
36+ enums : %w[ a b c ] ,
37+ }
38+
3339 action_definition = {
3440 name : 'my_action' ,
3541 fields : [ foo ] ,
7682 }
7783 }
7884 }
85+ enums_action_definition = {
86+ name : 'enums_action' ,
87+ fields : [ foo , enum ] ,
88+ hooks : {
89+ :change => {
90+ 'foo' => -> ( context ) {
91+ fields = context [ :fields ]
92+ fields [ 'enum' ] [ :enums ] = %w[ c d e ]
93+ return fields
94+ }
95+ }
96+ }
97+ }
7998 action = ForestLiana ::Model ::Action . new ( action_definition )
8099 fail_action = ForestLiana ::Model ::Action . new ( fail_action_definition )
81100 cheat_action = ForestLiana ::Model ::Action . new ( cheat_action_definition )
101+ enums_action = ForestLiana ::Model ::Action . new ( enums_action_definition )
82102 island = ForestLiana . apimap . find { |collection | collection . name . to_s == ForestLiana . name_for ( Island ) }
83- island . actions = [ action , fail_action , cheat_action ]
103+ island . actions = [ action , fail_action , cheat_action , enums_action ]
84104
85105 describe 'call /load' do
86106 params = { recordIds : [ 1 ] , collectionName : 'Island' }
134154 post '/forest/actions/cheat_action/hooks/change' , JSON . dump ( params ) , 'CONTENT_TYPE' => 'application/json'
135155 expect ( response . status ) . to eq ( 500 )
136156 end
157+
158+ it 'should reset value when enums has changed' do
159+ updated_enum = enum . clone . merge ( { :previousValue => nil , :value => 'a' } ) # set value to a
160+ p = { recordIds : [ 1 ] , fields : [ updated_foo , updated_enum ] , collectionName : 'Island' , changedField : 'foo' }
161+ post '/forest/actions/enums_action/hooks/change' , JSON . dump ( p ) , 'CONTENT_TYPE' => 'application/json'
162+ expect ( response . status ) . to eq ( 200 )
163+ expected_enum = updated_enum . clone . merge ( { :enums => %w[ c d e ] , :value => nil } ) . stringify_keys
164+ expect ( JSON . parse ( response . body ) ) . to eq ( { 'fields' => [ updated_foo . stringify_keys , expected_enum ] } )
165+ end
166+
137167 end
138168 end
139169end
0 commit comments