Port of the Python/PyQt6 app: same library database, playlists, hero panel, lyrics, tag editor, MusicBrainz/cover tools, CD ripping, MPRIS and tray. New: right-click 'Set <tag> to "value"' writes the clicked cell's tag into every selected file (with undo). The seek bar now runs off a monotonic position clock so it can't jump back and forth. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
139 lines
5.5 KiB
Rust
139 lines
5.5 KiB
Rust
//! Offscreen UI screenshots (no window): `MULBERRY_TEST=1 MULBERRY_SCRATCH=… cargo test --test shots -- --nocapture`.
|
|
//! Uses a scratch copy of the user's library so nothing real is modified.
|
|
|
|
use eframe::egui::{self, pos2, vec2, Event, Key, Modifiers, PointerButton};
|
|
use egui_kittest::Harness;
|
|
use mulberry::app::App;
|
|
|
|
type H<'a> = Harness<'a, App>;
|
|
|
|
fn setup_env() -> String {
|
|
let sc = std::path::PathBuf::from(std::env::var("MULBERRY_SCRATCH").expect("set MULBERRY_SCRATCH"));
|
|
std::env::set_var("MULBERRY_TEST", "1");
|
|
std::env::set_var("XDG_DATA_HOME", sc.join("data"));
|
|
std::env::set_var("XDG_CONFIG_HOME", sc.join("config"));
|
|
std::env::set_var("XDG_CACHE_HOME", sc.join("cache"));
|
|
let out = sc.join("shots").to_string_lossy().into_owned();
|
|
std::fs::create_dir_all(&out).unwrap();
|
|
out
|
|
}
|
|
|
|
fn click(h: &mut H, pos: egui::Pos2, button: PointerButton, mods: Modifiers) {
|
|
h.input_mut().events.push(Event::ModifiersChanged(mods));
|
|
h.input_mut().events.push(Event::PointerMoved(pos));
|
|
h.step();
|
|
h.input_mut().events.push(Event::PointerButton { pos, button, pressed: true, modifiers: mods });
|
|
h.step();
|
|
h.input_mut().events.push(Event::PointerButton { pos, button, pressed: false, modifiers: mods });
|
|
h.step();
|
|
h.input_mut().events.push(Event::ModifiersChanged(Modifiers::NONE));
|
|
h.step();
|
|
}
|
|
|
|
fn key(h: &mut H, k: Key, mods: Modifiers) {
|
|
h.input_mut().events.push(Event::Key { key: k, physical_key: Some(k), pressed: true, repeat: false, modifiers: mods });
|
|
h.step();
|
|
h.input_mut().events.push(Event::Key { key: k, physical_key: Some(k), pressed: false, repeat: false, modifiers: mods });
|
|
h.step();
|
|
}
|
|
|
|
fn settle(h: &mut H, n: usize) {
|
|
for _ in 0..n {
|
|
h.step();
|
|
std::thread::sleep(std::time::Duration::from_millis(30));
|
|
}
|
|
}
|
|
|
|
fn shot(h: &mut H, out: &str, name: &str) {
|
|
settle(h, 3);
|
|
h.render().expect("render").save(format!("{out}/{name}.png")).unwrap();
|
|
}
|
|
|
|
fn new_harness<'a>() -> H<'a> {
|
|
let h = Harness::builder().with_size(vec2(1380.0, 860.0)).wgpu().build_eframe(|cc| App::new(cc, vec![]));
|
|
// the real app gets system-font fallback from eframe; the test harness doesn't
|
|
h.ctx.set_missing_glyph_policy(eframe::epaint::text::MissingGlyphPolicy::Tofu);
|
|
h
|
|
}
|
|
|
|
#[test]
|
|
fn ui_tour() {
|
|
let out = setup_env();
|
|
let mut h = new_harness();
|
|
settle(&mut h, 30);
|
|
shot(&mut h, &out, "main");
|
|
|
|
// ---- sidebar tabs
|
|
for (x, name) in [(34.0, "lib"), (92.0, "files"), (211.0, "radio"), (270.0, "cd")] {
|
|
click(&mut h, pos2(x, 60.0), PointerButton::Primary, Modifiers::NONE);
|
|
settle(&mut h, 6);
|
|
shot(&mut h, &out, name);
|
|
}
|
|
// library: expand the first artist and first album
|
|
click(&mut h, pos2(34.0, 60.0), PointerButton::Primary, Modifiers::NONE);
|
|
settle(&mut h, 4);
|
|
click(&mut h, pos2(23.0, 154.0), PointerButton::Primary, Modifiers::NONE);
|
|
settle(&mut h, 4);
|
|
click(&mut h, pos2(40.0, 190.0), PointerButton::Primary, Modifiers::NONE);
|
|
shot(&mut h, &out, "lib_expanded");
|
|
|
|
// ---- menu bar
|
|
click(&mut h, pos2(120.0, 18.0), PointerButton::Primary, Modifiers::NONE);
|
|
shot(&mut h, &out, "menubar");
|
|
key(&mut h, Key::Escape, Modifiers::NONE);
|
|
|
|
// ---- dialogs
|
|
key(&mut h, Key::Comma, Modifiers::COMMAND);
|
|
shot(&mut h, &out, "settings");
|
|
for (y, name) in [(115.0, "settings_play"), (165.0, "settings_look"), (215.0, "settings_scrobble")] {
|
|
click(&mut h, pos2(300.0, y + 40.0), PointerButton::Primary, Modifiers::NONE);
|
|
shot(&mut h, &out, name);
|
|
}
|
|
key(&mut h, Key::Escape, Modifiers::NONE);
|
|
click(&mut h, pos2(520.0, 560.0), PointerButton::Primary, Modifiers::NONE);
|
|
click(&mut h, pos2(520.0, 620.0), PointerButton::Primary, Modifiers::SHIFT);
|
|
key(&mut h, Key::E, Modifiers::COMMAND);
|
|
shot(&mut h, &out, "tags");
|
|
key(&mut h, Key::Escape, Modifiers::NONE);
|
|
|
|
// ---- focus mode, compact / hidden hero
|
|
key(&mut h, Key::F11, Modifiers::NONE);
|
|
shot(&mut h, &out, "focus");
|
|
key(&mut h, Key::F11, Modifiers::NONE);
|
|
mulberry::config::settings().set("appearance/hero", "compact");
|
|
shot(&mut h, &out, "compact");
|
|
mulberry::config::settings().set("appearance/hero", "hidden");
|
|
shot(&mut h, &out, "hidden");
|
|
mulberry::config::settings().set("appearance/hero", "full");
|
|
}
|
|
|
|
#[test]
|
|
fn dialogs_tour() {
|
|
let out = setup_env();
|
|
let mut h = new_harness();
|
|
settle(&mut h, 20);
|
|
for (action, name) in [("equalizer", "d_eq"), ("export_all", "d_export"), ("about", "d_about"), ("settings", "d_settings")] {
|
|
h.state_mut().do_action(action);
|
|
shot(&mut h, &out, name);
|
|
key(&mut h, Key::Escape, Modifiers::NONE);
|
|
settle(&mut h, 2);
|
|
}
|
|
// settings pages
|
|
h.state_mut().do_action("settings");
|
|
settle(&mut h, 3);
|
|
for (i, y) in [(1, 258.0), (2, 308.0), (3, 358.0), (4, 408.0), (5, 458.0)] {
|
|
click(&mut h, pos2(350.0, y), PointerButton::Primary, Modifiers::NONE);
|
|
shot(&mut h, &out, &format!("d_settings_{i}"));
|
|
}
|
|
key(&mut h, Key::Escape, Modifiers::NONE);
|
|
// rip dialog with two fake CD tracks
|
|
let mut s = mulberry::song::Song::new("cdda://1");
|
|
s.title = "Track 1".into();
|
|
s.track = 1;
|
|
s.cd_track = 1;
|
|
h.state_mut().dialog = Some(mulberry::ui::dialogs::Dialog::rip(vec![s]));
|
|
shot(&mut h, &out, "d_rip");
|
|
key(&mut h, Key::Escape, Modifiers::NONE);
|
|
h.state_mut().dialog = Some(mulberry::ui::dialogs::Dialog::lyrics_editor("[00:01.00]hello\n[00:05.00]world".into()));
|
|
shot(&mut h, &out, "d_lyrics");
|
|
}
|