Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from OTAnalytics.plugin_ui.nicegui_gui.nicegui.elements.button_form import ButtonForm
from OTAnalytics.plugin_ui.nicegui_gui.test_constants import TEST_ID

MARKER_BUTTON_EXPORT_EVENT_LIST = "button-export-event-list"
MARKER_BUTTON_EXPORT_TRACK_STATISTICS = "button-export-track-statistics"


Expand Down Expand Up @@ -41,7 +42,7 @@ def build(self) -> None:
AnalysisKeys.BUTTON_TEXT_EXPORT_EVENT_LIST
),
on_click=self._viewmodel.export_events,
)
).props(f"{TEST_ID}={MARKER_BUTTON_EXPORT_EVENT_LIST}")
with ui.row():
self._button_export_counts = ui.button(
self._resource_manager.get(AnalysisKeys.BUTTON_TEXT_EXPORT_COUNTS),
Expand Down
35 changes: 35 additions & 0 deletions tests/acceptance/test_create_important_test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
click_update_offset_button,
create_flow,
create_section,
export_event_list,
export_track_statistics,
get_loaded_tracks_canvas_from_otconfig,
load_main_page,
Expand Down Expand Up @@ -311,3 +312,37 @@ 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_event_list_reference_file(
self,
external_app: NiceGUITestServer,
page: Page,
resource_manager: ResourceManager,
test_data_tmp_dir: Path,
) -> None:
"""Generate reference events_reference.csv file using Desktop GUI.

This test:
- Loads a pre-configured project with video, tracks, sections, and flows
- Clicks "Export eventlist ..."
- Selects "CSV (OpenTrafficCam)" format (default)
- 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 event list
output_path = export_event_list(
page, external_app, resource_manager, test_data_tmp_dir, otconfig_path
)

# Copy to the main test data directory for reuse
permanent_path = data_dir / "events_reference.csv"
shutil.copy(output_path, permanent_path)
63 changes: 63 additions & 0 deletions tests/acceptance/test_export_event_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"""Test to export event list and compare with reference file.

This test:
1. Loads a pre-configured project with video, tracks, sections, and flows
2. Clicks "Export eventlist ..." button
3. Verifies export dialog appears
4. Selects "CSV (OpenTrafficCam)" format (default)
5. Uses default values and clicks OK
6. Verifies file is created with default name
7. 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_event_list

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_event_list(
page: Page,
external_app: NiceGUITestServer,
resource_manager: ResourceManager,
test_data_tmp_dir: Path,
) -> None:
"""Test export event list functionality.

Test Steps:
1. Load pre-configured project with tracks, sections, and flows
2. Click "Export eventlist ..." button
3. Verify popup appears for selecting output format
4. Select "CSV (OpenTrafficCam)" (default)
5. Use default file name (name of the project or start date)
6. Click "Ok"
7. Verify file is created in execution folder with default name
8. 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 event list
output_path = export_event_list(
page, external_app, resource_manager, test_data_tmp_dir, otconfig_path
)

# Compare with reference file
reference_path = data_dir / "events_reference.csv"
compare_csv_files(output_path, reference_path)
48 changes: 48 additions & 0 deletions tests/utils/playwright_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
MARKER_VIDEO_TABLE,
)
from OTAnalytics.plugin_ui.nicegui_gui.pages.analysis_form.container import (
MARKER_BUTTON_EXPORT_EVENT_LIST,
MARKER_BUTTON_EXPORT_TRACK_STATISTICS,
)
from OTAnalytics.plugin_ui.nicegui_gui.pages.canvas_and_files_form.canvas_form import (
Expand Down Expand Up @@ -525,6 +526,53 @@ def export_file_via_dialog(page: Page, output_dir: Path) -> Path:
return output_dir / current_filename


def export_event_list(
page: Page,
external_app: Any,
resource_manager: Any,
test_data_tmp_dir: Path,
otconfig_path: Path,
) -> Path:
"""Export event list from a pre-configured project.

This function:
- Loads the main page
- Opens the specified otconfig file
- Clicks the export event list 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 event list 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 eventlist ..." button
export_button = search_for_marker_element(
page, MARKER_BUTTON_EXPORT_EVENT_LIST
).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"Event list file not created: {output_path}"

return output_path


def export_track_statistics(
page: Page,
external_app: Any,
Expand Down
Loading