浏览代码

add pytest

Falko Schindler 1 年之前
父节点
当前提交
999068c30a
共有 2 个文件被更改,包括 11 次插入4 次删除
  1. 1 1
      nicegui/elements/mixins/validation_element.py
  2. 10 3
      tests/test_select.py

+ 1 - 1
nicegui/elements/mixins/validation_element.py

@@ -46,7 +46,7 @@ class ValidationElement(ValueElement):
         self.error = None
         return True
 
-    def disable_auto_validation(self) -> None:
+    def without_auto_validation(self) -> None:
         """Disable automatic validation on value change."""
         self._auto_validation = False
 

+ 10 - 3
tests/test_select.py

@@ -172,10 +172,17 @@ def test_keep_filtered_options(multiple: bool, screen: Screen):
         screen.should_contain('B2')
 
 
-def test_select_validation(screen: Screen):
-    ui.select(['A', 'BC', 'DEF'], value='A', validation={'Too long': lambda v: len(v) < 3})
+@pytest.mark.parametrize('auto_validation', [True, False])
+def test_select_validation(auto_validation: bool, screen: Screen):
+    select = ui.select(['A', 'BC', 'DEF'], value='A', validation={'Too long': lambda v: len(v) < 3})
+    if not auto_validation:
+        select.without_auto_validation()
 
     screen.open('/')
     screen.click('A')
     screen.click('DEF')
-    screen.should_contain('Too long')
+    screen.wait(0.5)
+    if auto_validation:
+        screen.should_contain('Too long')
+    else:
+        screen.should_not_contain('Too long')