11import os
22import shutil
33import tempfile
4- from importlib . resources import files
4+ from datetime import datetime
55from pathlib import Path
66from unittest .mock import MagicMock
77
1010from textual .widgets import Button , Collapsible , Input
1111
1212from virtualship .cli ._plan import ExpeditionEditor , PlanApp
13- from virtualship .utils import EXPEDITION
13+ from virtualship .models import (
14+ Expedition ,
15+ InstrumentsConfig ,
16+ Location ,
17+ Schedule ,
18+ Waypoint ,
19+ )
20+ from virtualship .utils import EXPEDITION , get_example_expedition
1421
1522NEW_SPEED = "8.0"
16- NEW_LAT = "0.05 "
17- NEW_LON = "0.05 "
23+ NEW_LAT = "0.015 "
24+ NEW_LON = "0.015 "
1825
1926
2027async def simulate_input (pilot , box , new_value ):
@@ -33,10 +40,34 @@ async def test_UI_changes():
3340 """Test making changes to UI inputs and saving to YAML (simulated botton presses and typing inputs)."""
3441 tmpdir = Path (tempfile .mkdtemp ())
3542
36- shutil .copy (
37- files ("virtualship.static" ).joinpath (EXPEDITION ),
38- tmpdir / EXPEDITION ,
43+ instruments_config = InstrumentsConfig .model_validate (
44+ yaml .safe_load (get_example_expedition ()).get ("instruments_config" )
3945 )
46+ ship_config = yaml .safe_load (get_example_expedition ()).get ("ship_config" )
47+ waypoints = [
48+ Waypoint (
49+ location = Location (0 , 0 ),
50+ time = datetime (2022 , 1 , 1 , 0 , 0 , 0 ),
51+ instrument = ["CTD" ],
52+ ),
53+ Waypoint (
54+ location = Location (0.01 , 0.01 ),
55+ time = datetime (2022 , 1 , 1 , 1 , 0 , 0 ),
56+ instrument = ["CTD" ],
57+ ),
58+ Waypoint (
59+ location = Location (0.02 , 0.02 ),
60+ time = datetime (2022 , 1 , 1 , 2 , 0 , 0 ),
61+ instrument = ["CTD" ],
62+ ),
63+ ]
64+ expedition = Expedition (
65+ schedule = Schedule (waypoints = waypoints ),
66+ instruments_config = instruments_config ,
67+ ship_config = ship_config ,
68+ )
69+
70+ expedition .to_yaml (tmpdir / EXPEDITION )
4071
4172 app = PlanApp (path = tmpdir )
4273
@@ -59,18 +90,18 @@ async def test_UI_changes():
5990 ship_speed_input = expedition_editor .query_one ("#speed" , Input )
6091 await simulate_input (pilot , ship_speed_input , NEW_SPEED )
6192
62- # change waypoint lat/lon (e.g. first waypoint)
93+ # change waypoint lat/lon (second waypoint)
6394 waypoints_collapsible = expedition_editor .query_one ("#waypoints" , Collapsible )
6495 if waypoints_collapsible .collapsed :
6596 waypoints_collapsible .collapsed = False
6697 await pilot .pause ()
67- wp_collapsible = waypoints_collapsible .query_one ("#wp1 " , Collapsible )
98+ wp_collapsible = waypoints_collapsible .query_one ("#wp2 " , Collapsible )
6899 if wp_collapsible .collapsed :
69100 wp_collapsible .collapsed = False
70101 await pilot .pause ()
71102 lat_input , lon_input = (
72- wp_collapsible .query_one ("#wp0_lat " , Input ),
73- wp_collapsible .query_one ("#wp0_lat " , Input ),
103+ wp_collapsible .query_one ("#wp1_lat " , Input ),
104+ wp_collapsible .query_one ("#wp1_lon " , Input ),
74105 )
75106 await simulate_input (pilot , lat_input , NEW_LAT )
76107 await simulate_input (pilot , lon_input , NEW_LON )
0 commit comments