Commit bbda8a8
authored
Fix select value being reset when toggling popup via User fixture (#5670)
### Motivation
Fixes #4894
When using the `User` fixture to test select elements, clicking a select
found by its label (e.g., `user.find('Fruit').click()`) to toggle the
popup would incorrectly reset the select's value to `None`.
The bug occurred because the click handler used `self.target` (which was
the label like `'Fruit'`) as the value to set. Since the label is not a
valid option in the select's options list, this triggered validation
that set the value to `None`.
### Implementation
Before setting the value, the code now checks if `self.target` is
actually a valid option:
- For list options: checks if `self.target in element._values`
- For dict options: checks if any option label matches `self.target`
If the target is not a valid option (meaning the user clicked the select
itself, not an option), the code just toggles the popup state without
modifying the value.
### Progress
- [x] I chose a meaningful title that completes the sentence: "If
applied, this PR will..."
- [x] The implementation is complete.
- [x] This is not a security issue.
- [x] Pytests have been added.
- [x] Documentation is not necessary.1 parent 3db2617 commit bbda8a8
File tree
2 files changed
+33
-9
lines changed- nicegui/testing
- tests
2 files changed
+33
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | | - | |
| 75 | + | |
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
| 86 | + | |
87 | 87 | | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
94 | 96 | | |
| 97 | + | |
95 | 98 | | |
96 | 99 | | |
97 | | - | |
| 100 | + | |
98 | 101 | | |
99 | 102 | | |
100 | 103 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
511 | 511 | | |
512 | 512 | | |
513 | 513 | | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
514 | 535 | | |
515 | 536 | | |
516 | 537 | | |
| |||
0 commit comments