diff options
author | 2024-12-06 04:06:41 +0100 | |
---|---|---|
committer | 2024-12-10 04:51:08 +0100 | |
commit | 1aeb317f2dbfb63215e6226073e67878ffa6503b (patch) | |
tree | d883266d796360a1e4d883dc82a4fb284f724790 /examples | |
parent | 8e3636d769d96ab5ba49a9647b72c59ae2226dd0 (diff) | |
download | iced-1aeb317f2dbfb63215e6226073e67878ffa6503b.tar.gz iced-1aeb317f2dbfb63215e6226073e67878ffa6503b.tar.bz2 iced-1aeb317f2dbfb63215e6226073e67878ffa6503b.zip |
Add image and hash snapshot-based testing to `iced_test`
Diffstat (limited to 'examples')
-rw-r--r-- | examples/gradient/src/main.rs | 10 | ||||
-rw-r--r-- | examples/todos/snapshots/creates_a_new_task.sha256 | 1 | ||||
-rw-r--r-- | examples/todos/src/main.rs | 15 |
3 files changed, 17 insertions, 9 deletions
diff --git a/examples/gradient/src/main.rs b/examples/gradient/src/main.rs index b2de069f..910ea9fc 100644 --- a/examples/gradient/src/main.rs +++ b/examples/gradient/src/main.rs @@ -1,5 +1,5 @@ -use iced::application; use iced::gradient; +use iced::theme; use iced::widget::{ checkbox, column, container, horizontal_space, row, slider, text, }; @@ -95,16 +95,14 @@ impl Gradient { .into() } - fn style(&self, theme: &Theme) -> application::Appearance { - use application::DefaultStyle; - + fn style(&self, theme: &Theme) -> theme::Style { if self.transparent { - application::Appearance { + theme::Style { background_color: Color::TRANSPARENT, text_color: theme.palette().text, } } else { - Theme::default_style(theme) + theme::default(theme) } } } 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(()) } } |