#![cfg(not(target_arch = "wasm32"))]
use standard_plugin::prelude::*;
use standard_plugin::surface::Model;
use standard_plugin::testing::{Harness, MockHost};
struct Counter {
card: Surface<Cells>,
count: u32,
}
impl UiPlugin for Counter {
fn activate(cx: &mut Context) -> Self {
let count = cx.values().get("counter.count").ok().flatten().unwrap_or(0);
Self {
card: Surface::new("card"),
count,
}
}
fn frame(&mut self, _frame: &Frame) {
self.card
.text(0, 0, &format!("count {}", self.count), Style::DEFAULT);
let _ = self.card.commit();
}
}
#[test]
fn the_harness_lays_out_frames_and_records_commits() {
let mut host = MockHost::new("counter").surface("card", Model::Cells);
host.values.insert("counter.count".into(), "41".into());
let mut harness = Harness::<Counter>::activate(host, "{}");
harness.resize("card", Geometry::cells(12, 1, (0, 0)));
harness.frame(0, 16, standard_plugin::Power::Mains);
let commits = harness.commits("card");
assert_eq!(commits.len(), 1);
assert!(commits[0].full, "the first commit covers the whole card");
harness.plugin(|counter| assert_eq!(counter.card.row_text(0), "count 41 "));
}