mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-28 13:02:21 +01:00
* history: optional stats strip above History behind a Labs toggle * history: fit the stats strip in narrow translated windows
4215 lines
145 KiB
Rust
4215 lines
145 KiB
Rust
use super::accessibility_tests::a11y_value;
|
||
use super::settings::{desktop_shortcut, recorded_binding, validate};
|
||
use super::*;
|
||
use crate::transcription::models::TranscriptionSelection;
|
||
use rune::render::Gpu;
|
||
use rune::text::TextSystem;
|
||
use rune::{Env, Key, KeyEvent, Mods, Runtime};
|
||
|
||
/// Tall enough to show every General section without scrolling.
|
||
const GOLDEN_SIZE: (f32, f32) = (980.0, 1720.0);
|
||
/// The window's own size, for the other panes.
|
||
const PANE_SIZE: (f32, f32) = (980.0, 760.0);
|
||
const GOLDEN_SCALE: f32 = 2.0;
|
||
|
||
fn runtime(scene: &str, dark: bool, size: (f32, f32)) -> Runtime<Ui> {
|
||
let mut state = Ui::with(AppSettings::default(), Service::Fixture(Vec::new()));
|
||
let (_, apply) = SCENES
|
||
.iter()
|
||
.find(|(name, _)| *name == scene)
|
||
.unwrap_or_else(|| panic!("no scene {scene}"));
|
||
apply(&mut state);
|
||
runtime_for(state, dark, size)
|
||
}
|
||
|
||
fn runtime_for(state: Ui, dark: bool, size: (f32, f32)) -> Runtime<Ui> {
|
||
let env = Env {
|
||
system_dark: dark,
|
||
scale: GOLDEN_SCALE,
|
||
};
|
||
let text = TextSystem::new(rune_theme_opencode::FONTS, rune_theme_opencode::FAMILIES);
|
||
let mut rt = crate::rune_ui::offscreen::runtime(state, view, size, env, text);
|
||
rt.poll = Some(poll);
|
||
rt.on_key = Some(on_key);
|
||
// Fixtures show the state at rest, so sequences that play on mount
|
||
// (a granted permission's Allowed) land before the first frame.
|
||
rt.settle_all();
|
||
rt.frame(0.0);
|
||
rt
|
||
}
|
||
|
||
fn sent(rt: &Runtime<Ui>) -> &[Request] {
|
||
match &rt.state.service {
|
||
Service::Fixture(sent) => sent,
|
||
_ => panic!("fixtures never reach a host"),
|
||
}
|
||
}
|
||
|
||
fn saved(rt: &Runtime<Ui>) -> usize {
|
||
rt.state.saved
|
||
}
|
||
|
||
/// The text shown, without the recorder's invisible sizing faces.
|
||
fn texts(rt: &Runtime<Ui>) -> Vec<String> {
|
||
rt.elements()
|
||
.into_iter()
|
||
.filter(|e| !e.path.contains("/faces/size"))
|
||
.filter_map(|e| e.text)
|
||
.collect()
|
||
}
|
||
|
||
/// The text under element `root` in the accessibility tree, in order,
|
||
/// without the recorder's invisible sizing faces.
|
||
fn texts_under(rt: &Runtime<Ui>, root: &str) -> Vec<String> {
|
||
rt.elements()
|
||
.into_iter()
|
||
.filter(|e| e.path.contains(root) && !e.path.contains("/faces/size"))
|
||
.filter_map(|e| e.text)
|
||
.collect()
|
||
}
|
||
|
||
/// Presses an element by key and lets every animation settle.
|
||
fn tap(rt: &mut Runtime<Ui>, key: &str) {
|
||
let (x, y) = rt.find(key).unwrap_or_else(|| panic!("no element {key}"));
|
||
rt.pointer_down(x, y);
|
||
rt.pointer_up(x, y);
|
||
settle(rt);
|
||
}
|
||
|
||
/// Wheels a scrolling body until `key` sits inside it, for a page taller
|
||
/// than the window.
|
||
fn scroll_into_view(rt: &mut Runtime<Ui>, key: &str, viewport: &str) {
|
||
for _ in 0..400 {
|
||
let view = element(rt, viewport).rect;
|
||
let target = element(rt, key).rect;
|
||
if target[1] >= view[1] && target[1] + target[3] <= view[1] + view[3] {
|
||
return;
|
||
}
|
||
// A positive delta moves the content down.
|
||
let dy = if target[1] < view[1] { 20.0 } else { -20.0 };
|
||
rt.wheel(view[0] + view[2] / 2.0, view[1] + view[3] / 2.0, dy);
|
||
rt.frame(1.0 / 60.0);
|
||
}
|
||
panic!("{key} never scrolled into {viewport}");
|
||
}
|
||
|
||
/// Opens Labs with every group unfolded, so each card is on screen.
|
||
fn open_labs(rt: &mut Runtime<Ui>) {
|
||
tap(rt, "nav-labs");
|
||
unfold_labs(rt);
|
||
}
|
||
|
||
fn unfold_labs(rt: &mut Runtime<Ui>) {
|
||
for group in crate::labs::Group::ALL {
|
||
rt.state
|
||
.settings
|
||
.labs
|
||
.groups
|
||
.insert(group.id().to_string(), true);
|
||
}
|
||
rt.invalidate();
|
||
settle(rt);
|
||
}
|
||
|
||
/// Chooses option `index` from the quiet select keyed `{key}-control`.
|
||
fn pick(rt: &mut Runtime<Ui>, key: &str, index: usize) {
|
||
tap(rt, &format!("{key}-control-trigger"));
|
||
tap_option(rt, index);
|
||
}
|
||
|
||
/// Scrolls an open select's list to option `index` and presses it.
|
||
fn tap_option(rt: &mut Runtime<Ui>, index: usize) {
|
||
let key = format!("option{index}");
|
||
for _ in 0..400 {
|
||
let option = element(rt, &key).rect;
|
||
let list = element(rt, "listbox").rect;
|
||
let middle = option[1] + option[3] / 2.0;
|
||
if middle > list[1] && middle < list[1] + list[3] {
|
||
break;
|
||
}
|
||
// A positive delta moves the content down, so bringing a row below
|
||
// the list into view needs a negative one.
|
||
let dy = if middle > list[1] + list[3] {
|
||
-20.0
|
||
} else {
|
||
20.0
|
||
};
|
||
rt.wheel(list[0] + list[2] / 2.0, list[1] + list[3] / 2.0, dy);
|
||
rt.frame(1.0 / 60.0);
|
||
}
|
||
tap(rt, &key);
|
||
}
|
||
|
||
/// A window tall enough for General with its Advanced fold open.
|
||
const TALL_SIZE: (f32, f32) = (980.0, 2800.0);
|
||
|
||
/// Opens a pane's Advanced fold, as its toggle does.
|
||
fn open_advanced(rt: &mut Runtime<Ui>, pane: Pane) {
|
||
if !rt.state.advanced.contains(&pane) {
|
||
rt.state.advanced.push(pane);
|
||
}
|
||
rt.invalidate();
|
||
rt.settle_all();
|
||
rt.frame(0.0);
|
||
settle(rt);
|
||
}
|
||
|
||
fn key(rt: &mut Runtime<Ui>, key: Key, mods: Mods) {
|
||
rt.key(KeyEvent { key, mods });
|
||
rt.frame(1.0 / 60.0);
|
||
}
|
||
|
||
#[test]
|
||
fn portal_desktops_show_what_they_granted_beside_each_recorder() {
|
||
let mut rt = runtime("portal", true, TALL_SIZE);
|
||
open_advanced(&mut rt, Pane::General);
|
||
let shown = texts(&rt);
|
||
for expected in [
|
||
"Shortcut",
|
||
"Your desktop granted F12",
|
||
"Your desktop granted Ctrl+Alt+V",
|
||
] {
|
||
assert!(
|
||
shown.iter().any(|text| text == expected),
|
||
"missing {expected:?} in {shown:?}"
|
||
);
|
||
}
|
||
assert!(!shown.iter().any(|text| text == "Desktop shortcuts"));
|
||
for recorder in ["dictation-hotkey", "paste-last-hotkey"] {
|
||
tap(&mut rt, recorder);
|
||
assert!(matches!(
|
||
rt.state.capture,
|
||
settings::Capture::Listening { .. }
|
||
));
|
||
key(&mut rt, Key::Escape, Mods::default());
|
||
assert_eq!(rt.state.capture, settings::Capture::Idle);
|
||
}
|
||
}
|
||
|
||
#[test]
|
||
fn a_mouse_shortcut_on_wayland_explains_the_desktop_command_route() {
|
||
let rt = runtime("portal-mouse", true, GOLDEN_SIZE);
|
||
let shown = texts(&rt);
|
||
assert!(
|
||
shown
|
||
.iter()
|
||
.any(|text| text.contains("Wayland desktop using the hex commands"))
|
||
);
|
||
assert!(!shown.iter().any(|text| text.contains("config.kdl")));
|
||
}
|
||
|
||
#[test]
|
||
fn a_refused_portal_shortcut_says_how_to_free_it() {
|
||
let mut rt = runtime("portal", true, GOLDEN_SIZE);
|
||
if let Some(view) = &mut rt.state.view {
|
||
view.listener.shortcuts = DesktopShortcuts::Portal(vec![DesktopGrantedShortcut {
|
||
name: "Dictation".into(),
|
||
trigger: None,
|
||
unconfirmed: false,
|
||
}]);
|
||
}
|
||
rt.invalidate();
|
||
rt.frame(0.0);
|
||
let shown = texts(&rt);
|
||
assert!(
|
||
shown
|
||
.iter()
|
||
.any(|text| text == "Your desktop did not grant this shortcut")
|
||
);
|
||
assert!(shown.iter().any(|text| text.contains("config.kdl")));
|
||
assert!(rt.find("dictation-hotkey").is_some());
|
||
assert!(rt.find("basics/refused").is_some());
|
||
open_advanced(&mut rt, Pane::General);
|
||
assert!(rt.find("output/card/refused").is_none());
|
||
}
|
||
|
||
/// #635: Hyprland's portal names no trigger, since its config binds the
|
||
/// keys, so the row says Hex can't confirm it and shows no refusal.
|
||
#[test]
|
||
fn an_unconfirmed_portal_shortcut_is_not_called_refused() {
|
||
let mut rt = runtime("portal", true, GOLDEN_SIZE);
|
||
if let Some(view) = &mut rt.state.view {
|
||
view.listener.shortcuts = DesktopShortcuts::Portal(vec![DesktopGrantedShortcut {
|
||
name: "Dictation".into(),
|
||
trigger: None,
|
||
unconfirmed: true,
|
||
}]);
|
||
}
|
||
rt.invalidate();
|
||
rt.frame(0.0);
|
||
let shown = texts(&rt);
|
||
assert!(
|
||
shown
|
||
.iter()
|
||
.any(|text| text == "Your desktop assigns this key itself, so Hex can't confirm it")
|
||
);
|
||
assert!(
|
||
!shown
|
||
.iter()
|
||
.any(|text| text == "Your desktop did not grant this shortcut")
|
||
);
|
||
assert!(rt.find("basics/refused").is_none());
|
||
}
|
||
|
||
/// #1120: a check the person asked for says how it went; the hourly check
|
||
/// alone keeps the footer's words.
|
||
#[test]
|
||
fn an_asked_update_check_says_how_it_went() {
|
||
fn status(rt: &mut Runtime<Ui>, status: DesktopUpdateStatus) {
|
||
rt.state
|
||
.view
|
||
.as_mut()
|
||
.expect("a service view")
|
||
.update_status = status;
|
||
rt.invalidate();
|
||
rt.frame(0.0);
|
||
}
|
||
let mut rt = runtime("portal", true, PANE_SIZE);
|
||
status(&mut rt, DesktopUpdateStatus::Current);
|
||
assert!(texts(&rt).iter().any(|text| text == "Check for updates"));
|
||
tap(&mut rt, "update-status");
|
||
assert!(
|
||
sent(&rt)
|
||
.iter()
|
||
.any(|request| matches!(request, Request::Desktop(DesktopAction::CheckForUpdates)))
|
||
);
|
||
status(&mut rt, DesktopUpdateStatus::Checking);
|
||
assert!(
|
||
texts(&rt)
|
||
.iter()
|
||
.any(|text| text == "Checking for updates…")
|
||
);
|
||
status(&mut rt, DesktopUpdateStatus::Current);
|
||
assert!(texts(&rt).iter().any(|text| text == "Hex is up to date"));
|
||
status(&mut rt, DesktopUpdateStatus::Failed);
|
||
assert!(
|
||
texts(&rt)
|
||
.iter()
|
||
.any(|text| text == "Couldn't check for updates")
|
||
);
|
||
}
|
||
|
||
#[test]
|
||
fn a_refused_note_sits_with_the_shortcut_the_desktop_kept() {
|
||
let mut rt = runtime("portal", true, GOLDEN_SIZE);
|
||
if let Some(view) = &mut rt.state.view {
|
||
view.listener.shortcuts = DesktopShortcuts::Portal(vec![
|
||
DesktopGrantedShortcut {
|
||
name: "Dictation".into(),
|
||
trigger: Some("F12".into()),
|
||
unconfirmed: false,
|
||
},
|
||
DesktopGrantedShortcut {
|
||
name: "Paste last dictation".into(),
|
||
trigger: None,
|
||
unconfirmed: false,
|
||
},
|
||
]);
|
||
}
|
||
rt.invalidate();
|
||
rt.frame(0.0);
|
||
open_advanced(&mut rt, Pane::General);
|
||
assert!(rt.find("output/card/refused").is_some());
|
||
assert!(rt.find("basics/refused").is_none());
|
||
}
|
||
|
||
#[test]
|
||
fn each_panes_advanced_fold_starts_closed_and_stays_its_own() {
|
||
let mut rt = runtime("portal", true, TALL_SIZE);
|
||
assert!(
|
||
rt.find("avoid-bluetooth-microphone").is_none(),
|
||
"closed at first"
|
||
);
|
||
tap(&mut rt, "advanced-toggle");
|
||
tap(&mut rt, "advanced-toggle");
|
||
tap(&mut rt, "advanced-toggle");
|
||
settle(&mut rt);
|
||
assert!(rt.find("avoid-bluetooth-microphone").is_some());
|
||
assert_eq!(rt.state.advanced, vec![Pane::General]);
|
||
}
|
||
|
||
#[test]
|
||
fn desktops_without_a_portal_list_commands_instead_of_recording_rows() {
|
||
let rt = runtime("commands", true, GOLDEN_SIZE);
|
||
assert!(texts(&rt).iter().any(|text| text == "hex dictation toggle"));
|
||
assert!(rt.find("dictation-hotkey").is_none());
|
||
assert!(rt.find("paste-last-hotkey").is_none());
|
||
}
|
||
|
||
#[test]
|
||
fn toggles_save_through_the_host() {
|
||
let mut rt = runtime("portal", true, TALL_SIZE);
|
||
assert!(rt.state.settings.paste_with_shift);
|
||
open_advanced(&mut rt, Pane::General);
|
||
tap(&mut rt, "terminal-paste");
|
||
assert!(!rt.state.settings.paste_with_shift);
|
||
assert_eq!(saved(&rt), 1);
|
||
assert!(sent(&rt).is_empty());
|
||
}
|
||
|
||
#[test]
|
||
fn gnome_desktops_point_to_the_clipboard_lab_until_it_is_on() {
|
||
let mut rt = runtime("portal", true, TALL_SIZE);
|
||
open_advanced(&mut rt, Pane::General);
|
||
assert!(
|
||
rt.find("clipboard-restore-note").is_none(),
|
||
"only desktops without data-control"
|
||
);
|
||
rt.state.platform.clipboard_unrestorable = true;
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
assert!(rt.find("clipboard-restore-note").is_some());
|
||
open_labs(&mut rt);
|
||
tap(&mut rt, "lab-gnome-clipboard-restore");
|
||
assert!(rt.state.settings.labs.gnome_clipboard_restore);
|
||
tap(&mut rt, "nav-general");
|
||
assert!(rt.find("terminal-paste").is_some(), "back on General");
|
||
assert!(rt.find("clipboard-restore-note").is_none());
|
||
}
|
||
|
||
#[test]
|
||
fn reset_brings_back_paste_lasts_default() {
|
||
use crate::app_settings::HotkeyBinding;
|
||
let default = HotkeyBinding::paste_last_default();
|
||
let mut rt = runtime("portal", true, TALL_SIZE);
|
||
open_advanced(&mut rt, Pane::General);
|
||
rt.state.settings.paste_last_hotkey = None;
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
let note = format!("Default shortcut: {}", default.keycaps().join("+"));
|
||
assert!(
|
||
texts(&rt).contains(¬e),
|
||
"the empty row names its default"
|
||
);
|
||
tap(&mut rt, "restore-paste-last");
|
||
assert_eq!(rt.state.settings.paste_last_hotkey, Some(default.clone()));
|
||
assert_eq!(saved(&rt), 1);
|
||
assert!(
|
||
rt.find("restore-paste-last").is_none(),
|
||
"hidden once the shortcut is the default"
|
||
);
|
||
|
||
// A default another shortcut already uses is refused, as recording it would be.
|
||
rt.state.settings.paste_last_hotkey = None;
|
||
rt.state.settings.raw_dictation_hotkey = Some(default);
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
tap(&mut rt, "restore-paste-last");
|
||
assert_eq!(rt.state.settings.paste_last_hotkey, None);
|
||
assert_eq!(saved(&rt), 1);
|
||
assert!(matches!(
|
||
rt.state.capture,
|
||
settings::Capture::Listening {
|
||
message: Some(_),
|
||
..
|
||
}
|
||
));
|
||
}
|
||
|
||
/// The Paste last recorder says Backspace turns it off, and plain
|
||
/// Backspace does; Dictation's recorder says nothing and keeps its binding.
|
||
#[test]
|
||
fn backspace_in_an_optional_recorder_turns_the_shortcut_off() {
|
||
let hint = "Press Backspace to turn it off";
|
||
let mut rt = runtime("portal", true, TALL_SIZE);
|
||
open_advanced(&mut rt, Pane::General);
|
||
assert!(rt.state.settings.paste_last_hotkey.is_some());
|
||
assert!(!texts(&rt).iter().any(|text| text == hint));
|
||
tap(&mut rt, "paste-last-hotkey");
|
||
assert!(texts(&rt).iter().any(|text| text == hint));
|
||
key(&mut rt, Key::Backspace, Mods::default());
|
||
assert_eq!(rt.state.settings.paste_last_hotkey, None);
|
||
assert!(!matches!(rt.state.capture, Capture::Listening { .. }));
|
||
assert!(!texts(&rt).iter().any(|text| text == hint));
|
||
|
||
let dictation = rt.state.settings.dictation_hotkey.clone();
|
||
tap(&mut rt, "dictation-hotkey");
|
||
assert!(!texts(&rt).iter().any(|text| text == hint));
|
||
key(&mut rt, Key::Backspace, Mods::default());
|
||
assert_eq!(rt.state.settings.dictation_hotkey, dictation);
|
||
assert!(matches!(
|
||
rt.state.capture,
|
||
Capture::Listening {
|
||
message: Some("Add a modifier"),
|
||
..
|
||
}
|
||
));
|
||
}
|
||
|
||
#[test]
|
||
fn choosing_an_update_channel_saves_it_and_checks_now() {
|
||
let mut rt = runtime("portal", true, GOLDEN_SIZE);
|
||
tap(&mut rt, "advanced-toggle");
|
||
assert_eq!(rt.state.settings.updates.channel, None);
|
||
let (other, index) = other_update_channel();
|
||
pick(&mut rt, "update-channel", index);
|
||
assert_eq!(rt.state.settings.updates.channel, Some(other));
|
||
assert_eq!(saved(&rt), 1);
|
||
assert!(matches!(
|
||
sent(&rt),
|
||
[Request::Desktop(DesktopAction::CheckForUpdates)]
|
||
));
|
||
pick(&mut rt, "update-channel", index);
|
||
assert_eq!(
|
||
saved(&rt),
|
||
1,
|
||
"choosing the same channel again saves nothing"
|
||
);
|
||
}
|
||
|
||
/// The channel this build does not follow, and its option's index: the
|
||
/// build's own channel depends on its version (a local build follows dev).
|
||
fn other_update_channel() -> (crate::app_settings::UpdateChannel, usize) {
|
||
let build = crate::updater::build_channel();
|
||
let index = crate::app_settings::UpdateChannel::ALL
|
||
.iter()
|
||
.position(|channel| *channel != build)
|
||
.unwrap();
|
||
(crate::app_settings::UpdateChannel::ALL[index], index)
|
||
}
|
||
|
||
#[test]
|
||
fn choosing_the_channel_in_effect_keeps_following_the_build() {
|
||
let mut rt = runtime("portal", true, GOLDEN_SIZE);
|
||
tap(&mut rt, "advanced-toggle");
|
||
assert_eq!(rt.state.settings.updates.channel, None);
|
||
let build = crate::updater::build_channel();
|
||
let index = crate::app_settings::UpdateChannel::ALL
|
||
.iter()
|
||
.position(|channel| *channel == build)
|
||
.unwrap();
|
||
pick(&mut rt, "update-channel", index);
|
||
assert_eq!(rt.state.settings.updates.channel, None);
|
||
assert_eq!(saved(&rt), 0);
|
||
assert!(sent(&rt).is_empty());
|
||
}
|
||
|
||
#[test]
|
||
fn installs_that_never_update_hide_the_update_channel() {
|
||
let mut rt = runtime("portal", true, GOLDEN_SIZE);
|
||
tap(&mut rt, "advanced-toggle");
|
||
assert!(rt.find("update-channel").is_some());
|
||
if let Some(view) = &mut rt.state.view {
|
||
view.update_status = DesktopUpdateStatus::PackageManager;
|
||
}
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
assert!(rt.find("update-channel").is_none());
|
||
if let Some(view) = &mut rt.state.view {
|
||
view.update_status = DesktopUpdateStatus::SourceBuild;
|
||
}
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
assert!(rt.find("update-channel").is_none());
|
||
}
|
||
|
||
#[test]
|
||
fn the_interface_language_menu_is_system_first_then_alphabetical() {
|
||
let mut rt = runtime("portal", true, GOLDEN_SIZE);
|
||
tap(&mut rt, "advanced-toggle");
|
||
let ordered = crate::desktop::i18n::language_menu_order();
|
||
assert_eq!(ordered[0], (None, "System"));
|
||
let deutsch = ordered
|
||
.iter()
|
||
.position(|(code, _)| *code == Some("de"))
|
||
.unwrap();
|
||
pick(&mut rt, "interface-language", deutsch);
|
||
assert_eq!(
|
||
rt.state.settings.ui_language.as_deref(),
|
||
Some("de"),
|
||
"the chosen row is the language it shows, not the catalog's index"
|
||
);
|
||
pick(&mut rt, "interface-language", 0);
|
||
assert_eq!(rt.state.settings.ui_language, None);
|
||
}
|
||
|
||
#[test]
|
||
fn quit_hex_in_the_sidebar_asks_the_host_to_quit() {
|
||
let mut rt = runtime("portal", true, PANE_SIZE);
|
||
tap(&mut rt, "quit");
|
||
assert!(rt.state.quit_requested);
|
||
}
|
||
|
||
#[test]
|
||
fn ctrl_q_quits_hex() {
|
||
let mut rt = runtime("portal", true, PANE_SIZE);
|
||
key(&mut rt, Key::Command('q'), Mods::default());
|
||
assert!(rt.state.quit_requested);
|
||
}
|
||
|
||
#[test]
|
||
fn enabling_sends_the_listener_action() {
|
||
let mut rt = runtime("disabled", true, GOLDEN_SIZE);
|
||
tap(&mut rt, "toggle-listening");
|
||
assert!(matches!(
|
||
sent(&rt),
|
||
[Request::Desktop(DesktopAction::StartListening)]
|
||
));
|
||
}
|
||
|
||
#[test]
|
||
fn the_microphone_switch_sits_beside_the_picker_and_needs_no_confirmation() {
|
||
let mut rt = runtime("portal", true, GOLDEN_SIZE);
|
||
assert!(
|
||
rt.find("basics/microphone-mode").is_some(),
|
||
"in General, not Advanced"
|
||
);
|
||
let ready = "The mic stays ready so dictation starts instantly; your system shows it in use";
|
||
let released = "The mic opens only while you dictate; the first moment can be clipped";
|
||
assert!(texts(&rt).iter().any(|text| text == ready));
|
||
tap(&mut rt, "microphone-mode");
|
||
assert!(rt.state.settings.release_microphone_while_idle);
|
||
assert!(texts(&rt).iter().any(|text| text == released));
|
||
tap(&mut rt, "microphone-mode");
|
||
assert!(!rt.state.settings.release_microphone_while_idle);
|
||
}
|
||
|
||
#[test]
|
||
fn recording_a_shortcut_sends_the_chord_to_the_host() {
|
||
let mut rt = runtime("portal", true, GOLDEN_SIZE);
|
||
tap(&mut rt, "dictation-hotkey");
|
||
assert!(matches!(
|
||
sent(&rt),
|
||
[Request::CaptureShortcutFor(ShortcutTarget::Dictation)]
|
||
));
|
||
key(&mut rt, Key::Text("d".into()), Mods::default());
|
||
assert!(matches!(
|
||
rt.state.capture,
|
||
Capture::Listening {
|
||
message: Some("Add a modifier"),
|
||
..
|
||
}
|
||
));
|
||
let mods = Mods {
|
||
ctrl: true,
|
||
alt: true,
|
||
cmd: true,
|
||
..Mods::default()
|
||
};
|
||
key(&mut rt, Key::Command('d'), mods);
|
||
let Some(Request::SetShortcut { target, shortcut }) = sent(&rt).last() else {
|
||
panic!("no shortcut sent: {:?}", sent(&rt));
|
||
};
|
||
assert_eq!(*target, ShortcutTarget::Dictation);
|
||
assert!(shortcut.control && shortcut.alt && !shortcut.shift && !shortcut.platform);
|
||
assert_eq!(shortcut.key, "d");
|
||
assert!(matches!(rt.state.capture, Capture::Saving { .. }));
|
||
}
|
||
|
||
#[cfg(target_os = "linux")]
|
||
#[test]
|
||
fn a_modifier_alone_says_linux_needs_a_key_and_suggests_one() {
|
||
use rune::Modifier;
|
||
let mut rt = runtime("portal", true, GOLDEN_SIZE);
|
||
// As the Linux app asks (`rune_ui::build`).
|
||
rt.set_modifier_keys(true);
|
||
tap(&mut rt, "dictation-hotkey");
|
||
let alt = Mods {
|
||
alt: true,
|
||
..Mods::default()
|
||
};
|
||
let modifier = |modifier, pressed| Key::Modifier { modifier, pressed };
|
||
key(&mut rt, modifier(Modifier::AltLeft, true), alt);
|
||
assert!(matches!(
|
||
rt.state.capture,
|
||
Capture::Listening { message: None, held, .. } if held.option.is_some()
|
||
));
|
||
key(&mut rt, modifier(Modifier::AltLeft, false), Mods::default());
|
||
assert!(matches!(
|
||
rt.state.capture,
|
||
Capture::Listening {
|
||
message: Some("Linux needs a key too. Hold these and press one, like Space"),
|
||
..
|
||
}
|
||
));
|
||
// Both Alts: Linux binds no side, so it says that instead.
|
||
key(&mut rt, modifier(Modifier::AltRight, true), alt);
|
||
key(&mut rt, modifier(Modifier::AltLeft, true), alt);
|
||
key(&mut rt, modifier(Modifier::AltLeft, false), alt);
|
||
assert!(matches!(
|
||
rt.state.capture,
|
||
Capture::Listening { message: None, .. }
|
||
));
|
||
key(
|
||
&mut rt,
|
||
modifier(Modifier::AltRight, false),
|
||
Mods::default(),
|
||
);
|
||
assert!(matches!(
|
||
rt.state.capture,
|
||
Capture::Listening {
|
||
message: Some("Linux can't bind both sides. Use one with a key, like Space"),
|
||
..
|
||
}
|
||
));
|
||
// Modifiers spent on a key say nothing when released.
|
||
key(&mut rt, modifier(Modifier::AltLeft, true), alt);
|
||
key(&mut rt, Key::Text("d".into()), alt);
|
||
assert!(matches!(rt.state.capture, Capture::Saving { .. }));
|
||
assert!(sent(&rt).iter().any(|request| matches!(
|
||
request,
|
||
Request::SetShortcut { shortcut, .. } if shortcut.alt && shortcut.key == "d"
|
||
)));
|
||
}
|
||
|
||
#[test]
|
||
fn escape_cancels_a_shortcut_recording() {
|
||
let mut rt = runtime("capturing", true, GOLDEN_SIZE);
|
||
key(&mut rt, Key::Escape, Mods::default());
|
||
assert_eq!(rt.state.capture, Capture::Idle);
|
||
assert!(matches!(sent(&rt), [Request::CancelShortcut]));
|
||
}
|
||
|
||
#[test]
|
||
fn a_recorder_shows_the_modifiers_held_so_far() {
|
||
use crate::app_settings::{HotkeyModifiers, ModifierSide};
|
||
let mut rt = runtime("capturing", true, GOLDEN_SIZE);
|
||
let held = HotkeyModifiers {
|
||
option: Some(ModifierSide::Either),
|
||
command: Some(ModifierSide::Either),
|
||
..HotkeyModifiers::default()
|
||
};
|
||
settings::hold(&mut rt.state, held);
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
let shown = texts(&rt);
|
||
let caps = HotkeyBinding {
|
||
modifiers: held,
|
||
key: None,
|
||
}
|
||
.keycaps();
|
||
for expected in caps.iter().map(String::as_str).chain(["…"]) {
|
||
assert!(
|
||
shown.iter().any(|text| text == expected),
|
||
"missing {expected:?} in {shown:?}"
|
||
);
|
||
}
|
||
assert!(!shown.iter().any(|text| text == "Press shortcut"));
|
||
settings::hold(&mut rt.state, HotkeyModifiers::default());
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
assert!(texts(&rt).iter().any(|text| text == "Press shortcut"));
|
||
}
|
||
|
||
#[test]
|
||
fn function_keys_and_super_record_as_linux_key_names() {
|
||
let f12 = recorded_binding(&KeyEvent {
|
||
key: Key::Function(12),
|
||
mods: Mods::default(),
|
||
})
|
||
.unwrap();
|
||
assert_eq!(desktop_shortcut(&f12).key, "f12");
|
||
let space = recorded_binding(&KeyEvent {
|
||
key: Key::Text(" ".into()),
|
||
mods: Mods {
|
||
logo: true,
|
||
..Mods::default()
|
||
},
|
||
})
|
||
.unwrap();
|
||
let shortcut = desktop_shortcut(&space);
|
||
assert_eq!(shortcut.key, "space");
|
||
assert!(shortcut.platform);
|
||
}
|
||
|
||
#[test]
|
||
fn shortcuts_that_collide_are_refused() {
|
||
let ui = portal_fixture();
|
||
let paste = ui.settings.paste_last_hotkey.clone().unwrap();
|
||
assert_eq!(
|
||
validate(&ui.settings, ShortcutTarget::Dictation, &paste),
|
||
Err("Already in use")
|
||
);
|
||
}
|
||
|
||
#[test]
|
||
fn service_settings_are_adopted_only_when_the_service_changes_them() {
|
||
let mut ui = portal_fixture();
|
||
let service = ui.settings.clone();
|
||
ui.adopt(service.clone());
|
||
ui.update(|settings| settings.paste_with_shift = false);
|
||
// The service has not reloaded yet: its stale copy must not win.
|
||
ui.adopt(service.clone());
|
||
assert!(!ui.settings.paste_with_shift);
|
||
let mut changed = service;
|
||
changed.enable_on_launch = false;
|
||
ui.adopt(changed);
|
||
assert!(!ui.settings.enable_on_launch);
|
||
}
|
||
|
||
#[test]
|
||
fn a_draft_saves_over_what_another_writer_changed_meanwhile() {
|
||
let mut ui = portal_fixture();
|
||
let service = ui.settings.clone();
|
||
ui.adopt(service.clone());
|
||
ui.vocabulary
|
||
.push(TextEdit::new("OpenCode"), TextEdit::default());
|
||
let start = std::time::Instant::now();
|
||
assert!(!ui.save_drafts(start), "waits for a pause");
|
||
// `hex settings set` (or a capture's saved rule) saves while it waits.
|
||
let mut elsewhere = service;
|
||
elsewhere.enable_on_launch = !elsewhere.enable_on_launch;
|
||
ui.adopt(elsewhere.clone());
|
||
assert_eq!(
|
||
ui.vocabulary.project()[0].term,
|
||
"OpenCode",
|
||
"the typing stays"
|
||
);
|
||
assert!(ui.save_drafts(start + DRAFT_DELAY));
|
||
assert_eq!(ui.settings.enable_on_launch, elsewhere.enable_on_launch);
|
||
assert_eq!(ui.settings.vocabulary[0].term, "OpenCode");
|
||
}
|
||
|
||
/// Typing in one editor keeps only that editor's text: the others take
|
||
/// what another writer saved, so the draft's save doesn't undo it.
|
||
#[test]
|
||
fn a_draft_keeps_only_its_own_editor() {
|
||
let mut ui = portal_fixture();
|
||
let service = ui.settings.clone();
|
||
ui.adopt(service.clone());
|
||
ui.vocabulary
|
||
.push(TextEdit::new("OpenCode"), TextEdit::default());
|
||
let start = std::time::Instant::now();
|
||
assert!(!ui.save_drafts(start), "waits for a pause");
|
||
let mut elsewhere = service;
|
||
elsewhere
|
||
.dictation_processing
|
||
.default_mode
|
||
.post_processing
|
||
.prompt = "Keep it short.".into();
|
||
ui.adopt(elsewhere);
|
||
assert!(ui.save_drafts(start + DRAFT_DELAY));
|
||
assert_eq!(ui.settings.vocabulary[0].term, "OpenCode");
|
||
assert_eq!(
|
||
ui.settings
|
||
.dictation_processing
|
||
.default_mode
|
||
.post_processing
|
||
.prompt,
|
||
"Keep it short."
|
||
);
|
||
}
|
||
|
||
fn settle(rt: &mut Runtime<Ui>) {
|
||
for _ in 0..60 {
|
||
rt.frame(1.0 / 60.0);
|
||
}
|
||
}
|
||
|
||
/// Saves paused drafts now, as the next poll after [`DRAFT_DELAY`] would.
|
||
fn flush(rt: &mut Runtime<Ui>) {
|
||
rt.state.flush_drafts();
|
||
settle(rt);
|
||
}
|
||
|
||
/// A shown window keeps drawing while its runtime animates, has input queued
|
||
/// or has live values pending (Rune's `Host::redraw`). Five seconds after
|
||
/// mounting, with nothing changing, the only motion left in any scene is the
|
||
/// pulsing dot of something live, Output's turning spark, or the
|
||
/// shortcut explainer's looping demo, and under Reduce Motion, which stills
|
||
/// them all, no scene asks for another frame.
|
||
#[test]
|
||
fn every_scene_stops_asking_for_frames() {
|
||
const FRAME: f64 = 1.0 / 60.0;
|
||
let wants_frame =
|
||
|rt: &mut Runtime<Ui>| rt.frame(FRAME) || rt.has_pending_input() || rt.live_pending();
|
||
let mut moving = Vec::new();
|
||
let mut drawing = Vec::new();
|
||
for (scene, _) in SCENES.iter().filter(|(name, _)| *name != "live") {
|
||
let mut rt = runtime(scene, true, PANE_SIZE);
|
||
for _ in 0..150 {
|
||
rt.frame(1.0 / 30.0);
|
||
}
|
||
if *scene != "shortcut-mode-motion" {
|
||
moving.extend(
|
||
rt.elements()
|
||
.into_iter()
|
||
.filter(|e| e.moving && !matches!(e.key.as_deref(), Some("dot")) && !spark(e))
|
||
.map(|e| format!("{scene}: {}", e.path)),
|
||
);
|
||
}
|
||
// Stilling a loop may land a spring or two first.
|
||
rt.set_system_reduced_motion(true);
|
||
for _ in 0..30 {
|
||
rt.frame(1.0 / 30.0);
|
||
}
|
||
if (0..30).any(|_| wants_frame(&mut rt)) {
|
||
drawing.push(*scene);
|
||
}
|
||
}
|
||
assert!(moving.is_empty(), "still moving after 5 s: {moving:#?}");
|
||
assert!(
|
||
drawing.is_empty(),
|
||
"still asking for frames under Reduce Motion: {drawing:?}"
|
||
);
|
||
}
|
||
|
||
#[test]
|
||
fn the_sidebar_always_shows_output() {
|
||
for scene in ["portal", "mac-settings", "mac-production"] {
|
||
let rt = runtime(scene, true, PANE_SIZE);
|
||
assert!(
|
||
rt.find("nav-output").is_some(),
|
||
"{scene} shows Output in the main sidebar"
|
||
);
|
||
assert!(Pane::Output.shown(&rt.state));
|
||
assert!(rt.find("nav-modes").is_none(), "Output replaces Modes");
|
||
}
|
||
}
|
||
|
||
/// Labs › Modes editor brings the old editor back as a main pane, right after
|
||
/// Output, and the Modes destination (the menu bar, `hex window show --pane
|
||
/// modes`) opens it instead of Output. Off, nothing changes.
|
||
#[test]
|
||
fn the_modes_editor_lab_brings_modes_back_to_the_sidebar() {
|
||
let mut rt = runtime("mac-labs", true, (980.0, 2000.0));
|
||
unfold_labs(&mut rt);
|
||
assert!(rt.find("nav-modes").is_none(), "off, Output replaces Modes");
|
||
// Off, the Modes destination still lands on Output.
|
||
show(&mut rt.state, Destination::Modes, &mut rune::Tx::default());
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
assert_eq!(rt.state.pane, Pane::Output);
|
||
// Its card turns the editor on.
|
||
tap(&mut rt, "nav-labs");
|
||
tap(&mut rt, "lab-modes-editor");
|
||
assert!(rt.state.settings.labs.modes_editor);
|
||
// It joins the sidebar right after Output, and Command-3 opens it.
|
||
tap(&mut rt, "nav-output");
|
||
assert!(rt.find("nav-modes").is_some());
|
||
let order = labs::order(&rt.state);
|
||
let output = order
|
||
.iter()
|
||
.position(|pane| *pane == Pane::Output)
|
||
.expect("Output is a main pane");
|
||
assert_eq!(order.get(output + 1), Some(&Pane::Modes));
|
||
key(&mut rt, Key::Command('3'), Mods::default());
|
||
settle(&mut rt);
|
||
assert_eq!(rt.state.pane, Pane::Modes, "Command-3 is Modes now");
|
||
// The menu bar and `hex window show --pane modes` open the editor too.
|
||
show(&mut rt.state, Destination::Modes, &mut rune::Tx::default());
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
assert_eq!(rt.state.pane, Pane::Modes);
|
||
// Off while the editor shows, the adoption fallback leaves the hidden
|
||
// pane for Output, as a saved `hex settings set labs.modes_editor off`
|
||
// does while the window shows it.
|
||
crate::labs::Feature::ModesEditor.set(&mut rt.state.settings, false);
|
||
assert!(!Pane::Modes.shown(&rt.state));
|
||
assert!(leave_hidden_pane(&mut rt.state));
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
assert_eq!(rt.state.pane, Pane::Output);
|
||
assert!(rt.find("nav-modes").is_none());
|
||
}
|
||
|
||
/// Labs › Neutral voice's Modes row follows the saved switch, not the
|
||
/// process-wide gate, and toggles the selected mode.
|
||
#[cfg(target_os = "macos")]
|
||
#[test]
|
||
fn neutral_voice_shows_in_modes_only_with_its_lab_and_toggles_the_mode() {
|
||
let mut rt = runtime("mac-labs", true, (980.0, 2000.0));
|
||
crate::labs::Feature::ModesEditor.set(&mut rt.state.settings, true);
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
tap(&mut rt, "nav-modes");
|
||
settle(&mut rt);
|
||
assert_eq!(rt.state.pane, Pane::Modes);
|
||
assert!(rt.find("neutral-voice").is_none(), "off, no row");
|
||
|
||
crate::labs::Feature::NeutralVoice.set(&mut rt.state.settings, true);
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
assert!(rt.find("neutral-voice").is_some(), "on, the row shows");
|
||
tap(&mut rt, "neutral-voice");
|
||
assert!(
|
||
rt.state
|
||
.settings
|
||
.dictation_processing
|
||
.default_mode
|
||
.neutral_voice
|
||
);
|
||
tap(&mut rt, "neutral-voice");
|
||
assert!(
|
||
!rt.state
|
||
.settings
|
||
.dictation_processing
|
||
.default_mode
|
||
.neutral_voice
|
||
);
|
||
}
|
||
|
||
#[test]
|
||
fn the_sidebar_switches_panes_and_keeps_settings() {
|
||
let mut rt = runtime("portal", true, PANE_SIZE);
|
||
for (key, pane) in [
|
||
("nav-output", Pane::Output),
|
||
("nav-history", Pane::History),
|
||
("nav-general", Pane::General),
|
||
] {
|
||
tap(&mut rt, key);
|
||
assert_eq!(rt.state.pane, pane);
|
||
}
|
||
assert!(sent(&rt).is_empty());
|
||
assert_eq!(saved(&rt), 0, "switching panes saves nothing");
|
||
}
|
||
|
||
#[test]
|
||
fn the_sidebar_switches_on_press_not_release() {
|
||
let mut rt = runtime("portal", true, PANE_SIZE);
|
||
settle(&mut rt);
|
||
let (x, y) = rt.find("nav-output").expect("the Output item");
|
||
rt.pointer_down(x, y);
|
||
rt.frame(1.0 / 60.0);
|
||
assert_eq!(rt.state.pane, Pane::Output);
|
||
rt.pointer_up(x, y);
|
||
rt.frame(1.0 / 60.0);
|
||
assert_eq!(rt.state.pane, Pane::Output);
|
||
}
|
||
|
||
#[test]
|
||
fn switching_panes_is_instant() {
|
||
let mut rt = runtime("portal", true, PANE_SIZE);
|
||
tap(&mut rt, "nav-labs");
|
||
settle(&mut rt);
|
||
let (x, y) = rt.find("nav-output").expect("the Output item");
|
||
rt.pointer_down(x, y);
|
||
rt.pointer_up(x, y);
|
||
rt.frame(1.0 / 60.0);
|
||
let panel: Vec<_> = rt
|
||
.elements()
|
||
.into_iter()
|
||
.filter(|e| e.path.contains("/panel/"))
|
||
.collect();
|
||
assert!(!panel.is_empty());
|
||
assert!(
|
||
!panel.iter().any(|e| e.key.as_deref() == Some("lede")),
|
||
"Labs left at once"
|
||
);
|
||
// Output's spark turns on its own; it is not a pane transition.
|
||
for element in panel.iter().filter(|e| !spark(e)) {
|
||
assert!(
|
||
element.opacity >= 0.999 && !element.moving,
|
||
"{} is still animating",
|
||
element.path
|
||
);
|
||
}
|
||
}
|
||
|
||
/// A frame of Output's turning spark or a word of its cycling examples,
|
||
/// which move on their own.
|
||
fn spark(e: &rune::ElementInfo) -> bool {
|
||
e.key
|
||
.as_deref()
|
||
.is_some_and(|key| key.starts_with("spark") || key.starts_with("example"))
|
||
}
|
||
|
||
fn element(rt: &Runtime<Ui>, key: &str) -> rune::ElementInfo {
|
||
let suffix = format!("/{key}");
|
||
rt.elements()
|
||
.into_iter()
|
||
.find(|e| !e.exiting && (e.key.as_deref() == Some(key) || e.path.ends_with(&suffix)))
|
||
.unwrap_or_else(|| panic!("no element {key}"))
|
||
}
|
||
|
||
/// The sidebar's items, top to bottom, with their drawn rects.
|
||
fn nav_items(rt: &Runtime<Ui>) -> Vec<(Pane, [f32; 4])> {
|
||
let mut items: Vec<_> = Pane::ALL
|
||
.iter()
|
||
.copied()
|
||
.filter_map(|pane| rt.presented(pane.key()).map(|(rect, _)| (pane, rect)))
|
||
.collect();
|
||
items.sort_by(|a, b| a.1[1].total_cmp(&b.1[1]));
|
||
items
|
||
}
|
||
|
||
/// A sidebar row: its pane and rect.
|
||
type NavRow = (Pane, [f32; 4]);
|
||
|
||
/// Neighbouring sidebar items with nothing but a gap between them: the
|
||
/// Labs row sits below the panes.
|
||
fn nav_neighbours(rt: &Runtime<Ui>) -> Vec<(NavRow, NavRow)> {
|
||
let labs = rt
|
||
.elements()
|
||
.into_iter()
|
||
.find(|e| e.key.as_deref() == Some("nav-labs"))
|
||
.map(|e| e.rect);
|
||
nav_items(rt)
|
||
.windows(2)
|
||
.map(|pair| (pair[0], pair[1]))
|
||
.filter(|((_, a), (_, b))| {
|
||
labs.is_none_or(|labs| labs[1] + labs[3] <= a[1] + a[3] || labs[1] >= b[1])
|
||
})
|
||
.collect()
|
||
}
|
||
|
||
/// The items whose hover shows, after one short frame: hover is instant.
|
||
fn hovered_items(rt: &mut Runtime<Ui>, x: f32, y: f32) -> Vec<Pane> {
|
||
rt.pointer_move(x, y);
|
||
rt.frame(1.0 / 120.0);
|
||
nav_items(rt)
|
||
.into_iter()
|
||
.filter(|(pane, _)| {
|
||
let opacity = element(rt, &format!("{}/hover", pane.key())).opacity;
|
||
assert!(
|
||
opacity == 0.0 || opacity == 1.0,
|
||
"{pane:?}'s hover is fading: {opacity}"
|
||
);
|
||
opacity == 1.0
|
||
})
|
||
.map(|(pane, _)| pane)
|
||
.collect()
|
||
}
|
||
|
||
/// A sidebar with Labs features turned on, as a developer sees it.
|
||
fn grouped_sidebar() -> Runtime<Ui> {
|
||
let mut rt = runtime("mac-settings", true, PANE_SIZE);
|
||
rt.state.platform.developer = true;
|
||
rt.state.labs_open = true;
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
assert!(
|
||
nav_items(&rt)
|
||
.iter()
|
||
.any(|(pane, _)| *pane == Pane::VoiceFilter)
|
||
);
|
||
rt
|
||
}
|
||
|
||
#[test]
|
||
fn the_nearest_sidebar_item_hovers_in_every_gap() {
|
||
let mut rt = grouped_sidebar();
|
||
let items = nav_items(&rt);
|
||
let x = items[0].1[0] + 40.0;
|
||
for ((above, a), (below, b)) in nav_neighbours(&rt) {
|
||
let (gap_top, gap_bottom) = (a[1] + a[3], b[1]);
|
||
let middle = (gap_top + gap_bottom) / 2.0;
|
||
assert_eq!(hovered_items(&mut rt, x, a[1] + a[3] / 2.0), [above]);
|
||
assert_eq!(hovered_items(&mut rt, x, gap_top + 0.5), [above]);
|
||
assert_eq!(hovered_items(&mut rt, x, middle - 0.5), [above]);
|
||
assert_eq!(hovered_items(&mut rt, x, middle + 0.5), [below]);
|
||
assert_eq!(hovered_items(&mut rt, x, gap_bottom - 0.5), [below]);
|
||
}
|
||
let (_, last) = items[items.len() - 1];
|
||
assert!(
|
||
hovered_items(&mut rt, x, last[1] + last[3] + 200.0).is_empty(),
|
||
"hover leaves at once"
|
||
);
|
||
}
|
||
|
||
#[test]
|
||
fn a_press_in_a_sidebar_gap_selects_the_nearest_item() {
|
||
let mut rt = grouped_sidebar();
|
||
let items = nav_items(&rt);
|
||
let x = items[0].1[0] + 40.0;
|
||
for ((above, a), (below, b)) in nav_neighbours(&rt) {
|
||
let middle = (a[1] + a[3] + b[1]) / 2.0;
|
||
for (y, pane) in [(middle - 0.5, above), (middle + 0.5, below)] {
|
||
// A fresh sidebar each time: choosing a main pane folds Labs.
|
||
rt = grouped_sidebar();
|
||
rt.pointer_move(x, y);
|
||
rt.pointer_down(x, y);
|
||
rt.frame(1.0 / 60.0);
|
||
assert_eq!(rt.state.pane, pane, "a press at {y} selects {pane:?}");
|
||
rt.pointer_up(x, y);
|
||
}
|
||
}
|
||
}
|
||
|
||
#[test]
|
||
fn a_settings_row_shows_no_hover_or_press_of_its_own() {
|
||
let mut rt = runtime("portal", true, TALL_SIZE);
|
||
open_advanced(&mut rt, Pane::General);
|
||
let before = rt.state.settings.avoid_bluetooth_microphone;
|
||
let (x, y) = rt
|
||
.find("avoid-bluetooth-microphone/lead/copy")
|
||
.expect("the row's title");
|
||
rt.pointer_move(x, y);
|
||
rt.frame(1.0 / 120.0);
|
||
let row = element(&rt, "avoid-bluetooth-microphone");
|
||
assert_eq!((row.hover, row.fill), (0.0, rune::Color::TRANSPARENT));
|
||
rt.pointer_down(x, y);
|
||
rt.frame(1.0 / 120.0);
|
||
assert_eq!(element(&rt, "avoid-bluetooth-microphone").press, 0.0);
|
||
rt.pointer_up(x, y);
|
||
settle(&mut rt);
|
||
assert_ne!(
|
||
rt.state.settings.avoid_bluetooth_microphone, before,
|
||
"pressing the row still flips it"
|
||
);
|
||
}
|
||
|
||
#[test]
|
||
fn hover_leaves_at_once() {
|
||
let mut rt = runtime("mac-settings", true, PANE_SIZE);
|
||
for key in ["update-status", "dictation-hotkey", "microphone-control"] {
|
||
let (x, y) = rt.find(key).unwrap_or_else(|| panic!("no element {key}"));
|
||
rt.pointer_move(x, y);
|
||
rt.frame(1.0 / 120.0);
|
||
assert_eq!(element(&rt, key).hover, 1.0, "{key} hovers at once");
|
||
rt.pointer_move(x, y + 400.0);
|
||
rt.frame(1.0 / 120.0);
|
||
assert_eq!(element(&rt, key).hover, 0.0, "{key} stops hovering at once");
|
||
}
|
||
}
|
||
|
||
/// Every hover in the tree, kit controls' inner tracks included, is at rest
|
||
/// or fully on one short frame after the pointer moves.
|
||
fn assert_hover_is_binary(rt: &Runtime<Ui>, what: &str) {
|
||
for e in rt.elements().into_iter().filter(|e| !e.exiting) {
|
||
assert!(
|
||
e.hover == 0.0 || e.hover == 1.0,
|
||
"{what}: {} is fading: {}",
|
||
e.path,
|
||
e.hover
|
||
);
|
||
}
|
||
}
|
||
|
||
#[test]
|
||
fn segments_and_switch_tracks_hover_at_once() {
|
||
let mut rt = runtime("portal", true, TALL_SIZE);
|
||
open_advanced(&mut rt, Pane::General);
|
||
let targets = [
|
||
rt.find("speech-engine-control-trigger"),
|
||
rt.find("avoid-bluetooth-microphone/switch"),
|
||
];
|
||
for (target, name) in targets.into_iter().zip(["select", "switch"]) {
|
||
let (x, y) = target.unwrap_or_else(|| panic!("no {name}"));
|
||
rt.pointer_move(x, y);
|
||
rt.frame(1.0 / 120.0);
|
||
assert_hover_is_binary(&rt, name);
|
||
assert!(
|
||
rt.elements().iter().any(|e| e.hover == 1.0),
|
||
"{name} hovers at once"
|
||
);
|
||
// Above the page, where nothing hovers.
|
||
rt.pointer_move(x, 2.0);
|
||
rt.frame(1.0 / 120.0);
|
||
assert_hover_is_binary(&rt, name);
|
||
assert!(
|
||
rt.elements().iter().all(|e| e.hover == 0.0),
|
||
"{name} stops hovering at once"
|
||
);
|
||
}
|
||
}
|
||
|
||
/// An unset model on a catalog with a ranked pick is Hex's own automatic
|
||
/// choice, not OpenCode's default; with no ranked model it really is
|
||
/// OpenCode's default.
|
||
#[test]
|
||
fn an_unset_model_says_automatic_only_while_hex_ranks_a_model() {
|
||
let mut rt = runtime("modes", true, PANE_SIZE);
|
||
rt.state.settings.dictation_processing.modes[0]
|
||
.post_processing
|
||
.model = None;
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
let shown = texts(&rt);
|
||
assert!(shown.iter().any(|text| text == "Automatic"), "{shown:?}");
|
||
assert!(!shown.iter().any(|text| text == "Default"), "{shown:?}");
|
||
|
||
rt.state.models.open_picker();
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
assert_eq!(
|
||
element(&rt, "model-picker-option-0").label.as_deref(),
|
||
Some("Automatic")
|
||
);
|
||
|
||
let mut rt = runtime("modes", true, PANE_SIZE);
|
||
rt.state.models = models::Models::fixture_unranked();
|
||
rt.state.settings.dictation_processing.modes[0]
|
||
.post_processing
|
||
.model = None;
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
let shown = texts(&rt);
|
||
assert!(shown.iter().any(|text| text == "Default"), "{shown:?}");
|
||
assert!(!shown.iter().any(|text| text == "Automatic"), "{shown:?}");
|
||
|
||
rt.state.models.open_picker();
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
assert_eq!(
|
||
element(&rt, "model-picker-option-0").label.as_deref(),
|
||
Some("Use OpenCode default")
|
||
);
|
||
}
|
||
|
||
#[test]
|
||
fn choosing_an_opencode_model_saves_it() {
|
||
let mut rt = runtime("modes", true, PANE_SIZE);
|
||
rt.state.models.open_picker();
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
tap(&mut rt, "model-picker-option-1");
|
||
assert_eq!(
|
||
rt.state.settings.dictation_processing.modes[0]
|
||
.post_processing
|
||
.model
|
||
.as_deref(),
|
||
Some("anthropic/claude-sonnet-4-5")
|
||
);
|
||
assert!(!rt.state.models.picker.is_open());
|
||
tap(&mut rt, "model-value");
|
||
assert!(rt.state.models.picker.is_open() && rt.state.models.picker.search().focused);
|
||
tap(&mut rt, "model-picker-option-0");
|
||
assert_eq!(
|
||
rt.state.settings.dictation_processing.modes[0]
|
||
.post_processing
|
||
.model,
|
||
None,
|
||
"back to the automatic model"
|
||
);
|
||
}
|
||
|
||
#[test]
|
||
fn a_long_model_list_fits_the_window_and_follows_the_highlight() {
|
||
let mut rt = runtime("modes", true, PANE_SIZE);
|
||
rt.state.models = models::Models::fixture_long();
|
||
rt.state.models.open_picker();
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
let [_, top, _, height] = rt.presented("viewport").unwrap().0;
|
||
assert!(
|
||
top + height <= PANE_SIZE.1 - 8.0,
|
||
"the list ends inside the window: {top} + {height}"
|
||
);
|
||
for _ in 0..40 {
|
||
key(&mut rt, Key::Down, Mods::default());
|
||
}
|
||
settle(&mut rt);
|
||
assert_eq!(rt.state.models.picker.active(), Some("40"));
|
||
let [_, row_top, _, row_height] = rt.presented("model-picker-option-40").unwrap().0;
|
||
assert!(
|
||
row_top >= top && row_top + row_height <= top + height,
|
||
"the highlighted row scrolled into view: {row_top} in {top}..{}",
|
||
top + height
|
||
);
|
||
}
|
||
|
||
#[test]
|
||
fn arrow_keys_move_the_search_highlight_and_enter_picks_it() {
|
||
let mut rt = runtime("modes", true, PANE_SIZE);
|
||
rt.state.models.open_picker();
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
key(&mut rt, Key::Down, Mods::default());
|
||
key(&mut rt, Key::Down, Mods::default());
|
||
key(&mut rt, Key::Up, Mods::default());
|
||
key(&mut rt, Key::Enter, Mods::default());
|
||
assert_eq!(
|
||
rt.state.settings.dictation_processing.modes[0]
|
||
.post_processing
|
||
.model
|
||
.as_deref(),
|
||
Some("anthropic/claude-sonnet-4-5")
|
||
);
|
||
assert!(!rt.state.models.picker.is_open());
|
||
|
||
let mut rt = runtime("modes-picker", true, GOLDEN_SIZE);
|
||
tap(&mut rt, "application-search");
|
||
// Visual Studio Code, WezTerm (Terminal's), Zed.
|
||
for _ in 0..3 {
|
||
key(&mut rt, Key::Down, Mods::default());
|
||
}
|
||
key(&mut rt, Key::Enter, Mods::default());
|
||
assert!(
|
||
rt.state.settings.dictation_processing.modes[0]
|
||
.applications
|
||
.contains(&"Zed".to_string())
|
||
);
|
||
}
|
||
|
||
#[test]
|
||
fn opencode_missing_offers_setup_instead_of_models() {
|
||
let mut rt = runtime("modes", true, PANE_SIZE);
|
||
rt.state.models = models::Models::fixture_not_running();
|
||
rt.state.settings.dictation_processing.modes[0]
|
||
.post_processing
|
||
.enabled = false;
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
assert!(rt.find("opencode-unavailable").is_some());
|
||
assert!(rt.find("open-opencode-setup").is_some());
|
||
assert!(rt.find("opencode-model").is_none());
|
||
}
|
||
|
||
#[test]
|
||
fn unavailable_opencode_is_explained_beside_each_switch() {
|
||
let beside = |rt: &Runtime<Ui>, row: &str| {
|
||
rt.elements()
|
||
.into_iter()
|
||
.filter(|e| e.path.contains(row) && e.path.ends_with("/description"))
|
||
.filter_map(|e| e.text)
|
||
.collect::<Vec<_>>()
|
||
};
|
||
let rt = runtime("modes-opencode-not-running", true, PANE_SIZE);
|
||
assert!(rt.find("processing-toggle").is_some());
|
||
assert_eq!(
|
||
beside(&rt, "processing-enabled"),
|
||
["OpenCode isn't running"]
|
||
);
|
||
assert!(
|
||
texts(&rt)
|
||
.iter()
|
||
.any(|text| text == "Install or start OpenCode to transform dictated text.")
|
||
);
|
||
}
|
||
|
||
#[test]
|
||
fn history_selects_deletes_and_clears_in_two_steps() {
|
||
let mut rt = runtime("history", true, PANE_SIZE);
|
||
tap(&mut rt, "history-entry3");
|
||
assert_eq!(rt.state.history.selected, Some(3));
|
||
// Delete… only asks. Cancel keeps the entry.
|
||
tap(&mut rt, "history-delete");
|
||
assert_eq!(rt.state.history.delete_armed, Some(3));
|
||
assert!(rt.find("history-confirm-delete").is_some());
|
||
assert!(rt.find("history-delete").is_none());
|
||
tap(&mut rt, "history-cancel-delete");
|
||
assert!(rt.state.history.delete_armed.is_none());
|
||
assert!(rt.state.history.entries.iter().any(|entry| entry.id == 3));
|
||
// Escape answers the confirmation too.
|
||
tap(&mut rt, "history-delete");
|
||
key(&mut rt, Key::Escape, Mods::default());
|
||
settle(&mut rt);
|
||
assert!(rt.state.history.delete_armed.is_none());
|
||
assert!(rt.find("history-confirm-delete").is_none());
|
||
assert!(rt.state.history.entries.iter().any(|entry| entry.id == 3));
|
||
// Only the confirmation deletes.
|
||
tap(&mut rt, "history-delete");
|
||
tap(&mut rt, "history-confirm-delete");
|
||
assert!(rt.state.history.delete_armed.is_none());
|
||
assert!(rt.state.history.entries.iter().all(|entry| entry.id != 3));
|
||
// Clear all history… sits at the bottom of the retention menu and only
|
||
// asks; Cancel keeps everything, and only the confirmation clears.
|
||
tap(&mut rt, "history-retention-field-trigger");
|
||
let clear = menu_item(&rt, "history-retention", "Clear all history…");
|
||
tap(&mut rt, &clear);
|
||
assert!(rt.state.history.clear_armed);
|
||
assert_eq!(rt.state.history.entries.len(), 2);
|
||
assert!(rt.find("history-retention-field-trigger").is_none());
|
||
tap(&mut rt, "history-cancel-clear");
|
||
assert!(!rt.state.history.clear_armed);
|
||
assert_eq!(rt.state.history.entries.len(), 2);
|
||
tap(&mut rt, "history-retention-field-trigger");
|
||
tap(&mut rt, &clear);
|
||
tap(&mut rt, "history-confirm-clear");
|
||
assert!(rt.state.history.entries.is_empty());
|
||
}
|
||
|
||
#[test]
|
||
fn history_clear_removes_a_usage_rollup_with_no_entries() {
|
||
use crate::history::{History, HistoryRetention, HistoryStore};
|
||
|
||
let directory =
|
||
std::env::temp_dir().join(format!("hex-rune-history-usage-{}", std::process::id()));
|
||
let _ = std::fs::remove_dir_all(&directory);
|
||
std::fs::create_dir_all(&directory).unwrap();
|
||
let path = directory.join("history.json");
|
||
let history = History::new(HistoryStore::open(
|
||
path.clone(),
|
||
HistoryRetention::Week,
|
||
crate::history::now_ms(),
|
||
));
|
||
crate::history::usage::count(
|
||
&crate::history::usage::path(&path),
|
||
crate::history::now_ms(),
|
||
5,
|
||
1_000,
|
||
)
|
||
.unwrap();
|
||
let check = history.clone();
|
||
let mut rt = runtime("history-empty", true, PANE_SIZE);
|
||
rt.state.history = history::HistoryPane::shared(Some(history));
|
||
rt.state
|
||
.history
|
||
.reload(rt.state.settings.labs.history_stats);
|
||
rt.state.pane = Pane::History;
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
assert!(check.has_usage(), "the rollup exists with no entries");
|
||
|
||
tap(&mut rt, "history-retention-field-trigger");
|
||
let clear = menu_item(&rt, "history-retention", "Clear all history…");
|
||
tap(&mut rt, &clear);
|
||
assert!(rt.state.history.clear_armed);
|
||
tap(&mut rt, "history-confirm-clear");
|
||
assert!(!check.has_usage(), "Clear all deleted the rollup");
|
||
let _ = std::fs::remove_dir_all(&directory);
|
||
}
|
||
|
||
#[test]
|
||
fn history_delete_confirmation_stops_when_the_pane_moves_on() {
|
||
use crate::history::{History, HistoryDraft, HistoryKind, HistoryRetention, HistoryStore};
|
||
let directory =
|
||
std::env::temp_dir().join(format!("hex-rune-history-disarm-{}", std::process::id()));
|
||
let _ = std::fs::remove_dir_all(&directory);
|
||
std::fs::create_dir_all(&directory).unwrap();
|
||
let history = History::new(HistoryStore::open(
|
||
directory.join("history.json"),
|
||
HistoryRetention::Week,
|
||
crate::history::now_ms(),
|
||
));
|
||
let record = |text: &str| {
|
||
history
|
||
.record(HistoryDraft {
|
||
kind: HistoryKind::Dictation,
|
||
raw_text: text.into(),
|
||
final_text: text.into(),
|
||
application: None,
|
||
processing: None,
|
||
audio_ms: 900,
|
||
inference_ms: 80,
|
||
total_ms: 200,
|
||
recording: None,
|
||
model: None,
|
||
})
|
||
.unwrap()
|
||
.unwrap()
|
||
};
|
||
let first = record("Ship it.");
|
||
let second = record("Ship it again.");
|
||
let mut rt = runtime("history-empty", true, PANE_SIZE);
|
||
rt.state.history = history::HistoryPane::shared(Some(history));
|
||
rt.state.history.selected = Some(first);
|
||
rt.state
|
||
.history
|
||
.reload(rt.state.settings.labs.history_stats);
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
// Choosing another entry answers Delete… and leaves the first entry be.
|
||
tap(&mut rt, "history-delete");
|
||
tap(&mut rt, &format!("history-entry{second}"));
|
||
assert!(rt.state.history.delete_armed.is_none());
|
||
assert!(
|
||
rt.state
|
||
.history
|
||
.entries
|
||
.iter()
|
||
.any(|entry| entry.id == first)
|
||
);
|
||
// Clear all history… answers it, then asks for its own confirmation.
|
||
tap(&mut rt, &format!("history-entry{first}"));
|
||
tap(&mut rt, "history-delete");
|
||
tap(&mut rt, "history-retention-field-trigger");
|
||
let clear = menu_item(&rt, "history-retention", "Clear all history…");
|
||
tap(&mut rt, &clear);
|
||
assert!(rt.state.history.delete_armed.is_none());
|
||
assert!(rt.find("history-confirm-delete").is_none());
|
||
tap(&mut rt, "history-cancel-clear");
|
||
// Leaving History answers it too.
|
||
tap(&mut rt, "history-delete");
|
||
tap(&mut rt, "nav-output");
|
||
tap(&mut rt, "nav-history");
|
||
assert!(rt.state.history.delete_armed.is_none());
|
||
assert!(rt.find("history-confirm-delete").is_none());
|
||
// A search answers it.
|
||
tap(&mut rt, "history-delete");
|
||
tap(&mut rt, "history-search");
|
||
rt.paste("zebra");
|
||
settle(&mut rt);
|
||
assert!(rt.state.history.delete_armed.is_none());
|
||
assert!(rt.find("history-confirm-delete").is_none());
|
||
let _ = std::fs::remove_dir_all(&directory);
|
||
}
|
||
|
||
#[test]
|
||
fn history_stats_button_opens_and_closes_the_dialog() {
|
||
let mut rt = runtime("history", true, PANE_SIZE);
|
||
assert!(!rt.state.settings.labs.history_stats);
|
||
assert!(rt.find("history-stats-open").is_none(), "off, no Stats");
|
||
rt.state.history.stats = Some(history::HistoryPane::fixture_stats());
|
||
rt.state.settings.labs.history_stats = true;
|
||
crate::labs::apply(&rt.state.settings.labs);
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
assert!(rt.find("history-stats-open").is_some(), "on, Stats shows");
|
||
assert!(
|
||
rt.find("history-stats").is_none(),
|
||
"the summary is no longer a block above the list"
|
||
);
|
||
|
||
tap(&mut rt, "history-stats-open");
|
||
assert!(rt.state.history.stats_open);
|
||
assert!(rt.find("history-stats-dialog").is_some());
|
||
assert!(texts(&rt).iter().any(|text| text == "Dictation stats"));
|
||
// Headline tiles, the daily chart, the app bars, Output's share, and
|
||
// Output time all show for the fixture, and the numbers group their
|
||
// thousands.
|
||
for key in [
|
||
"tile-dictations",
|
||
"tile-words",
|
||
"tile-time-saved",
|
||
"tile-wpm",
|
||
"tile-streak",
|
||
"tile-busiest-hour",
|
||
"history-stats-typing",
|
||
"history-stats-daily",
|
||
"history-stats-hours",
|
||
"history-stats-apps",
|
||
"history-stats-changed",
|
||
"history-stats-output-time",
|
||
] {
|
||
assert!(rt.find(key).is_some(), "{key} shows");
|
||
}
|
||
let shown = texts(&rt);
|
||
assert!(shown.iter().any(|text| text == "128,402"), "{shown:?}");
|
||
assert!(shown.iter().any(|text| text == "1,284"), "{shown:?}");
|
||
// Labs › Dictation stats adds the year heatmap from its rollup.
|
||
rt.state.history.usage = Some(history::HistoryPane::fixture_usage());
|
||
rt.state.settings.labs.history_stats = true;
|
||
crate::labs::apply(&rt.state.settings.labs);
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
assert!(
|
||
rt.find("history-stats-yearly").is_some(),
|
||
"the heatmap shows"
|
||
);
|
||
assert!(rt.find("history-stats-typing").is_some());
|
||
tap(&mut rt, "history-stats-close");
|
||
assert!(!rt.state.history.stats_open);
|
||
assert!(rt.find("history-stats-dialog").is_none());
|
||
|
||
tap(&mut rt, "history-stats-open");
|
||
let pane = rt.state.pane;
|
||
key(
|
||
&mut rt,
|
||
Key::Command('1'),
|
||
Mods {
|
||
cmd: true,
|
||
..Mods::default()
|
||
},
|
||
);
|
||
assert!(rt.state.history.stats_open);
|
||
assert_eq!(
|
||
rt.state.pane, pane,
|
||
"Command-1 waits while the stats dialog is open"
|
||
);
|
||
rt.update(on_close);
|
||
settle(&mut rt);
|
||
assert!(
|
||
!rt.state.history.stats_open,
|
||
"closing the window closes the dialog"
|
||
);
|
||
|
||
tap(&mut rt, "history-stats-open");
|
||
rt.update(|ui, tx| show(ui, Destination::History, tx));
|
||
settle(&mut rt);
|
||
assert!(
|
||
!rt.state.history.stats_open,
|
||
"showing History again closes the dialog"
|
||
);
|
||
|
||
tap(&mut rt, "history-stats-open");
|
||
key(&mut rt, Key::Escape, Mods::default());
|
||
settle(&mut rt);
|
||
assert!(!rt.state.history.stats_open, "Escape closes the dialog");
|
||
assert!(
|
||
focused(&rt).ends_with("history-stats-open"),
|
||
"focus returns to Stats: {}",
|
||
focused(&rt)
|
||
);
|
||
|
||
tap(&mut rt, "history-stats-open");
|
||
rt.state.history.stats = Some(Default::default());
|
||
rt.state.history.usage = None;
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
assert!(
|
||
!rt.state.history.stats_open,
|
||
"emptying the stats closes the dialog"
|
||
);
|
||
assert!(rt.find("history-stats-open").is_none());
|
||
|
||
rt.state.history.stats = Some(history::HistoryPane::fixture_stats());
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
tap(&mut rt, "history-stats-open");
|
||
rt.state.settings.labs.history_stats = false;
|
||
crate::labs::apply(&rt.state.settings.labs);
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
assert!(
|
||
!rt.state.history.stats_open,
|
||
"turning the lab off closes the dialog"
|
||
);
|
||
assert!(rt.find("history-stats-open").is_none());
|
||
}
|
||
|
||
/// The dialog leaves out the sections a summary has nothing for, and keeps
|
||
/// the tiles.
|
||
#[test]
|
||
fn history_stats_dialog_hides_sections_with_nothing_to_show() {
|
||
let mut rt = runtime("history", true, PANE_SIZE);
|
||
rt.state.history.stats = Some(crate::history::stats::HistoryStats {
|
||
dictations: 3,
|
||
words: 12,
|
||
..Default::default()
|
||
});
|
||
rt.state.settings.labs.history_stats = true;
|
||
crate::labs::apply(&rt.state.settings.labs);
|
||
rt.state.history.stats_open = true;
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
assert!(rt.find("history-stats-dialog").is_some());
|
||
assert!(rt.find("tile-dictations").is_some());
|
||
for key in [
|
||
"history-stats-daily",
|
||
"history-stats-apps",
|
||
"history-stats-output-time",
|
||
] {
|
||
assert!(rt.find(key).is_none(), "{key} stays out");
|
||
}
|
||
// With no Output changes at all, its meter still reads zero.
|
||
assert!(rt.find("history-stats-changed").is_some());
|
||
}
|
||
|
||
/// Labs › Stats on History needs both labs and something to summarize.
|
||
#[test]
|
||
fn history_stats_strip_needs_both_labs_and_stats() {
|
||
let mut rt = runtime("history", true, PANE_SIZE);
|
||
rt.state.history.stats = Some(history::HistoryPane::fixture_stats());
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
assert!(rt.find("history-stats-strip").is_none(), "off by default");
|
||
|
||
rt.state.settings.labs.history_stats = true;
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
assert!(
|
||
rt.find("history-stats-strip").is_none(),
|
||
"Dictation stats alone shows no strip"
|
||
);
|
||
|
||
rt.state.settings.labs.history_stats = false;
|
||
rt.state.settings.labs.history_stats_strip = true;
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
assert!(
|
||
rt.find("history-stats-strip").is_none(),
|
||
"the strip's own switch alone shows nothing"
|
||
);
|
||
|
||
rt.state.settings.labs.history_stats = true;
|
||
rt.state.history.stats = None;
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
assert!(
|
||
rt.find("history-stats-strip").is_none(),
|
||
"with no stats there is nothing to show"
|
||
);
|
||
|
||
rt.state.history.stats = Some(history::HistoryPane::fixture_stats());
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
assert!(
|
||
rt.find("history-stats-strip").is_some(),
|
||
"both labs on and stats present, the strip shows"
|
||
);
|
||
}
|
||
|
||
/// The strip and the dialog's tiles draw the same six numbers from one
|
||
/// function, so they can't drift.
|
||
#[test]
|
||
fn history_stats_strip_shows_the_dialogs_six_headline_numbers() {
|
||
let mut rt = runtime("history", true, PANE_SIZE);
|
||
rt.state.history.stats = Some(history::HistoryPane::fixture_stats());
|
||
rt.state.settings.labs.history_stats = true;
|
||
rt.state.settings.labs.history_stats_strip = true;
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
let strip = texts_under(&rt, "history-stats-strip/");
|
||
assert_eq!(strip.len(), 12, "six values and six labels: {strip:?}");
|
||
for value in ["1,284", "128,402", "123"] {
|
||
assert!(
|
||
strip.iter().any(|text| text == value),
|
||
"{value} shows: {strip:?}"
|
||
);
|
||
}
|
||
|
||
tap(&mut rt, "history-stats-open");
|
||
let tiles = texts_under(&rt, "tiles/");
|
||
assert_eq!(
|
||
strip, tiles,
|
||
"the strip and the dialog show the same six values and labels"
|
||
);
|
||
}
|
||
|
||
/// The strip fits the smallest window in a long-language column: its cells
|
||
/// share the row and truncate instead of running past the pane.
|
||
#[test]
|
||
fn history_stats_strip_fits_the_smallest_window_in_russian() {
|
||
let mut rt = runtime("history-stats-strip", true, (860.0, 560.0));
|
||
crate::desktop::i18n::apply(Some("ru"));
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
let (strip, _) = rt.presented("history-stats-strip").expect("the strip");
|
||
for key in [
|
||
"dictations",
|
||
"words",
|
||
"time-saved",
|
||
"wpm",
|
||
"streak",
|
||
"busiest-hour",
|
||
] {
|
||
let (cell, _) = rt
|
||
.presented(&format!("strip-{key}"))
|
||
.unwrap_or_else(|| panic!("strip-{key} draws"));
|
||
assert!(
|
||
cell[0] >= strip[0] && cell[0] + cell[2] <= strip[0] + strip[2],
|
||
"strip-{key} stays inside the strip: {cell:?} in {strip:?}"
|
||
);
|
||
}
|
||
}
|
||
|
||
/// The full Stats button and dialog stay exactly as they were with the strip
|
||
/// on, and the strip stays behind them.
|
||
#[test]
|
||
fn history_stats_button_and_dialog_still_work_with_the_strip_on() {
|
||
let mut rt = runtime("history", true, PANE_SIZE);
|
||
rt.state.history.stats = Some(history::HistoryPane::fixture_stats());
|
||
rt.state.settings.labs.history_stats = true;
|
||
rt.state.settings.labs.history_stats_strip = true;
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
assert!(rt.find("history-stats-strip").is_some());
|
||
assert!(rt.find("history-stats-open").is_some(), "Stats still shows");
|
||
|
||
tap(&mut rt, "history-stats-open");
|
||
assert!(rt.state.history.stats_open);
|
||
assert!(rt.find("history-stats-dialog").is_some());
|
||
for key in [
|
||
"tile-dictations",
|
||
"tile-words",
|
||
"tile-time-saved",
|
||
"tile-wpm",
|
||
"tile-streak",
|
||
"tile-busiest-hour",
|
||
] {
|
||
assert!(rt.find(key).is_some(), "{key} shows");
|
||
}
|
||
tap(&mut rt, "history-stats-close");
|
||
assert!(!rt.state.history.stats_open);
|
||
assert!(
|
||
rt.find("history-stats-strip").is_some(),
|
||
"the strip stays above the list"
|
||
);
|
||
}
|
||
|
||
/// The dialog's worst case in the window's least size: it stays inside the
|
||
/// window, keeps its title and Close, and scrolls the sections between them.
|
||
#[test]
|
||
fn the_stats_dialog_fits_the_smallest_window_with_a_scrolling_body() {
|
||
let rt = runtime("history-stats", true, (860.0, 560.0));
|
||
let (dialog, _) = rt.presented("history-stats-dialog").expect("the dialog");
|
||
assert!(
|
||
dialog[1] >= 0.0 && dialog[1] + dialog[3] <= 560.0,
|
||
"the dialog fits the window: {dialog:?}"
|
||
);
|
||
let (close, _) = rt.presented("history-stats-close").expect("Close");
|
||
assert!(
|
||
close[1] + close[3] <= dialog[1] + dialog[3],
|
||
"Close stays inside the dialog: {close:?} in {dialog:?}"
|
||
);
|
||
let (body, _) = rt.presented("history-stats-body").expect("the body");
|
||
let (sections, _) = rt
|
||
.presented("history-stats-sections")
|
||
.expect("the sections");
|
||
assert!(
|
||
sections[3] > body[3],
|
||
"the body scrolls: {sections:?} in {body:?}"
|
||
);
|
||
assert!(
|
||
body[1] + body[3] <= close[1],
|
||
"the scrolling viewport ends before the footer: {body:?} in {close:?}"
|
||
);
|
||
}
|
||
|
||
/// At a tall window the sections fit, so the dialog draws no scroll body at
|
||
/// all and takes the sections' own height. The year heatmap and hourly strip
|
||
/// make a richer dialog than the default window's, so this uses a taller one.
|
||
#[test]
|
||
fn the_stats_dialog_has_no_scroll_body_when_its_sections_fit() {
|
||
let rt = runtime("history-stats", true, (980.0, 1_080.0));
|
||
assert!(
|
||
rt.find("history-stats-body-scroll-area").is_none(),
|
||
"no scroll body"
|
||
);
|
||
let (body, _) = rt.presented("history-stats-body").expect("the body");
|
||
let (sections, _) = rt
|
||
.presented("history-stats-sections")
|
||
.expect("the sections");
|
||
assert!(
|
||
sections[3] <= body[3],
|
||
"the sections fit the body: {sections:?} in {body:?}"
|
||
);
|
||
}
|
||
|
||
/// History, settled.
|
||
fn history_multi() -> Runtime<Ui> {
|
||
let mut rt = runtime("history", true, PANE_SIZE);
|
||
settle(&mut rt);
|
||
rt
|
||
}
|
||
|
||
/// Holds `mods` for the press that follows.
|
||
fn hold(rt: &mut Runtime<Ui>, mods: Mods) {
|
||
rt.physical_input(rune::PhysicalInput::Modifiers(mods));
|
||
rt.frame(1.0 / 60.0);
|
||
}
|
||
|
||
/// Shift, which extends a list selection from its anchor.
|
||
fn shift() -> Mods {
|
||
Mods {
|
||
shift: true,
|
||
..Mods::default()
|
||
}
|
||
}
|
||
|
||
/// Command on macOS, Control elsewhere, which toggles a row.
|
||
fn command() -> Mods {
|
||
Mods {
|
||
cmd: true,
|
||
..Mods::default()
|
||
}
|
||
}
|
||
|
||
#[test]
|
||
fn history_selects_several_with_shift_command_and_drag() {
|
||
let mut rt = history_multi();
|
||
// The rows are newest first: 3, 2, 1.
|
||
tap(&mut rt, "history-entry2");
|
||
assert_eq!(rt.state.history.selection.len(), 1);
|
||
assert!(
|
||
rt.find("history-selection-copy").is_none(),
|
||
"one entry keeps its own card"
|
||
);
|
||
|
||
// Shift-click selects every row between the anchor and the one clicked.
|
||
hold(&mut rt, shift());
|
||
tap(&mut rt, "history-entry1");
|
||
hold(&mut rt, Mods::default());
|
||
assert_eq!(rt.state.history.selected, Some(1));
|
||
assert_eq!(rt.state.history.selection.len(), 2);
|
||
assert!(rt.state.history.selection.contains(2));
|
||
assert!(
|
||
texts(&rt)
|
||
.iter()
|
||
.any(|text| text == "2 dictations selected")
|
||
);
|
||
assert!(rt.find("history-selection-copy").is_some());
|
||
|
||
// Command-click toggles the row it lands on and becomes the anchor.
|
||
hold(&mut rt, command());
|
||
tap(&mut rt, "history-entry3");
|
||
hold(&mut rt, Mods::default());
|
||
assert_eq!(rt.state.history.selection.len(), 3);
|
||
assert!(
|
||
texts(&rt)
|
||
.iter()
|
||
.any(|text| text == "3 dictations selected")
|
||
);
|
||
|
||
hold(&mut rt, command());
|
||
tap(&mut rt, "history-entry2");
|
||
hold(&mut rt, Mods::default());
|
||
assert!(!rt.state.history.selection.contains(2));
|
||
assert_eq!(rt.state.history.selection.len(), 2);
|
||
|
||
// A press dragged over other rows selects from it through them.
|
||
let (x, y) = rt.find("history-entry2").unwrap();
|
||
let (to_x, to_y) = rt.find("history-entry1").unwrap();
|
||
rt.pointer_down(x, y);
|
||
rt.pointer_move(to_x, to_y);
|
||
rt.pointer_up(to_x, to_y);
|
||
settle(&mut rt);
|
||
assert_eq!(rt.state.history.selection.len(), 2);
|
||
assert!(rt.state.history.selection.contains(2));
|
||
assert!(rt.state.history.selection.contains(1));
|
||
assert!(!rt.state.history.selection.contains(3));
|
||
}
|
||
|
||
/// Presses row `key` and lets go 2 pt away: a shaky click, not a drag.
|
||
fn tap_jitter(rt: &mut Runtime<Ui>, key: &str) {
|
||
let (x, y) = rt.find(key).unwrap_or_else(|| panic!("no element {key}"));
|
||
rt.pointer_down(x, y);
|
||
rt.pointer_move(x + 2.0, y - 1.0);
|
||
rt.pointer_up(x + 2.0, y - 1.0);
|
||
settle(rt);
|
||
}
|
||
|
||
#[test]
|
||
fn history_a_jittered_press_keeps_a_command_toggle() {
|
||
let mut rt = history_multi();
|
||
tap(&mut rt, "history-entry3");
|
||
hold(&mut rt, command());
|
||
tap_jitter(&mut rt, "history-entry2");
|
||
hold(&mut rt, Mods::default());
|
||
assert_eq!(rt.state.history.selection.len(), 2);
|
||
assert!(rt.state.history.selection.contains(3));
|
||
assert!(rt.state.history.selection.contains(2));
|
||
assert_eq!(rt.state.history.selected, Some(2));
|
||
}
|
||
|
||
#[test]
|
||
fn history_a_jittered_press_keeps_a_shift_range() {
|
||
let mut rt = history_multi();
|
||
tap(&mut rt, "history-entry3");
|
||
hold(&mut rt, shift());
|
||
tap_jitter(&mut rt, "history-entry1");
|
||
hold(&mut rt, Mods::default());
|
||
assert_eq!(rt.state.history.selection.len(), 3);
|
||
for id in [1, 2, 3] {
|
||
assert!(rt.state.history.selection.contains(id));
|
||
}
|
||
assert_eq!(rt.state.history.selected, Some(1));
|
||
}
|
||
|
||
#[test]
|
||
fn history_a_press_dragged_inside_its_row_keeps_a_command_toggle() {
|
||
let mut rt = history_multi();
|
||
tap(&mut rt, "history-entry3");
|
||
let (x, y) = rt.find("history-entry2").unwrap();
|
||
hold(&mut rt, command());
|
||
// 8 pt along the same row: past the click slop, but still row 2, so the
|
||
// release must not choose row 2 a second time and undo the toggle.
|
||
rt.pointer_down(x, y);
|
||
rt.pointer_move(x + 8.0, y);
|
||
rt.pointer_up(x + 8.0, y);
|
||
settle(&mut rt);
|
||
hold(&mut rt, Mods::default());
|
||
assert_eq!(rt.state.history.selection.len(), 2);
|
||
assert!(rt.state.history.selection.contains(3));
|
||
assert!(rt.state.history.selection.contains(2));
|
||
assert_eq!(rt.state.history.selected, Some(2));
|
||
}
|
||
|
||
/// Presses row `from`, drags over row `to`, and lets go at `at` on the row it
|
||
/// pressed, all in the frames the moves take: the release and the last move
|
||
/// share one, so no drawn tree shows the drag back on its own row.
|
||
fn drag_out_and_back(rt: &mut Runtime<Ui>, from: &str, to: &str, at: (f32, f32)) {
|
||
let (from_x, from_y) = rt.find(from).unwrap_or_else(|| panic!("no element {from}"));
|
||
let (to_x, to_y) = rt.find(to).unwrap_or_else(|| panic!("no element {to}"));
|
||
rt.pointer_down(from_x, from_y);
|
||
rt.pointer_move(to_x, to_y);
|
||
rt.pointer_move(at.0, at.1);
|
||
rt.pointer_up(at.0, at.1);
|
||
settle(rt);
|
||
}
|
||
|
||
#[test]
|
||
fn history_a_drag_back_onto_its_row_selects_only_that_row() {
|
||
let mut rt = history_multi();
|
||
tap(&mut rt, "history-entry3");
|
||
let (x, y) = rt.find("history-entry2").unwrap();
|
||
hold(&mut rt, command());
|
||
// Out to row 1 and back onto row 2, 8 pt from where the press landed: the
|
||
// range shrinks back to row 2, and that row's release must not toggle it
|
||
// off again.
|
||
drag_out_and_back(&mut rt, "history-entry2", "history-entry1", (x + 8.0, y));
|
||
hold(&mut rt, Mods::default());
|
||
assert_eq!(rt.state.history.selection.len(), 1);
|
||
assert!(rt.state.history.selection.contains(2));
|
||
assert_eq!(rt.state.history.selected, Some(2));
|
||
}
|
||
|
||
#[test]
|
||
fn history_a_drag_back_near_its_press_selects_only_that_row() {
|
||
let mut rt = history_multi();
|
||
tap(&mut rt, "history-entry3");
|
||
let (x, y) = rt.find("history-entry2").unwrap();
|
||
hold(&mut rt, command());
|
||
// The return lands 2 pt from the press, under the click slop: the press is
|
||
// a drag now, so it still ranges back to row 2 instead of leaving row 1.
|
||
drag_out_and_back(
|
||
&mut rt,
|
||
"history-entry2",
|
||
"history-entry1",
|
||
(x + 2.0, y - 1.0),
|
||
);
|
||
hold(&mut rt, Mods::default());
|
||
assert_eq!(rt.state.history.selection.len(), 1);
|
||
assert!(rt.state.history.selection.contains(2));
|
||
assert_eq!(rt.state.history.selected, Some(2));
|
||
}
|
||
|
||
#[test]
|
||
fn history_keyboard_activation_selects_a_row_in_the_set() {
|
||
let mut rt = history_multi();
|
||
tap(&mut rt, "history-entry3");
|
||
hold(&mut rt, shift());
|
||
tap(&mut rt, "history-entry2");
|
||
hold(&mut rt, Mods::default());
|
||
assert_eq!(rt.state.history.selection.len(), 2);
|
||
assert_eq!(rt.state.history.selected, Some(2));
|
||
// Up moves focus from the pressed row to row 3, which the set holds but
|
||
// the card does not show, and presses it there.
|
||
key(&mut rt, Key::Up, Mods::default());
|
||
settle(&mut rt);
|
||
assert_eq!(rt.state.history.selection.len(), 1);
|
||
assert!(rt.state.history.selection.contains(3));
|
||
assert_eq!(rt.state.history.selected, Some(3));
|
||
}
|
||
|
||
#[test]
|
||
fn history_selection_copies_oldest_first() {
|
||
let mut rt = history_multi();
|
||
tap(&mut rt, "history-entry3");
|
||
hold(&mut rt, shift());
|
||
tap(&mut rt, "history-entry1");
|
||
hold(&mut rt, Mods::default());
|
||
tap(&mut rt, "history-selection-copy");
|
||
assert_eq!(
|
||
rt.copy_request.as_deref(),
|
||
Some(
|
||
"Thanks for sending this over! I'll review it today and follow up with comments.\n\n\
|
||
The deploy failed because the cache key changed.\n\n\
|
||
Let's move the standup to ten thirty tomorrow."
|
||
)
|
||
);
|
||
assert!(texts(&rt).iter().any(|text| text == "Copied"));
|
||
}
|
||
|
||
// The notches affect too few pixels to trip the whole-window golden tolerance.
|
||
#[test]
|
||
fn history_rounds_only_the_exposed_ends_of_selected_rows() {
|
||
let _goldens = Goldens::collect();
|
||
for dark in [false, true] {
|
||
for separated in [false, true] {
|
||
let mut rt = runtime("history", dark, PANE_SIZE);
|
||
// A search-result snapshot: adjacent entries need not have consecutive ids.
|
||
rt.state.history.entries[0].id = 17;
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
tap(&mut rt, "history-entry17");
|
||
hold(&mut rt, if separated { command() } else { shift() });
|
||
tap(&mut rt, "history-entry1");
|
||
hold(&mut rt, Mods::default());
|
||
rt.pointer_move(0.0, 0.0);
|
||
settle(&mut rt);
|
||
let rows = [17, 2, 1].map(|id| element(&rt, &format!("history-entry{id}")).rect);
|
||
let render = render_runtime(rt, PANE_SIZE);
|
||
if let Some((w, _, pixels)) = &render {
|
||
let pixel = |x: f32, y: f32| {
|
||
let at = ((y * GOLDEN_SCALE) as usize * *w as usize
|
||
+ (x * GOLDEN_SCALE) as usize)
|
||
* 4;
|
||
&pixels[at..at + 4]
|
||
};
|
||
let [x, top, width, height] = rows[0];
|
||
let fill = pixel(x + 2.0, top + height / 2.0);
|
||
for edge in [x + 1.0, x + width - 1.5] {
|
||
assert_ne!(pixel(edge, top + 0.5), fill, "rounded top");
|
||
for [_, join, _, _] in &rows[1..] {
|
||
for y in [join - 0.5, join + 0.5] {
|
||
assert_eq!(pixel(edge, y) == fill, !separated, "join at {join}");
|
||
}
|
||
}
|
||
assert_ne!(
|
||
pixel(edge, rows[2][1] + rows[2][3] - 1.0),
|
||
fill,
|
||
"rounded bottom"
|
||
);
|
||
}
|
||
}
|
||
if !separated {
|
||
check_render("history-selected-range", dark, render);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
#[test]
|
||
fn history_selection_deletes_in_two_steps() {
|
||
let mut rt = history_multi();
|
||
tap(&mut rt, "history-entry3");
|
||
hold(&mut rt, shift());
|
||
tap(&mut rt, "history-entry2");
|
||
hold(&mut rt, Mods::default());
|
||
assert_eq!(rt.state.history.selection.len(), 2);
|
||
|
||
tap(&mut rt, "history-selection-delete");
|
||
assert!(rt.state.history.selection.delete_armed);
|
||
assert_eq!(rt.state.history.entries.len(), 3, "Delete asks first");
|
||
tap(&mut rt, "history-selection-cancel-delete");
|
||
assert!(!rt.state.history.selection.delete_armed);
|
||
assert_eq!(rt.state.history.entries.len(), 3);
|
||
|
||
tap(&mut rt, "history-selection-delete");
|
||
assert!(texts(&rt).iter().any(|text| text == "Delete 2 dictations"));
|
||
tap(&mut rt, "history-selection-confirm-delete");
|
||
assert_eq!(rt.state.history.entries.len(), 1);
|
||
assert_eq!(rt.state.history.entries[0].id, 1);
|
||
assert_eq!(rt.state.history.selection.len(), 0);
|
||
assert_eq!(rt.state.history.selected, None);
|
||
assert!(rt.find("history-selection-copy").is_none());
|
||
}
|
||
|
||
#[test]
|
||
fn history_command_click_keeps_the_selected_row() {
|
||
let mut rt = history_multi();
|
||
tap(&mut rt, "history-entry2");
|
||
assert_eq!(rt.state.history.selected, Some(2));
|
||
|
||
// The one selected row joins the set first, so Command-clicking another
|
||
// row keeps it instead of dropping it.
|
||
hold(&mut rt, command());
|
||
tap(&mut rt, "history-entry3");
|
||
hold(&mut rt, Mods::default());
|
||
assert_eq!(rt.state.history.selection.len(), 2);
|
||
assert!(rt.state.history.selection.contains(2));
|
||
assert!(rt.state.history.selection.contains(3));
|
||
assert_eq!(rt.state.history.selected, Some(3));
|
||
assert!(rt.find("history-selection-copy").is_some());
|
||
}
|
||
|
||
#[test]
|
||
fn history_command_click_deselects_the_only_selected_row() {
|
||
let mut rt = history_multi();
|
||
tap(&mut rt, "history-entry2");
|
||
assert_eq!(rt.state.history.selected, Some(2));
|
||
|
||
// The one selected row is the whole set: Command deselects it, leaving
|
||
// nothing selected.
|
||
hold(&mut rt, command());
|
||
tap(&mut rt, "history-entry2");
|
||
hold(&mut rt, Mods::default());
|
||
assert_eq!(rt.state.history.selection.len(), 0);
|
||
assert_eq!(rt.state.history.selected, None);
|
||
assert!(!rt.state.history.is_selected(2));
|
||
}
|
||
|
||
#[test]
|
||
fn history_menu_sets_retention_and_keep_recordings() {
|
||
let mut rt = runtime("history-menu", true, PANE_SIZE);
|
||
let shown = texts(&rt);
|
||
assert!(shown.iter().any(|text| text == "Kept 7 days"));
|
||
let day = menu_item(&rt, "history-retention", "24 hours");
|
||
tap(&mut rt, &day);
|
||
assert_eq!(
|
||
rt.state.settings.history_retention,
|
||
crate::history::HistoryRetention::Day
|
||
);
|
||
assert!(texts(&rt).iter().any(|text| text == "Kept 24 hours"));
|
||
tap(&mut rt, "history-retention-field-trigger");
|
||
let audio = menu_item(&rt, "history-retention", "Keep audio too");
|
||
tap(&mut rt, &audio);
|
||
assert!(rt.state.settings.labs.keep_recordings);
|
||
tap(&mut rt, "history-retention-field-trigger");
|
||
let off = menu_item(&rt, "history-retention", "Off");
|
||
tap(&mut rt, &off);
|
||
assert!(texts(&rt).iter().any(|text| text == "History off"));
|
||
}
|
||
|
||
/// The key of `menu`'s item labelled `label`.
|
||
fn menu_item(rt: &Runtime<Ui>, menu: &str, label: &str) -> String {
|
||
let prefix = format!("{menu}-item");
|
||
rt.elements()
|
||
.into_iter()
|
||
.filter_map(|e| e.key.filter(|key| key.starts_with(&prefix)).zip(e.label))
|
||
.find(|(_, shown)| shown == label)
|
||
.map(|(key, _)| key)
|
||
.unwrap_or_else(|| panic!("{menu} has no {label:?}"))
|
||
}
|
||
|
||
/// What is still changing one short frame after an input: hover and press
|
||
/// overlays between their ends, fades, travel, and fills that differ from
|
||
/// where they settle.
|
||
fn still_changing(rt: &mut Runtime<Ui>, within: &str) -> Vec<String> {
|
||
rt.frame(1.0 / 120.0);
|
||
let now = rt.elements();
|
||
settle(rt);
|
||
let later = rt.elements();
|
||
let mut changing = Vec::new();
|
||
for e in now.iter().filter(|e| e.path.contains(within) && !e.exiting) {
|
||
let rest = later.iter().find(|l| l.path == e.path && !l.exiting);
|
||
if e.moving || (e.opacity > 0.001 && e.opacity < 0.999) {
|
||
changing.push(format!("{} moving or fading ({})", e.path, e.opacity));
|
||
}
|
||
if let Some(rest) = rest
|
||
&& (e.fill != rest.fill
|
||
|| e.text_color != rest.text_color
|
||
|| (e.hover - rest.hover).abs() > 0.001
|
||
|| (e.press - rest.press).abs() > 0.001
|
||
|| (e.opacity - rest.opacity).abs() > 0.001)
|
||
{
|
||
changing.push(format!("{} differs from its rest", e.path));
|
||
}
|
||
}
|
||
changing
|
||
}
|
||
|
||
/// List rows are as fast as they can be: hover is a fill that lands at once,
|
||
/// and a press selects the row and swaps the detail in the same frame.
|
||
#[test]
|
||
fn list_rows_select_and_hover_at_once() {
|
||
for (scene, row, pane) in [
|
||
("history", "history-entry3", "history-pane"),
|
||
("modes", "mode-global", "/panel/"),
|
||
] {
|
||
let mut rt = runtime(scene, true, PANE_SIZE);
|
||
settle(&mut rt);
|
||
let (x, y) = rt.find(row).expect("a row");
|
||
rt.pointer_move(x, y);
|
||
let hovered = still_changing(&mut rt, pane);
|
||
assert!(hovered.is_empty(), "{scene}: hover animates: {hovered:#?}");
|
||
assert!(element(&rt, row).hover > 0.999, "{scene}: no hover fill");
|
||
rt.pointer_down(x, y);
|
||
let pressed = still_changing(&mut rt, pane);
|
||
assert!(
|
||
pressed.is_empty(),
|
||
"{scene}: selection animates: {pressed:#?}"
|
||
);
|
||
rt.pointer_up(x, y);
|
||
let released = still_changing(&mut rt, pane);
|
||
assert!(
|
||
released.is_empty(),
|
||
"{scene}: release animates: {released:#?}"
|
||
);
|
||
}
|
||
let mut rt = runtime("history", true, PANE_SIZE);
|
||
let (x, y) = rt.find("history-entry3").expect("a row");
|
||
rt.pointer_down(x, y);
|
||
rt.frame(1.0 / 120.0);
|
||
assert_eq!(rt.state.history.selected, Some(3), "selects on the press");
|
||
rt.pointer_up(x, y);
|
||
}
|
||
|
||
/// A row's Copy copies that entry without selecting it.
|
||
#[test]
|
||
fn a_rows_copy_leaves_the_selection() {
|
||
let mut rt = runtime("history", true, PANE_SIZE);
|
||
let (x, y) = rt.find("history-entry1").expect("a row");
|
||
rt.pointer_move(x, y);
|
||
settle(&mut rt);
|
||
let copy = rt
|
||
.elements()
|
||
.into_iter()
|
||
.find(|e| e.path.contains("history-entry1/") && e.key.as_deref() == Some("row-copy"))
|
||
.expect("the row's Copy");
|
||
let (x, y) = (
|
||
copy.rect[0] + copy.rect[2] / 2.0,
|
||
copy.rect[1] + copy.rect[3] / 2.0,
|
||
);
|
||
rt.pointer_move(x, y);
|
||
rt.pointer_down(x, y);
|
||
rt.pointer_up(x, y);
|
||
settle(&mut rt);
|
||
assert_eq!(rt.state.history.copied, Some(1));
|
||
assert_eq!(rt.state.history.selected, Some(2));
|
||
}
|
||
|
||
/// A hovered row's Copy, pressed a point inside its right edge, copies
|
||
/// rather than scrolling when the list overflows under the scroll bar. The
|
||
/// row fill still reaches the search field's edge, so selection stays flush.
|
||
#[test]
|
||
fn a_rows_copy_clears_the_scroll_bar() {
|
||
let mut rt = runtime("history", true, PANE_SIZE);
|
||
let seeds = rt.state.history.entries.clone();
|
||
for (index, seed) in seeds.iter().cycle().take(40).enumerate() {
|
||
let mut entry = seed.clone();
|
||
entry.id = 1_000 + index as u64;
|
||
rt.state.history.entries.push(entry);
|
||
}
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
rt.elements()
|
||
.into_iter()
|
||
.find(|e| e.key.as_deref() == Some("scroll-bar") && e.path.contains("history-scroll"))
|
||
.expect("an overflowing list shows its scroll bar");
|
||
|
||
let row = element(&rt, "history-entry1").rect;
|
||
rt.pointer_move(row[0] + row[2] / 2.0, row[1] + row[3] / 2.0);
|
||
settle(&mut rt);
|
||
let copy = rt
|
||
.elements()
|
||
.into_iter()
|
||
.find(|e| e.path.contains("history-entry1/") && e.key.as_deref() == Some("row-copy"))
|
||
.expect("the row's Copy")
|
||
.rect;
|
||
let (x, y) = (copy[0] + copy[2] - 1.0, copy[1] + copy[3] / 2.0);
|
||
rt.pointer_move(x, y);
|
||
rt.pointer_down(x, y);
|
||
rt.pointer_up(x, y);
|
||
settle(&mut rt);
|
||
assert_eq!(
|
||
rt.state.history.copied,
|
||
Some(1),
|
||
"a press on the Copy's right edge copies"
|
||
);
|
||
|
||
let search = element(&rt, "history-search").rect;
|
||
let row = element(&rt, "history-entry2").rect;
|
||
assert!(
|
||
(row[0] + row[2] - (search[0] + search[2])).abs() < 0.5,
|
||
"the selected row ends at {} but the search field at {}",
|
||
row[0] + row[2],
|
||
search[0] + search[2]
|
||
);
|
||
}
|
||
|
||
#[test]
|
||
fn history_copy_writes_the_clipboard() {
|
||
let mut rt = runtime("history", true, PANE_SIZE);
|
||
tap(&mut rt, "history-copy");
|
||
assert_eq!(
|
||
rt.copy_request.as_deref(),
|
||
Some("The deploy failed because the cache key changed.")
|
||
);
|
||
assert_eq!(rt.state.history.copied, Some(2));
|
||
}
|
||
|
||
#[test]
|
||
fn history_search_without_matches_says_so() {
|
||
use crate::history::{History, HistoryDraft, HistoryKind, HistoryRetention, HistoryStore};
|
||
let directory = std::env::temp_dir().join(format!("hex-rune-history-{}", std::process::id()));
|
||
let _ = std::fs::remove_dir_all(&directory);
|
||
std::fs::create_dir_all(&directory).unwrap();
|
||
let store = HistoryStore::open(
|
||
directory.join("history.json"),
|
||
HistoryRetention::Week,
|
||
crate::history::now_ms(),
|
||
);
|
||
let history = History::new(store);
|
||
history
|
||
.record(HistoryDraft {
|
||
kind: HistoryKind::Dictation,
|
||
raw_text: "ship it".into(),
|
||
final_text: "Ship it.".into(),
|
||
application: None,
|
||
processing: None,
|
||
audio_ms: 900,
|
||
inference_ms: 80,
|
||
total_ms: 200,
|
||
recording: None,
|
||
model: None,
|
||
})
|
||
.unwrap();
|
||
let mut rt = runtime("history-empty", true, PANE_SIZE);
|
||
rt.state.history = history::HistoryPane::shared(Some(history));
|
||
rt.state
|
||
.history
|
||
.reload(rt.state.settings.labs.history_stats);
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
assert!(texts(&rt).iter().all(|text| text != "No dictations match."));
|
||
tap(&mut rt, "history-search");
|
||
rt.paste("zebra");
|
||
settle(&mut rt);
|
||
assert!(rt.state.history.entries.is_empty());
|
||
let texts = texts(&rt);
|
||
assert!(texts.iter().any(|text| text == "No dictations match."));
|
||
assert!(
|
||
texts
|
||
.iter()
|
||
.all(|text| text != "No dictations retained yet.")
|
||
);
|
||
let _ = std::fs::remove_dir_all(&directory);
|
||
}
|
||
|
||
#[test]
|
||
fn transcribe_again_offers_a_language_only_for_models_that_take_one() {
|
||
use crate::transcription::models::{AUTO_LANGUAGE, TranscriptionModelId};
|
||
let whisper = history::language_choices(TranscriptionModelId::WhisperLargeV3Turbo).unwrap();
|
||
assert_eq!(whisper[0], AUTO_LANGUAGE);
|
||
assert!(whisper.contains(&"en") && whisper.contains(&"es"));
|
||
assert!(history::language_choices(TranscriptionModelId::ParakeetV3).is_none());
|
||
assert!(history::language_choices(TranscriptionModelId::GigaAmV3).is_none());
|
||
|
||
let mut rt = runtime("history", true, GOLDEN_SIZE);
|
||
rt.state.settings.labs.keep_recordings = true;
|
||
rt.state.settings.transcription.language = "es".into();
|
||
history::choose_model(
|
||
&mut rt.state,
|
||
2,
|
||
TranscriptionModelId::WhisperLargeV3Turbo,
|
||
"Whisper",
|
||
);
|
||
let pending = rt.state.history.pending.as_ref().unwrap();
|
||
assert_eq!(pending.id, 2);
|
||
assert_eq!(pending.language, "es", "it starts at the saved language");
|
||
assert!(
|
||
rt.state.history.again.is_none(),
|
||
"nothing runs before Transcribe"
|
||
);
|
||
assert_eq!(rt.state.settings.transcription.language, "es");
|
||
|
||
rt.state.settings.transcription.language = "pl".into();
|
||
history::choose_model(
|
||
&mut rt.state,
|
||
2,
|
||
TranscriptionModelId::CohereTranscribe,
|
||
"Cohere",
|
||
);
|
||
let pending = rt.state.history.pending.as_ref().unwrap();
|
||
assert!(
|
||
history::language_choices(TranscriptionModelId::CohereTranscribe)
|
||
.unwrap()
|
||
.contains(&pending.language.as_str()),
|
||
"an unsupported saved language falls back to one the model has"
|
||
);
|
||
}
|
||
|
||
#[test]
|
||
fn transcribe_again_shows_only_with_its_lab_and_replace_updates_the_entry() {
|
||
use crate::history::{
|
||
History, HistoryDraft, HistoryKind, HistoryRetention, HistoryStore, Recording,
|
||
};
|
||
let directory = std::env::temp_dir().join(format!("hex-rune-again-{}", std::process::id()));
|
||
let _ = std::fs::remove_dir_all(&directory);
|
||
std::fs::create_dir_all(&directory).unwrap();
|
||
let history = History::new(HistoryStore::open(
|
||
directory.join("history.json"),
|
||
HistoryRetention::Week,
|
||
crate::history::now_ms(),
|
||
));
|
||
let draft = |recording| HistoryDraft {
|
||
kind: HistoryKind::Dictation,
|
||
raw_text: "ship it".into(),
|
||
final_text: "Ship it.".into(),
|
||
application: None,
|
||
processing: None,
|
||
audio_ms: 900,
|
||
inference_ms: 80,
|
||
total_ms: 200,
|
||
recording,
|
||
model: Some("Parakeet v3".into()),
|
||
};
|
||
let plain = history.record(draft(None)).unwrap().unwrap();
|
||
let id = history
|
||
.record(draft(Some(Recording::from_samples(vec![0.2; 1_600]))))
|
||
.unwrap()
|
||
.unwrap();
|
||
let mut rt = runtime("history-empty", true, GOLDEN_SIZE);
|
||
rt.state.history = history::HistoryPane::shared(Some(history.clone()));
|
||
rt.state
|
||
.history
|
||
.reload(rt.state.settings.labs.history_stats);
|
||
rt.state.history.selected = Some(id);
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
assert!(rt.find("again").is_none(), "off, History is unchanged");
|
||
|
||
rt.state.settings.labs.keep_recordings = true;
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
assert!(rt.find("again").is_some());
|
||
assert!(rt.find("again-play").is_some(), "audio can be played");
|
||
rt.state.history.selected = Some(plain);
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
assert!(
|
||
rt.find("again").is_none(),
|
||
"an entry without audio has nothing to transcribe"
|
||
);
|
||
assert!(rt.find("again-play").is_none());
|
||
|
||
rt.state.history.selected = Some(id);
|
||
rt.state.history.again = Some(history::Again::finished(
|
||
id,
|
||
"Whisper",
|
||
Ok("Ship it now.".into()),
|
||
));
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
assert!(texts(&rt).iter().any(|text| text == "Ship it now."));
|
||
tap(&mut rt, "again-copy");
|
||
assert_eq!(rt.copy_request.as_deref(), Some("Ship it now."));
|
||
tap(&mut rt, "again-replace");
|
||
settle(&mut rt);
|
||
assert!(rt.state.history.again.is_none());
|
||
let entry = history
|
||
.search("")
|
||
.into_iter()
|
||
.find(|entry| entry.id == id)
|
||
.unwrap();
|
||
assert_eq!(entry.final_text, "Ship it now.");
|
||
assert_eq!(entry.model.as_deref(), Some("Whisper"));
|
||
assert!(entry.has_recording(), "replacing keeps the recording");
|
||
assert_eq!(entry.versions.len(), 1);
|
||
assert_eq!(entry.versions[0].final_text, "Ship it.");
|
||
assert_eq!(entry.versions[0].model.as_deref(), Some("Parakeet v3"));
|
||
|
||
// The kept version shows with its model, copies, and comes back.
|
||
let shown = texts(&rt);
|
||
assert!(shown.iter().any(|text| text == "Whisper"), "{shown:?}");
|
||
assert!(shown.iter().any(|text| text.starts_with("Parakeet v3 · ")));
|
||
tap(&mut rt, "version0/actions/copy");
|
||
assert_eq!(rt.copy_request.as_deref(), Some("Ship it."));
|
||
tap(&mut rt, "version0/actions/use");
|
||
settle(&mut rt);
|
||
let entry = history
|
||
.search("")
|
||
.into_iter()
|
||
.find(|entry| entry.id == id)
|
||
.unwrap();
|
||
assert_eq!(entry.final_text, "Ship it.");
|
||
assert_eq!(entry.versions[0].final_text, "Ship it now.");
|
||
|
||
rt.state.settings.labs.keep_recordings = false;
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
assert!(rt.find("versions").is_none(), "off, the versions hide");
|
||
assert!(rt.find("again-play").is_none(), "off, Play hides");
|
||
assert!(
|
||
texts(&rt).iter().any(|text| text == "Parakeet v3"),
|
||
"the model shows either way"
|
||
);
|
||
let _ = std::fs::remove_dir_all(&directory);
|
||
}
|
||
|
||
#[test]
|
||
fn copy_audio_shows_only_with_its_lab_and_keep_recordings() {
|
||
use crate::history::{
|
||
History, HistoryDraft, HistoryKind, HistoryRetention, HistoryStore, Recording,
|
||
};
|
||
let directory =
|
||
std::env::temp_dir().join(format!("hex-rune-copy-audio-{}", std::process::id()));
|
||
let _ = std::fs::remove_dir_all(&directory);
|
||
std::fs::create_dir_all(&directory).unwrap();
|
||
let history = History::new(HistoryStore::open(
|
||
directory.join("history.json"),
|
||
HistoryRetention::Week,
|
||
crate::history::now_ms(),
|
||
));
|
||
let id = history
|
||
.record(HistoryDraft {
|
||
kind: HistoryKind::Dictation,
|
||
raw_text: "ship it".into(),
|
||
final_text: "Ship it.".into(),
|
||
application: None,
|
||
processing: None,
|
||
audio_ms: 900,
|
||
inference_ms: 80,
|
||
total_ms: 200,
|
||
recording: Some(Recording::from_samples(vec![0.2; 1_600])),
|
||
model: Some("Parakeet v3".into()),
|
||
})
|
||
.unwrap()
|
||
.unwrap();
|
||
let mut rt = runtime("history-empty", true, GOLDEN_SIZE);
|
||
rt.state.history = history::HistoryPane::shared(Some(history.clone()));
|
||
rt.state
|
||
.history
|
||
.reload(rt.state.settings.labs.history_stats);
|
||
rt.state.history.selected = Some(id);
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
assert!(
|
||
rt.find("again-copy-audio").is_none(),
|
||
"off, History is unchanged"
|
||
);
|
||
|
||
rt.state.settings.labs.keep_recordings = true;
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
assert!(
|
||
rt.find("again-copy-audio").is_none(),
|
||
"Keep recordings alone does not add Copy audio"
|
||
);
|
||
|
||
rt.state.settings.labs.copy_dictation_audio = true;
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
assert!(
|
||
rt.find("again-copy-audio").is_some(),
|
||
"both switches on, the kept audio can be copied"
|
||
);
|
||
|
||
// A text Copy waits for a running Copy audio, which still lands the WAV
|
||
// on the clipboard; the pending state is kept.
|
||
let (sender, receiver) = std::sync::mpsc::channel();
|
||
rt.state.history.audio = Some(history::AudioCopy::pending(id, receiver));
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
tap(&mut rt, "history-copy");
|
||
assert_eq!(
|
||
rt.copy_request.as_deref(),
|
||
None,
|
||
"a pending Copy audio wins over a text Copy"
|
||
);
|
||
assert!(
|
||
rt.state.history.audio.is_some(),
|
||
"the pending Copy audio is kept"
|
||
);
|
||
drop(sender);
|
||
rt.state.history.audio = None;
|
||
|
||
rt.state.settings.labs.keep_recordings = false;
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
assert!(
|
||
rt.find("again-copy-audio").is_none(),
|
||
"turning Keep recordings off hides it again"
|
||
);
|
||
let _ = std::fs::remove_dir_all(&directory);
|
||
}
|
||
|
||
#[test]
|
||
fn leaving_an_entry_or_turning_off_keep_recordings_stops_playback() {
|
||
use crate::history::playback::Playback;
|
||
let mut rt = runtime("history", true, GOLDEN_SIZE);
|
||
rt.state.settings.labs.keep_recordings = true;
|
||
for entry in &mut rt.state.history.entries {
|
||
if entry.id == 2 {
|
||
entry.recording_bytes = 32_000;
|
||
}
|
||
}
|
||
let start = |rt: &mut Runtime<Ui>| {
|
||
rt.state.history.selected = Some(2);
|
||
rt.state.history.playback = Some(Playback::test_playing(2));
|
||
rt.invalidate();
|
||
settle(rt);
|
||
assert!(
|
||
rt.state
|
||
.history
|
||
.playback
|
||
.as_ref()
|
||
.is_some_and(Playback::playing),
|
||
"the playback starts"
|
||
);
|
||
assert_eq!(
|
||
element(rt, "again-play").label.as_deref(),
|
||
Some("Stop"),
|
||
"the card offers Stop while it plays"
|
||
);
|
||
};
|
||
let stopped = |rt: &Runtime<Ui>| {
|
||
assert!(
|
||
!rt.state
|
||
.history
|
||
.playback
|
||
.as_ref()
|
||
.is_some_and(Playback::playing),
|
||
"the playback stopped"
|
||
);
|
||
};
|
||
let play = |rt: &Runtime<Ui>| {
|
||
assert_eq!(
|
||
element(rt, "again-play").label.as_deref(),
|
||
Some("Play"),
|
||
"the card offers Play again"
|
||
);
|
||
};
|
||
|
||
// Leaving for another entry.
|
||
start(&mut rt);
|
||
rt.state.history.selected = Some(3);
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
stopped(&rt);
|
||
rt.state.history.selected = Some(2);
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
play(&rt);
|
||
|
||
// Leaving History.
|
||
start(&mut rt);
|
||
rt.state.pane = Pane::General;
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
stopped(&rt);
|
||
rt.state.pane = Pane::History;
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
play(&rt);
|
||
|
||
// Turning the lab off.
|
||
start(&mut rt);
|
||
rt.state.settings.labs.keep_recordings = false;
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
stopped(&rt);
|
||
assert!(rt.find("again-play").is_none(), "off, Play hides");
|
||
|
||
rt.state.settings.labs.keep_recordings = true;
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
play(&rt);
|
||
|
||
// Closing the window: a hidden window only polls when woken, so on_close
|
||
// stops the playback itself.
|
||
start(&mut rt);
|
||
on_close(&mut rt.state, &mut rune::Tx::default());
|
||
stopped(&rt);
|
||
}
|
||
|
||
#[test]
|
||
fn modes_add_select_and_delete() {
|
||
let mut rt = runtime("modes", true, PANE_SIZE);
|
||
tap(&mut rt, "add-mode");
|
||
assert_eq!(rt.state.settings.dictation_processing.modes.len(), 3);
|
||
assert_eq!(rt.state.modes.selected, modes::Selection::Custom(2));
|
||
assert_eq!(
|
||
rt.state.settings.dictation_processing.modes[2].name,
|
||
"Mode 3"
|
||
);
|
||
tap(&mut rt, "delete-mode");
|
||
assert!(rt.state.modes.delete_armed.is_some());
|
||
tap(&mut rt, "confirm-delete-mode");
|
||
assert_eq!(rt.state.settings.dictation_processing.modes.len(), 2);
|
||
assert_eq!(rt.state.modes.selected, modes::Selection::Default);
|
||
}
|
||
|
||
#[test]
|
||
fn mode_corrections_and_names_save_from_their_fields() {
|
||
let mut rt = runtime("modes", true, PANE_SIZE);
|
||
tap(&mut rt, "add-correction");
|
||
assert_eq!(
|
||
rt.state.settings.dictation_processing.modes[0]
|
||
.replacements
|
||
.len(),
|
||
3
|
||
);
|
||
rt.paste("dax");
|
||
settle(&mut rt);
|
||
flush(&mut rt);
|
||
assert_eq!(
|
||
rt.state.settings.dictation_processing.modes[0].replacements[2].matched_phrase,
|
||
"dax"
|
||
);
|
||
tap(&mut rt, "correction0/remove");
|
||
let phrases: Vec<String> = rt.state.settings.dictation_processing.modes[0]
|
||
.replacements
|
||
.iter()
|
||
.map(|r| r.matched_phrase.clone())
|
||
.collect();
|
||
assert_eq!(phrases, ["hex app", "dax"]);
|
||
}
|
||
|
||
#[test]
|
||
fn mode_transformations_add_reorder_and_remove() {
|
||
let mut rt = runtime("modes", true, GOLDEN_SIZE);
|
||
// The + opens a menu of only the transformations the mode lacks.
|
||
assert!(rt.find("transformation-option0").is_none());
|
||
tap(&mut rt, "add-transformation");
|
||
assert!(rt.find("transformation-option0").is_some());
|
||
assert!(rt.find("transformation-option1").is_none());
|
||
tap(&mut rt, "transformation-option0");
|
||
assert!(rt.find("transformation-option0").is_none());
|
||
let ids = |rt: &Runtime<Ui>| {
|
||
rt.state.settings.dictation_processing.modes[0]
|
||
.transformations
|
||
.clone()
|
||
};
|
||
assert_eq!(ids(&rt), ["smart-punctuation", "normalize-links"]);
|
||
let saves = saved(&rt);
|
||
// Drag the second row's handle up one row: the rows reorder while the
|
||
// pointer moves and the order is saved once, on release.
|
||
let (x, y) = rt.find("transformation1/handle").expect("a drag handle");
|
||
rt.pointer_move(x, y);
|
||
rt.pointer_down(x, y);
|
||
for step in 1..=8 {
|
||
rt.pointer_move(x, y - step as f32 * 5.0);
|
||
rt.frame(1.0 / 60.0);
|
||
}
|
||
assert_eq!(ids(&rt), ["smart-punctuation", "normalize-links"]);
|
||
let shown: Vec<String> = rt
|
||
.elements()
|
||
.into_iter()
|
||
.filter(|e| e.path.ends_with("/name") && e.path.contains("/transformation"))
|
||
.filter_map(|e| e.text)
|
||
.collect();
|
||
assert_eq!(shown, ["Normalize links", "Smart punctuation"]);
|
||
rt.pointer_up(x, y - 40.0);
|
||
rt.frame(1.0 / 60.0);
|
||
assert_eq!(ids(&rt), ["normalize-links", "smart-punctuation"]);
|
||
assert_eq!(saved(&rt), saves + 1);
|
||
tap(&mut rt, "transformation0/remove");
|
||
assert_eq!(ids(&rt), ["smart-punctuation"]);
|
||
}
|
||
|
||
#[test]
|
||
fn the_transformation_menu_offers_what_the_mode_lacks_and_escape_closes_it() {
|
||
let mut rt = runtime("modes-transformation-menu", true, GOLDEN_SIZE);
|
||
let offered: Vec<String> = rt
|
||
.elements()
|
||
.into_iter()
|
||
.filter(|e| e.path.contains("transformation-option") && e.path.ends_with("/name"))
|
||
.filter_map(|e| e.text)
|
||
.collect();
|
||
assert_eq!(offered, ["Normalize links"]);
|
||
key(&mut rt, Key::Escape, Mods::default());
|
||
settle(&mut rt);
|
||
assert!(rt.state.open.is_none());
|
||
assert!(rt.find("transformation-option0").is_none());
|
||
}
|
||
|
||
#[test]
|
||
fn escape_cancels_a_transformation_reorder_without_saving() {
|
||
let mut rt = runtime("modes", true, GOLDEN_SIZE);
|
||
tap(&mut rt, "add-transformation");
|
||
tap(&mut rt, "transformation-option0");
|
||
let order = |rt: &Runtime<Ui>| {
|
||
rt.state.settings.dictation_processing.modes[0]
|
||
.transformations
|
||
.clone()
|
||
};
|
||
let before = order(&rt);
|
||
let saves = saved(&rt);
|
||
let (x, y) = rt.find("transformation1/handle").expect("a drag handle");
|
||
rt.pointer_move(x, y);
|
||
rt.pointer_down(x, y);
|
||
for step in 1..=8 {
|
||
rt.pointer_move(x, y - step as f32 * 5.0);
|
||
rt.frame(1.0 / 60.0);
|
||
}
|
||
key(&mut rt, Key::Escape, Mods::default());
|
||
rt.pointer_up(x, y - 40.0);
|
||
rt.frame(1.0 / 60.0);
|
||
assert_eq!(order(&rt), before);
|
||
assert_eq!(saved(&rt), saves);
|
||
}
|
||
|
||
#[test]
|
||
fn escape_restores_a_slider_dragged_from_its_press() {
|
||
let mut rt = runtime("mac-voice-filter", true, (980.0, 1300.0));
|
||
open_advanced(&mut rt, Pane::VoiceFilter);
|
||
let strength = |rt: &Runtime<Ui>| rt.state.platform.tuning.strength;
|
||
let before = strength(&rt);
|
||
let saves = saved(&rt);
|
||
let (x, y) = rt.find("fun-slider-strength/track").expect("a slider");
|
||
rt.pointer_move(x, y);
|
||
rt.pointer_down(x, y);
|
||
rt.pointer_move(x + 60.0, y);
|
||
rt.frame(1.0 / 60.0);
|
||
assert_ne!(strength(&rt), before);
|
||
key(&mut rt, Key::Escape, Mods::default());
|
||
rt.frame(1.0 / 60.0);
|
||
assert_eq!(strength(&rt), before);
|
||
rt.pointer_up(x + 60.0, y);
|
||
rt.frame(1.0 / 60.0);
|
||
assert_eq!(strength(&rt), before);
|
||
assert_eq!(saved(&rt), saves);
|
||
}
|
||
|
||
#[test]
|
||
fn a_chosen_file_joins_the_catalog_and_the_mode() {
|
||
let mut rt = runtime("modes-picker", true, GOLDEN_SIZE);
|
||
let application = crate::application_catalog::InstalledApplication {
|
||
name: "helix".into(),
|
||
bundle_id: None,
|
||
path: "/usr/bin/helix".into(),
|
||
};
|
||
modes::chosen_application(&mut rt.state, Ok(Some(application)));
|
||
assert!(
|
||
rt.state.settings.dictation_processing.modes[0]
|
||
.applications
|
||
.contains(&"helix".to_string())
|
||
);
|
||
modes::chosen_application(&mut rt.state, Ok(None));
|
||
assert!(rt.state.modes.application_error.is_none());
|
||
modes::chosen_application(&mut rt.state, Err("no file chooser portal".into()));
|
||
assert_eq!(
|
||
rt.state.modes.application_error.as_deref(),
|
||
Some("no file chooser portal")
|
||
);
|
||
}
|
||
|
||
#[test]
|
||
fn mode_applications_refuse_one_another_modes_use() {
|
||
// In Chat, WezTerm is offered but belongs to Terminal.
|
||
let mut rt = runtime("modes-picker", true, GOLDEN_SIZE);
|
||
let chat = |rt: &Runtime<Ui>| {
|
||
rt.state.settings.dictation_processing.modes[0]
|
||
.applications
|
||
.clone()
|
||
};
|
||
tap(&mut rt, "available1");
|
||
assert!(rt.state.modes.application_error.is_some());
|
||
assert!(!chat(&rt).contains(&"WezTerm".to_string()));
|
||
tap(&mut rt, "available2");
|
||
assert!(chat(&rt).contains(&"Zed".to_string()));
|
||
}
|
||
|
||
#[test]
|
||
fn the_transcription_picker_asks_the_service_for_a_model() {
|
||
let mut rt = runtime("picker", true, PANE_SIZE);
|
||
tap(&mut rt, "model2/action/cell/slot/choose-model");
|
||
assert!(matches!(
|
||
sent(&rt),
|
||
[Request::ChooseModel {
|
||
model: TranscriptionModelId::WhisperLargeV3Turbo,
|
||
..
|
||
}]
|
||
));
|
||
assert_eq!(
|
||
rt.state.picker.fallback, None,
|
||
"Whisper keeps the saved English"
|
||
);
|
||
tap(&mut rt, "close-picker");
|
||
assert!(!rt.state.is_modal(Modal::Picker));
|
||
}
|
||
|
||
#[test]
|
||
fn choosing_the_selected_installed_but_unchecked_model_checks_it() {
|
||
use crate::transcription::models::{self, ModelRuntime};
|
||
|
||
let directory =
|
||
std::env::temp_dir().join(format!("hex-picker-unchecked-{}", std::process::id()));
|
||
let _ = std::fs::remove_dir_all(&directory);
|
||
std::fs::create_dir_all(&directory).unwrap();
|
||
models::set_test_models_dir(Some(directory.clone()));
|
||
let model = models::definition(TranscriptionModelId::ParakeetUnifiedEnglish);
|
||
let ModelRuntime::Gguf(artifact) = &model.runtime else {
|
||
unreachable!("Parakeet Unified English is a GGUF model")
|
||
};
|
||
std::fs::File::create(directory.join(artifact.local_name()))
|
||
.unwrap()
|
||
.set_len(artifact.bytes)
|
||
.unwrap();
|
||
|
||
let mut rt = runtime("picker", true, PANE_SIZE);
|
||
rt.state.settings.transcription = TranscriptionSelection {
|
||
model: model.id,
|
||
language: "en".into(),
|
||
};
|
||
// Readiness here comes from the filesystem: the file is installed but
|
||
// has no verification receipt yet.
|
||
rt.state.picker.installed = None;
|
||
picker::choose(&mut rt.state, &model);
|
||
assert_eq!(
|
||
sent(&rt),
|
||
[Request::ChooseModel {
|
||
model: model.id,
|
||
language: "en".into(),
|
||
}]
|
||
);
|
||
|
||
models::set_test_models_dir(None);
|
||
std::fs::remove_dir_all(directory).unwrap();
|
||
}
|
||
|
||
/// Scrolls the full model list until `key` is inside it, then presses it.
|
||
fn tap_in_model_list(rt: &mut Runtime<Ui>, key: &str) {
|
||
for _ in 0..400 {
|
||
let target = element(rt, key).rect;
|
||
let list = element(rt, "model-scroll").rect;
|
||
let middle = target[1] + target[3] / 2.0;
|
||
if middle > list[1] && middle < list[1] + list[3] {
|
||
break;
|
||
}
|
||
let dy = if middle > list[1] + list[3] {
|
||
20.0
|
||
} else {
|
||
-20.0
|
||
};
|
||
rt.wheel(list[0] + list[2] / 2.0, list[1] + list[3] / 2.0, dy);
|
||
rt.frame(1.0 / 60.0);
|
||
}
|
||
tap(rt, key);
|
||
}
|
||
|
||
#[test]
|
||
fn a_model_without_the_saved_language_falls_back_to_its_own_visibly() {
|
||
let mut rt = runtime("picker", true, PANE_SIZE);
|
||
rt.state.settings.transcription = TranscriptionSelection {
|
||
model: TranscriptionModelId::WhisperLargeV3Turbo,
|
||
language: "he".into(),
|
||
};
|
||
rt.state.picker.installed = Some(Vec::new());
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
// Parakeet is folded away with the models that don't speak Hebrew.
|
||
tap(&mut rt, "more-models");
|
||
tap(&mut rt, "other-languages");
|
||
let shown = texts(&rt);
|
||
assert!(
|
||
shown.contains(&"Choosing it switches the language to English".to_owned()),
|
||
"{shown:?}"
|
||
);
|
||
tap_in_model_list(&mut rt, "model-parakeet_unified_en/actions/choose-model");
|
||
assert_eq!(
|
||
sent(&rt),
|
||
[Request::ChooseModel {
|
||
model: TranscriptionModelId::ParakeetUnifiedEnglish,
|
||
language: "en".into(),
|
||
}]
|
||
);
|
||
// The service saves the pair; Settings names the change and fixes the
|
||
// language, since the model has only English.
|
||
rt.state.settings.transcription = TranscriptionSelection {
|
||
model: TranscriptionModelId::ParakeetUnifiedEnglish,
|
||
language: "en".into(),
|
||
};
|
||
rt.invalidate();
|
||
tap(&mut rt, "close-picker");
|
||
let shown = texts(&rt);
|
||
assert!(
|
||
shown.contains(
|
||
&"Parakeet Unified English doesn't support Hebrew, so the language changed to English"
|
||
.to_owned()
|
||
),
|
||
"{shown:?}"
|
||
);
|
||
assert!(rt.find("transcription-language-control-item0").is_none());
|
||
tap(&mut rt, "transcription-language-control");
|
||
assert_eq!(rt.state.open, None, "a single language opens no menu");
|
||
}
|
||
|
||
#[test]
|
||
fn single_language_models_hide_the_language_row_without_a_fallback() {
|
||
let single = runtime("mac-settings", true, PANE_SIZE);
|
||
assert!(single.find("transcription-language").is_none());
|
||
let multi = runtime("language-menu", true, PANE_SIZE);
|
||
assert!(multi.find("transcription-language").is_some());
|
||
let fallback = runtime("language-fallback", true, PANE_SIZE);
|
||
assert!(fallback.find("transcription-language").is_some());
|
||
}
|
||
|
||
#[test]
|
||
fn browsing_the_picker_never_changes_the_language() {
|
||
let mut rt = runtime("picker", true, PANE_SIZE);
|
||
let before = rt.state.settings.transcription.clone();
|
||
for _ in 0..12 {
|
||
key(&mut rt, Key::Tab, Mods::default());
|
||
}
|
||
rt.pointer_move(400.0, 300.0);
|
||
settle(&mut rt);
|
||
assert_eq!(rt.state.settings.transcription, before);
|
||
assert!(sent(&rt).is_empty());
|
||
}
|
||
|
||
#[test]
|
||
fn changing_only_the_language_prepares_the_same_model_again() {
|
||
let mut rt = runtime("portal", true, GOLDEN_SIZE);
|
||
rt.state.settings.transcription.model = TranscriptionModelId::WhisperLargeV3Turbo;
|
||
rt.state.picker.fallback = Some(picker::LanguageFallback {
|
||
model: TranscriptionModelId::WhisperLargeV3Turbo,
|
||
from: "xx".into(),
|
||
});
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
tap(&mut rt, "transcription-language-control-trigger");
|
||
assert_eq!(rt.state.open, Some(Menu::Pick("transcription-language")));
|
||
// Whisper lists every language by name, Auto first.
|
||
let japanese = crate::transcription::models::menu_order(
|
||
&crate::transcription::models::definition(TranscriptionModelId::WhisperLargeV3Turbo)
|
||
.language_choices(),
|
||
)
|
||
.iter()
|
||
.position(|code| *code == "ja")
|
||
.unwrap();
|
||
tap_option(&mut rt, japanese);
|
||
assert_eq!(rt.state.open, None);
|
||
assert_eq!(
|
||
sent(&rt),
|
||
[Request::ChooseModel {
|
||
model: TranscriptionModelId::WhisperLargeV3Turbo,
|
||
language: "ja".into(),
|
||
}]
|
||
);
|
||
assert_eq!(
|
||
rt.state.picker.fallback, None,
|
||
"an explicit choice clears the note"
|
||
);
|
||
}
|
||
|
||
/// Whisper's language list is longer than its menu shows, so the check on
|
||
/// the saved language would sit below the edge. The press that opens the
|
||
/// menu reveals it.
|
||
#[test]
|
||
fn the_language_menu_opens_on_its_chosen_language() {
|
||
let mut rt = runtime("portal", true, GOLDEN_SIZE);
|
||
rt.state.settings.transcription.model = TranscriptionModelId::WhisperLargeV3Turbo;
|
||
rt.state.settings.transcription.language = "fr".into();
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
tap(&mut rt, "transcription-language-control-trigger");
|
||
assert_eq!(rt.state.open, Some(Menu::Pick("transcription-language")));
|
||
let french = crate::transcription::models::menu_order(
|
||
&crate::transcription::models::definition(TranscriptionModelId::WhisperLargeV3Turbo)
|
||
.language_choices(),
|
||
)
|
||
.iter()
|
||
.position(|code| *code == "fr")
|
||
.unwrap();
|
||
let row = element(&rt, &format!("option{french}")).rect;
|
||
let list = element(&rt, "listbox").rect;
|
||
assert!(
|
||
row[1] >= list[1] - 0.5 && row[1] + row[3] <= list[1] + list[3] + 0.5,
|
||
"row {row:?} outside list {list:?}"
|
||
);
|
||
let auto = element(&rt, "option0").rect;
|
||
assert!(
|
||
auto[1] < list[1],
|
||
"Auto {auto:?} still at the top of {list:?}: the menu never moved"
|
||
);
|
||
}
|
||
|
||
/// Labs › Vocabulary files adds Import and Export to the sheet, and only
|
||
/// then: off, the sheet is exactly as before.
|
||
#[test]
|
||
fn the_vocabulary_sheet_offers_files_only_with_its_lab_on() {
|
||
let mut rt = runtime("mac-settings-vocabulary", true, GOLDEN_SIZE);
|
||
settle(&mut rt);
|
||
assert!(rt.find("add-term").is_some());
|
||
assert!(rt.find("import-vocabulary").is_none());
|
||
assert!(rt.find("export-vocabulary").is_none());
|
||
rt.state.settings.labs.vocabulary_files = true;
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
assert!(rt.find("import-vocabulary").is_some());
|
||
assert!(rt.find("export-vocabulary").is_some());
|
||
assert!(rt.find("add-term").is_some());
|
||
assert!(rt.find("close-vocabulary").is_some());
|
||
}
|
||
|
||
/// General's Vocabulary row opens the sheet, and Escape closes it.
|
||
#[test]
|
||
fn the_vocabulary_row_opens_its_sheet() {
|
||
let mut rt = runtime("portal", true, GOLDEN_SIZE);
|
||
tap(&mut rt, "vocabulary-control");
|
||
settle(&mut rt);
|
||
assert!(rt.state.is_modal(Modal::Vocabulary));
|
||
assert!(rt.find("add-term").is_some());
|
||
assert!(rt.find("vocabulary-boost").is_none());
|
||
key(&mut rt, Key::Escape, Mods::default());
|
||
settle(&mut rt);
|
||
assert!(!rt.state.is_modal(Modal::Vocabulary));
|
||
}
|
||
|
||
/// A settle frame plus an outside press closes the sheet with its exit: the runtime lands the
|
||
/// tree the press found, so both layers fade instead of vanishing.
|
||
#[test]
|
||
fn an_outside_press_on_a_settle_frame_still_exits_the_vocabulary_sheet() {
|
||
let mut rt = runtime("mac-settings-vocabulary", true, GOLDEN_SIZE);
|
||
let bounds = element(&rt, "vocabulary-layer").rect;
|
||
let (x, y) = (bounds[0] + 8.0, bounds[1] + bounds[3] / 2.0);
|
||
rt.settle_all();
|
||
rt.pointer_down(x, y);
|
||
rt.pointer_up(x, y);
|
||
rt.frame(1.0 / 60.0);
|
||
for key in ["vocabulary-scrim", "vocabulary-layer"] {
|
||
let layer = rt
|
||
.elements()
|
||
.into_iter()
|
||
.find(|e| e.key.as_deref() == Some(key))
|
||
.unwrap_or_else(|| panic!("{key} vanished in the settle frame"));
|
||
assert!(layer.exiting, "{key} is not exiting");
|
||
assert!(
|
||
layer.opacity > 0.0 && layer.opacity < 1.0,
|
||
"{key} opacity {}",
|
||
layer.opacity
|
||
);
|
||
}
|
||
settle(&mut rt);
|
||
assert!(rt.find("vocabulary-scrim").is_none());
|
||
assert!(rt.find("vocabulary-layer").is_none());
|
||
}
|
||
|
||
/// Add term on a list longer than the sheet scrolls the new row into view.
|
||
#[test]
|
||
fn add_term_scrolls_the_new_row_into_view() {
|
||
let mut rt = runtime("mac-settings-vocabulary", true, GOLDEN_SIZE);
|
||
rt.state.settings.vocabulary = (0..14)
|
||
.map(|index| crate::dictation::vocabulary::VocabularyEntry {
|
||
term: format!("term {index}"),
|
||
sounds_like: Vec::new(),
|
||
})
|
||
.collect();
|
||
rt.state.vocabulary = super::vocabulary::VocabularyEditor::new(&rt.state.settings.vocabulary);
|
||
rt.state.modal = Some(Modal::Vocabulary);
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
tap(&mut rt, "add-term");
|
||
settle(&mut rt);
|
||
let id = rt.state.vocabulary.last_row().unwrap();
|
||
let new_row = element(&rt, &format!("term{id}")).rect;
|
||
let list = element(&rt, "term-scroll").rect;
|
||
assert!(
|
||
new_row[1] >= list[1] && new_row[1] + new_row[3] <= list[1] + list[3] + 0.5,
|
||
"row {new_row:?} outside list {list:?}"
|
||
);
|
||
}
|
||
|
||
/// The wheel scrolls a term list longer than the sheet, wherever the
|
||
/// pointer is over it: on a row's field or between rows (#906).
|
||
#[test]
|
||
fn the_wheel_scrolls_a_long_term_list() {
|
||
let mut rt = runtime("portal", true, (900.0, 480.0));
|
||
rt.state.settings.vocabulary = (0..75)
|
||
.map(|index| crate::dictation::vocabulary::VocabularyEntry {
|
||
term: format!("term {index}"),
|
||
sounds_like: vec![format!("sound {index}")],
|
||
})
|
||
.collect();
|
||
rt.state.vocabulary = super::vocabulary::VocabularyEditor::new(&rt.state.settings.vocabulary);
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
tap(&mut rt, "vocabulary-control");
|
||
settle(&mut rt);
|
||
let first = |rt: &Runtime<Ui>| element(rt, "term0").rect[1];
|
||
let list = element(&rt, "term-scroll").rect;
|
||
// Beside the fields, on a term field, and on a "sounds like" field; a
|
||
// mouse wheel's line steps, then a touchpad's precise gesture.
|
||
for (x, precise) in [
|
||
(list[0] + 1.0, false),
|
||
(list[0] + 40.0, true),
|
||
(list[0] + list[2] - 8.0, false),
|
||
] {
|
||
let before = first(&rt);
|
||
wheel_down(&mut rt, x, list[1] + list[3] / 2.0, precise);
|
||
assert!(
|
||
first(&rt) < before - 100.0,
|
||
"the list didn't scroll at x {x}"
|
||
);
|
||
}
|
||
}
|
||
|
||
/// The model picker's full list scrolls with the wheel too. The picker opens
|
||
/// on the comparison, which fits without scrolling, so this opens every model.
|
||
#[test]
|
||
fn the_wheel_scrolls_the_model_picker() {
|
||
let mut rt = runtime("picker-custom-models", true, (900.0, 480.0));
|
||
let list = element(&rt, "model-scroll").rect;
|
||
let first = |rt: &Runtime<Ui>| {
|
||
rt.elements()
|
||
.into_iter()
|
||
.find(|e| e.path.contains("model-scroll/inset/"))
|
||
.map(|e| e.rect[1])
|
||
.unwrap()
|
||
};
|
||
let before = first(&rt);
|
||
wheel_down(
|
||
&mut rt,
|
||
list[0] + list[2] / 2.0,
|
||
list[1] + list[3] / 2.0,
|
||
true,
|
||
);
|
||
assert!(first(&rt) < before - 50.0, "the picker didn't scroll");
|
||
}
|
||
|
||
/// Ten wheel steps down at (x, y), as the window's platform sends them: the
|
||
/// pointer moves there first, and a gesture begins, moves, and ends.
|
||
fn wheel_down(rt: &mut Runtime<Ui>, x: f32, y: f32, precise: bool) {
|
||
rt.pointer_move(x, y);
|
||
rt.frame(1.0 / 60.0);
|
||
for step in 0..10 {
|
||
let phase = match step {
|
||
0 => rune::GesturePhase::Began,
|
||
9 => rune::GesturePhase::Ended,
|
||
_ => rune::GesturePhase::Moved,
|
||
};
|
||
rt.wheel_event(
|
||
rune::WheelEvent::new(0.0, -30.0)
|
||
.at(x, y)
|
||
.phase(phase)
|
||
.precise(precise),
|
||
);
|
||
rt.frame(1.0 / 60.0);
|
||
}
|
||
settle(rt);
|
||
}
|
||
|
||
/// A model whose transcription takes no vocabulary says so on the Vocabulary
|
||
/// row and in its sheet; Parakeet-based and prompt-reading models show none.
|
||
#[test]
|
||
fn the_vocabulary_row_says_when_the_model_ignores_the_list() {
|
||
let note = "Cohere Transcribe doesn't use these terms; rewriting and search still do";
|
||
let shows_note = |rt: &Runtime<Ui>| texts(rt).iter().any(|text| text == note);
|
||
let sheet_note = |rt: &Runtime<Ui>| {
|
||
rt.elements()
|
||
.into_iter()
|
||
.any(|e| !e.exiting && e.key.as_deref() == Some("unused"))
|
||
};
|
||
let mut rt = runtime("portal", true, GOLDEN_SIZE);
|
||
assert!(!shows_note(&rt));
|
||
rt.state.settings.transcription.model = TranscriptionModelId::CohereTranscribe;
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
assert!(shows_note(&rt), "{:?}", texts(&rt));
|
||
tap(&mut rt, "vocabulary-control");
|
||
assert!(rt.state.is_modal(Modal::Vocabulary));
|
||
assert!(sheet_note(&rt));
|
||
key(&mut rt, Key::Escape, Mods::default());
|
||
settle(&mut rt);
|
||
for model in [
|
||
TranscriptionModelId::UnderdogBark3Pro,
|
||
TranscriptionModelId::WhisperLargeV3Turbo,
|
||
TranscriptionModelId::QwenCleoAsr17B,
|
||
] {
|
||
rt.state.settings.transcription.model = model;
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
assert!(
|
||
!texts(&rt)
|
||
.iter()
|
||
.any(|text| text.contains("doesn't use these terms"))
|
||
);
|
||
}
|
||
|
||
let rt = runtime("vocabulary-unused", true, PANE_SIZE);
|
||
assert!(rt.state.is_modal(Modal::Vocabulary));
|
||
assert!(sheet_note(&rt));
|
||
}
|
||
|
||
/// The Sounds row opens the sheet. A set's play button plays its dictation
|
||
/// without choosing it, and pressing it again stops it; picking a set saves
|
||
/// it and plays it; Escape closes the sheet.
|
||
#[test]
|
||
fn the_sound_sets_sheet_plays_and_chooses_sets() {
|
||
use crate::feedback::SoundSet;
|
||
let mut rt = runtime("portal", true, GOLDEN_SIZE);
|
||
rt.state.settings.sound_effects = false;
|
||
rt.state.settings.sound_effect_volume = 0.23;
|
||
assert_eq!(rt.state.settings.sound_theme, SoundSet::Classic);
|
||
open_advanced(&mut rt, Pane::General);
|
||
assert!(texts(&rt).iter().any(|text| text == "Off"));
|
||
tap(&mut rt, "sound-set-control");
|
||
assert!(rt.state.is_modal(Modal::SoundSets));
|
||
let playing = |rt: &Runtime<Ui>| rt.state.sound_sets.playing();
|
||
|
||
tap(&mut rt, "set-click/lines/top/play");
|
||
assert_eq!(playing(&rt), Some(SoundSet::Click));
|
||
assert_eq!(rt.state.settings.sound_theme, SoundSet::Classic);
|
||
tap(&mut rt, "set-click/lines/top/play");
|
||
assert_eq!(playing(&rt), None);
|
||
|
||
tap(&mut rt, "set-wood");
|
||
assert_eq!(rt.state.settings.sound_theme, SoundSet::Wood);
|
||
assert_eq!(playing(&rt), Some(SoundSet::Wood));
|
||
assert!(rt.find("set-wood/check/mark").is_some());
|
||
assert!(rt.find("set-classic/check/mark").is_none());
|
||
|
||
key(&mut rt, Key::Escape, Mods::default());
|
||
settle(&mut rt);
|
||
assert!(!rt.state.is_modal(Modal::SoundSets));
|
||
assert_eq!(playing(&rt), None);
|
||
assert!(!rt.state.settings.sound_effects);
|
||
assert_eq!(rt.state.settings.sound_effect_volume, 0.23);
|
||
}
|
||
|
||
#[test]
|
||
fn a_download_in_progress_can_be_cancelled() {
|
||
let mut rt = runtime("picker-downloading", true, PANE_SIZE);
|
||
tap(&mut rt, "model1/action/cell/slot/preparing/cancel-model");
|
||
assert!(matches!(sent(&rt), [Request::CancelModel]));
|
||
}
|
||
|
||
fn focused(rt: &Runtime<Ui>) -> String {
|
||
rt.elements()
|
||
.into_iter()
|
||
.find(|e| e.focused)
|
||
.map(|e| e.path)
|
||
.unwrap_or_default()
|
||
}
|
||
|
||
fn tab_to(rt: &mut Runtime<Ui>, target: &str) {
|
||
let mut seen = Vec::new();
|
||
for _ in 0..60 {
|
||
if focused(rt).ends_with(target) {
|
||
return;
|
||
}
|
||
seen.push(focused(rt));
|
||
key(rt, Key::Tab, Mods::default());
|
||
}
|
||
panic!("Tab never reached {target}: {seen:?}");
|
||
}
|
||
|
||
#[test]
|
||
fn the_sidebar_moves_with_arrows_and_command_numbers() {
|
||
let mut rt = runtime("portal", true, PANE_SIZE);
|
||
key(&mut rt, Key::Tab, Mods::default());
|
||
assert!(
|
||
focused(&rt).ends_with("nav-general"),
|
||
"Tab enters at the current pane"
|
||
);
|
||
key(&mut rt, Key::Down, Mods::default());
|
||
assert_eq!(rt.state.pane, Pane::Output, "selection follows the arrows");
|
||
let command = Mods {
|
||
cmd: true,
|
||
..Mods::default()
|
||
};
|
||
let shown = labs::order(&rt.state);
|
||
key(&mut rt, Key::Command('3'), command);
|
||
assert_eq!(rt.state.pane, shown[2]);
|
||
assert!(
|
||
focused(&rt).ends_with(shown[2].key()),
|
||
"focus follows the shortcut"
|
||
);
|
||
key(&mut rt, Key::Command('1'), command);
|
||
assert_eq!(rt.state.pane, Pane::General);
|
||
key(&mut rt, Key::Command('9'), command);
|
||
assert_eq!(rt.state.pane, Pane::General, "no ninth pane");
|
||
key(&mut rt, Key::Up, Mods::default());
|
||
assert_eq!(rt.state.pane, Pane::General, "Up stops at the first pane");
|
||
let main = labs::main_panes(&rt.state);
|
||
let last = *main.last().unwrap();
|
||
key(
|
||
&mut rt,
|
||
Key::Command(char::from(b'0' + main.len() as u8)),
|
||
command,
|
||
);
|
||
key(&mut rt, Key::Down, Mods::default());
|
||
assert!(rt.state.labs_open, "Down from the last pane opens Labs");
|
||
assert!(
|
||
focused(&rt).ends_with("nav-labs"),
|
||
"focus follows to the Labs item: {}",
|
||
focused(&rt)
|
||
);
|
||
key(&mut rt, Key::Down, Mods::default());
|
||
assert_eq!(rt.state.pane, Pane::WhatsNew);
|
||
assert!(!rt.state.labs_open);
|
||
assert!(focused(&rt).ends_with("nav-whats-new"));
|
||
key(&mut rt, Key::Down, Mods::default());
|
||
assert_eq!(rt.state.pane, Pane::WhatsNew, "Down stops before Quit");
|
||
key(&mut rt, Key::Up, Mods::default());
|
||
assert!(rt.state.labs_open, "Up from What's new returns to Labs");
|
||
key(&mut rt, Key::Up, Mods::default());
|
||
assert_eq!(rt.state.pane, last, "Up returns to the last pane");
|
||
assert!(!rt.state.labs_open);
|
||
}
|
||
|
||
#[test]
|
||
fn toggle_rows_take_focus_and_flip_on_space() {
|
||
let mut rt = runtime("portal", true, GOLDEN_SIZE);
|
||
assert!(rt.state.settings.paste_with_shift);
|
||
open_advanced(&mut rt, Pane::General);
|
||
tab_to(&mut rt, "terminal-paste");
|
||
key(&mut rt, Key::Text(" ".into()), Mods::default());
|
||
assert!(!rt.state.settings.paste_with_shift);
|
||
}
|
||
|
||
#[test]
|
||
fn the_picker_keeps_focus_inside_and_escape_returns_it() {
|
||
let mut rt = runtime("portal", true, GOLDEN_SIZE);
|
||
tab_to(&mut rt, "transcription-control");
|
||
key(&mut rt, Key::Text(" ".into()), Mods::default());
|
||
settle(&mut rt);
|
||
assert!(rt.state.is_modal(Modal::Picker));
|
||
for _ in 0..12 {
|
||
key(&mut rt, Key::Tab, Mods::default());
|
||
assert!(
|
||
focused(&rt).contains("transcription-picker"),
|
||
"focus left the picker: {}",
|
||
focused(&rt)
|
||
);
|
||
}
|
||
key(&mut rt, Key::Escape, Mods::default());
|
||
settle(&mut rt);
|
||
assert!(!rt.state.is_modal(Modal::Picker));
|
||
assert!(focused(&rt).ends_with("transcription-control"));
|
||
}
|
||
|
||
#[test]
|
||
fn history_rows_select_with_arrows() {
|
||
let mut rt = runtime("history", true, PANE_SIZE);
|
||
tap(&mut rt, "history-entry3");
|
||
key(&mut rt, Key::Down, Mods::default());
|
||
assert_ne!(rt.state.history.selected, Some(3));
|
||
key(&mut rt, Key::Up, Mods::default());
|
||
assert_eq!(rt.state.history.selected, Some(3));
|
||
}
|
||
|
||
#[test]
|
||
fn settings_opens_the_picker_and_names_the_model_and_language_apart() {
|
||
let mut rt = runtime("portal", true, GOLDEN_SIZE);
|
||
let shown = texts(&rt);
|
||
assert!(
|
||
shown.contains(&"Parakeet Unified English".to_owned()),
|
||
"{shown:?}"
|
||
);
|
||
assert!(
|
||
!shown.iter().any(|text| text.contains(" · Parakeet")),
|
||
"{shown:?}"
|
||
);
|
||
tap(&mut rt, "transcription-control");
|
||
assert!(rt.state.is_modal(Modal::Picker));
|
||
}
|
||
|
||
#[test]
|
||
fn a_new_install_opens_the_first_run() {
|
||
use crate::desktop::onboarding::{PermissionState, SetupStatus};
|
||
let fresh = SetupStatus {
|
||
microphone: PermissionState::Ready,
|
||
accessibility: PermissionState::Ready,
|
||
transcription_model: false,
|
||
};
|
||
let mut ui = portal_fixture();
|
||
ui.platform.permissions = fresh;
|
||
ui.picker.installed = Some(Vec::new());
|
||
ui.tour = Some(onboarding::Tour::replay(&ui.settings, &ui.platform));
|
||
onboarding_kit::live::open(&mut ui);
|
||
assert!(ui.first_run.is_some(), "the story opens over the tour");
|
||
}
|
||
|
||
#[test]
|
||
fn onboarding_downloads_the_model_through_the_service() {
|
||
let mut rt = runtime("onboarding", true, PANE_SIZE);
|
||
// The download starts as soon as onboarding opens.
|
||
assert!(matches!(
|
||
sent(&rt),
|
||
[Request::ChooseModel {
|
||
model: TranscriptionModelId::ParakeetUnifiedEnglish,
|
||
..
|
||
}]
|
||
));
|
||
assert!(texts(&rt).contains(&"Setting up Hex".to_owned()));
|
||
// The service finishes: the model is installed and the practice opens.
|
||
rt.state.picker.installed = Some(vec![TranscriptionModelId::ParakeetUnifiedEnglish]);
|
||
settle(&mut rt);
|
||
rt.update(|ui, _| onboarding_kit::live::fixture_resume(ui, Page::Try));
|
||
settle(&mut rt);
|
||
let step = |rt: &Runtime<Ui>| rt.state.tour.as_ref().unwrap().flow.step();
|
||
assert_eq!(step(&rt), crate::desktop::onboarding::Step::TryIt);
|
||
// The practice can be left with Done; Start using Hex closes onboarding.
|
||
tap(&mut rt, "done");
|
||
tap(&mut rt, "start-using-hex");
|
||
assert!(rt.state.tour.is_none(), "Start using Hex closes setup");
|
||
assert!(rt.state.first_run.is_none());
|
||
}
|
||
|
||
#[test]
|
||
fn a_found_model_moves_on_without_a_download_and_back_returns_to_it() {
|
||
let mut rt = runtime("onboarding-model-found", false, PANE_SIZE);
|
||
assert!(rt.find("model-list").is_some());
|
||
tap(&mut rt, "model1");
|
||
// The service saves the pick and has the found file ready: the list
|
||
// stays, with no "Setting up Hex" download page.
|
||
rt.state.settings.transcription = TranscriptionSelection {
|
||
model: TranscriptionModelId::ParakeetV3,
|
||
language: "en".into(),
|
||
};
|
||
rt.state.picker.installed = Some(vec![TranscriptionModelId::ParakeetV3]);
|
||
settle(&mut rt);
|
||
let shown = texts(&rt);
|
||
assert!(
|
||
shown.contains(&"Choose a speech model".to_owned()),
|
||
"{shown:?}"
|
||
);
|
||
assert!(!shown.contains(&"Setting up Hex".to_owned()), "{shown:?}");
|
||
assert!(
|
||
shown.contains(&"Parakeet Unified English".to_owned()),
|
||
"the rows stay"
|
||
);
|
||
tap(&mut rt, "continue");
|
||
rt.update(|ui, _| onboarding_kit::live::fixture_resume(ui, Page::Demo));
|
||
settle(&mut rt);
|
||
let s = rt.state.first_run.as_ref().unwrap();
|
||
assert!(s.had_model, "a model here needs no download pill");
|
||
assert!(!texts(&rt).contains(&"Setting up Hex".to_owned()));
|
||
// Back returns to the list to change the pick.
|
||
tap(&mut rt, "back");
|
||
assert!(rt.find("model-list").is_some());
|
||
}
|
||
|
||
#[test]
|
||
fn a_failed_download_names_its_cause_and_offers_a_model_file() {
|
||
let mut rt = runtime("onboarding", false, PANE_SIZE);
|
||
if let Some(view) = &mut rt.state.view {
|
||
view.transcription.preparing = None;
|
||
view.transcription.error = Some(
|
||
"Couldn't reach huggingface.co through the proxy proxy.corp:8080: the proxy refused (403)\n\nCheck your connection, then retry, or choose a model file."
|
||
.into(),
|
||
);
|
||
}
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
let shown = texts(&rt);
|
||
assert!(
|
||
shown.contains(
|
||
&"Couldn't reach huggingface.co through the proxy proxy.corp:8080: the proxy refused (403)"
|
||
.to_owned()
|
||
),
|
||
"{shown:?}"
|
||
);
|
||
assert!(shown.contains(&"Use a model file…".to_owned()), "{shown:?}");
|
||
assert!(shown.contains(&"Try again".to_owned()), "{shown:?}");
|
||
}
|
||
|
||
#[test]
|
||
fn with_no_model_found_onboarding_downloads_the_recommended_model_with_no_list() {
|
||
for scene in ["onboarding", "mac-onboarding"] {
|
||
let rt = runtime(scene, false, PANE_SIZE);
|
||
assert!(rt.state.found.models.is_empty());
|
||
// The download starts on its own, before any step or pick.
|
||
assert!(
|
||
matches!(
|
||
sent(&rt),
|
||
[Request::ChooseModel {
|
||
model: TranscriptionModelId::ParakeetUnifiedEnglish,
|
||
..
|
||
}]
|
||
),
|
||
"{scene}: {:?}",
|
||
sent(&rt)
|
||
);
|
||
let shown = texts(&rt);
|
||
assert!(rt.find("model-list").is_none(), "{scene}: no model list");
|
||
assert!(
|
||
shown.contains(&"Setting up Hex".to_owned()),
|
||
"{scene}: {shown:?}"
|
||
);
|
||
assert!(
|
||
!shown.contains(&"Choose a speech model".to_owned()),
|
||
"{scene}: {shown:?}"
|
||
);
|
||
}
|
||
}
|
||
|
||
#[test]
|
||
fn the_onboarding_model_list_starts_the_row_picked_or_the_recommended_one() {
|
||
// Continue with no pick starts the selected, recommended model.
|
||
let mut rt = runtime("onboarding-model-found", false, PANE_SIZE);
|
||
assert!(sent(&rt).is_empty(), "nothing starts before a pick");
|
||
tap(&mut rt, "continue");
|
||
assert!(matches!(
|
||
sent(&rt),
|
||
[Request::ChooseModel {
|
||
model: TranscriptionModelId::ParakeetUnifiedEnglish,
|
||
..
|
||
}]
|
||
));
|
||
// Picking a found catalog model uses it, with no download of ours.
|
||
let mut rt = runtime("onboarding-model-found", false, PANE_SIZE);
|
||
tap(&mut rt, "model1");
|
||
assert!(matches!(
|
||
sent(&rt),
|
||
[Request::ChooseModel {
|
||
model: TranscriptionModelId::ParakeetV3,
|
||
..
|
||
}]
|
||
));
|
||
assert_eq!(rt.state.found.picked, Some(1));
|
||
}
|
||
|
||
/// The microphone field's value. An open menu is modal, so the field behind
|
||
/// it leaves the accessibility tree: it is read with the menu closed.
|
||
fn microphone_value(rt: &mut Runtime<Ui>) -> Option<String> {
|
||
let open = rt.state.open.take();
|
||
rt.invalidate();
|
||
settle(rt);
|
||
let value = a11y_value(rt, "microphone-control");
|
||
rt.state.open = open;
|
||
rt.invalidate();
|
||
settle(rt);
|
||
value
|
||
}
|
||
|
||
#[test]
|
||
fn the_microphone_field_names_the_input_in_use() {
|
||
let field = microphone_value;
|
||
let mut rt = runtime("mac-settings", true, TALL_SIZE);
|
||
assert_eq!(field(&mut rt).as_deref(), Some("System default, Alex Pods"));
|
||
|
||
let mut rt = runtime("mac-microphone-missing", true, TALL_SIZE);
|
||
assert_eq!(field(&mut rt).as_deref(), Some("System default, Alex Pods"));
|
||
let texts = texts(&rt);
|
||
assert!(texts.contains(&"not connected".to_owned()), "{texts:?}");
|
||
assert!(texts.contains(&"Shure MV7 isn't connected; using your Mac's input".to_owned()));
|
||
}
|
||
|
||
#[test]
|
||
fn a_closed_lid_names_the_input_standing_in_for_the_built_in_microphone() {
|
||
let note = "MacBook Pro Microphone is off while the lid is closed, so Hex listens to Studio Display Microphone";
|
||
let field = microphone_value;
|
||
let mut rt = runtime("mac-microphone-lid-closed", true, TALL_SIZE);
|
||
assert_eq!(
|
||
field(&mut rt).as_deref(),
|
||
Some("System default, Studio Display Microphone")
|
||
);
|
||
let shown = texts(&rt);
|
||
assert!(shown.contains(¬e.to_owned()), "{shown:?}");
|
||
assert!(shown.contains(&"off while the lid is closed".to_owned()));
|
||
|
||
// A saved built-in microphone shows the default standing in, too.
|
||
rt.state.settings.microphone = Some("MacBook Pro Microphone".into());
|
||
if let Ok(devices) = &mut rt.state.microphones {
|
||
devices.default_is_off_with_lid_closed = false;
|
||
}
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
assert_eq!(
|
||
field(&mut rt).as_deref(),
|
||
Some("System default, Studio Display Microphone")
|
||
);
|
||
assert!(texts(&rt).contains(¬e.to_owned()));
|
||
}
|
||
|
||
#[test]
|
||
fn a_passed_over_bluetooth_default_names_the_input_in_use() {
|
||
let note = "Alex Pods is Bluetooth, so Hex listens to MacBook Pro Microphone";
|
||
let mut rt = runtime("mac-microphone-bluetooth", true, TALL_SIZE);
|
||
assert_eq!(
|
||
a11y_value(&rt, "microphone-control").as_deref(),
|
||
Some("System default, MacBook Pro Microphone")
|
||
);
|
||
assert!(texts(&rt).contains(¬e.to_owned()), "{:?}", texts(&rt));
|
||
|
||
tap(&mut rt, "avoid-bluetooth-microphone");
|
||
assert!(!rt.state.settings.avoid_bluetooth_microphone);
|
||
// A saved Bluetooth microphone is used as named, without the note.
|
||
rt.state.settings.avoid_bluetooth_microphone = true;
|
||
rt.state.settings.microphone = Some("Alex Pods".into());
|
||
rt.invalidate();
|
||
settle(&mut rt);
|
||
assert!(!texts(&rt).contains(¬e.to_owned()));
|
||
}
|
||
|
||
/// `HEX_ANNOTATE_SNAPS=<folder>` writes the Annotate pane, light and dark,
|
||
/// tall enough to show How it works.
|
||
#[cfg(hex_capture)]
|
||
#[test]
|
||
fn annotate_pane_snapshots() {
|
||
let Some(folder) = std::env::var_os("HEX_ANNOTATE_SNAPS") else {
|
||
return;
|
||
};
|
||
let folder = std::path::PathBuf::from(folder);
|
||
std::fs::create_dir_all(&folder).unwrap();
|
||
for dark in [false, true] {
|
||
let Some((width, height, pixels)) = render("mac-scrawl", dark, (PANE_SIZE.0, 1500.0))
|
||
else {
|
||
eprintln!("skipping Annotate snapshots: no GPU adapter");
|
||
return;
|
||
};
|
||
let theme = if dark { "dark" } else { "light" };
|
||
let path = folder.join(format!("annotate-pane-{theme}.png"));
|
||
rune::render::write_png(&path, width, height, &pixels).unwrap();
|
||
}
|
||
}
|
||
|
||
// ---------------------------------------------------------------------------
|
||
// Goldens: offscreen GPU renders compared with checked-in PNGs. Set
|
||
// HEX_UPDATE_GOLDENS=1 to rewrite them. Without a GPU adapter they skip,
|
||
// unless HEX_REQUIRE_GPU is set (scripts/check-onboarding.sh).
|
||
// HEX_GOLDEN_RENDERS=<folder> also writes every render there.
|
||
|
||
/// One device for every golden, used one render at a time: creating Vulkan
|
||
/// devices from parallel test threads crashed Mesa's RADV on Linux.
|
||
fn gpu() -> Option<std::sync::MutexGuard<'static, Gpu>> {
|
||
static GPU: std::sync::OnceLock<Option<std::sync::Mutex<Gpu>>> = std::sync::OnceLock::new();
|
||
GPU.get_or_init(|| {
|
||
Gpu::try_new(Gpu::instance(), None)
|
||
.ok()
|
||
.map(std::sync::Mutex::new)
|
||
})
|
||
.as_ref()
|
||
.map(|gpu| {
|
||
gpu.lock()
|
||
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
||
})
|
||
}
|
||
|
||
fn render(scene: &str, dark: bool, size: (f32, f32)) -> Option<(u32, u32, Vec<u8>)> {
|
||
render_runtime(runtime(scene, dark, size), size)
|
||
}
|
||
|
||
fn render_runtime(mut rt: Runtime<Ui>, size: (f32, f32)) -> Option<(u32, u32, Vec<u8>)> {
|
||
let gpu = gpu()?;
|
||
let mut renderer = crate::rune_ui::offscreen::renderer(&gpu.device);
|
||
let (width, height) = (
|
||
(size.0 * GOLDEN_SCALE) as u32,
|
||
(size.1 * GOLDEN_SCALE) as u32,
|
||
);
|
||
let target = crate::rune_ui::offscreen::target(&gpu.device, width, height);
|
||
renderer.prepare(
|
||
&gpu.device,
|
||
&gpu.queue,
|
||
&mut rt.text.atlas,
|
||
&rt.instances,
|
||
(width, height),
|
||
);
|
||
renderer.upload_images(&gpu.device, &gpu.queue, &mut rt.images);
|
||
let mut encoder = gpu.device.create_command_encoder(&Default::default());
|
||
// The window's own compositor: the UI, the first run's GPU stage, and
|
||
// the Sounds sheet's HUD.
|
||
rune::compose::Compositor::render(
|
||
&mut super::WindowCompositor::default(),
|
||
&mut rune::compose::Frame {
|
||
device: &gpu.device,
|
||
queue: &gpu.queue,
|
||
encoder: &mut encoder,
|
||
target: &target.view,
|
||
format: crate::rune_ui::offscreen::format(),
|
||
size: (width, height),
|
||
dt: 0.0,
|
||
update_ms: 0.0,
|
||
rt: &mut rt,
|
||
ui: &mut renderer,
|
||
},
|
||
);
|
||
target.copy(&mut encoder);
|
||
renderer.submit(&gpu.queue, encoder);
|
||
Some((width, height, target.read(&gpu.device)))
|
||
}
|
||
|
||
fn golden_path(name: &str) -> std::path::PathBuf {
|
||
std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
|
||
.join("tests/golden")
|
||
.join(format!("rune-{name}.png"))
|
||
}
|
||
|
||
fn read_png(path: &std::path::Path) -> (u32, u32, Vec<u8>) {
|
||
let decoder = png::Decoder::new(std::io::BufReader::new(std::fs::File::open(path).unwrap()));
|
||
let mut reader = decoder.read_info().unwrap();
|
||
let mut pixels = vec![0; reader.output_buffer_size().unwrap()];
|
||
let info = reader.next_frame(&mut pixels).unwrap();
|
||
pixels.truncate(info.buffer_size());
|
||
(info.width, info.height, pixels)
|
||
}
|
||
|
||
fn check_golden(scene: &str, dark: bool, size: (f32, f32)) {
|
||
check_render(scene, dark, render(scene, dark, size));
|
||
}
|
||
|
||
fn check_render(scene: &str, dark: bool, pixels: Option<(u32, u32, Vec<u8>)>) {
|
||
let name = format!("{scene}-{}", if dark { "dark" } else { "light" });
|
||
let Some((width, height, pixels)) = pixels else {
|
||
assert!(
|
||
std::env::var_os("HEX_REQUIRE_GPU").is_none(),
|
||
"golden {name}: no GPU adapter, and HEX_REQUIRE_GPU is set"
|
||
);
|
||
eprintln!("skipping golden {name}: no GPU adapter");
|
||
return;
|
||
};
|
||
if let Some(folder) = std::env::var_os("HEX_GOLDEN_RENDERS") {
|
||
let folder = std::path::PathBuf::from(folder);
|
||
std::fs::create_dir_all(&folder).unwrap();
|
||
rune::render::write_png(&folder.join(format!("{name}.png")), width, height, &pixels)
|
||
.unwrap();
|
||
}
|
||
let path = golden_path(&name);
|
||
if std::env::var_os("HEX_UPDATE_GOLDENS").is_some() {
|
||
std::fs::create_dir_all(path.parent().unwrap()).unwrap();
|
||
rune::render::write_png(&path, width, height, &pixels).unwrap();
|
||
return;
|
||
}
|
||
if !path.exists() {
|
||
let actual = std::env::temp_dir().join(format!("rune-settings-{name}-actual.png"));
|
||
rune::render::write_png(&actual, width, height, &pixels).unwrap();
|
||
let miss = format!(
|
||
"{} is missing; run with HEX_UPDATE_GOLDENS=1 (render at {})",
|
||
path.display(),
|
||
actual.display()
|
||
);
|
||
if !GOLDEN_MISSES.with(|misses| {
|
||
misses
|
||
.borrow_mut()
|
||
.as_mut()
|
||
.map(|misses| misses.push(miss.clone()))
|
||
.is_some()
|
||
}) {
|
||
panic!("{miss}");
|
||
}
|
||
return;
|
||
}
|
||
let (golden_width, golden_height, golden) = read_png(&path);
|
||
assert_eq!(
|
||
(golden_width, golden_height),
|
||
(width, height),
|
||
"{name} size changed"
|
||
);
|
||
// GPU drivers differ in the last bit of blending and glyph coverage;
|
||
// a layout or colour change moves far more than this.
|
||
let differing = pixels
|
||
.chunks(4)
|
||
.zip(golden.chunks(4))
|
||
.filter(|(a, b)| a.iter().zip(b.iter()).any(|(x, y)| x.abs_diff(*y) > 12))
|
||
.count();
|
||
let limit = (width * height) as usize / 500;
|
||
if differing > limit {
|
||
let actual = std::env::temp_dir().join(format!("rune-settings-{name}-actual.png"));
|
||
rune::render::write_png(&actual, width, height, &pixels).unwrap();
|
||
let miss = format!(
|
||
"{name}: {differing} pixels differ (limit {limit}); actual render at {}",
|
||
actual.display()
|
||
);
|
||
if !GOLDEN_MISSES.with(|misses| {
|
||
misses
|
||
.borrow_mut()
|
||
.as_mut()
|
||
.map(|misses| misses.push(miss.clone()))
|
||
.is_some()
|
||
}) {
|
||
panic!("{miss}");
|
||
}
|
||
}
|
||
}
|
||
|
||
thread_local! {
|
||
static GOLDEN_MISSES: std::cell::RefCell<Option<Vec<String>>> =
|
||
const { std::cell::RefCell::new(None) };
|
||
}
|
||
|
||
/// The lab What's new lists first: the newest offered lab, tie-broken by
|
||
/// its place in the registry, as the feed sorts it.
|
||
fn newest_offered_lab(ui: &Ui) -> &'static str {
|
||
labs::offered_labs(ui)
|
||
.into_iter()
|
||
.max_by_key(|(feature, _)| {
|
||
(
|
||
feature.added(),
|
||
crate::labs::Feature::ALL
|
||
.iter()
|
||
.position(|known| known == feature)
|
||
.unwrap_or(0),
|
||
)
|
||
})
|
||
.expect("the fixture offers a lab")
|
||
.0
|
||
.name()
|
||
}
|
||
|
||
#[test]
|
||
fn whats_new_opens_controls_without_changing_them() {
|
||
let _goldens = Goldens::collect();
|
||
for dark in [true, false] {
|
||
for scene in ["whats-new", "whats-new-newest", "whats-new-sounds"] {
|
||
let mut rt = runtime("mac-settings", dark, PANE_SIZE);
|
||
let newest = newest_offered_lab(&rt.state);
|
||
let before = serde_json::to_value(&rt.state.settings).unwrap();
|
||
tap(&mut rt, "nav-whats-new");
|
||
assert_eq!(rt.state.pane, Pane::WhatsNew);
|
||
if scene != "whats-new" {
|
||
let key = if scene == "whats-new-newest" {
|
||
format!("open-lab-{newest}")
|
||
} else {
|
||
"open-sounds".to_owned()
|
||
};
|
||
// The feed is taller than the window; reach the oldest entry
|
||
// before pressing it.
|
||
scroll_into_view(&mut rt, &key, "whats-new-scroll");
|
||
tap(&mut rt, &key);
|
||
if scene == "whats-new-newest" {
|
||
assert!(
|
||
rt.state.labs_open && rt.find(&format!("lab-card-{newest}")).is_some(),
|
||
"the newest lab's card opens"
|
||
);
|
||
} else {
|
||
assert!(rt.find("sound-sets").is_some());
|
||
}
|
||
}
|
||
assert_eq!(serde_json::to_value(&rt.state.settings).unwrap(), before);
|
||
check_render(scene, dark, render_runtime(rt, PANE_SIZE));
|
||
}
|
||
}
|
||
}
|
||
|
||
/// What's new lists the newest lab the registry offers, no more than eight
|
||
/// labs, and each lab's button and row keys are its own.
|
||
#[test]
|
||
fn whats_new_lists_the_newest_offered_labs() {
|
||
let mut rt = runtime("mac-settings", true, (980.0, 2600.0));
|
||
let newest = newest_offered_lab(&rt.state);
|
||
tap(&mut rt, "nav-whats-new");
|
||
let buttons: Vec<String> = rt
|
||
.elements()
|
||
.into_iter()
|
||
.filter_map(|element| element.key)
|
||
.filter_map(|key| key.strip_prefix("open-lab-").map(str::to_string))
|
||
.collect();
|
||
assert_eq!(buttons.first().map(String::as_str), Some(newest));
|
||
assert_eq!(
|
||
buttons.len(),
|
||
labs::offered_labs(&rt.state).len().min(8),
|
||
"every offered lab up to eight: {buttons:?}"
|
||
);
|
||
let mut unique = buttons.clone();
|
||
unique.sort();
|
||
unique.dedup();
|
||
assert_eq!(
|
||
buttons.len(),
|
||
unique.len(),
|
||
"no two labs share a button: {buttons:?}"
|
||
);
|
||
assert!(rt.find("open-sounds").is_some(), "sounds stays");
|
||
for lab in unique {
|
||
assert!(
|
||
rt.find(&format!("highlight-{lab}")).is_some(),
|
||
"{lab}'s row has its own key"
|
||
);
|
||
}
|
||
tap(&mut rt, &format!("open-lab-{newest}"));
|
||
assert!(rt.state.labs_open && rt.find(&format!("lab-card-{newest}")).is_some());
|
||
}
|
||
|
||
/// Collects every golden mismatch in a test and fails once at the end, so
|
||
/// one CI run uploads every render that moved rather than only the first.
|
||
struct Goldens;
|
||
|
||
impl Goldens {
|
||
fn collect() -> Self {
|
||
GOLDEN_MISSES.with(|misses| *misses.borrow_mut() = Some(Vec::new()));
|
||
Self
|
||
}
|
||
}
|
||
|
||
impl Drop for Goldens {
|
||
fn drop(&mut self) {
|
||
let misses = GOLDEN_MISSES
|
||
.with(|misses| misses.borrow_mut().take())
|
||
.unwrap_or_default();
|
||
if !misses.is_empty() && !std::thread::panicking() {
|
||
panic!("{}", misses.join("\n"));
|
||
}
|
||
}
|
||
}
|
||
|
||
/// Every pane in both appearances; General at its full height.
|
||
#[test]
|
||
fn goldens() {
|
||
let _goldens = Goldens::collect();
|
||
for dark in [true, false] {
|
||
check_golden("portal", dark, GOLDEN_SIZE);
|
||
for scene in [
|
||
"history",
|
||
"history-stats-strip",
|
||
"captures",
|
||
"mac-labs",
|
||
"mac-labs-link",
|
||
"mac-labs-yolo-mode",
|
||
"output",
|
||
"modes",
|
||
"modes-picker",
|
||
"picker-downloading",
|
||
// Labs › Transcribe dropped audio: the hint a file drag shows and
|
||
// the toast of the file running with its progress.
|
||
"drop-hover",
|
||
"drop-running",
|
||
] {
|
||
check_golden(scene, dark, PANE_SIZE);
|
||
}
|
||
}
|
||
check_golden("commands", true, GOLDEN_SIZE);
|
||
check_golden("menus", false, GOLDEN_SIZE);
|
||
// A list longer than the window fades at its scrolling edge (#840).
|
||
check_golden("language-menu", false, GOLDEN_SIZE);
|
||
check_golden("modes-opencode-not-running", false, PANE_SIZE);
|
||
check_golden("output-trust", false, PANE_SIZE);
|
||
check_golden("picker-custom-models", false, PANE_SIZE);
|
||
check_golden("picker-found", false, PANE_SIZE);
|
||
check_golden("vocabulary-budget", false, PANE_SIZE);
|
||
check_golden("windows-labs", false, PANE_SIZE);
|
||
check_golden("linux-labs", false, PANE_SIZE);
|
||
check_golden("history-menu", true, PANE_SIZE);
|
||
}
|
||
|
||
mod application_picker;
|
||
mod drop_transcribe;
|
||
mod onboarding_check;
|
||
mod panes;
|
||
|
||
/// Rune hands focus back to a menu's trigger when it closes. A key the
|
||
/// window means for something else must not reach that trigger.
|
||
#[test]
|
||
fn the_recorder_still_gets_space_and_enter_after_a_menu_closes() {
|
||
for scene in ["menus", "language-menu"] {
|
||
for recorded in [Key::Text(" ".into()), Key::Enter] {
|
||
let mut rt = runtime(scene, true, GOLDEN_SIZE);
|
||
assert!(rt.state.open.is_some(), "{scene} opens a menu");
|
||
key(&mut rt, Key::Escape, Mods::default());
|
||
settle(&mut rt);
|
||
assert!(rt.state.open.is_none(), "{scene}: Escape closes the menu");
|
||
tap(&mut rt, "dictation-hotkey");
|
||
assert!(matches!(
|
||
rt.state.capture,
|
||
settings::Capture::Listening { .. }
|
||
));
|
||
key(&mut rt, recorded.clone(), Mods::default());
|
||
settle(&mut rt);
|
||
assert!(
|
||
rt.state.open.is_none(),
|
||
"{scene}: {recorded:?} reopened a menu while recording"
|
||
);
|
||
}
|
||
}
|
||
}
|
||
|
||
/// The trust prompt shows what an unapproved config reaches, and Allow
|
||
/// pins this config's hash and hides it.
|
||
#[test]
|
||
fn the_trust_prompt_lists_what_a_config_reaches_until_it_is_allowed() {
|
||
let mut rt = runtime("output-trust", false, PANE_SIZE);
|
||
let shown = texts(&rt);
|
||
assert!(
|
||
shown
|
||
.iter()
|
||
.any(|text| text == "Your transformations want to use the network and run programs")
|
||
);
|
||
assert!(shown.iter().any(|text| text == "Hosts: localhost"));
|
||
assert!(shown.iter().any(|text| text == "Programs: pandoc, say"));
|
||
tap(&mut rt, "allow-transformations");
|
||
settle(&mut rt);
|
||
assert_eq!(
|
||
rt.state.modes.approved.as_deref(),
|
||
Some("0".repeat(64).as_str())
|
||
);
|
||
assert!(rt.find("allow-transformations").is_none());
|
||
}
|
||
|
||
/// Labs › Transform typed text: Output's Typed text section and its
|
||
/// recorder appear only with the lab on, and the recorder listens like the
|
||
/// raw dictation shortcut's.
|
||
#[cfg(target_os = "linux")]
|
||
#[test]
|
||
fn typed_text_shows_its_recorder_only_with_its_lab() {
|
||
let output = |on: bool| {
|
||
let mut state = Ui::with(AppSettings::default(), Service::Fixture(Vec::new()));
|
||
output::fixture(&mut state);
|
||
state.pane = Pane::Output;
|
||
state.settings.labs.typed_text = on;
|
||
runtime_for(state, false, TALL_SIZE)
|
||
};
|
||
let off = output(false);
|
||
assert!(off.find("typed-text-hotkey").is_none());
|
||
assert!(!texts(&off).iter().any(|text| text == "Typed text"));
|
||
|
||
let mut on = output(true);
|
||
assert!(on.find("typed-text-hotkey").is_some());
|
||
tap(&mut on, "typed-text-hotkey");
|
||
assert!(
|
||
texts(&on).iter().any(|text| text == "Press shortcut"),
|
||
"the recorder listens"
|
||
);
|
||
}
|
||
|
||
/// Labs › Fix results in Output: the Try row offers Vocabulary and Fix
|
||
/// this only with the toggle on, and Fix this copies for the sentence typed.
|
||
#[test]
|
||
fn output_fixes_show_only_with_their_lab_and_fix_this_copies_for_the_sentence() {
|
||
let output = |on: bool| {
|
||
let mut state = Ui::with(AppSettings::default(), Service::Fixture(Vec::new()));
|
||
output::fixture(&mut state);
|
||
state.pane = Pane::Output;
|
||
state.settings.labs.output_fixes = on;
|
||
runtime_for(state, false, TALL_SIZE)
|
||
};
|
||
let off = output(false);
|
||
assert!(off.find("output-vocabulary").is_none());
|
||
assert!(off.find("fix-this").is_none());
|
||
|
||
let mut on = output(true);
|
||
assert!(on.find("output-vocabulary").is_some());
|
||
tap(&mut on, "fix-this");
|
||
assert!(on.state.output.prompt_copied);
|
||
assert_eq!(
|
||
on.state.output.fix_copied.as_deref(),
|
||
Some("Um, open code shipped the hex app today.")
|
||
);
|
||
tap(&mut on, "output-vocabulary");
|
||
assert!(on.state.is_modal(Modal::Vocabulary));
|
||
}
|
||
|
||
#[test]
|
||
fn fluid_speech_pros_details_list_only_the_fleurs_rows_its_card_publishes() {
|
||
let mut state = Ui::with(AppSettings::default(), Service::Fixture(Vec::new()));
|
||
super::picker::all_fixture(&mut state);
|
||
state.picker.details =
|
||
super::model_details::DetailsState::open_with_table(TranscriptionModelId::FluidSpeechPro);
|
||
let rt = runtime_for(state, false, GOLDEN_SIZE);
|
||
assert!(rt.find("published-bg").is_some());
|
||
assert!(rt.find("published-de").is_some());
|
||
// The card publishes no FLEURS English figure, so the table has no
|
||
// English row; the conditions say so in its place.
|
||
assert!(rt.find("published-en").is_none());
|
||
assert!(
|
||
texts(&rt)
|
||
.iter()
|
||
.any(|text| text.contains("publishes no FLEURS English figure"))
|
||
);
|
||
assert!(rt.find("published-toggle").is_some());
|
||
}
|