Skip to content

Commit 93dea82

Browse files
committed
[ADD] tests for onchange methods in custom fields UI
1 parent ee1961b commit 93dea82

2 files changed

Lines changed: 105 additions & 0 deletions

File tree

spp_custom_fields_ui/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
## 2025-11-20
44

5+
### 2025-11-20 14:45:00 - [ADD] tests for onchange methods in custom fields UI
6+
7+
- Added test_10_onchange_field_category to test field category changes
8+
- Added test_11_onchange_kinds to test kinds assignment updates
9+
- Added test_12_onchange_target_type to test target type changes
10+
- Added test_13_onchange_has_presence to test presence flag changes
11+
- Improves codecov coverage for onchange methods
12+
513
### 2025-11-20 10:24:55 - [FIX] add safety check to prevent reload on wrong page after navigation
614

715
- Added URL verification before executing scheduled page reload

spp_custom_fields_ui/tests/test_custom_fields_ui.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,100 @@ def test_09_set_compute_error_on_type_change(self):
196196
"Changing the type of a field is not yet supported",
197197
):
198198
field.set_compute()
199+
200+
def test_10_onchange_field_category(self):
201+
"""Test _onchange_field_category updates compute field"""
202+
field = self.field_model.create(
203+
{
204+
"name": "x_cst_grp_test_category",
205+
"model_id": self.model_id.id,
206+
"field_description": "Test Category Change",
207+
"ttype": "char",
208+
"state": "manual",
209+
"target_type": "grp",
210+
"field_category": "cst",
211+
}
212+
)
213+
self.assertFalse(field.compute)
214+
215+
# Change to indicator category
216+
field.field_category = "ind"
217+
field.ttype = "integer"
218+
field._onchange_field_category()
219+
220+
self.assertTrue(field.compute, "Compute field should be set when field_category changes to indicator")
221+
222+
def test_11_onchange_kinds(self):
223+
"""Test _onchange_kinds updates compute field"""
224+
field = self.field_model.create(
225+
{
226+
"name": "x_ind_grp_test_kinds",
227+
"model_id": self.model_id.id,
228+
"field_description": "Test Kinds Change",
229+
"draft_name": "test_kinds",
230+
"ttype": "integer",
231+
"state": "manual",
232+
"target_type": "grp",
233+
"field_category": "ind",
234+
}
235+
)
236+
237+
# Add kinds
238+
field.kinds = [(6, 0, [self.kind_head.id])]
239+
field._onchange_kinds()
240+
241+
self.assertTrue(field.compute, "Compute field should be set when kinds are changed")
242+
self.assertIn(self.kind_head.name, field.compute, "Kind name should be in compute field")
243+
244+
def test_12_onchange_target_type(self):
245+
"""Test _onchange_target_type updates compute field"""
246+
field = self.field_model.create(
247+
{
248+
"name": "x_ind_grp_test_target",
249+
"model_id": self.model_id.id,
250+
"field_description": "Test Target Type Change",
251+
"draft_name": "test_target",
252+
"ttype": "integer",
253+
"state": "manual",
254+
"target_type": "grp",
255+
"field_category": "ind",
256+
}
257+
)
258+
field.set_compute()
259+
initial_compute = field.compute
260+
261+
# Change target type
262+
field.target_type = "indv"
263+
field._onchange_target_type()
264+
265+
self.assertTrue(field.compute, "Compute field should be set when target_type changes")
266+
self.assertNotEqual(
267+
initial_compute, field.compute, "Compute field should be different after target_type change"
268+
)
269+
270+
def test_13_onchange_has_presence(self):
271+
"""Test _onchange_has_presence changes field type and compute"""
272+
field = self.field_model.create(
273+
{
274+
"name": "x_ind_indv_test_presence",
275+
"model_id": self.model_id.id,
276+
"field_description": "Test Presence Change",
277+
"draft_name": "test_presence",
278+
"ttype": "integer",
279+
"state": "manual",
280+
"target_type": "indv",
281+
"field_category": "ind",
282+
"has_presence": False,
283+
}
284+
)
285+
286+
# Enable presence
287+
field.has_presence = True
288+
field._onchange_has_presence()
289+
290+
self.assertTrue(field.compute, "Compute field should be set when has_presence is enabled")
291+
self.assertIn(
292+
"presence_only=True",
293+
field.compute,
294+
"Compute field should contain presence_only=True when has_presence is enabled",
295+
)

0 commit comments

Comments
 (0)