forked from zauberzeug/nicegui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
zauberzeug#329 add tests for expansion and the very similar dialog el…
…ement
- Loading branch information
1 parent
32eb46b
commit 13555bb
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |