Browse Source

another code review

Falko Schindler 1 year ago
parent
commit
2ca3f765b7
7 changed files with 20 additions and 18 deletions
  1. 4 2
      nicegui/element.py
  2. 1 1
      pyproject.toml
  3. 1 1
      tests/screen.py
  4. 4 4
      tests/test_auto_context.py
  5. 5 5
      tests/test_button.py
  6. 2 2
      tests/test_joystick.py
  7. 3 3
      tests/test_log.py

+ 4 - 2
nicegui/element.py

@@ -311,10 +311,12 @@ class Element(Visibility):
         Can be overridden to perform cleanup.
         """
 
-    def use_component(self, name: str) -> None:
+    def use_component(self, name: str) -> Self:
         """Register a ``*.js`` Vue component to be used by this element."""
         self.components.append(name)
+        return self
 
-    def use_library(self, name: str) -> None:
+    def use_library(self, name: str) -> Self:
         """Register a JavaScript library to be used by this element."""
         self.libraries.append(name)
+        return self

+ 1 - 1
pyproject.toml

@@ -1,6 +1,6 @@
 [tool.poetry]
 name = "nicegui"
-version = "1.3.0"
+version = "0.1.0"
 description = "Create web-based user interfaces with Python. The nice way."
 authors = ["Zauberzeug GmbH <info@zauberzeug.com>"]
 license = "MIT"

+ 1 - 1
tests/screen.py

@@ -140,7 +140,7 @@ class Screen:
         except NoSuchElementException as e:
             raise AssertionError(f'Could not find "{text}"') from e
 
-    def find_by_id(self, element: ui.element) -> WebElement:
+    def find_element(self, element: ui.element) -> WebElement:
         return self.selenium.find_element(By.ID, f'c{element.id}')
 
     def find_by_tag(self, name: str) -> WebElement:

+ 4 - 4
tests/test_auto_context.py

@@ -43,9 +43,9 @@ def test_adding_elements_with_async_await(screen: Screen):
     with screen.implicitly_wait(10.0):
         screen.should_contain('A')
         screen.should_contain('B')
-    cA = screen.find_by_id(cardA)
+    cA = screen.find_element(cardA)
     cA.find_element(By.XPATH, './/*[contains(text(), "A")]')
-    cB = screen.find_by_id(cardB)
+    cB = screen.find_element(cardB)
     cB.find_element(By.XPATH, './/*[contains(text(), "B")]')
 
 
@@ -129,7 +129,7 @@ def test_adding_elements_from_different_tasks(screen: Screen):
     background_tasks.create(add_label2())
     screen.should_contain('1')
     screen.should_contain('2')
-    c1 = screen.find_by_id(card1)
+    c1 = screen.find_element(card1)
     c1.find_element(By.XPATH, './/*[contains(text(), "1")]')
-    c2 = screen.find_by_id(card2)
+    c2 = screen.find_element(card2)
     c2.find_element(By.XPATH, './/*[contains(text(), "2")]')

+ 5 - 5
tests/test_button.py

@@ -11,11 +11,11 @@ def test_quasar_colors(screen: Screen):
     b5 = ui.button(color='#ff0000')
 
     screen.open('/')
-    assert screen.find_by_id(b1).value_of_css_property('background-color') == 'rgba(88, 152, 212, 1)'
-    assert screen.find_by_id(b2).value_of_css_property('background-color') == 'rgba(0, 0, 0, 0)'
-    assert screen.find_by_id(b3).value_of_css_property('background-color') == 'rgba(239, 83, 80, 1)'
-    assert screen.find_by_id(b4).value_of_css_property('background-color') == 'rgba(239, 68, 68, 1)'
-    assert screen.find_by_id(b5).value_of_css_property('background-color') == 'rgba(255, 0, 0, 1)'
+    assert screen.find_element(b1).value_of_css_property('background-color') == 'rgba(88, 152, 212, 1)'
+    assert screen.find_element(b2).value_of_css_property('background-color') == 'rgba(0, 0, 0, 0)'
+    assert screen.find_element(b3).value_of_css_property('background-color') == 'rgba(239, 83, 80, 1)'
+    assert screen.find_element(b4).value_of_css_property('background-color') == 'rgba(239, 68, 68, 1)'
+    assert screen.find_element(b5).value_of_css_property('background-color') == 'rgba(255, 0, 0, 1)'
 
 
 def test_enable_disable(screen: Screen):

+ 2 - 2
tests/test_joystick.py

@@ -11,7 +11,7 @@ def test_joystick(screen: Screen):
     coordinates = ui.label('start 0, 0')
 
     screen.open('/')
-    joystick = screen.find_by_id(j)
+    joystick = screen.find_element(j)
     assert joystick
     screen.should_contain('start 0, 0')
 
@@ -35,6 +35,6 @@ def test_styling_joystick(screen: Screen):
     j = ui.joystick().style('background-color: gray;').classes('shadow-lg')
 
     screen.open('/')
-    joystick = screen.find_by_id(j)
+    joystick = screen.find_element(j)
     assert 'background-color: gray;' in joystick.get_attribute('style')
     assert 'shadow-lg' in joystick.get_attribute('class')

+ 3 - 3
tests/test_log.py

@@ -11,11 +11,11 @@ def test_log(screen: Screen):
     log.push('D')
 
     screen.open('/')
-    assert screen.find_by_id(log).text == 'B\nC\nD'
+    assert screen.find_element(log).text == 'B\nC\nD'
 
     log.clear()
     screen.wait(0.5)
-    assert screen.find_by_id(log).text == ''
+    assert screen.find_element(log).text == ''
 
 
 def test_log_with_newlines(screen: Screen):
@@ -25,7 +25,7 @@ def test_log_with_newlines(screen: Screen):
     log.push('C\nD')
 
     screen.open('/')
-    assert screen.find_by_id(log).text == 'B\nC\nD'
+    assert screen.find_element(log).text == 'B\nC\nD'
 
 
 def test_replace_log(screen: Screen):