Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/dwarves

crates/nornir-warehouse-nav/tests/robot_universe_fit_flies.rs

//! **⊙ fit flies in the universe star-field** — the viewer's ⊙ fit takes the camera
//! back to the whole cloud on the SHARED smooth zoom-and-pan path
//! (`facett_graphpan::fly_to_bounds` over `facett_core::fly`), like every other view,
//! never in one jump: a quarter second after the click the camera is between where the
//! viewer left it and the fit, and it lands exactly on the fit.

#![cfg(not(target_arch = "wasm32"))]

use std::cell::RefCell;
use std::rc::Rc;

use egui::{pos2, vec2};
use egui_kittest::kittest::Queryable;
use egui_kittest::Harness;
use facett_core::Facet;
use nornir_warehouse_nav::WarehouseNav;

fn camera(nav: &Rc<RefCell<WarehouseNav>>) -> (egui::Vec2, f32) {
    let v = nav.borrow().world_view_snapshot();
    (v.pan, v.zoom)
}

#[test]
fn the_universe_fit_flies_on_the_shared_path() {
    let nav = Rc::new(RefCell::new(WarehouseNav::from_fixture_with_functions(2_000)));
    let n = nav.clone();
    let mut h = Harness::builder().with_size(vec2(1200.0, 900.0)).build_ui(move |ui| {
        n.borrow_mut().ui(ui);
    });
    nav.borrow_mut().update_json(r#"{"world_target":2000}"#);
    nav.borrow_mut().update_json(r#"{"universe":true}"#);
    h.run();
    h.run();
    let fit = camera(&nav);

    // the viewer drags the star-field away
    let (a, b) = (pos2(600.0, 600.0), pos2(900.0, 750.0));
    h.hover_at(a);
    h.step();
    h.drag_at(a);
    h.step();
    h.hover_at(b);
    h.step();
    h.drop_at(b);
    h.step();
    let left = camera(&nav);
    assert!((left.0 - fit.0).length() > 100.0, "the drag moved the camera: {left:?} vs the fit {fit:?}");

    h.get_by_label("⊙ fit").click();
    h.step(); // the click lands: a flight starts where the camera IS
    h.step(); // a quarter second in
    let mid = camera(&nav);
    let (to_fit, to_left) = ((mid.0 - fit.0).length(), (mid.0 - left.0).length());
    assert!(to_fit > 1.0 && to_left > 1.0, "a quarter second after ⊙ fit the camera is ON THE WAY, not jumped: {mid:?} (left {left:?}, fit {fit:?})");

    h.run();
    let end = camera(&nav);
    assert!((end.0 - fit.0).length() < 0.5 && (end.1 - fit.1).abs() < 1e-3, "it lands on the fit: {end:?} vs {fit:?}");
    assert!(Facet::state_json(&*nav.borrow())["universe"] == true);
}