Thing 2.0 cut 7a: commands (activate, Drafts, minted invocations, lifecycle, effects as data) #25
1 changed files with 56 additions and 0 deletions
Thing 2.0 cut 7a: tests for each command source kind and the wrong-key result
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
commit
bf7534859b
|
|
@ -949,3 +949,59 @@ fn stranger() -> CommandInvocation {
|
|||
invocation.invocation_id = "33333333-3333-4333-8333-333333333333".into();
|
||||
invocation
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_command_source_kind_fires_its_command_and_captures_its_own_draft_kind() {
|
||||
let slider = Node::Slider(SliderNode { common: common("vol"), min: 0.0, max: 1.0, step: 0.1, value: lit_number(0.2), commit: command("go") });
|
||||
let select = Node::Select(SelectNode {
|
||||
common: common("pick"),
|
||||
options: OptionList::Literal(LiteralOptions { options: vec![SelectOption { value: "a".into(), label: "A".into() }] }),
|
||||
value: record_bind(path(&["Theme"]), None),
|
||||
on_change: command("go"),
|
||||
});
|
||||
let overlay = Node::Overlay(OverlayNode {
|
||||
common: common("dialog"),
|
||||
anchor: Anchor::Viewport,
|
||||
modal: true,
|
||||
dismiss: command("go"),
|
||||
children: vec![],
|
||||
});
|
||||
let number = input("num", InputKind::Number, "1", "go");
|
||||
let document = surface(
|
||||
PROVIDER,
|
||||
boxed("root", vec![slider, select, overlay, number, input("txt", InputKind::Text, "t", "go")]),
|
||||
vec![decl("go", &["vol", "pick", "num"], None)],
|
||||
);
|
||||
let mut rig = Rig::new(MemState::new(), &document);
|
||||
// Drafts of each kind are what the captures send.
|
||||
rig.set_draft(&nid("vol"), InputValue::Number(NumberValue { value: 0.9 }));
|
||||
rig.set_draft(&nid("pick"), InputValue::Choice(ChoiceValue { value: "a".into() }));
|
||||
rig.set_draft(&nid("num"), InputValue::Number(NumberValue { value: 7.0 }));
|
||||
let mut ids = SeqIds::new();
|
||||
rig.act(&nid("dialog"), ActivationKind::Press, PINNED_NOW, &mut ids);
|
||||
rig.act(&nid("txt"), ActivationKind::Submit, PINNED_NOW, &mut ids);
|
||||
let minted = rig.commands.take_outbound();
|
||||
assert_eq!(minted.len(), 2);
|
||||
assert_eq!(minted[0].source, nid("dialog"));
|
||||
assert_eq!(minted[0].captured[0].value, InputValue::Number(NumberValue { value: 0.9 }));
|
||||
assert_eq!(minted[0].captured[1].value, InputValue::Choice(ChoiceValue { value: "a".into() }));
|
||||
assert_eq!(minted[0].captured[2].value, InputValue::Number(NumberValue { value: 7.0 }));
|
||||
assert_eq!(minted[1].source, nid("txt"));
|
||||
rig.act(&nid("vol"), ActivationKind::Change(InputValue::Number(NumberValue { value: 0.4 })), PINNED_NOW, &mut ids);
|
||||
rig.act(&nid("pick"), ActivationKind::Change(InputValue::Choice(ChoiceValue { value: "a".into() })), PINNED_NOW, &mut ids);
|
||||
let changed = rig.commands.take_outbound();
|
||||
assert_eq!(changed.len(), 2);
|
||||
assert_eq!(changed[0].source, nid("vol"));
|
||||
assert_eq!(changed[0].captured[0].value, InputValue::Number(NumberValue { value: 0.4 }));
|
||||
assert_eq!(changed[1].source, nid("pick"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_result_filed_under_the_wrong_key_says_so() {
|
||||
let mut rig = Rig::new(MemState::new(), &go_surface());
|
||||
let mine = rig.mint("go", PINNED_NOW);
|
||||
let body = CommandResult::pending(&mine, seq(1), "x");
|
||||
let address = rig.result_address(&CommandResult::pending(&mine, seq(2), "").record_key());
|
||||
let answered = rig.apply(&Change::Upsert(Entry { address, record: Record::Result(body) }), at(1));
|
||||
assert_eq!(answered.diagnostics[0].detail, "the result is not the one its key names");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue