thing-core: drain state updates between frames and assert expected dismiss/scroll in keyboard tests

This commit is contained in:
Meta Vens 2026-12-06 01:01:09 +01:00
commit 2d027c248b

View file

@ -146,6 +146,7 @@ fn complete_latest(host: &mut Host, invocation: &CommandInvocation) {
let provider = ProviderId::new(PROVIDER);
let result = CommandResult::completed(invocation, seq(1), None, false, None);
host.state.put(&provider, &result);
host.frame(vec![]);
}
#[test]
@ -257,7 +258,7 @@ fn modal_trap_f05_opener_restore_and_escape() {
// Escape mints dismiss whatever has focus inside the modal.
let esc = host.frame(vec![key(Key::Escape)]);
assert_eq!(esc.outbound.len(), 1, "{mode:?}");
assert_eq!(esc.outbound[0].command.as_str(), "cancel", "{mode:?}");
assert_eq!(esc.outbound[0].command.as_str(), "dismiss", "{mode:?}");
}
// Modal opening from a focused background button saves opener, traps focus, and closing returns to opener.
@ -330,7 +331,8 @@ fn focus_survives_republish_and_repeat_reorder_and_falls_back_on_removal() {
// Tab to item-0000, then Tab to item-0001.
host.frame(vec![key(Key::Tab)]);
host.frame(vec![key(Key::Tab)]);
// Reorder by deleting item-0000 and republishing? First check republish keeping id keeps focus.
// Reorder by inserting item-0000a before item-0001, and republish: focus keeps item-0001.
host.state.put_state(&ProviderId::new(FEED), "item-0000a", &Item { id: "item-0000a".into(), title: "item-0000a".into() });
host.state.put(&doc.provider_id, &doc);
assert_eq!(focus_rings(&host.frame(vec![])).len(), 1);
// Activating Enter fires on item-0001.
@ -338,22 +340,29 @@ fn focus_survives_republish_and_repeat_reorder_and_falls_back_on_removal() {
assert_eq!(out1.outbound[0].items, vec!["item-0001"]);
complete_latest(&mut host, &out1.outbound[0]);
// Remove item-0001: fallback must move to nearest preceding focusable (item-0000).
// Remove item-0001: fallback must move to nearest preceding focusable (item-0000a).
host.state.delete(&Address {
provider: ProviderId::new(FEED),
schema: SchemaId::new("gamecult.thing.test.item.v1"),
key: RecordKey::new("item-0001"),
});
host.frame(vec![]);
let after_del_1 = host.frame(vec![key(Key::Enter)]);
assert_eq!(after_del_1.outbound[0].items, vec!["item-0000"]);
assert_eq!(after_del_1.outbound[0].items, vec!["item-0000a"]);
complete_latest(&mut host, &after_del_1.outbound[0]);
// Remove item-0000 (first in order, no preceding): fallback must move to next (item-0002).
// Remove item-0000a and item-0000 (first in order, no preceding): fallback must move to next (item-0002).
host.state.delete(&Address {
provider: ProviderId::new(FEED),
schema: SchemaId::new("gamecult.thing.test.item.v1"),
key: RecordKey::new("item-0000a"),
});
host.state.delete(&Address {
provider: ProviderId::new(FEED),
schema: SchemaId::new("gamecult.thing.test.item.v1"),
key: RecordKey::new("item-0000"),
});
host.frame(vec![]);
let after_del_0 = host.frame(vec![key(Key::Enter)]);
assert_eq!(after_del_0.outbound[0].items, vec!["item-0002"]);
@ -525,13 +534,14 @@ fn key_scroll_and_reveal_in_pixels_and_cells() {
// Scroll pane down by 5 rows with wheel, then Tab to row 0 (scrolled out above!).
// Reveal must bring row 0 inside pane at offset 0 (least offset).
let before_scroll = host.frame(vec![]);
let scrolled = host.frame(vec![InputEvent::Wheel {
at: inside(pane_rect),
delta: (0.0, step * 5.0),
unit: WheelUnit::Units,
modifiers: mods(),
}]);
assert_ne!(scrolled.commands, host.frame(vec![]).commands);
assert_ne!(scrolled.commands, before_scroll.commands);
let revealed = host.frame(vec![key(Key::Tab)]);
let rings = focus_rings(&revealed);