diff --git a/OTAnalytics/plugin_ui/nicegui_gui/pages/analysis_form/container.py b/OTAnalytics/plugin_ui/nicegui_gui/pages/analysis_form/container.py index b23231b40..0bb1bcaf6 100644 --- a/OTAnalytics/plugin_ui/nicegui_gui/pages/analysis_form/container.py +++ b/OTAnalytics/plugin_ui/nicegui_gui/pages/analysis_form/container.py @@ -13,6 +13,7 @@ from OTAnalytics.plugin_ui.nicegui_gui.test_constants import TEST_ID MARKER_BUTTON_EXPORT_TRACK_STATISTICS = "button-export-track-statistics" +MARKER_BUTTON_EXPORT_ROAD_USER_ASSIGNMENT = "button-export-road-user-assignment" class AnalysisForm(ButtonForm, AbstractFrame): @@ -53,7 +54,7 @@ def build(self) -> None: AnalysisKeys.BUTTON_TEXT_EXPORT_ROAD_USER_ASSIGNMENT ), on_click=self._viewmodel.export_road_user_assignments, - ) + ).props(f"{TEST_ID}={MARKER_BUTTON_EXPORT_ROAD_USER_ASSIGNMENT}") with ui.row(): self._button_export_track_statistics = ui.button( self._resource_manager.get( diff --git a/tests/acceptance/test_create_important_test_data.py b/tests/acceptance/test_create_important_test_data.py index a07ac5745..30a145e8c 100644 --- a/tests/acceptance/test_create_important_test_data.py +++ b/tests/acceptance/test_create_important_test_data.py @@ -47,6 +47,7 @@ click_update_offset_button, create_flow, create_section, + export_road_user_assignments, export_track_statistics, get_loaded_tracks_canvas_from_otconfig, load_main_page, @@ -311,3 +312,39 @@ def test_generate_track_statistics_reference_file( # Copy to the main test data directory for reuse permanent_path = data_dir / "track_statistics_reference.csv" shutil.copy(output_path, permanent_path) + + @pytest.mark.timeout(ACCEPTANCE_TEST_PYTEST_TIMEOUT) + @pytest.mark.playwright + @pytest.mark.usefixtures("external_app") + def test_generate_road_user_assignments_reference_file( + self, + external_app: NiceGUITestServer, + page: Page, + resource_manager: ResourceManager, + test_data_tmp_dir: Path, + ) -> None: + """Generate reference road_user_assignments.csv file using Desktop GUI. + + This test: + - Loads a pre-configured project with video, tracks, sections, and flows + - Clicks "Export road user assignments ..." + - Uses default values in the export dialog + - Saves the file + - Copies it to the test data directory as reference + + The resulting file can be used by other tests to compare exported output. + """ + data_dir = Path(__file__).parents[1] / "data" + otconfig_path = data_dir / "sections_created_test_file.otconfig" + + # Export road user assignments + output_path = export_road_user_assignments( + page, external_app, resource_manager, test_data_tmp_dir, otconfig_path + ) + + # Copy to the main test data directory for reuse + permanent_path = ( + data_dir + / "Testvideo_Cars-Cyclist_FR20_2020-01-01_00-00-00.road_user_assignments.csv" # noqa + ) + shutil.copy(output_path, permanent_path) diff --git a/tests/acceptance/test_export_road_user_assignments.py b/tests/acceptance/test_export_road_user_assignments.py new file mode 100644 index 000000000..458c5b28f --- /dev/null +++ b/tests/acceptance/test_export_road_user_assignments.py @@ -0,0 +1,67 @@ +"""Test to export road user assignments and compare with reference file. + +This test: +1. Loads a pre-configured project with video, tracks, sections, and flows +2. Clicks "Export road user assignments ..." button +3. Verifies export dialog appears +4. Uses default values and clicks OK +5. Verifies file is created with default name +6. Compares exported file with reference file from Desktop GUI +""" + +from pathlib import Path + +import pytest +from playwright.sync_api import Page # type: ignore + +from OTAnalytics.application.resources.resource_manager import ResourceManager +from tests.acceptance.conftest import NiceGUITestServer +from tests.utils.playwright_helpers import ( + compare_csv_files, + export_road_user_assignments, +) + +playwright = pytest.importorskip( + "playwright.sync_api", reason="pytest-playwright is required for this test" +) + + +@pytest.mark.timeout(300) +@pytest.mark.playwright +@pytest.mark.usefixtures("external_app") +def test_export_road_user_assignments( + page: Page, + external_app: NiceGUITestServer, + resource_manager: ResourceManager, + test_data_tmp_dir: Path, +) -> None: + """Test export road user assignments functionality. + + Test Steps: + 1. Load pre-configured project with tracks, sections, and flows + 2. Click "Export road user assignments ..." button + 3. Verify popup appears for selecting output format + 4. Use default values + 5. Click "Ok" + 6. Verify file is created in execution folder with name "road_user_assignments.csv" + 7. Compare the exported file with reference file from Desktop GUI + + Expected Results: + - Export dialog appears when button is clicked + - File is created with correct default name + - Exported file matches reference file content + """ + data_dir = Path(__file__).parents[1] / "data" + otconfig_path = data_dir / "sections_created_test_file.otconfig" + + # Export road user assignments + output_path = export_road_user_assignments( + page, external_app, resource_manager, test_data_tmp_dir, otconfig_path + ) + + # Compare with reference file + reference_path = ( + data_dir + / "Testvideo_Cars-Cyclist_FR20_2020-01-01_00-00-00.road_user_assignments.csv" + ) + compare_csv_files(output_path, reference_path) diff --git a/tests/utils/playwright_helpers.py b/tests/utils/playwright_helpers.py index e5b725967..3053682b0 100644 --- a/tests/utils/playwright_helpers.py +++ b/tests/utils/playwright_helpers.py @@ -50,6 +50,7 @@ MARKER_VIDEO_TABLE, ) from OTAnalytics.plugin_ui.nicegui_gui.pages.analysis_form.container import ( + MARKER_BUTTON_EXPORT_ROAD_USER_ASSIGNMENT, MARKER_BUTTON_EXPORT_TRACK_STATISTICS, ) from OTAnalytics.plugin_ui.nicegui_gui.pages.canvas_and_files_form.canvas_form import ( @@ -572,6 +573,55 @@ def export_track_statistics( return output_path +def export_road_user_assignments( + page: Page, + external_app: Any, + resource_manager: Any, + test_data_tmp_dir: Path, + otconfig_path: Path, +) -> Path: + """Export road user assignments from a pre-configured project. + + This function: + - Loads the main page + - Opens the specified otconfig file + - Clicks the export road user assignments button + - Handles the export dialog + - Returns the path to the exported file + + Args: + page: The Playwright page object + external_app: The NiceGUI test server + resource_manager: The resource manager for localized text + test_data_tmp_dir: Directory where the file should be exported + otconfig_path: Path to the otconfig file to load + + Returns: + Path to the exported road user assignments file + """ + # Setup: Load tracks with preconfigured file + load_main_page(page, external_app) + + # Load the otconfig file + open_project_otconfig(page, resource_manager, otconfig_path) + + # Click "Export road user assignments ..." button + export_button = search_for_marker_element( + page, MARKER_BUTTON_EXPORT_ROAD_USER_ASSIGNMENT + ).first + export_button.click() + + # Handle export dialog and get output path + output_path = export_file_via_dialog(page, test_data_tmp_dir) + + # Verify the file was created + assert ( + output_path.exists() + ), f"Road user assignments file not created: {output_path}" + + return output_path + + # ---------------------- # File comparison helpers # ----------------------