Files
soundcraft/crates/ui-egui/tests/audio_device.rs
Brandon ThomasandClaude Opus 5.5 3d1a30b61d Audio device: keep the new choice only once the devices reopen with it
ui.audio_device and Playback Engine › Apply wrote ui.audio before
apply_audio_config could refuse (while recording), so the saved choice no
longer matched the open device. apply_audio_config now takes the new
configuration and stores it only after the refusal check. Adds a test for
ui.audio_device: no-op query, a bad rate, refusal while recording, and an
applied change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 04:43:55 -04:00

28 lines
1.3 KiB
Rust

//! `ui.audio_device`: the audio device choice is kept only once the devices reopen with it.
use serde_json::json;
use soundcraft_ui_egui::{Services, SoundApp};
#[test]
fn the_audio_device_choice_is_kept_only_when_it_is_applied() {
let mut app = SoundApp::new(soundcraft_engine::Engine::default(), None, Services::default());
let before = app.ui.audio.clone();
let r = app.run("ui.audio_device", json!({})).unwrap();
assert_eq!(r["config"], json!(before), "no change: just the choice and the device");
assert!(app.run("ui.audio_device", json!({"sample_rate": 12})).is_err());
assert_eq!(app.ui.audio, before, "an out-of-range rate changes nothing");
app.engine.transport.recording = true;
let err = app.run("ui.audio_device", json!({"buffer_size": 256, "output": "Elsewhere"})).unwrap_err();
assert!(err.contains("stop recording"), "{err}");
assert_eq!(app.ui.audio, before, "refused while recording: the saved choice stays the open device's");
app.engine.transport.recording = false;
// Opens the chosen device, or the default, or a silent clock without one.
let r = app.run("ui.audio_device", json!({"buffer_size": 256})).unwrap();
assert_eq!(app.ui.audio.buffer_size, Some(256));
assert_eq!(r["config"]["buffer_size"], 256);
assert!(r["device"].is_object(), "{r}");
}