Files
musicplayer/test/musicplayer/control_test.gleam
Alexander Heldt 0ef94d7c89 Key handling is state aware
By forwarding all `Key`s to the agent and allow it to decide what should
be done, instead of converting the `Key` to a `Control` and then decide
what should be done
2025-12-25 17:49:34 +01:00

33 lines
865 B
Gleam

import gleam/list
import gleeunit
import musicplayer/control.{type Control, type Mode}
import musicplayer/input/key.{type Key, Char}
pub fn main() -> Nil {
gleeunit.main()
}
type TestCase {
TestCase(key: Key, mode: Mode, expected: Result(Control, Nil))
}
pub fn control_from_key_test() {
let idle_tests = [
TestCase(Char(" "), control.Idle, Ok(control.TogglePlayPause)),
TestCase(Char("/"), control.Idle, Ok(control.Search("", True))),
TestCase(Char("q"), control.Idle, Ok(control.Exit)),
]
let search_tests = [
TestCase(Char("a"), control.Searching(""), Ok(control.Search("a", True))),
TestCase(Char("b"), control.Searching("a"), Ok(control.Search("ab", True))),
]
let test_cases = [idle_tests, search_tests]
list.each(list.flatten(test_cases), fn(tc) {
assert tc.expected == control.from_key(tc.key, tc.mode)
})
}