nigig-org/crates/apps/nigig-traffic/tests/ui_basic.rs

65 lines
2.5 KiB
Rust
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//! Headless smoke tests (NOT GUI coverage).
//!
//! These never launch the GUI or render a frame: they prove the catalog
//! builds road geometry and the fixed-step loop runs. Real navigation,
//! render, touch, lifecycle, and persistence journeys live in
//! `tests/runtime_ui.rs` (headless production path) and `tests/ui.rs`
//! (GUI harness, currently ignored with reason/owner/expiry).
use nigig_traffic::game_frame::RenderMode;
use nigig_traffic::traffic::TrafficWorld;
#[test]
fn traffic_world_loads_and_ticks() {
let mut world = TrafficWorld::new();
world.load_scenario(0);
let scenario = world.scenario().expect("scenario loaded").clone();
assert!(!scenario.title.is_empty());
// Tick a few frames with no input – should stay in Intro then Driving
let input = makepad_game_blocks::DriveInput::default();
for _ in 0..70 {
world.tick(&input);
}
assert!(world.run.tick >= 70);
// Intro books exactly 60 ticks, then the run goes live.
assert_eq!(world.run.phase, nigig_traffic::traffic::Phase::Driving);
}
#[test]
fn traffic_world_navigates_scenarios() {
let mut world = TrafficWorld::new();
world.load_scenario(0);
let first = world.scenario().expect("scenario loaded").id;
world.next();
let second = world.scenario().expect("scenario loaded").id;
assert_ne!(first, second);
world.prev();
assert_eq!(world.scenario().expect("scenario loaded").id, first);
}
#[test]
fn render_mode_labels_are_stable() {
assert_eq!(RenderMode::TopDown.label(), "Top-Down");
assert_eq!(RenderMode::Chase25D.label(), "Chase-Cam (2.5D)");
assert_eq!(RenderMode::Full3D.label(), "Full 3D");
}
#[test]
fn traffic_world_builds_first_scenarios_without_panic() {
// Headless smoke: every scenario must build road geometry and survive
// ticks (no panics in `build_world_for`, id ordering, or `evaluate`
// with no scenario edge cases). The actual GPU frame is only written by
// a real headless binary run, not by this test.
let all = TrafficWorld::all_scenarios();
assert!(all.len() >= 47);
for (idx, s) in all.iter().enumerate() {
let mut world = TrafficWorld::new();
world.load_scenario(idx);
// Intro (60) + 60 driving ticks: exercises phase flip + evaluator.
for _ in 0..120 {
world.tick(&makepad_game_blocks::DriveInput::default());
}
assert_eq!(world.run.tick, 120, "{}", s.id);
assert_eq!(world.run.phase, nigig_traffic::traffic::Phase::Driving);
}
}