- scrobble.log in the data folder records queued, sent and failed scrobbles (stdout goes nowhere, so failures were invisible) - Queued scrobbles retry every 2 minutes; maybe_periodic was never called - One flush at a time, so a listen is never sent twice - The playing track's listen is queued on quit and sent on the next start - Listen time keeps counting while the window is hidden (Wayland stops frames) - Last.fm: says nothing is sent while logged out; waiting scrobbles can be discarded - Settings › Scrobbling: one card per service with its own send checkbox, text left and buttons right on one centre line; row labels left-aligned - iOS: send the listen as soon as it counts (not only at track change), retry every 2 minutes, log sends - Android: retry queued scrobbles every 2 minutes while playing Co-Authored-By: Claude Opus 5.5 <[email protected]>
170 lines
7 KiB
Rust
170 lines
7 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");
|
||
}
|
||
|
||
/// Settings › Scrobbling with Last.fm logged out (queue waiting) and ListenBrainz connected.
|
||
#[test]
|
||
fn scrobble_settings() {
|
||
let out = setup_env();
|
||
let st = mulberry::config::settings();
|
||
st.set("lastfm/enabled", true);
|
||
st.set("lastfm/session", "");
|
||
st.set("listenbrainz/enabled", true);
|
||
st.set("listenbrainz/token", "test-token");
|
||
st.set("listenbrainz/user", "tester");
|
||
let mut h = new_harness();
|
||
settle(&mut h, 20);
|
||
h.state_mut().do_action("settings");
|
||
settle(&mut h, 3);
|
||
if let Some(mulberry::ui::dialogs::Dialog::Settings(s)) = h.state_mut().dialog.as_mut() {
|
||
s.page = 3;
|
||
}
|
||
shot(&mut h, &out, "scrobble_settings");
|
||
if let Some(mulberry::ui::dialogs::Dialog::Settings(s)) = h.state_mut().dialog.as_mut() {
|
||
s.page = 1;
|
||
}
|
||
shot(&mut h, &out, "playback_settings");
|
||
// the startup flush (10 s) writes the scrobble log; queued Last.fm scrobbles wait while logged out
|
||
std::fs::write(mulberry::config::PATHS.data.join("scrobble_cache.json"), r#"[{"svc":"lastfm","ts":1796000000,"song":{"url":"/x.mp3","title":"T","artist":"A"}}]"#).unwrap();
|
||
let _ = std::fs::remove_file(mulberry::config::PATHS.data.join("scrobble.log"));
|
||
let _ = mulberry::scrobble::Scrobbler::new(h.state().bus.clone());
|
||
std::thread::sleep(std::time::Duration::from_secs(12));
|
||
let log = std::fs::read_to_string(mulberry::config::PATHS.data.join("scrobble.log")).unwrap_or_default();
|
||
assert!(log.contains("lastfm: 1 scrobble(s) wait for a login"), "scrobble.log: {log}");
|
||
}
|