Test different Theme variants in styling example

This commit is contained in:
Héctor Ramón Jiménez 2025-04-01 02:54:45 +02:00
parent ced4276a5e
commit 2b7d8eaaca
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
27 changed files with 69 additions and 35 deletions

View file

@ -167,3 +167,42 @@ impl Styling {
self.theme.clone()
}
}
#[cfg(test)]
mod tests {
use super::*;
use rayon::prelude::*;
use iced_test::{Error, simulator};
#[test]
#[ignore]
fn it_showcases_every_theme() -> Result<(), Error> {
Theme::ALL
.par_iter()
.map(|theme| {
let mut styling = Styling::default();
styling.update(Message::ThemeChanged(theme.clone()));
let theme = styling.theme();
let mut ui = simulator(styling.view());
let snapshot = ui.snapshot(&theme)?;
assert!(
snapshot.matches_hash(format!(
"snapshots/{theme}",
theme = theme
.to_string()
.to_ascii_lowercase()
.replace(" ", "_")
))?,
"snapshots for {theme} should match!"
);
Ok(())
})
.collect()
}
}