mirror of
https://github.com/lahfir/agent-desktop.git
synced 2026-07-27 01:22:16 +00:00
test: consolidate ref and locator fixtures
This commit is contained in:
parent
bdca8f9824
commit
d04732f368
13 changed files with 57 additions and 286 deletions
|
|
@ -331,7 +331,7 @@ pub(crate) fn load_ref_entry(
|
|||
|
||||
#[cfg(test)]
|
||||
#[path = "helpers_test_support.rs"]
|
||||
mod test_support;
|
||||
pub(super) mod test_support;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "helpers_tests.rs"]
|
||||
|
|
|
|||
|
|
@ -48,3 +48,16 @@ pub(super) fn text_entry() -> RefEntry {
|
|||
entry.capabilities.available_actions = vec!["SetValue".into()];
|
||||
entry
|
||||
}
|
||||
|
||||
pub(in crate::commands) fn save_one_ref_snapshot(role: &str, available_action: &str) -> String {
|
||||
let mut entry = entry();
|
||||
entry.identity.role = role.into();
|
||||
entry.identity.name = Some("Target".into());
|
||||
entry.capabilities.available_actions = vec![available_action.into()];
|
||||
let mut refmap = crate::refs::RefMap::new();
|
||||
refmap.allocate(entry);
|
||||
crate::refs_store::RefStore::new()
|
||||
.unwrap()
|
||||
.save_new_snapshot(&refmap)
|
||||
.unwrap()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,9 @@
|
|||
use super::*;
|
||||
use crate::adapter::{ActionOps, InputOps, ObservationOps, SystemOps};
|
||||
use crate::commands::helpers::test_support::save_one_ref_snapshot;
|
||||
use crate::{
|
||||
AdapterError, Direction,
|
||||
action_request::ActionRequest,
|
||||
action_result::ActionResult,
|
||||
adapter::NativeHandle,
|
||||
commands::stale_retry_test_support::StaleRetryCounter,
|
||||
refs::{RefEntry, RefMap},
|
||||
refs_store::RefStore,
|
||||
AdapterError, Direction, action_request::ActionRequest, action_result::ActionResult,
|
||||
adapter::NativeHandle, commands::stale_retry_test_support::StaleRetryCounter, refs::RefEntry,
|
||||
refs_test_support::HomeGuard,
|
||||
};
|
||||
|
||||
|
|
@ -52,47 +48,7 @@ impl SystemOps for StaleThenOkAdapter {
|
|||
}
|
||||
|
||||
fn snapshot_id() -> String {
|
||||
let mut refmap = RefMap::new();
|
||||
let bounds = crate::Rect {
|
||||
x: 1.0,
|
||||
y: 1.0,
|
||||
width: 20.0,
|
||||
height: 20.0,
|
||||
};
|
||||
refmap.allocate(RefEntry {
|
||||
process: crate::RefProcess {
|
||||
pid: crate::ProcessId::new(1),
|
||||
process_instance: Some("test-instance".into()),
|
||||
},
|
||||
identity: crate::RefEntryIdentity {
|
||||
role: "scrollarea".into(),
|
||||
name: Some("Target".into()),
|
||||
value: None,
|
||||
description: None,
|
||||
native_id: None,
|
||||
},
|
||||
geometry: crate::RefGeometry {
|
||||
bounds: Some(bounds),
|
||||
bounds_hash: bounds.bounds_hash(),
|
||||
},
|
||||
capabilities: crate::RefCapabilities {
|
||||
states: vec![],
|
||||
available_actions: vec!["Scroll".into()],
|
||||
},
|
||||
source: crate::RefSource {
|
||||
source_app: None,
|
||||
source_window_id: None,
|
||||
source_window_title: None,
|
||||
source_window_bounds_hash: None,
|
||||
source_surface: crate::adapter::SnapshotSurface::Window,
|
||||
},
|
||||
scope: crate::RefScope {
|
||||
root_ref: None,
|
||||
path_is_absolute: false,
|
||||
path: smallvec::SmallVec::new(),
|
||||
},
|
||||
});
|
||||
RefStore::new().unwrap().save_new_snapshot(&refmap).unwrap()
|
||||
save_one_ref_snapshot("scrollarea", "Scroll")
|
||||
}
|
||||
|
||||
/// Regression for the F2 fix: before it, `scroll::execute` always built its
|
||||
|
|
|
|||
|
|
@ -1,13 +1,9 @@
|
|||
use super::*;
|
||||
use crate::adapter::{ActionOps, InputOps, ObservationOps, SystemOps};
|
||||
use crate::commands::helpers::test_support::save_one_ref_snapshot;
|
||||
use crate::{
|
||||
AdapterError,
|
||||
action_request::ActionRequest,
|
||||
action_result::ActionResult,
|
||||
adapter::NativeHandle,
|
||||
commands::stale_retry_test_support::StaleRetryCounter,
|
||||
refs::{RefEntry, RefMap},
|
||||
refs_store::RefStore,
|
||||
AdapterError, action_request::ActionRequest, action_result::ActionResult,
|
||||
adapter::NativeHandle, commands::stale_retry_test_support::StaleRetryCounter, refs::RefEntry,
|
||||
refs_test_support::HomeGuard,
|
||||
};
|
||||
|
||||
|
|
@ -52,47 +48,7 @@ impl SystemOps for StaleThenOkAdapter {
|
|||
}
|
||||
|
||||
fn snapshot_id() -> String {
|
||||
let mut refmap = RefMap::new();
|
||||
let bounds = crate::Rect {
|
||||
x: 1.0,
|
||||
y: 1.0,
|
||||
width: 20.0,
|
||||
height: 20.0,
|
||||
};
|
||||
refmap.allocate(RefEntry {
|
||||
process: crate::RefProcess {
|
||||
pid: crate::ProcessId::new(1),
|
||||
process_instance: Some("test-instance".into()),
|
||||
},
|
||||
identity: crate::RefEntryIdentity {
|
||||
role: "combobox".into(),
|
||||
name: Some("Target".into()),
|
||||
value: None,
|
||||
description: None,
|
||||
native_id: None,
|
||||
},
|
||||
geometry: crate::RefGeometry {
|
||||
bounds: Some(bounds),
|
||||
bounds_hash: bounds.bounds_hash(),
|
||||
},
|
||||
capabilities: crate::RefCapabilities {
|
||||
states: vec![],
|
||||
available_actions: vec!["Select".into()],
|
||||
},
|
||||
source: crate::RefSource {
|
||||
source_app: None,
|
||||
source_window_id: None,
|
||||
source_window_title: None,
|
||||
source_window_bounds_hash: None,
|
||||
source_surface: crate::adapter::SnapshotSurface::Window,
|
||||
},
|
||||
scope: crate::RefScope {
|
||||
root_ref: None,
|
||||
path_is_absolute: false,
|
||||
path: smallvec::SmallVec::new(),
|
||||
},
|
||||
});
|
||||
RefStore::new().unwrap().save_new_snapshot(&refmap).unwrap()
|
||||
save_one_ref_snapshot("combobox", "Select")
|
||||
}
|
||||
|
||||
/// Regression for the F2 fix: before it, `select::execute` always built its
|
||||
|
|
|
|||
|
|
@ -1,13 +1,9 @@
|
|||
use super::*;
|
||||
use crate::adapter::{ActionOps, InputOps, ObservationOps, SystemOps};
|
||||
use crate::commands::helpers::test_support::save_one_ref_snapshot;
|
||||
use crate::{
|
||||
AdapterError,
|
||||
action_request::ActionRequest,
|
||||
action_result::ActionResult,
|
||||
adapter::NativeHandle,
|
||||
commands::stale_retry_test_support::StaleRetryCounter,
|
||||
refs::{RefEntry, RefMap},
|
||||
refs_store::RefStore,
|
||||
AdapterError, action_request::ActionRequest, action_result::ActionResult,
|
||||
adapter::NativeHandle, commands::stale_retry_test_support::StaleRetryCounter, refs::RefEntry,
|
||||
refs_test_support::HomeGuard,
|
||||
};
|
||||
|
||||
|
|
@ -56,47 +52,7 @@ impl SystemOps for StaleThenOkAdapter {
|
|||
}
|
||||
|
||||
fn snapshot_id() -> String {
|
||||
let mut refmap = RefMap::new();
|
||||
let bounds = crate::Rect {
|
||||
x: 1.0,
|
||||
y: 1.0,
|
||||
width: 20.0,
|
||||
height: 20.0,
|
||||
};
|
||||
refmap.allocate(RefEntry {
|
||||
process: crate::RefProcess {
|
||||
pid: crate::ProcessId::new(1),
|
||||
process_instance: Some("test-instance".into()),
|
||||
},
|
||||
identity: crate::RefEntryIdentity {
|
||||
role: "textfield".into(),
|
||||
name: Some("Target".into()),
|
||||
value: None,
|
||||
description: None,
|
||||
native_id: None,
|
||||
},
|
||||
geometry: crate::RefGeometry {
|
||||
bounds: Some(bounds),
|
||||
bounds_hash: bounds.bounds_hash(),
|
||||
},
|
||||
capabilities: crate::RefCapabilities {
|
||||
states: vec![],
|
||||
available_actions: vec!["SetValue".into()],
|
||||
},
|
||||
source: crate::RefSource {
|
||||
source_app: None,
|
||||
source_window_id: None,
|
||||
source_window_title: None,
|
||||
source_window_bounds_hash: None,
|
||||
source_surface: crate::adapter::SnapshotSurface::Window,
|
||||
},
|
||||
scope: crate::RefScope {
|
||||
root_ref: None,
|
||||
path_is_absolute: false,
|
||||
path: smallvec::SmallVec::new(),
|
||||
},
|
||||
});
|
||||
RefStore::new().unwrap().save_new_snapshot(&refmap).unwrap()
|
||||
save_one_ref_snapshot("textfield", "SetValue")
|
||||
}
|
||||
|
||||
/// Regression for the F2 fix: before it, `set_value::execute` always built its
|
||||
|
|
|
|||
|
|
@ -1,13 +1,9 @@
|
|||
use super::*;
|
||||
use crate::adapter::{ActionOps, InputOps, ObservationOps, SystemOps};
|
||||
use crate::commands::helpers::test_support::save_one_ref_snapshot;
|
||||
use crate::{
|
||||
AdapterError,
|
||||
action_request::ActionRequest,
|
||||
action_result::ActionResult,
|
||||
adapter::NativeHandle,
|
||||
commands::stale_retry_test_support::StaleRetryCounter,
|
||||
refs::{RefEntry, RefMap},
|
||||
refs_store::RefStore,
|
||||
AdapterError, action_request::ActionRequest, action_result::ActionResult,
|
||||
adapter::NativeHandle, commands::stale_retry_test_support::StaleRetryCounter, refs::RefEntry,
|
||||
refs_test_support::HomeGuard,
|
||||
};
|
||||
|
||||
|
|
@ -56,47 +52,7 @@ impl SystemOps for StaleThenOkAdapter {
|
|||
}
|
||||
|
||||
fn snapshot_id() -> String {
|
||||
let mut refmap = RefMap::new();
|
||||
let bounds = crate::Rect {
|
||||
x: 1.0,
|
||||
y: 1.0,
|
||||
width: 20.0,
|
||||
height: 20.0,
|
||||
};
|
||||
refmap.allocate(RefEntry {
|
||||
process: crate::RefProcess {
|
||||
pid: crate::ProcessId::new(1),
|
||||
process_instance: Some("test-instance".into()),
|
||||
},
|
||||
identity: crate::RefEntryIdentity {
|
||||
role: "textfield".into(),
|
||||
name: Some("Target".into()),
|
||||
value: None,
|
||||
description: None,
|
||||
native_id: None,
|
||||
},
|
||||
geometry: crate::RefGeometry {
|
||||
bounds: Some(bounds),
|
||||
bounds_hash: bounds.bounds_hash(),
|
||||
},
|
||||
capabilities: crate::RefCapabilities {
|
||||
states: vec![],
|
||||
available_actions: vec!["SetValue".into()],
|
||||
},
|
||||
source: crate::RefSource {
|
||||
source_app: None,
|
||||
source_window_id: None,
|
||||
source_window_title: None,
|
||||
source_window_bounds_hash: None,
|
||||
source_surface: crate::adapter::SnapshotSurface::Window,
|
||||
},
|
||||
scope: crate::RefScope {
|
||||
root_ref: None,
|
||||
path_is_absolute: false,
|
||||
path: smallvec::SmallVec::new(),
|
||||
},
|
||||
});
|
||||
RefStore::new().unwrap().save_new_snapshot(&refmap).unwrap()
|
||||
save_one_ref_snapshot("textfield", "SetValue")
|
||||
}
|
||||
|
||||
/// Regression for the F2 fix: before it, `type_text::execute` always built its
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use super::resolve_query_tests::window;
|
||||
use super::test_support::window;
|
||||
use super::{
|
||||
LocatorMaterialization, LocatorResolveRequest, LocatorSelection, ObservationRequest,
|
||||
ObservationRoot, ObservedTree, resolve_query,
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use super::test_support::window;
|
||||
use super::{
|
||||
LocatorMaterialization, LocatorResolveRequest, LocatorSelection, LocatorStats,
|
||||
ObservationRequest, ObservationRoot, ObservedTree, resolve_query,
|
||||
};
|
||||
use crate::{
|
||||
AdapterError, AppError, ErrorCode, WindowInfo,
|
||||
AdapterError, AppError, ErrorCode,
|
||||
adapter::{ActionOps, InputOps, ObservationOps, SystemOps},
|
||||
locator::{LocatorQuery, StatePredicate},
|
||||
};
|
||||
|
|
@ -84,21 +85,6 @@ fn child_label_cap(_: usize) -> ObservedTree {
|
|||
observed_tree(true, stats)
|
||||
}
|
||||
|
||||
pub(super) fn window() -> WindowInfo {
|
||||
WindowInfo {
|
||||
id: "w-1".into(),
|
||||
title: "Fixture".into(),
|
||||
app: "FixtureApp".into(),
|
||||
pid: crate::ProcessId::new(42),
|
||||
process_instance: Some("test-instance".into()),
|
||||
bounds: None,
|
||||
state: crate::WindowState {
|
||||
is_focused: true,
|
||||
..Default::default()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resolve_query_validates_before_calling_the_adapter() {
|
||||
let adapter = CountingAdapter {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
use super::test_support::window;
|
||||
use super::{
|
||||
IdentifierEvidence, LocatorField, LocatorMaterialization, LocatorResolveRequest,
|
||||
LocatorSelection, ObservationRequest, ObservationRoot, ObservationSource, ObservedTree,
|
||||
resolve_query,
|
||||
};
|
||||
use crate::{
|
||||
AdapterError, ElementIdentifier, IdentifierKind, LocatorQuery, NativeHandle, Rect, WindowInfo,
|
||||
AdapterError, ElementIdentifier, IdentifierKind, LocatorQuery, NativeHandle, Rect,
|
||||
adapter::{ActionOps, InputOps, ObservationOps, SystemOps},
|
||||
};
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
|
@ -279,18 +280,3 @@ fn moved_bounds() -> Rect {
|
|||
..button_bounds()
|
||||
}
|
||||
}
|
||||
|
||||
fn window() -> WindowInfo {
|
||||
WindowInfo {
|
||||
id: "w-1".into(),
|
||||
title: "Fixture".into(),
|
||||
app: "FixtureApp".into(),
|
||||
pid: crate::ProcessId::new(42),
|
||||
process_instance: Some("test-instance".into()),
|
||||
bounds: None,
|
||||
state: crate::WindowState {
|
||||
is_focused: true,
|
||||
..Default::default()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
use super::test_support::window;
|
||||
use super::{
|
||||
IdentifierEvidence, LocatorField, LocatorMaterialization, LocatorResolveRequest,
|
||||
LocatorSelection, ObservationRequest, ObservationRoot, ObservationSource, ObservedTree,
|
||||
resolve_query,
|
||||
};
|
||||
use crate::{
|
||||
AdapterError, AppError, LocatorQuery, NativeHandle, Rect, WindowInfo,
|
||||
AdapterError, AppError, LocatorQuery, NativeHandle, Rect,
|
||||
adapter::{ActionOps, InputOps, ObservationOps, SystemOps},
|
||||
};
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
|
@ -253,18 +254,3 @@ fn bounds() -> Rect {
|
|||
height: 30.0,
|
||||
}
|
||||
}
|
||||
|
||||
fn window() -> WindowInfo {
|
||||
WindowInfo {
|
||||
id: "w-1".into(),
|
||||
title: "Fixture".into(),
|
||||
app: "FixtureApp".into(),
|
||||
pid: crate::ProcessId::new(42),
|
||||
process_instance: Some("test-instance".into()),
|
||||
bounds: None,
|
||||
state: crate::WindowState {
|
||||
is_focused: true,
|
||||
..Default::default()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
use super::test_support::window;
|
||||
use super::{
|
||||
IdentifierEvidence, LocatorField, LocatorMaterialization, LocatorResolveRequest,
|
||||
LocatorSelection, ObservationRequest, ObservationRoot, ObservationSource, ObservedTree,
|
||||
resolve_query,
|
||||
};
|
||||
use crate::{
|
||||
AdapterError, AppError, ContainmentPredicate, LocatorQuery, NativeHandle, Rect, WindowInfo,
|
||||
AdapterError, AppError, ContainmentPredicate, LocatorQuery, NativeHandle, Rect,
|
||||
adapter::{ActionOps, InputOps, ObservationOps, SystemOps},
|
||||
};
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
|
@ -314,18 +315,3 @@ fn root_bounds() -> Rect {
|
|||
height: 200.0,
|
||||
}
|
||||
}
|
||||
|
||||
fn window() -> WindowInfo {
|
||||
WindowInfo {
|
||||
id: "w-1".into(),
|
||||
title: "Fixture".into(),
|
||||
app: "FixtureApp".into(),
|
||||
pid: crate::ProcessId::new(42),
|
||||
process_instance: Some("test-instance".into()),
|
||||
bounds: None,
|
||||
state: crate::WindowState {
|
||||
is_focused: true,
|
||||
..Default::default()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
use super::test_support::window;
|
||||
use super::{
|
||||
IdentifierEvidence, LocatorEvidence, LocatorField, LocatorMaterialization, LocatorRefEvidence,
|
||||
LocatorResolveRequest, LocatorSelection, LocatorStats, ObservationRequest, ObservationRoot,
|
||||
ObservationSource, ObservedTree, resolve_query,
|
||||
};
|
||||
use crate::{
|
||||
AdapterError, ElementIdentifier, IdentifierKind, LocatorQuery, NativeHandle, Rect, WindowInfo,
|
||||
AdapterError, ElementIdentifier, IdentifierKind, LocatorQuery, NativeHandle, Rect,
|
||||
adapter::{ActionOps, InputOps, ObservationOps, SystemOps},
|
||||
};
|
||||
use std::{
|
||||
|
|
@ -252,18 +253,3 @@ fn button_bounds() -> Rect {
|
|||
height: 30.0,
|
||||
}
|
||||
}
|
||||
|
||||
fn window() -> WindowInfo {
|
||||
WindowInfo {
|
||||
id: "w-1".into(),
|
||||
title: "Fixture".into(),
|
||||
app: "FixtureApp".into(),
|
||||
pid: crate::ProcessId::new(42),
|
||||
process_instance: Some("test-instance".into()),
|
||||
bounds: None,
|
||||
state: crate::WindowState {
|
||||
is_focused: true,
|
||||
..Default::default()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,21 @@ use super::{
|
|||
};
|
||||
use crate::{WindowInfo, refs::RefPath};
|
||||
|
||||
pub(super) fn window() -> WindowInfo {
|
||||
WindowInfo {
|
||||
id: "w-1".into(),
|
||||
title: "Fixture".into(),
|
||||
app: "FixtureApp".into(),
|
||||
pid: crate::ProcessId::new(42),
|
||||
process_instance: Some("test-instance".into()),
|
||||
bounds: None,
|
||||
state: crate::WindowState {
|
||||
is_focused: true,
|
||||
..Default::default()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn evidence(role: &str, name: Option<&str>) -> LocatorEvidence {
|
||||
LocatorEvidence {
|
||||
role: LocatorField::Known(role.to_string()),
|
||||
|
|
@ -46,18 +61,7 @@ pub(crate) fn tree(
|
|||
ObservedTree {
|
||||
nodes,
|
||||
roots,
|
||||
source: ObservationSource::Window(WindowInfo {
|
||||
id: "w-1".into(),
|
||||
title: "Fixture".into(),
|
||||
app: "FixtureApp".into(),
|
||||
pid: crate::ProcessId::new(42),
|
||||
process_instance: Some("test-instance".into()),
|
||||
bounds: None,
|
||||
state: crate::WindowState {
|
||||
is_focused: true,
|
||||
..Default::default()
|
||||
},
|
||||
}),
|
||||
source: ObservationSource::Window(window()),
|
||||
stats: LocatorStats::default(),
|
||||
structurally_complete,
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue