Files
command-center/tests/gen-keybinds.bats
T
Frank f63d11de85 feat(blankpad): desk.sh profile switcher, hotplug autoswitch daemon, keybinds doc generator + bats suite
- desk.sh: list/current/switch/cycle/match/capture over cfg/desk-*.kdl
  profiles; apply = relink display.kdl, niri validate (rollback on fail),
  load-config-file, noctalia notification; match scores // requires: lines
  (EDID long names) against live niri msg outputs
- desk-autoswitch.sh: watch niri msg --json event-stream for
  OutputsChanged, debounced desk.sh match --apply, reconnect loop
- blankpad-desk-autoswitch.service: ConditionHost=blankpad user unit
- gen-keybinds.sh: keybinds.kdl -> markdown cheat sheet (sections from
  // --- headers, hotkey-overlay-title preferred over action)
- tests/: 27 bats cases, all green (desk 16, gen-keybinds 6,
  niri-config 5 incl. real niri validate on the assembled tree with
  each desk profile active)
2026-10-09 14:40:26 -07:00

71 lines
2.2 KiB
Bash
Executable File

#!/usr/bin/env bats
# tests/gen-keybinds.bats — black-box tests for scripts/gen-keybinds.sh
#
# Contract: parse a keybinds.kdl into a markdown cheat sheet on stdout,
# or into a file with --write OUT. Observable surface: markdown rows,
# section headers, exit status, written file.
setup() {
GEN="$BATS_TEST_DIRNAME/../scripts/gen-keybinds.sh"
TMP="$(mktemp -d)"
cat > "$TMP/keybinds.kdl" <<'EOF'
binds {
// ─── Applications ───
Mod+Return hotkey-overlay-title="Open Terminal: Ghostty" { spawn "ghostty"; }
Mod+D hotkey-overlay-title="Open App Launcher: noctalia launcher" { spawn-sh "noctalia msg panel-toggle launcher"; }
Mod+E { spawn "nautilus"; }
// ─── Screenshots ───
Print hotkey-overlay-title="Fullscreen screenshot" { spawn-sh "noctalia msg screenshot-fullscreen"; }
// a plain comment, not a section
Mod+Shift+ESCAPE { show-hotkey-overlay; }
}
EOF
}
teardown() {
rm -rf "$TMP"
}
@test "renders a row per bind with title preferred over action" {
run "$GEN" "$TMP/keybinds.kdl"
[ "$status" -eq 0 ]
[[ "$output" == *'| `Mod+D` | Open App Launcher: noctalia launcher |'* ]]
[[ "$output" == *'| `Mod+Return` | Open Terminal: Ghostty |'* ]]
}
@test "binds without a title render their action" {
run "$GEN" "$TMP/keybinds.kdl"
[[ "$output" == *'| `Mod+E` | spawn "nautilus" |'* ]]
[[ "$output" == *'| `Mod+Shift+ESCAPE` | show-hotkey-overlay |'* ]]
}
@test "section comments become headers; plain comments are ignored" {
run "$GEN" "$TMP/keybinds.kdl"
[[ "$output" == *"## Applications"* ]]
[[ "$output" == *"## Screenshots"* ]]
[[ "$output" != *"a plain comment"* ]]
}
@test "row count matches bind count" {
run "$GEN" "$TMP/keybinds.kdl"
local rows
rows="$(grep -c '^| `' <<<"$output")"
[ "$rows" -eq 5 ]
}
@test "--write writes the markdown to the given path" {
run "$GEN" "$TMP/keybinds.kdl" --write "$TMP/out/keybindings.md"
[ "$status" -eq 0 ]
[ -f "$TMP/out/keybindings.md" ]
grep -q '| `Mod+D` | Open App Launcher: noctalia launcher |' "$TMP/out/keybindings.md"
grep -q 'GENERATED' "$TMP/out/keybindings.md"
}
@test "missing input file fails loudly" {
run "$GEN" "$TMP/nope.kdl"
[ "$status" -ne 0 ]
[[ "$output" == *"no such file"* ]]
}