Dispatch source hit testing for native pointer clicks
Verify Tessera GUI / verify (push) Failing after 7m31s

This commit is contained in:
2026-10-21 15:37:26 +08:00
parent d19fab55b9
commit 7b11e32eb6
14 changed files with 560 additions and 30 deletions
+129 -1
View File
@@ -801,6 +801,120 @@ mod tests {
const EXAMPLE: &str = include_str!("../examples/hello.endor");
const PAGE: &str = include_str!("../examples/page.endor");
#[test]
fn source_hit_filters_shape_falls_back_and_requires_matching_press_release() {
for (press, release, expected_hits, expected_background) in [
([64.0, 64.0], [64.0, 64.0], "1", "0"),
([144.0, 64.0], [144.0, 64.0], "0", "1"),
([64.0, 64.0], [144.0, 64.0], "0", "0"),
([9999.0, 9999.0], [9999.0, 9999.0], "0", "0"),
] {
let (mut session, initial) = ReplSession::load(
include_str!("../examples/source-hit.endor"),
"app.main",
81,
1,
)
.unwrap();
let circle = initial
.frame
.mounts
.iter()
.find(|mount| mount.interactive && mount.width == 160.0)
.unwrap();
session
.dispatch(&crate::events::Input {
session: 81,
layout_version: initial.frame.layout_version,
mount: circle.id,
kind: "click".into(),
point: Some(release),
press_point: Some(press),
})
.unwrap();
assert_eq!(
session.execute("hits.value", "app.main").unwrap().value,
expected_hits
);
assert_eq!(
session
.execute("background.value", "app.main")
.unwrap()
.value,
expected_background
);
}
}
#[test]
fn source_hit_rejects_wrong_result_and_business_writes_before_callbacks() {
for (body, message) in [
("return 1", "hitTest must return Bool"),
(
"self.hits.increment()\nreturn point.inCircle(40, 40, 40)",
"read-only",
),
] {
let source = include_str!("../examples/source-hit.endor")
.replace("return point.inCircle(40, 40, 40)", body);
let (mut session, initial) = ReplSession::load(&source, "app.main", 82, 1).unwrap();
let circle = initial
.frame
.mounts
.iter()
.find(|mount| mount.interactive && mount.width == 160.0)
.unwrap();
let error = session
.dispatch(&crate::events::Input {
session: 82,
layout_version: initial.frame.layout_version,
mount: circle.id,
kind: "click".into(),
point: Some([64.0, 64.0]),
press_point: Some([64.0, 64.0]),
})
.err()
.unwrap();
assert!(error.to_string().contains(message), "{error}");
assert!(session.is_faulted());
let globals = session.candidate.globals.unwrap();
let Value::Object(hits) = session
.candidate
.vm
.dict_get(globals, &Value::Text("hits".into()))
.unwrap()
.unwrap()
else {
panic!("state")
};
assert_eq!(
session.candidate.vm.get_attr(hits, "value").unwrap(),
Value::Number(0.into())
);
}
}
#[test]
fn ordinary_block_subscription_updates_interactivity_after_disconnect() {
let source = r##"hits = ui.state(0)
rect = RectBlock(80, 40, 0, "#DDEEFF")
token = rect.on("click", hits.increment)
page = Page()
page.render(rect)"##;
let (mut session, initial) = ReplSession::load(source, "app.main", 83, 1).unwrap();
assert!(initial.frame.mounts.iter().any(|mount| mount.interactive));
let result = session.execute("token.disconnect()", "app.main").unwrap();
assert!(
result
.document
.unwrap()
.frame
.mounts
.iter()
.all(|mount| !mount.interactive)
);
}
#[test]
fn source_paint_can_rebind_old_plain_reference_to_new_result_without_mutating_it() {
let source = r##"class ReboundRect: RectBlock {
@@ -1198,11 +1312,21 @@ mod tests {
}
fn click_document(session: &mut ReplSession, document: &RenderDocument) -> RenderDocument {
let globals = session.candidate.globals.unwrap();
let Value::Object(button) = session
.candidate
.vm
.dict_get(globals, &Value::Text("button".into()))
.unwrap()
.unwrap()
else {
panic!("Button")
};
let mount = document
.frame
.mounts
.iter()
.find(|mount| mount.interactive)
.find(|mount| mount.interactive && mount.block_id == button.to_string())
.unwrap();
session
.dispatch(&crate::events::Input {
@@ -1210,6 +1334,8 @@ mod tests {
layout_version: document.frame.layout_version,
mount: mount.id,
kind: "click".into(),
point: None,
press_point: None,
})
.unwrap()
.document
@@ -1486,6 +1612,8 @@ mod tests {
layout_version: initial.frame.layout_version,
mount: mount.id,
kind: "click".into(),
point: None,
press_point: None,
};
let updated = session.dispatch(&event).unwrap().document.unwrap();
updated.validate().unwrap();