80 lines
2.6 KiB
Go
80 lines
2.6 KiB
Go
package main
|
|
|
|
import (
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.stormux.org/storm/barnard/config"
|
|
"git.stormux.org/storm/barnard/noise"
|
|
"git.stormux.org/storm/barnard/uiterm"
|
|
)
|
|
|
|
func TestOutputScrollScopeLeavesInputHomeAndEndAlone(t *testing.T) {
|
|
if outputScrollAllowed(uiViewInput) {
|
|
t.Fatal("message input unexpectedly allowed global chat scrolling")
|
|
}
|
|
for _, view := range []string{uiViewTree, uiViewAdmin} {
|
|
if !outputScrollAllowed(view) {
|
|
t.Errorf("%s unexpectedly disabled chat scrolling", view)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestAudioSettingsExposeCurrentValuesAndPersistMicChanges(t *testing.T) {
|
|
configPath := filepath.Join(t.TempDir(), "barnard.toml")
|
|
userConfig := config.NewConfig(&configPath)
|
|
b := &Barnard{UserConfig: userConfig, NoiseSuppressor: noise.NewSuppressor()}
|
|
|
|
items := b.audioSettingsItems()
|
|
labels := make([]string, 0, len(items))
|
|
for _, item := range items {
|
|
labels = append(labels, item.String())
|
|
}
|
|
joined := strings.Join(labels, "\n")
|
|
for _, wanted := range []string{"Automatic gain control: on", "Noise suppression: off", "Remember transmission state: off", "Microphone level: 100 percent"} {
|
|
if !strings.Contains(joined, wanted) {
|
|
t.Errorf("settings did not include %q:\n%s", wanted, joined)
|
|
}
|
|
}
|
|
|
|
items[0].(adminItem).action()
|
|
items[1].(adminItem).action()
|
|
b.setTransmitting(true)
|
|
items[2].(adminItem).action()
|
|
reloaded := config.NewConfig(&configPath)
|
|
if reloaded.GetAGCEnabled() {
|
|
t.Fatal("settings action did not persist disabled automatic gain control")
|
|
}
|
|
if !reloaded.GetNoiseSuppressionEnabled() {
|
|
t.Fatal("settings action did not persist enabled noise suppression")
|
|
}
|
|
if !reloaded.GetRememberTransmissionState() {
|
|
t.Fatal("settings action did not persist enabled transmission-state remembering")
|
|
}
|
|
if !reloaded.GetTransmissionActive() {
|
|
t.Fatal("settings action did not capture the active transmission state")
|
|
}
|
|
|
|
if got := b.adjustMicVolume(-0.1); got < 0.899 || got > 0.901 {
|
|
t.Fatalf("adjusted microphone level = %v, want 0.9", got)
|
|
}
|
|
if got := config.NewConfig(&configPath).GetMicVolume(); got < 0.899 || got > 0.901 {
|
|
t.Fatalf("persisted microphone level = %v, want 0.9", got)
|
|
}
|
|
if got := b.setMicVolume(2); got != 1 {
|
|
t.Fatalf("clamped microphone level = %v, want 1", got)
|
|
}
|
|
}
|
|
|
|
func TestKeyboardHelpUsesConfiguredBindings(t *testing.T) {
|
|
f2 := uiterm.KeyF2
|
|
b := &Barnard{Hotkeys: &config.Hotkeys{
|
|
HelpMenu: &f2,
|
|
}}
|
|
items := b.keyboardHelpItems()
|
|
if len(items) == 0 || !strings.Contains(items[0].(adminItem).children[0].String(), "F2") {
|
|
t.Fatal("keyboard help did not use the configured help binding")
|
|
}
|
|
}
|