feat(ui): Implement Track Browser and progress visualization in MMA Dashboard
This commit is contained in:
66
tests/test_mma_dashboard_refresh.py
Normal file
66
tests/test_mma_dashboard_refresh.py
Normal file
@@ -0,0 +1,66 @@
|
||||
import pytest
|
||||
from unittest.mock import patch, MagicMock
|
||||
from gui_2 import App
|
||||
|
||||
@pytest.fixture
|
||||
def app_instance():
|
||||
# We patch the dependencies of App.__init__ to avoid side effects
|
||||
with (
|
||||
patch('gui_2.load_config', return_value={'ai': {}, 'projects': {}}),
|
||||
patch('gui_2.save_config'),
|
||||
patch('gui_2.project_manager') as mock_pm,
|
||||
patch('gui_2.session_logger'),
|
||||
patch('gui_2.immapp.run'),
|
||||
patch.object(App, '_load_active_project'),
|
||||
patch.object(App, '_fetch_models'),
|
||||
patch.object(App, '_load_fonts'),
|
||||
patch.object(App, '_post_init')
|
||||
):
|
||||
app = App()
|
||||
# Ensure project and ui_files_base_dir are set for _refresh_from_project
|
||||
app.project = {}
|
||||
app.ui_files_base_dir = "."
|
||||
# Return the app and the mock_pm for use in tests
|
||||
yield app, mock_pm
|
||||
|
||||
def test_mma_dashboard_refresh(app_instance):
|
||||
app, mock_pm = app_instance
|
||||
|
||||
# 1. Define mock tracks
|
||||
mock_tracks = [
|
||||
MagicMock(id="track_1", description="Track 1"),
|
||||
MagicMock(id="track_2", description="Track 2")
|
||||
]
|
||||
|
||||
# 2. Patch get_all_tracks to return our mock list
|
||||
mock_pm.get_all_tracks.return_value = mock_tracks
|
||||
|
||||
# 3. Call _refresh_from_project
|
||||
app._refresh_from_project()
|
||||
|
||||
# 4. Verify that app.tracks contains the mock tracks
|
||||
assert hasattr(app, 'tracks'), "App instance should have a 'tracks' attribute"
|
||||
assert app.tracks == mock_tracks
|
||||
assert len(app.tracks) == 2
|
||||
assert app.tracks[0].id == "track_1"
|
||||
assert app.tracks[1].id == "track_2"
|
||||
|
||||
# Verify get_all_tracks was called with the correct base_dir
|
||||
mock_pm.get_all_tracks.assert_called_with(app.ui_files_base_dir)
|
||||
|
||||
def test_mma_dashboard_initialization_refresh(app_instance):
|
||||
"""
|
||||
Checks that _refresh_from_project is called during initialization if
|
||||
_load_active_project is NOT mocked to skip it (but here it IS mocked in fixture).
|
||||
This test verifies that calling it manually works as expected for initialization scenarios.
|
||||
"""
|
||||
app, mock_pm = app_instance
|
||||
|
||||
mock_tracks = [MagicMock(id="init_track", description="Initial Track")]
|
||||
mock_pm.get_all_tracks.return_value = mock_tracks
|
||||
|
||||
# Simulate the refresh that would happen during a project load
|
||||
app._refresh_from_project()
|
||||
|
||||
assert app.tracks == mock_tracks
|
||||
assert app.tracks[0].id == "init_track"
|
||||
Reference in New Issue
Block a user