Some checks failed
rust-ci / checks (push) Has been cancelled
- Rust workspace: 7 library crates, icenetd CLI, icenet-city (Slint GUI) - Sim: fix false Delivered after a route cut, derive traffic class from payload size, per-link airtime slots (link capacity, queueing) - Docs: single docs/STATUS.md for all figures, remove v0.2/egui leftovers, drop unimplemented seed claims, uncheck store-and-forward - License: LGPL-3.0-or-later (LICENSE, LICENSES/GPL-3.0.txt)
100 lines
2.9 KiB
Rust
100 lines
2.9 KiB
Rust
//! Regression tests for UI commands with no graphical backend.
|
|
use icenet_city::state::UiState;
|
|
use icenet_core::{NodeId, TrafficClass};
|
|
use icenet_sim::DeliveryState;
|
|
|
|
#[test]
|
|
fn photo_avoids_slow_radio_after_fast_links_are_disabled() {
|
|
let mut app = UiState::default();
|
|
for index in [2, 3, 4, 5] {
|
|
app.city.set_link_enabled(index, false);
|
|
}
|
|
app.send(true);
|
|
assert_eq!(
|
|
app.city.messages.last().unwrap().status,
|
|
DeliveryState::Queued
|
|
);
|
|
assert!(
|
|
app.city
|
|
.route(NodeId(1), NodeId(3), TrafficClass::Text, 128)
|
|
.is_some()
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn toggling_a_device_and_restarting_are_deterministic() {
|
|
let mut app = UiState::default();
|
|
app.toggle_node(2);
|
|
assert!(
|
|
!app.city
|
|
.devices
|
|
.iter()
|
|
.find(|d| d.id == NodeId(2))
|
|
.unwrap()
|
|
.online
|
|
);
|
|
app = UiState::default();
|
|
assert!(app.city.devices.iter().all(|d| d.online));
|
|
}
|
|
|
|
#[test]
|
|
fn editor_adds_a_link_and_cycles_endpoints() {
|
|
let mut app = UiState::default();
|
|
app.add_node();
|
|
assert_eq!(app.to, NodeId(7));
|
|
app.connect();
|
|
assert!(
|
|
app.city
|
|
.links
|
|
.iter()
|
|
.any(|link| link.a == NodeId(1) && link.b == NodeId(7))
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn drag_uses_a_fixed_start_pointer_offset() {
|
|
let mut app = UiState::default();
|
|
app.start_drag(1, 409.0, 186.0);
|
|
app.drag_to(470.0, 240.0);
|
|
app.drag_to(530.0, 290.0);
|
|
let node = app
|
|
.city
|
|
.devices
|
|
.iter()
|
|
.find(|device| device.id == NodeId(1))
|
|
.expect("demo node");
|
|
assert!((node.x - 191.0).abs() < f32::EPSILON);
|
|
assert!((node.y - 189.0).abs() < f32::EPSILON);
|
|
app.end_drag();
|
|
app.drag_to(0.0, 0.0);
|
|
let node = app
|
|
.city
|
|
.devices
|
|
.iter()
|
|
.find(|device| device.id == NodeId(1))
|
|
.expect("demo node");
|
|
assert!((node.x - 191.0).abs() < f32::EPSILON);
|
|
}
|
|
|
|
#[test]
|
|
fn exports_csv_and_json_to_requested_paths() {
|
|
let mut app = UiState::default();
|
|
app.send(false);
|
|
let stamp = format!("icenet-test-{}", std::process::id());
|
|
let csv_path = std::env::temp_dir().join(format!("{stamp}.csv"));
|
|
let json_path = std::env::temp_dir().join(format!("{stamp}.json"));
|
|
|
|
app.export_csv(&csv_path).expect("csv export");
|
|
let csv = std::fs::read_to_string(&csv_path).expect("read csv");
|
|
assert!(csv.starts_with("id,from,to,class,bytes,status,"));
|
|
assert_eq!(csv.lines().count(), 2);
|
|
assert!(app.last_export.contains(&stamp));
|
|
|
|
app.export_json(&json_path).expect("json export");
|
|
let json = std::fs::read_to_string(&json_path).expect("read json");
|
|
assert!(json.contains("\"messages\""));
|
|
assert!(json.contains("\"devices\""));
|
|
|
|
std::fs::remove_file(csv_path).expect("cleanup csv");
|
|
std::fs::remove_file(json_path).expect("cleanup json");
|
|
}
|