summaryrefslogtreecommitdiffstats
path: root/examples/todos
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-12-06 04:06:41 +0100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-12-10 04:51:08 +0100
commit1aeb317f2dbfb63215e6226073e67878ffa6503b (patch)
treed883266d796360a1e4d883dc82a4fb284f724790 /examples/todos
parent8e3636d769d96ab5ba49a9647b72c59ae2226dd0 (diff)
downloadiced-1aeb317f2dbfb63215e6226073e67878ffa6503b.tar.gz
iced-1aeb317f2dbfb63215e6226073e67878ffa6503b.tar.bz2
iced-1aeb317f2dbfb63215e6226073e67878ffa6503b.zip
Add image and hash snapshot-based testing to `iced_test`
Diffstat (limited to 'examples/todos')
-rw-r--r--examples/todos/snapshots/creates_a_new_task.sha2561
-rw-r--r--examples/todos/src/main.rs15
2 files changed, 13 insertions, 3 deletions
diff --git a/examples/todos/snapshots/creates_a_new_task.sha256 b/examples/todos/snapshots/creates_a_new_task.sha256
new file mode 100644
index 00000000..fcfee315
--- /dev/null
+++ b/examples/todos/snapshots/creates_a_new_task.sha256
@@ -0,0 +1 @@
+5047c10c4ea050393b686185b8d03b3c3738b47182f9892fb68df589ec46bd4b \ No newline at end of file
diff --git a/examples/todos/src/main.rs b/examples/todos/src/main.rs
index 51d09962..ff38c6ce 100644
--- a/examples/todos/src/main.rs
+++ b/examples/todos/src/main.rs
@@ -15,7 +15,7 @@ pub fn main() -> iced::Result {
iced::application(Todos::title, Todos::update, Todos::view)
.subscription(Todos::subscription)
- .font(include_bytes!("../fonts/icons.ttf").as_slice())
+ .font(Todos::ICON_FONT)
.window_size((500.0, 800.0))
.run_with(Todos::new)
}
@@ -48,6 +48,8 @@ enum Message {
}
impl Todos {
+ const ICON_FONT: &[u8] = include_bytes!("../fonts/icons.ttf");
+
fn new() -> (Self, Command<Message>) {
(
Self::Loading,
@@ -449,11 +451,10 @@ fn empty_message(message: &str) -> Element<'_, Message> {
}
// Fonts
-const ICONS: Font = Font::with_name("Iced-Todos-Icons");
fn icon(unicode: char) -> Text<'static> {
text(unicode.to_string())
- .font(ICONS)
+ .font(Font::with_name("Iced-Todos-Icons"))
.width(20)
.align_x(Center)
}
@@ -594,6 +595,8 @@ mod tests {
#[test]
fn it_creates_a_new_task() -> Result<(), test::Error> {
+ test::load_font(Todos::ICON_FONT)?;
+
let (mut todos, _command) = Todos::new();
let _command = todos.update(Message::Loaded(Err(LoadError::File)));
@@ -610,6 +613,12 @@ mod tests {
let mut interface = test::interface(todos.view());
let _ = interface.find(selector::text("Create the universe"))?;
+ let snapshot = interface.snapshot()?;
+ assert!(
+ snapshot.matches_hash("snapshots/creates_a_new_task")?,
+ "snapshots should match!"
+ );
+
Ok(())
}
}