Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add snapshot test for the help view #8955

Merged
merged 2 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions crates/viewer/re_ui/examples/re_ui_example/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ mod drag_and_drop;
mod hierarchical_drag_and_drop;
mod right_panel;

use egui::Modifiers;
use re_ui::filter_widget::format_matching_text;
use re_ui::{
filter_widget::FilterState, list_item, CommandPalette, ContextExt as _, DesignTokens, Help,
UICommand, UICommandSender, UiExt as _,
ModifiersText, UICommand, UICommandSender, UiExt as _,
};
use re_ui::{icon_text, icons, notifications};

Expand Down Expand Up @@ -483,7 +484,14 @@ impl egui_tiles::Behavior<Tab> for MyTileTreeBehavior {
Help::new("Help example")
.docs_link("https://rerun.io/docs/reference/types/views/map_view")
.control("Pan", icon_text!(icons::LEFT_MOUSE_CLICK, "+ drag"))
.control("Zoom", icon_text!("Ctrl/Cmd +", icons::SCROLL))
.control(
"Zoom",
icon_text!(
ModifiersText(Modifiers::COMMAND, ui.ctx()),
"+",
icons::SCROLL
),
)
.control("Reset view", icon_text!("double", icons::LEFT_MOUSE_CLICK))
.ui(ui);
});
Expand Down
66 changes: 66 additions & 0 deletions crates/viewer/re_ui/tests/help_ui_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
use egui::os::OperatingSystem;
use egui::{vec2, Modifiers};
use egui_kittest::kittest::Queryable;
use egui_kittest::{Harness, SnapshotResults};
use re_ui::{icon_text, icons, Help, ModifiersText, MouseButtonText, UiExt};

#[test]
fn test_help() {
let mut snapshot_results = SnapshotResults::new();
// We show different shortcuts based on the OS
for os in [OperatingSystem::Windows, OperatingSystem::Mac] {
let mut harness = Harness::builder()
.with_size(vec2(240.0, 420.0))
.build_ui(|ui| {
ui.ctx().set_os(os);
re_ui::apply_style_and_install_loaders(ui.ctx());

ui.help_hover_button().on_hover_ui(|ui| {
let mut help = Help::new("Help example")
.docs_link("https://rerun.io/docs/reference/types/views/map_view")
.control("Pan", icon_text!(icons::LEFT_MOUSE_CLICK, "+ drag"))
.control(
"Zoom",
icon_text!(
ModifiersText(Modifiers::COMMAND, ui.ctx()),
"+",
icons::SCROLL
),
)
.control("Reset view", icon_text!("double", icons::LEFT_MOUSE_CLICK));

for modifier in [
Modifiers::ALT,
Modifiers::SHIFT,
Modifiers::CTRL,
Modifiers::COMMAND,
Modifiers::MAC_CMD,
Modifiers::NONE,
] {
help = help.control(
format!("{:?}", modifier),
icon_text!(ModifiersText(modifier, ui.ctx())),
);
}

for btn in [
egui::PointerButton::Primary,
egui::PointerButton::Secondary,
egui::PointerButton::Middle,
egui::PointerButton::Extra1,
egui::PointerButton::Extra2,
] {
help = help.control(format!("{:?}", btn), icon_text!(MouseButtonText(btn)));
}

help.ui(ui);
});
});

harness.get_by_label("❓").hover();

harness.run();

snapshot_results.add(harness.try_snapshot(&format!("help_{os:?}")));
}
}
3 changes: 3 additions & 0 deletions crates/viewer/re_ui/tests/snapshots/help_Mac.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions crates/viewer/re_ui/tests/snapshots/help_Windows.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading