mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Merge branch 'main' into multiselect
This commit is contained in:
File diff suppressed because one or more lines are too long
45
tests/snapshot_tests/snapshot_apps/input_validation.py
Normal file
45
tests/snapshot_tests/snapshot_apps/input_validation.py
Normal file
@@ -0,0 +1,45 @@
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.validation import Number
|
||||
from textual.widgets import Input
|
||||
|
||||
VALIDATORS = [
|
||||
Number(minimum=1, maximum=5),
|
||||
]
|
||||
|
||||
|
||||
class InputApp(App):
|
||||
CSS = """
|
||||
Input.-valid {
|
||||
border: tall $success 60%;
|
||||
}
|
||||
Input.-valid:focus {
|
||||
border: tall $success;
|
||||
}
|
||||
Input {
|
||||
margin: 1 2;
|
||||
}
|
||||
"""
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Input(
|
||||
placeholder="Enter a number between 1 and 5",
|
||||
validators=VALIDATORS,
|
||||
)
|
||||
yield Input(
|
||||
placeholder="Enter a number between 1 and 5",
|
||||
validators=VALIDATORS,
|
||||
)
|
||||
yield Input(
|
||||
placeholder="Enter a number between 1 and 5",
|
||||
validators=VALIDATORS,
|
||||
)
|
||||
yield Input(
|
||||
placeholder="Enter a number between 1 and 5",
|
||||
validators=VALIDATORS,
|
||||
)
|
||||
|
||||
|
||||
app = InputApp()
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run()
|
||||
@@ -84,6 +84,19 @@ def test_input_and_focus(snap_compare):
|
||||
assert snap_compare(WIDGET_EXAMPLES_DIR / "input.py", press=press)
|
||||
|
||||
|
||||
def test_input_validation(snap_compare):
|
||||
"""Checking that invalid styling is applied. The snapshot app itself
|
||||
also adds styling for -valid which gives a green border."""
|
||||
press = [
|
||||
*"-2", # -2 is invalid, so -invalid should be applied
|
||||
"tab",
|
||||
"3", # This is valid, so -valid should be applied
|
||||
"tab",
|
||||
*"-2", # -2 is invalid, so -invalid should be applied (and :focus, since we stop here)
|
||||
]
|
||||
assert snap_compare(SNAPSHOT_APPS_DIR / "input_validation.py", press=press)
|
||||
|
||||
|
||||
def test_buttons_render(snap_compare):
|
||||
# Testing button rendering. We press tab to focus the first button too.
|
||||
assert snap_compare(WIDGET_EXAMPLES_DIR / "button.py", press=["tab"])
|
||||
|
||||
Reference in New Issue
Block a user