feat(test): bind text assertions to targets

This commit is contained in:
slhx agent
2026-07-13 10:07:40 +02:00
parent e70c863da7
commit 6b4bb97aaa
3 changed files with 65 additions and 5 deletions
+27 -3
View File
@@ -462,17 +462,41 @@ impl EffectInspector {
self.has_resource(target.__hemx_resource_id())
}
/// Assert that a generated target receives a text update, without matching raw effects.
/// Check that a generated target receives a text update, without matching raw effects.
/// req: test/001 req: dx/006
pub fn updates_text(&self, target: impl GeneratedTarget) -> bool {
self.has_text_update_containing(target.__hemx_resource_id(), "")
}
/// Check that a generated target receives a text update containing a fragment.
///
/// This associates the payload condition with the intended target, unlike a separate global
/// [`Self::payload_contains`] check that can accidentally match another operation.
/// req: test/001 req: test/018 req: dx/006
pub fn updates_text_containing(&self, target: impl GeneratedTarget, needle: &str) -> bool {
self.has_text_update_containing(target.__hemx_resource_id(), needle)
}
/// Assert that a generated target receives a text update containing a fragment.
/// req: test/001 req: test/018 req: dx/006
#[track_caller]
pub fn assert_updates_text_containing(&self, target: impl GeneratedTarget, needle: &str) {
let resource = target.__hemx_resource_id();
assert!(
self.has_text_update_containing(resource, needle),
"expected a text update for {resource:?} containing {needle:?}; actual effects: {:#?}",
self.batch.ops
);
}
fn has_text_update_containing(&self, resource: ResourceId, needle: &str) -> bool {
self.batch.ops.iter().any(|op| {
matches!(
op,
Effect::Put {
target,
payload: Payload::Text(_),
} if target.resource == resource
payload: Payload::Text(text),
} if target.resource == resource && text.contains(needle)
)
})
}