Add MP4 scan progress visibility in UI

- Add broadcast_scan_started, broadcast_scan_progress, broadcast_scan_completed to WebSocketService
- Inject WebSocketService into AnimeService for real-time scan progress broadcasts
- Add CSS styles for scan progress overlay with spinner, stats, and completion state
- Update app.js to handle scan events and display progress overlay
- Add unit tests for new WebSocket broadcast methods
- All 1022 tests passing
This commit is contained in:
2025-12-23 18:24:32 +01:00
parent 9b071fe370
commit a24f07a36e
8 changed files with 633 additions and 20 deletions

View File

@@ -433,6 +433,63 @@ class TestWebSocketService:
assert call_args["data"]["code"] == error_code
assert call_args["data"]["message"] == error_message
@pytest.mark.asyncio
async def test_broadcast_scan_started(self, service, mock_websocket):
"""Test broadcasting scan started event."""
connection_id = "test-conn"
directory = "/home/user/anime"
await service.connect(mock_websocket, connection_id)
await service.broadcast_scan_started(directory)
assert mock_websocket.send_json.called
call_args = mock_websocket.send_json.call_args[0][0]
assert call_args["type"] == "scan_started"
assert call_args["data"]["directory"] == directory
assert "timestamp" in call_args
@pytest.mark.asyncio
async def test_broadcast_scan_progress(self, service, mock_websocket):
"""Test broadcasting scan progress event."""
connection_id = "test-conn"
directories_scanned = 25
files_found = 150
current_directory = "/home/user/anime/Attack on Titan"
await service.connect(mock_websocket, connection_id)
await service.broadcast_scan_progress(
directories_scanned, files_found, current_directory
)
assert mock_websocket.send_json.called
call_args = mock_websocket.send_json.call_args[0][0]
assert call_args["type"] == "scan_progress"
assert call_args["data"]["directories_scanned"] == directories_scanned
assert call_args["data"]["files_found"] == files_found
assert call_args["data"]["current_directory"] == current_directory
assert "timestamp" in call_args
@pytest.mark.asyncio
async def test_broadcast_scan_completed(self, service, mock_websocket):
"""Test broadcasting scan completed event."""
connection_id = "test-conn"
total_directories = 100
total_files = 500
elapsed_seconds = 12.5
await service.connect(mock_websocket, connection_id)
await service.broadcast_scan_completed(
total_directories, total_files, elapsed_seconds
)
assert mock_websocket.send_json.called
call_args = mock_websocket.send_json.call_args[0][0]
assert call_args["type"] == "scan_completed"
assert call_args["data"]["total_directories"] == total_directories
assert call_args["data"]["total_files"] == total_files
assert call_args["data"]["elapsed_seconds"] == elapsed_seconds
assert "timestamp" in call_args
class TestGetWebSocketService:
"""Test cases for get_websocket_service factory function."""