Files
moonmix/model/view_test.mbt
T
nandi 02b08cb471
CI / check (push) Successful in 10s
CI / native (push) Successful in 1m10s
Better icons: device/app icon chains, volume icons, app icon (#2)
2026-11-23 01:07:41 +00:00

79 lines
2.2 KiB
MoonBit

///|
test "playback rows" {
let s = sample_state()
let rows = @model.rows(s, Playback)
assert_eq(rows.length(), 1)
let r = rows[0]
assert_eq(r.title, "Firefox")
assert_eq(r.subtitle, "Big Buck Bunny")
assert_eq(r.volume_text, "100% (0.00 dB)")
assert_eq(r.choices.map(fn(c) { c.id }), [40, 41])
assert_eq(r.current_choice, 1)
assert_eq(r.choices[1].name, "bluez_output.headphones")
}
///|
test "recording rows route to sources" {
let s = sample_state()
let r = @model.rows(s, Recording)[0]
assert_eq(r.title, "OBS")
assert_eq(r.choices.map(fn(c) { c.id }), [50])
assert_eq(r.current_choice, 0)
}
///|
test "device rows" {
let s = sample_state()
let outs = @model.rows(s, OutputDevices)
assert_eq(outs.map(fn(r) { r.is_default }), [true, false])
assert_eq(outs[1].volume_text, "50% (-18.06 dB)")
assert_eq(outs[0].subtitle, "alsa_output.pci.analog-stereo")
assert_eq(outs[0].choices, [])
let ins = @model.rows(s, InputDevices)
assert_eq(ins.length(), 1)
assert_true(ins[0].mute)
assert_true(ins[0].is_default)
assert_eq(ins[0].icons[0], "audio-input-microphone-symbolic")
assert_eq(ins[0].volume_icon, "audio-volume-muted-symbolic")
}
///|
test "stream without app name falls back" {
let s = @model.State::new()
let _ = s.apply(Upsert(@model.Node::new(7, "Stream/Output/Audio")))
let r = @model.rows(s, Playback)[0]
assert_eq(r.title, "Stream 7")
assert_eq(r.current_choice, -1)
assert_false(r.has_volume)
assert_eq(r.volume_text, "")
}
///|
test "diff rows" {
let s = sample_state()
let before = @model.rows(s, OutputDevices)
let _ = s.apply(Remove(41))
let _ = s.apply(
Upsert(@model.Node::new(42, "Audio/Sink", description="HDMI")),
)
let _ = s.apply(Upsert({ ..s.nodes.get(40).unwrap(), mute: true, }))
let after = @model.rows(s, OutputDevices)
assert_eq(@model.diff_rows(before, after), {
removed: [41],
added: [42],
updated: [40],
})
assert_eq(@model.diff_rows(after, after), {
removed: [],
added: [],
updated: [],
})
}
///|
test "tab labels" {
assert_eq(@model.Tab::all().map(fn(t) { t.label() }), [
"Playback", "Recording", "Output Devices", "Input Devices",
])
}