30
30
description : nil ,
31
31
widget : nil ,
32
32
}
33
+ enum = {
34
+ field : 'enum' ,
35
+ type : 'Enum' ,
36
+ enums : %w[ a b c ] ,
37
+ }
38
+
33
39
action_definition = {
34
40
name : 'my_action' ,
35
41
fields : [ foo ] ,
76
82
}
77
83
}
78
84
}
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
+ }
79
98
action = ForestLiana ::Model ::Action . new ( action_definition )
80
99
fail_action = ForestLiana ::Model ::Action . new ( fail_action_definition )
81
100
cheat_action = ForestLiana ::Model ::Action . new ( cheat_action_definition )
101
+ enums_action = ForestLiana ::Model ::Action . new ( enums_action_definition )
82
102
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 ]
84
104
85
105
describe 'call /load' do
86
106
params = { recordIds : [ 1 ] , collectionName : 'Island' }
134
154
post '/forest/actions/cheat_action/hooks/change' , JSON . dump ( params ) , 'CONTENT_TYPE' => 'application/json'
135
155
expect ( response . status ) . to eq ( 500 )
136
156
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
+
137
167
end
138
168
end
139
169
end
0 commit comments