From c70ce5af89e4e942eb81bc3b66327b2add4d9c78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Thu, 11 Sep 2025 06:24:13 +0200 Subject: [PATCH] Add `id` helper to `selector` module --- examples/todos/src/main.rs | 4 ++-- selector/src/lib.rs | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/examples/todos/src/main.rs b/examples/todos/src/main.rs index 98f6e90f..1aaaf614 100644 --- a/examples/todos/src/main.rs +++ b/examples/todos/src/main.rs @@ -617,8 +617,8 @@ fn presets() -> impl Iterator> { mod tests { use super::*; - use iced::widget; use iced::{Settings, Theme}; + use iced_test::selector::id; use iced_test::{Error, Simulator}; fn simulator(todos: &Todos) -> Simulator<'_, Message> { @@ -638,7 +638,7 @@ mod tests { let _command = todos.update(Message::Loaded(Err(LoadError::File))); let mut ui = simulator(&todos); - let _input = ui.click(widget::Id::new("new-task"))?; + let _input = ui.click(id("new-task"))?; let _ = ui.typewrite("Create the universe"); let _ = ui.tap_key(keyboard::key::Named::Enter); diff --git a/selector/src/lib.rs b/selector/src/lib.rs index ae1c733d..050d6a49 100644 --- a/selector/src/lib.rs +++ b/selector/src/lib.rs @@ -9,7 +9,7 @@ pub use find::{Find, FindAll}; pub use target::Target; use crate::core::Point; -use crate::core::widget::Id; +use crate::core::widget; pub trait Selector { type Output; @@ -79,7 +79,7 @@ impl Selector for String { } } -impl Selector for Id { +impl Selector for widget::Id { type Output = target::Match; fn select(&mut self, target: Target<'_>) -> Option { @@ -124,3 +124,8 @@ where format!("custom selector: {}", std::any::type_name_of_val(self)) } } + +/// Creates a new [`Selector`] that matches widgets with the given [`widget::Id`]. +pub fn id(id: impl Into) -> impl Selector { + id.into() +}