|
@@ -1,4 +1,3 @@
|
|
-from selenium.webdriver.common.action_chains import ActionChains
|
|
|
|
from selenium.webdriver.common.by import By
|
|
from selenium.webdriver.common.by import By
|
|
|
|
|
|
from nicegui import ui
|
|
from nicegui import ui
|
|
@@ -7,51 +6,6 @@ from nicegui.element import Element
|
|
from .screen import Screen
|
|
from .screen import Screen
|
|
|
|
|
|
|
|
|
|
-def test_keyboard(screen: Screen):
|
|
|
|
- result = ui.label()
|
|
|
|
- keyboard = ui.keyboard(on_key=lambda e: result.set_text(f'{e.key, e.action}'))
|
|
|
|
-
|
|
|
|
- screen.open('/')
|
|
|
|
- assert screen.selenium.find_element(By.ID, keyboard.id)
|
|
|
|
- ActionChains(screen.selenium).send_keys('t').perform()
|
|
|
|
- screen.should_contain('t, KeyboardAction(keydown=False, keyup=True, repeat=False)')
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-def test_joystick(screen: Screen):
|
|
|
|
- j = ui.joystick(on_move=lambda e: coordinates.set_text(f'move {e.x:.3f}, {e.y:.3f}'),
|
|
|
|
- on_end=lambda _: coordinates.set_text('end 0, 0'))
|
|
|
|
- coordinates = ui.label('start 0, 0')
|
|
|
|
-
|
|
|
|
- screen.open('/')
|
|
|
|
- joystick = screen.selenium.find_element(By.ID, j.id)
|
|
|
|
- assert joystick
|
|
|
|
- screen.should_contain('start 0, 0')
|
|
|
|
- ActionChains(screen.selenium).move_to_element_with_offset(joystick, 25, 25)\
|
|
|
|
- .click_and_hold().pause(1).move_by_offset(20, 20).pause(1).perform()
|
|
|
|
- screen.should_contain('move 0.400, -0.400')
|
|
|
|
- ActionChains(screen.selenium).move_to_element_with_offset(joystick, 25, 25).click().perform()
|
|
|
|
- screen.should_contain('end 0, 0')
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-def test_styling_joystick(screen: Screen):
|
|
|
|
- j = ui.joystick().style('background-color: gray;').classes('shadow-lg')
|
|
|
|
-
|
|
|
|
- screen.open('/')
|
|
|
|
- joystick = screen.selenium.find_element(By.ID, j.id)
|
|
|
|
- assert 'background-color: gray;' in joystick.get_attribute('style')
|
|
|
|
- assert 'shadow-lg' in joystick.get_attribute('class')
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-def test_input_with_multi_word_error_message(screen: Screen):
|
|
|
|
- input = ui.input(label='some input')
|
|
|
|
- ui.button('set error', on_click=lambda: input.props('error error-message="Some multi word error message"'))
|
|
|
|
-
|
|
|
|
- screen.open('/')
|
|
|
|
- screen.should_not_contain('Some multi word error message')
|
|
|
|
- screen.click('set error')
|
|
|
|
- screen.should_contain('Some multi word error message')
|
|
|
|
-
|
|
|
|
-
|
|
|
|
def test_classes(screen: Screen):
|
|
def test_classes(screen: Screen):
|
|
label = ui.label('Some label')
|
|
label = ui.label('Some label')
|
|
|
|
|
|
@@ -142,31 +96,32 @@ def test_props(screen: Screen):
|
|
assert_props('standard', 'labeled')
|
|
assert_props('standard', 'labeled')
|
|
|
|
|
|
|
|
|
|
-def test_adding_toggle_options(screen: Screen):
|
|
|
|
- label = ui.label()
|
|
|
|
- toggle = ui.toggle(['A', 'B', 'C'], on_change=lambda e: label.set_text(f'Choice: {e.value}'))
|
|
|
|
-
|
|
|
|
- def add_option():
|
|
|
|
- toggle.options.append('D')
|
|
|
|
- toggle.update()
|
|
|
|
-
|
|
|
|
- ui.button('Add option', on_click=add_option)
|
|
|
|
-
|
|
|
|
- screen.open('/')
|
|
|
|
- screen.click('A')
|
|
|
|
- screen.should_contain('Choice: A')
|
|
|
|
-
|
|
|
|
- screen.should_not_contain('D')
|
|
|
|
- screen.click('Add option')
|
|
|
|
- screen.should_contain('D')
|
|
|
|
- screen.click('D')
|
|
|
|
- screen.should_contain('Choice: D')
|
|
|
|
-
|
|
|
|
|
|
+def test_remove_and_clear(screen: Screen):
|
|
|
|
+ with ui.row() as row:
|
|
|
|
+ ui.label('Label A')
|
|
|
|
+ b = ui.label('Label B')
|
|
|
|
+ ui.label('Label C')
|
|
|
|
|
|
-def test_base64_image(screen: Screen):
|
|
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894Ap/wyDw+NsZhMAWTiA+B9Tx21JpG+cZmf5haLKHk9mgysCp1bTmXaZhJJvIvpq3HTSpq83V7BM65qAHrc1chdrchdrdjE9HbPNUjIXa2bV49GA6tC22yWTJsoCLhXPq3ZRHKlbW1OpWigxihSYxQzMWMxCNQYi1MLNAXxZ9fnuKOygkckO0+7qjgrR3hhWy0uc3qZ72bCAPwWjmd9mPvv28kW0UDfuMyJP4JFkK/RwAd/zfD4Vgd3OaycaW9c1/dDKMLn1+eAtQf7P1kN41gqe38haPqE4imF7sFR3hmbZiyWIKEo+KJL9F6b4tFfx1jeINMMLcQYWIjijyU2JfpG/tMvsokSSSkAYVytJ5eB/hIoKQxBUdWiHsSycHLlz0gP6T8lepD+xTQjvKnT/mXKlCmzAX8Dl7JCqRHaepQAAAAASUVORK5CYII=').style('width: 50px;')
|
|
|
|
|
|
+ ui.button('Remove B', on_click=lambda: row.remove(b))
|
|
|
|
+ ui.button('Remove 0', on_click=lambda: row.remove(0))
|
|
|
|
+ ui.button('Clear', on_click=lambda: row.clear())
|
|
|
|
|
|
screen.open('/')
|
|
screen.open('/')
|
|
- screen.wait(0.2)
|
|
|
|
- image = screen.selenium.find_element(By.CLASS_NAME, 'q-img__image')
|
|
|
|
- assert 'data:image/png;base64,iVB' in image.get_attribute('src')
|
|
|
|
|
|
+ screen.should_contain('Label A')
|
|
|
|
+ screen.should_contain('Label B')
|
|
|
|
+ screen.should_contain('Label C')
|
|
|
|
+
|
|
|
|
+ screen.click('Remove B')
|
|
|
|
+ screen.should_contain('Label A')
|
|
|
|
+ screen.should_not_contain('Label B')
|
|
|
|
+ screen.should_contain('Label C')
|
|
|
|
+
|
|
|
|
+ screen.click('Remove 0')
|
|
|
|
+ screen.should_not_contain('Label A')
|
|
|
|
+ screen.should_not_contain('Label B')
|
|
|
|
+ screen.should_contain('Label C')
|
|
|
|
+
|
|
|
|
+ screen.click('Clear')
|
|
|
|
+ screen.should_not_contain('Label A')
|
|
|
|
+ screen.should_not_contain('Label B')
|
|
|
|
+ screen.should_not_contain('Label C')
|