Preview voice profile edits and restore parent speech
This commit is contained in:
1 parent
1b42dde756
commit
b21fceb311
7 files changed
+175
-11
No files matched your search
@@ -7,6 +7,7 @@ import (
|
||||
"errors"
|
||||
"git.stormux.org/storm/cthulhu/internal/config"
|
||||
"git.stormux.org/storm/cthulhu/internal/input"
|
||||
"git.stormux.org/storm/cthulhu/internal/preferences"
|
||||
"git.stormux.org/storm/cthulhu/internal/speech"
|
||||
"git.stormux.org/storm/screenreader-common/voiceprofiles"
|
||||
"log/slog"
|
||||
@@ -115,3 +116,64 @@ func TestQuickVoiceProfileDefaultIsFocusedApplicationVoice(t *testing.T) {
|
||||
t.Fatal("inherited application voice was not the global voice", saved)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAppliedNewVoiceProfileIsImmediatelyAvailableAcrossApplications(t *testing.T) {
|
||||
settings := config.DefaultSettings()
|
||||
settings.Path = filepath.Join(t.TempDir(), "settings.toml")
|
||||
store, err := config.NewStore(settings.Path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := store.Save(settings); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := store.SaveForApplication("Mapped Application", settings); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
worker := newPreferencesWorker(slog.New(slog.DiscardHandler), settings, settingsUpdateFunc(func(context.Context, speech.Settings) error { return nil }))
|
||||
worker.switchApplication(t.Context(), "Mapped Application")
|
||||
if !worker.beginEdit(t.Context(), "") {
|
||||
t.Fatal("global preferences did not open")
|
||||
}
|
||||
values := preferences.FromSettings(worker.editing)
|
||||
values.VoiceProfiles.Profiles = []voiceprofiles.Profile{{Name: "Reading", Driver: "speech-dispatcher", Rate: 30, Volume: 80}}
|
||||
if result := worker.apply(t.Context(), preferences.Request{Values: values, Save: true}); !result.Accepted {
|
||||
t.Fatal(result.Message)
|
||||
}
|
||||
loaded, err := store.Load()
|
||||
if err != nil || len(loaded.VoiceProfiles.Profiles) != 1 {
|
||||
t.Fatal("new profile was not saved", loaded.VoiceProfiles, err)
|
||||
}
|
||||
for _, application := range []string{"Mapped Application", "Other Application"} {
|
||||
worker.switchApplication(t.Context(), application)
|
||||
selectQuickSetting(t, worker, "speech.profile")
|
||||
worker.handleSpeechCommand(t.Context(), input.IncreaseSpeechSetting)
|
||||
if got := config.Primary_voice(worker.settings); got.Rate != 30 || got.Volume != 80 {
|
||||
t.Fatal("new profile unavailable without restart", application, got)
|
||||
}
|
||||
worker.handleSpeechCommand(t.Context(), input.IncreaseSpeechSetting) // Return to Default.
|
||||
}
|
||||
}
|
||||
|
||||
func TestProfileVoicePreviewReachesBackendWithoutCommitting(t *testing.T) {
|
||||
settings := config.DefaultSettings()
|
||||
updater := &voiceConfigurationRecorder{}
|
||||
worker := newPreferencesWorker(slog.New(slog.DiscardHandler), settings, updater)
|
||||
profile := voiceprofiles.Profile{Name: "Reading", Driver: "speech-dispatcher", Module: "fixture", Language: "es", Voice: "Reading voice", Rate: 30, Pitch: -10, Volume: 80}
|
||||
draft, err := config.Apply_primary_voice(settings, profile)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if response := worker.preview(t.Context(), preferences.Request{Values: preferences.FromSettings(draft), Preview: true}); !response.Accepted {
|
||||
t.Fatal(response.Message)
|
||||
}
|
||||
if got := config.Primary_voice(updater.settings); !voiceprofiles.Same_voice(got, profile) {
|
||||
t.Fatal("profile preview did not reach the speech backend", got)
|
||||
}
|
||||
if !reflect.DeepEqual(worker.settings, settings) || len(worker.settings.VoiceProfiles.Profiles) != 0 {
|
||||
t.Fatal("profile preview committed reader settings")
|
||||
}
|
||||
if response := worker.restorePreview(t.Context()); !response.Accepted || !reflect.DeepEqual(updater.settings, settings) {
|
||||
t.Fatal("profile preview did not restore the working voice", response)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user