-
-
Notifications
You must be signed in to change notification settings - Fork 538
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for ChoiceElement duplicate
self.update()
calls and basic Choic…
…eElement unit testing (#3736) * Fix duplicate `self.update()` call * Add basic unit testing for choice_element * Add test for thing I was complaining about in the first place (lol oops) * Add requested changes
- Loading branch information
1 parent
fe3cbc2
commit d6d4ecd
Showing
2 changed files
with
69 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from nicegui import events, ui | ||
from nicegui.testing import Screen | ||
|
||
def test_radio_click(screen: Screen): | ||
r = ui.radio(['A', 'B', 'C']) | ||
|
||
screen.open('/') | ||
screen.click('A') | ||
assert r.value == 'A' | ||
screen.click('B') | ||
assert r.value == 'B' | ||
|
||
def test_radio_click_already_selected(screen: Screen): | ||
r = ui.radio(['A', 'B', 'C'], value='B') | ||
|
||
screen.open('/') | ||
screen.click('B') | ||
assert r.value == 'B' | ||
|
||
def test_radio_set_value(screen: Screen): | ||
r = ui.radio(['A', 'B', 'C']) | ||
|
||
screen.open('/') | ||
r.set_value('B') | ||
assert r.value == 'B' | ||
|
||
def test_radio_set_options(screen: Screen): | ||
r = ui.radio(['A', 'B', 'C']) | ||
|
||
screen.open('/') | ||
r.set_options(['D', 'E', 'F']) | ||
assert r.options == ['D', 'E', 'F'] | ||
|
||
def test_radio_set_options_value_still_valid(screen: Screen): | ||
r = ui.radio(['A', 'B', 'C'], value='C') | ||
|
||
screen.open('/') | ||
r.set_options(['C', 'D', 'E']) | ||
assert r.value == 'C' | ||
|
||
def test_radio_set_options_value_none(screen: Screen): | ||
r = ui.radio(['A', 'B', 'C'], value='C') | ||
|
||
screen.open('/') | ||
r.set_options(['D', 'E', 'F']) | ||
assert r.value is None | ||
|
||
def test_radio_set_options_value(screen: Screen): | ||
r = ui.radio(['A', 'B', 'C']) | ||
|
||
screen.open('/') | ||
r.set_options(['D', 'E', 'F'], value='E') | ||
assert r.value == 'E' | ||
|
||
def test_radio_set_options_value_callback(screen: Screen): | ||
"""Fix for https://github.com/zauberzeug/nicegui/issues/3733. | ||
When using `set_options` with the value argument set and the `on_change` callback active on the element, | ||
`on_change` should never pass `None` through, even if the old value is not within the new list of element options. | ||
""" | ||
|
||
def check_change_is_not_none(e: events.ValueChangeEventArguments): | ||
assert e.value is not None | ||
|
||
r = ui.radio(['A', 'B', 'C'], on_change=check_change_is_not_none) | ||
|
||
screen.open('/') | ||
r.set_options(['D', 'E', 'F'], value='F') |