Skip to content

Commit

Permalink
zauberzeug#329 add tests for expansion and the very similar dialog el…
Browse files Browse the repository at this point in the history
…ement
  • Loading branch information
falkoschindler committed Feb 1, 2023
1 parent 32eb46b commit 13555bb
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tests/test_dialog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from typing import List

from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys

from nicegui import ui

from .screen import Screen


def test_open_close_dialog(screen: Screen):
with ui.dialog() as d, ui.card():
ui.label('Content')
ui.button('Close', on_click=d.close)
ui.button('Open', on_click=d.open)

screen.open('/')
screen.should_not_contain('Content')
screen.click('Open')
screen.wait(0.5)
screen.should_contain('Content')
screen.click('Close')
screen.wait(0.5)
screen.should_not_contain('Content')


def test_await_dialog(screen: Screen):
with ui.dialog() as dialog, ui.card():
ui.label('Are you sure?')
with ui.row():
ui.button('Yes', on_click=lambda: dialog.submit('Yes'))
ui.button('No', on_click=lambda: dialog.submit('No'))

async def show() -> None:
results.append(await dialog)
results: List[str] = []
ui.button('Open', on_click=show)

screen.open('/')
screen.click('Open')
screen.click('Yes')
screen.click('Open')
screen.click('No')
screen.click('Open')
ActionChains(screen.selenium).send_keys(Keys.ESCAPE).perform()
screen.wait(0.5)
assert results == ['Yes', 'No', None]
20 changes: 20 additions & 0 deletions tests/test_expansion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from nicegui import ui

from .screen import Screen


def test_open_close_expansion(screen: Screen):
with ui.expansion('Expansion') as e:
ui.label('Content')
ui.button('Open', on_click=e.open)
ui.button('Close', on_click=e.close)

screen.open('/')
screen.should_contain('Expansion')
screen.should_not_contain('Content')
screen.click('Open')
screen.wait(0.5)
screen.should_contain('Content')
screen.click('Close')
screen.wait(0.5)
screen.should_not_contain('Content')

0 comments on commit 13555bb

Please sign in to comment.