Add id helper to selector module
This commit is contained in:
parent
bc9951f84f
commit
c70ce5af89
2 changed files with 9 additions and 4 deletions
|
|
@ -617,8 +617,8 @@ fn presets() -> impl Iterator<Item = Preset<Todos, Message>> {
|
|||
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);
|
||||
|
|
|
|||
|
|
@ -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<Self::Output> {
|
||||
|
|
@ -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<widget::Id>) -> impl Selector<Output = target::Match> {
|
||||
id.into()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue