Skip to content

Commit

Permalink
Add snapshot tests for failed images with alt text
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmerlin committed Dec 29, 2024
1 parent 05052ab commit d43e34d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
7 changes: 4 additions & 3 deletions crates/egui/src/widgets/image.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{borrow::Cow, sync::Arc, time::Duration};

use emath::{Float as _, Rot2};
use emath::{Align, Float as _, Rot2};
use epaint::{
text::{LayoutJob, TextFormat, TextWrapping},
RectShape,
Expand Down Expand Up @@ -635,7 +635,8 @@ pub fn paint_texture_load_result(
Err(_) => {
let font_id = TextStyle::Body.resolve(ui.style());
let mut job = LayoutJob::default();
job.wrap = TextWrapping::wrap_at_width(rect.width());
job.wrap = TextWrapping::truncate_at_width(rect.width());
job.halign = Align::Center;
job.append(
"⚠",
0.0,
Expand All @@ -658,7 +659,7 @@ pub fn paint_texture_load_result(
}
let galley = ui.painter().layout_job(job);
ui.painter().galley(
rect.center() - 0.5 * galley.size(),
rect.center() - Vec2::Y * galley.size().y * 0.5,
galley,
ui.visuals().text_color(),
);
Expand Down
18 changes: 17 additions & 1 deletion crates/egui_kittest/tests/regression_tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use egui::Button;
use egui::{Button, Image, Vec2, Widget};
use egui_kittest::{kittest::Queryable, Harness};

#[test]
Expand Down Expand Up @@ -27,3 +27,19 @@ pub fn focus_should_skip_over_disabled_buttons() {
let button_1 = harness.get_by_label("Button 1");
assert!(button_1.is_focused());
}

#[test]
fn image_failed() {
let mut harness = Harness::new_ui(|ui| {
Image::new("file://invalid/path")
.alt_text("I have an alt text")
.max_size(Vec2::new(100.0, 100.0))
.ui(ui);
});

harness.run();
harness.fit_contents();

#[cfg(all(feature = "wgpu", feature = "snapshot"))]
harness.wgpu_snapshot("image_snapshots");
}
3 changes: 3 additions & 0 deletions crates/egui_kittest/tests/snapshots/image_snapshots.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d43e34d

Please sign in to comment.