Files
video-sync/desktop-client/test_app.py
2026-03-03 22:50:02 +11:00

61 lines
2.2 KiB
Python

import pytest
from PyQt6.QtCore import Qt
from main import VlcSyncApp
def test_app_ui_flow(qtbot):
# Initialize the main application
app = VlcSyncApp()
qtbot.addWidget(app)
# 1. Test Lobby View
assert app.stacked_widget.currentIndex() == 0
assert not app.lobby_widget.create_room_btn.isEnabled()
# Fill out the Lobby Form
app.lobby_widget.username_input.setText("PyTestUser")
# Mocking file selection instead of opening the native dialog
app.lobby_widget.local_file_path = "test_pytest.mkv"
app.lobby_widget.local_file_name = "test_pytest.mkv"
app.lobby_widget.local_file_size = 1048576
app.lobby_widget.check_inputs()
# Button should now be active
assert app.lobby_widget.create_room_btn.isEnabled()
# 2. Test Creating Room matches integration pipeline
qtbot.mouseClick(app.lobby_widget.create_room_btn, Qt.MouseButton.LeftButton)
# Wait for the WebSocket connected signal, the room_created server response, and UI transition
def check_room_joined():
assert app.stacked_widget.currentIndex() == 1
assert len(app.room_code) > 2
qtbot.waitUntil(check_room_joined, timeout=5000)
# 3. Test Chat flow End-to-End
# Type a message
qtbot.keyClicks(app.room_widget.chat_input, "Automated UI Test Message")
# Click Send
qtbot.mouseClick(app.room_widget.chat_send_btn, Qt.MouseButton.LeftButton)
# Wait until the Bun server grabs the websocket payload, stores it, and broadcasts it back to the UI!
def check_chat_received():
assert "Automated UI Test Message" in app.room_widget.chat_messages.toPlainText()
qtbot.waitUntil(check_chat_received, timeout=3000)
# 4. Test Playback Sync (UI updates and internal flags)
assert app.room_widget.play_btn.text() == ""
# Click Play
qtbot.mouseClick(app.room_widget.play_btn, Qt.MouseButton.LeftButton)
def check_playback_started():
assert app.room_widget.play_btn.text() == ""
qtbot.waitUntil(check_playback_started, timeout=2000)
# Clean up background threads
app._on_room_leave()