Переглянути джерело

add set_source tests for ui.video and ui.audio

Rodja Trappe 1 рік тому
батько
коміт
42b3b4c61f
2 змінених файлів з 32 додано та 4 видалено
  1. 16 2
      tests/test_audio.py
  2. 16 2
      tests/test_video.py

+ 16 - 2
tests/test_audio.py

@@ -1,15 +1,18 @@
 from nicegui import ui
 from nicegui.testing import Screen
 
+SONG1 = 'https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3'
+SONG2 = 'https://www.soundhelix.com/examples/mp3/SoundHelix-Song-2.mp3'
+
 
 def test_replace_audio(screen: Screen):
     with ui.row() as container:
-        ui.audio('https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3')
+        ui.audio(SONG1)
 
     def replace():
         container.clear()
         with container:
-            ui.audio('https://www.soundhelix.com/examples/mp3/SoundHelix-Song-2.mp3')
+            ui.audio(SONG2)
     ui.button('Replace', on_click=replace)
 
     screen.open('/')
@@ -17,3 +20,14 @@ def test_replace_audio(screen: Screen):
     screen.click('Replace')
     screen.wait(0.5)
     assert screen.find_by_tag('audio').get_attribute('src').endswith('SoundHelix-Song-2.mp3')
+
+
+def test_change_source(screen: Screen):
+    audio = ui.audio(SONG1)
+    ui.button('Change source', on_click=lambda: audio.set_source(SONG2))
+
+    screen.open('/')
+    assert screen.find_by_tag('audio').get_attribute('src').endswith('SoundHelix-Song-1.mp3')
+    screen.click('Change source')
+    screen.wait(0.5)
+    assert screen.find_by_tag('audio').get_attribute('src').endswith('SoundHelix-Song-2.mp3')

+ 16 - 2
tests/test_video.py

@@ -1,15 +1,18 @@
 from nicegui import ui
 from nicegui.testing import Screen
 
+VIDEO1 = 'https://storage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4'
+VIDEO2 = 'https://storage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4'
+
 
 def test_replace_video(screen: Screen):
     with ui.row() as container:
-        ui.video('https://storage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4')
+        ui.video(VIDEO1)
 
     def replace():
         container.clear()
         with container:
-            ui.video('https://storage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4')
+            ui.video(VIDEO2)
     ui.button('Replace', on_click=replace)
 
     screen.open('/')
@@ -17,3 +20,14 @@ def test_replace_video(screen: Screen):
     screen.click('Replace')
     screen.wait(0.5)
     assert screen.find_by_tag('video').get_attribute('src').endswith('ElephantsDream.mp4')
+
+
+def test_change_source(screen: Screen):
+    audio = ui.video(VIDEO1)
+    ui.button('Change source', on_click=lambda: audio.set_source(VIDEO2))
+
+    screen.open('/')
+    assert screen.find_by_tag('video').get_attribute('src').endswith('BigBuckBunny.mp4')
+    screen.click('Change source')
+    screen.wait(0.5)
+    assert screen.find_by_tag('video').get_attribute('src').endswith('ElephantsDream.mp4')