|
@@ -1,11 +1,21 @@
|
|
|
|
+from pathlib import Path
|
|
from typing import List
|
|
from typing import List
|
|
|
|
|
|
import pytest
|
|
import pytest
|
|
from selenium.webdriver.common.action_chains import ActionChains
|
|
from selenium.webdriver.common.action_chains import ActionChains
|
|
|
|
|
|
-from nicegui import ui
|
|
|
|
|
|
+from nicegui import app, ui
|
|
from nicegui.testing import Screen
|
|
from nicegui.testing import Screen
|
|
|
|
|
|
|
|
+URL_PATH1 = '/test1.jpg'
|
|
|
|
+URL_PATH2 = '/test2.jpg'
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+@pytest.fixture(autouse=True)
|
|
|
|
+def provide_image_files():
|
|
|
|
+ app.add_static_file(local_file=Path(__file__).parent / 'media' / 'test1.jpg', url_path=URL_PATH1)
|
|
|
|
+ app.add_static_file(local_file=Path(__file__).parent / 'media' / 'test2.jpg', url_path=URL_PATH2)
|
|
|
|
+
|
|
|
|
|
|
def test_set_source_in_tab(screen: Screen):
|
|
def test_set_source_in_tab(screen: Screen):
|
|
"""https://github.com/zauberzeug/nicegui/issues/488"""
|
|
"""https://github.com/zauberzeug/nicegui/issues/488"""
|
|
@@ -21,21 +31,20 @@ def test_set_source_in_tab(screen: Screen):
|
|
with ui.tab_panel('B'):
|
|
with ui.tab_panel('B'):
|
|
ui.label('Tab B')
|
|
ui.label('Tab B')
|
|
await ui.context.client.connected()
|
|
await ui.context.client.connected()
|
|
- img.set_source('https://picsum.photos/id/29/640/360')
|
|
|
|
|
|
+ img.set_source(URL_PATH1)
|
|
|
|
|
|
screen.open('/')
|
|
screen.open('/')
|
|
screen.wait(0.5)
|
|
screen.wait(0.5)
|
|
- assert screen.find_by_tag('img').get_attribute('src') == 'https://picsum.photos/id/29/640/360'
|
|
|
|
|
|
+ assert screen.find_by_tag('img').get_attribute('src').endswith(URL_PATH1)
|
|
screen.click('B')
|
|
screen.click('B')
|
|
screen.wait(0.5)
|
|
screen.wait(0.5)
|
|
screen.click('A')
|
|
screen.click('A')
|
|
- assert screen.find_by_tag('img').get_attribute('src') == 'https://picsum.photos/id/29/640/360'
|
|
|
|
|
|
+ assert screen.find_by_tag('img').get_attribute('src').endswith(URL_PATH1)
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('cross', [True, False])
|
|
@pytest.mark.parametrize('cross', [True, False])
|
|
def test_with_cross(screen: Screen, cross: bool):
|
|
def test_with_cross(screen: Screen, cross: bool):
|
|
- ui.interactive_image('https://picsum.photos/id/29/640/360',
|
|
|
|
- content='<circle cx="100" cy="100" r="15" />', cross=cross)
|
|
|
|
|
|
+ ui.interactive_image(URL_PATH1, content='<circle cx="100" cy="100" r="15" />', cross=cross)
|
|
|
|
|
|
screen.open('/')
|
|
screen.open('/')
|
|
screen.find_by_tag('svg')
|
|
screen.find_by_tag('svg')
|
|
@@ -46,25 +55,25 @@ def test_with_cross(screen: Screen, cross: bool):
|
|
|
|
|
|
def test_replace_interactive_image(screen: Screen):
|
|
def test_replace_interactive_image(screen: Screen):
|
|
with ui.row() as container:
|
|
with ui.row() as container:
|
|
- ui.interactive_image('https://picsum.photos/id/29/640/360')
|
|
|
|
|
|
+ ui.interactive_image(URL_PATH1)
|
|
|
|
|
|
def replace():
|
|
def replace():
|
|
container.clear()
|
|
container.clear()
|
|
with container:
|
|
with container:
|
|
- ui.interactive_image('https://picsum.photos/id/30/640/360')
|
|
|
|
|
|
+ ui.interactive_image(URL_PATH2)
|
|
ui.button('Replace', on_click=replace)
|
|
ui.button('Replace', on_click=replace)
|
|
|
|
|
|
screen.open('/')
|
|
screen.open('/')
|
|
- assert (screen.find_by_tag('img').get_attribute('src') or '').endswith('id/29/640/360')
|
|
|
|
|
|
+ assert (screen.find_by_tag('img').get_attribute('src') or '').endswith(URL_PATH1)
|
|
screen.click('Replace')
|
|
screen.click('Replace')
|
|
screen.wait(0.5)
|
|
screen.wait(0.5)
|
|
- assert (screen.find_by_tag('img').get_attribute('src') or '').endswith('id/30/640/360')
|
|
|
|
|
|
+ assert (screen.find_by_tag('img').get_attribute('src') or '').endswith(URL_PATH2)
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('cross', [True, False])
|
|
@pytest.mark.parametrize('cross', [True, False])
|
|
def test_mousemove_event(screen: Screen, cross: bool):
|
|
def test_mousemove_event(screen: Screen, cross: bool):
|
|
counter = {'value': 0}
|
|
counter = {'value': 0}
|
|
- ii = ui.interactive_image('https://picsum.photos/id/29/640/360', cross=cross, events=['mousemove'],
|
|
|
|
|
|
+ ii = ui.interactive_image(URL_PATH1, cross=cross, events=['mousemove'],
|
|
on_mouse=lambda: counter.update(value=counter['value'] + 1))
|
|
on_mouse=lambda: counter.update(value=counter['value'] + 1))
|
|
|
|
|
|
screen.open('/')
|
|
screen.open('/')
|
|
@@ -80,15 +89,13 @@ def test_mousemove_event(screen: Screen, cross: bool):
|
|
|
|
|
|
def test_loaded_event(screen: Screen):
|
|
def test_loaded_event(screen: Screen):
|
|
sources: List[str] = []
|
|
sources: List[str] = []
|
|
- ii = ui.interactive_image('https://picsum.photos/id/29/640/360')
|
|
|
|
|
|
+ ii = ui.interactive_image(URL_PATH1)
|
|
ii.on('loaded', lambda e: sources.append(e.args['source']))
|
|
ii.on('loaded', lambda e: sources.append(e.args['source']))
|
|
- ui.button('Change Source', on_click=lambda: ii.set_source('https://picsum.photos/id/30/640/360'))
|
|
|
|
|
|
+ ui.button('Change Source', on_click=lambda: ii.set_source(URL_PATH2))
|
|
|
|
|
|
screen.open('/')
|
|
screen.open('/')
|
|
- screen.wait(0.5)
|
|
|
|
- assert len(sources) == 1
|
|
|
|
|
|
+ screen.wait_for(lambda: len(sources) == 1)
|
|
screen.click('Change Source')
|
|
screen.click('Change Source')
|
|
- screen.wait(1.5)
|
|
|
|
- assert len(sources) == 2
|
|
|
|
- assert sources[1].endswith('id/30/640/360')
|
|
|
|
|
|
+ screen.wait_for(lambda: len(sources) == 2)
|
|
|
|
+ assert sources[1].endswith(URL_PATH2)
|
|
assert screen.find_by_tag('img').get_attribute('src') == sources[1]
|
|
assert screen.find_by_tag('img').get_attribute('src') == sources[1]
|