diff --git a/crates/eframe/src/epi.rs b/crates/eframe/src/epi.rs index bd46a2a88319..1a3dadf4ed6b 100644 --- a/crates/eframe/src/epi.rs +++ b/crates/eframe/src/epi.rs @@ -121,6 +121,7 @@ impl CreationContext<'_> { storage: None, gl: None, get_proc_address: None, + #[cfg(feature = "wgpu")] wgpu_render_state: None, raw_window_handle: Err(HandleError::NotSupported), raw_display_handle: Err(HandleError::NotSupported), @@ -682,6 +683,7 @@ impl Frame { raw_display_handle: Err(HandleError::NotSupported), raw_window_handle: Err(HandleError::NotSupported), storage: None, + #[cfg(feature = "wgpu")] wgpu_render_state: None, } } diff --git a/crates/egui_demo_app/src/apps/image_viewer.rs b/crates/egui_demo_app/src/apps/image_viewer.rs index ad7a8448640c..b756065c2622 100644 --- a/crates/egui_demo_app/src/apps/image_viewer.rs +++ b/crates/egui_demo_app/src/apps/image_viewer.rs @@ -52,8 +52,8 @@ impl eframe::App for ImageViewer { fn update(&mut self, ctx: &egui::Context, _: &mut eframe::Frame) { egui::TopBottomPanel::new(TopBottomSide::Top, "url bar").show(ctx, |ui| { ui.horizontal_centered(|ui| { - ui.label("URI:"); - ui.text_edit_singleline(&mut self.uri_edit_text); + let label = ui.label("URI:"); + ui.text_edit_singleline(&mut self.uri_edit_text).labelled_by(label.id); if ui.small_button("✔").clicked() { ctx.forget_image(&self.current_uri); self.uri_edit_text = self.uri_edit_text.trim().to_owned(); diff --git a/crates/egui_demo_app/tests/snapshots/clock.png b/crates/egui_demo_app/tests/snapshots/clock.png new file mode 100644 index 000000000000..6d7ede206776 --- /dev/null +++ b/crates/egui_demo_app/tests/snapshots/clock.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c0b7c0b88ece54c5225be734ef2850da6da00a05846111ecb49cc8945d52782f +size 322361 diff --git a/crates/egui_demo_app/tests/snapshots/easymarkeditor.png b/crates/egui_demo_app/tests/snapshots/easymarkeditor.png new file mode 100644 index 000000000000..cd245d84aada --- /dev/null +++ b/crates/egui_demo_app/tests/snapshots/easymarkeditor.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:69a2e57c83dcaded21e06bbefd97a09ba4dc6cbab8ab04d005a99dc676cfed69 +size 180025 diff --git a/crates/egui_demo_app/tests/snapshots/imageviewer.png b/crates/egui_demo_app/tests/snapshots/imageviewer.png new file mode 100644 index 000000000000..cd4eb98e8260 --- /dev/null +++ b/crates/egui_demo_app/tests/snapshots/imageviewer.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f15800cf5a1f8653149c3dd90554fca3905403559c919a2b2574b3359e14919a +size 97994 diff --git a/crates/egui_demo_app/tests/test_demo_app.rs b/crates/egui_demo_app/tests/test_demo_app.rs index 4b477bdcf5d3..2c13a3dfe9d3 100644 --- a/crates/egui_demo_app/tests/test_demo_app.rs +++ b/crates/egui_demo_app/tests/test_demo_app.rs @@ -1,4 +1,5 @@ use egui::accesskit::Role; +use egui::{Key, Modifiers}; use egui_demo_app::{Anchor, WrapApp}; use egui_kittest::kittest::Queryable; @@ -16,24 +17,50 @@ fn test_demo_app() { .map(|(name, anchor, _)| (name, anchor)) .collect::>(); - #[cfg(feature = "wgpu")] - assert!( - apps.iter() - .find(|(_, anchor)| matches!(anchor, Anchor::Custom3d)) - .is_some(), - "Expected to find the Custom3d app.", - ); + // #[cfg(feature = "wgpu")] + // assert!( + // apps.iter() + // .find(|(_, anchor)| matches!(anchor, Anchor::Custom3d)) + // .is_some(), + // "Expected to find the Custom3d app.", + // ); let mut results = vec![]; for (name, anchor) in apps { - // The widget gallery demo shows the current date, so we can't use it for snapshot testing - if matches!(anchor, Anchor::Demo) { - continue; - } - harness.get_by_role_and_label(Role::Button, name).click(); + match anchor { + // The widget gallery demo shows the current date, so we can't use it for snapshot testing + Anchor::Demo => { + continue; + } + // This is already tested extensively elsewhere + Anchor::Rendering => { + continue; + } + // We don't want to rely on a network connection for tests + Anchor::Http => { + continue; + } + // Load a local image where we know it exists and loads quickly + Anchor::ImageViewer => { + harness.run(); + + harness + .get_by_role_and_label(Role::TextInput, "URI:") + .focus(); + harness.press_key_modifiers(Modifiers::COMMAND, Key::A); + + harness + .get_by_role_and_label(Role::TextInput, "URI:") + .type_text(format!("file://../eframe/data/icon.png")); + + harness.get_by_role_and_label(Role::Button, "✔").click(); + } + _ => {} + } + harness.run(); harness diff --git a/crates/egui_kittest/src/builder.rs b/crates/egui_kittest/src/builder.rs index 2b53cace85cc..e6aa8f7cf884 100644 --- a/crates/egui_kittest/src/builder.rs +++ b/crates/egui_kittest/src/builder.rs @@ -99,12 +99,9 @@ impl HarnessBuilder { } /// Create a new [Harness] from the given eframe creation closure. - /// If the wgpu feature is enabled and [HarnessBuilder::wgpu] was called, the - /// [eframe::CreationContext] and [eframe::Frame] will have a [egui_wgpu::RenderState] - /// attached. pub fn build_eframe<'a>( self, - build: impl FnOnce(&mut eframe::CreationContext) -> State, + build: impl FnOnce(&mut eframe::CreationContext<'a>) -> State, ) -> Harness<'a, State> where State: eframe::App, diff --git a/crates/egui_kittest/src/lib.rs b/crates/egui_kittest/src/lib.rs index e4971d80c6db..6271d78f72cd 100644 --- a/crates/egui_kittest/src/lib.rs +++ b/crates/egui_kittest/src/lib.rs @@ -23,7 +23,7 @@ use std::mem; use crate::app_kind::AppKind; use crate::event::EventState; pub use builder::*; -use egui::{Pos2, Rect, TexturesDelta, Vec2, ViewportId}; +use egui::{Modifiers, Pos2, Rect, TexturesDelta, Vec2, ViewportId}; use kittest::{Node, Queryable}; /// The test Harness. This contains everything needed to run the test. @@ -155,7 +155,7 @@ impl<'a, State> Harness<'a, State> { } /// Create a new [Harness] from the given eframe creation closure. - pub fn new_eframe(builder: impl FnOnce(&mut eframe::CreationContext) -> State) -> Self + pub fn new_eframe(builder: impl FnOnce(&mut eframe::CreationContext<'a>) -> State) -> Self where State: eframe::App, { @@ -277,6 +277,25 @@ impl<'a, State> Harness<'a, State> { physical_key: None, }); } + + /// Press a key with modifiers. + /// This will create a key down event and a key up event. + pub fn press_key_modifiers(&mut self, modifiers: Modifiers, key: egui::Key) { + self.input.events.push(egui::Event::Key { + key, + pressed: true, + modifiers, + repeat: false, + physical_key: None, + }); + self.input.events.push(egui::Event::Key { + key, + pressed: false, + modifiers, + repeat: false, + physical_key: None, + }); + } } /// Utilities for stateless harnesses.