summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-12-03 22:03:06 +0100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-12-10 04:51:08 +0100
commitd09d5d45ae4697eef277dfe30756b91c7d802a94 (patch)
treece1852b218aa46f5400cee383ccfb68faa61abaf /examples
parentd6182299b9db7a1928b7740736d53196e33d66e3 (diff)
downloadiced-d09d5d45ae4697eef277dfe30756b91c7d802a94.tar.gz
iced-d09d5d45ae4697eef277dfe30756b91c7d802a94.tar.bz2
iced-d09d5d45ae4697eef277dfe30756b91c7d802a94.zip
Draft `iced_test` crate and test `todos` example
Diffstat (limited to 'examples')
-rw-r--r--examples/todos/Cargo.toml3
-rw-r--r--examples/todos/src/main.rs33
2 files changed, 36 insertions, 0 deletions
diff --git a/examples/todos/Cargo.toml b/examples/todos/Cargo.toml
index 0d72be86..65c34a8f 100644
--- a/examples/todos/Cargo.toml
+++ b/examples/todos/Cargo.toml
@@ -26,6 +26,9 @@ uuid = { version = "1.0", features = ["js"] }
web-sys = { workspace = true, features = ["Window", "Storage"] }
wasm-timer.workspace = true
+[dev-dependencies]
+iced_test.workspace = true
+
[package.metadata.deb]
assets = [
["target/release-opt/todos", "usr/bin/iced-todos", "755"],
diff --git a/examples/todos/src/main.rs b/examples/todos/src/main.rs
index 25e3ead2..8772bb80 100644
--- a/examples/todos/src/main.rs
+++ b/examples/todos/src/main.rs
@@ -584,3 +584,36 @@ impl SavedState {
Ok(())
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ use iced::test;
+ use iced::test::selector;
+
+ #[test]
+ fn it_creates_a_new_task() {
+ let (mut todos, _command) = Todos::new();
+ let _command = todos.update(Message::Loaded(Err(LoadError::File)));
+
+ let mut interface = test::interface(todos.view());
+
+ let _input = interface
+ .click("new-task")
+ .expect("new-task input must be present");
+
+ interface.typewrite("Create the universe");
+ interface.press_key(keyboard::key::Named::Enter);
+
+ for message in interface.into_messages() {
+ let _command = todos.update(message);
+ }
+
+ let mut interface = test::interface(todos.view());
+
+ let _ = interface
+ .find(selector::text("Create the universe"))
+ .expect("New task must be present");
+ }
+}