1
- import { mountedComponent , screen } from "../../../../../test-utils" ;
1
+ import { fromJS } from "immutable" ;
2
+ import { mountedComponent , screen , userEvent } from "../../../../../test-utils" ;
2
3
import { FieldRecord , FormSectionRecord } from "../../../records" ;
3
4
import { TEXT_FIELD } from "../../../constants" ;
4
5
@@ -46,7 +47,7 @@ describe("<SubformDialogFields />", () => {
46
47
describe ( "when a field of a subform is also a subform" , ( ) => {
47
48
const subFormProps = {
48
49
mode : { isShow : true } ,
49
- formSection : { unqique_id : "test_id" } ,
50
+ formSection : { unique_id : "test_id" } ,
50
51
recordType : "cases" ,
51
52
recordModuleID : "primeromodule-cp" ,
52
53
parentValues : { } ,
@@ -60,6 +61,7 @@ describe("<SubformDialogFields />", () => {
60
61
unique_id : "perpetratorsId" ,
61
62
visible : true ,
62
63
type : "subform" ,
64
+ display_name : { en : "Perpetrators Subform" } ,
63
65
subform_section_id : FormSectionRecord ( {
64
66
unique_id : "perpetrators" ,
65
67
fields : [
@@ -79,7 +81,17 @@ describe("<SubformDialogFields />", () => {
79
81
80
82
it ( "render the SubformFieldSubform" , ( ) => {
81
83
mountedComponent ( < SubformDialogFields { ...subFormProps } /> , { } , [ ] , { } , { registerField : ( ) => { } } ) ;
82
- expect ( screen . getByTestId ( "subform-field-subform" ) ) . toBeInTheDocument ( 1 ) ;
84
+ expect ( screen . getByTestId ( "subform-field-subform" ) ) . toBeInTheDocument ( ) ;
85
+ } ) ;
86
+
87
+ it ( "render the SubformField" , ( ) => {
88
+ mountedComponent ( < SubformDialogFields { ...subFormProps } /> , { } , [ ] , { } , { registerField : ( ) => { } } ) ;
89
+ expect ( screen . getByTestId ( "subform-field" ) ) . toBeInTheDocument ( ) ;
90
+ } ) ;
91
+
92
+ it ( "render the subform" , ( ) => {
93
+ mountedComponent ( < SubformDialogFields { ...subFormProps } /> , { } , [ ] , { } , { registerField : ( ) => { } } ) ;
94
+ expect ( screen . getByText ( "Perpetrators Subform" ) ) . toBeInTheDocument ( ) ;
83
95
} ) ;
84
96
} ) ;
85
97
@@ -114,4 +126,82 @@ describe("<SubformDialogFields />", () => {
114
126
expect ( screen . getAllByTestId ( "form-section-field" ) ) . toHaveLength ( 1 ) ;
115
127
} ) ;
116
128
} ) ;
129
+
130
+ describe ( "when a field has tag properties" , ( ) => {
131
+ const tagProps = {
132
+ mode : { isEdit : true } ,
133
+ formSection : { unique_id : "test_id" } ,
134
+ field : FieldRecord ( {
135
+ name : "attack_on_hospitals" ,
136
+ subform_section_id : FormSectionRecord ( {
137
+ unique_id : "attack_on_hospitals" ,
138
+ fields : [
139
+ FieldRecord ( {
140
+ name : "facility_attack_type" ,
141
+ visible : true ,
142
+ type : "select_box" ,
143
+ multiple : true ,
144
+ option_strings_source : "lookup lookup-facility-attack-type" ,
145
+ option_strings_condition : {
146
+ hospitals : { in : { violation_category : [ "attack_on_hospitals" ] } }
147
+ }
148
+ } )
149
+ ]
150
+ } )
151
+ } ) ,
152
+ recordType : "cases" ,
153
+ recordModuleID : "primeromodule-cp" ,
154
+ values : { } ,
155
+ parentValues : {
156
+ violation_category : [ "attack_on_hospitals" , "killing" ]
157
+ }
158
+ } ;
159
+
160
+ const stateWithLookups = fromJS ( {
161
+ forms : {
162
+ options : {
163
+ lookups : [
164
+ {
165
+ id : 1 ,
166
+ name : { en : "Facility Attack Type" } ,
167
+ unique_id : "lookup-facility-attack-type" ,
168
+ values : [
169
+ { id : "attack_on_hospitals" , display_text : { en : "Attack on hospitals" } , tags : [ "hospitals" ] } ,
170
+ { id : "other" , display_text : { en : "Other" } , tags : [ ] }
171
+ ]
172
+ }
173
+ ]
174
+ }
175
+ }
176
+ } ) ;
177
+
178
+ it ( "renders the options tagged as hospitals if the condition is met" , async ( ) => {
179
+ mountedComponent ( < SubformDialogFields { ...tagProps } /> , stateWithLookups , [ ] , { } , { registerField : ( ) => { } } ) ;
180
+ const user = userEvent . setup ( ) ;
181
+
182
+ const autoCompleteDropdown = screen . getByRole ( "button" , { name : "Open" } ) ;
183
+
184
+ await user . click ( autoCompleteDropdown ) ;
185
+
186
+ expect ( screen . getByText ( "Attack on hospitals" ) ) . toBeInTheDocument ( ) ;
187
+ } ) ;
188
+
189
+ it ( "renders all options if the condition is not met" , async ( ) => {
190
+ mountedComponent (
191
+ < SubformDialogFields { ...{ ...tagProps , parentValues : { } } } /> ,
192
+ stateWithLookups ,
193
+ [ ] ,
194
+ { } ,
195
+ { registerField : ( ) => { } }
196
+ ) ;
197
+ const user = userEvent . setup ( ) ;
198
+
199
+ const autoCompleteDropdown = screen . getByRole ( "button" , { name : "Open" } ) ;
200
+
201
+ await user . click ( autoCompleteDropdown ) ;
202
+
203
+ expect ( screen . getByText ( "Attack on hospitals" ) ) . toBeInTheDocument ( ) ;
204
+ expect ( screen . getByText ( "Other" ) ) . toBeInTheDocument ( ) ;
205
+ } ) ;
206
+ } ) ;
117
207
} ) ;
0 commit comments