// Copyright (c) 2026 Storm Dragon // Authors: Storm Dragon, Angus Kola // SPDX-License-Identifier: GPL-3.0-or-later package app import ( "context" "errors" "testing" "time" ) func TestClipboardWorkerAnnouncesContentAndAccessError(t *testing.T) { for _, test := range []struct { name string read func(context.Context) (string, error) wantText string }{ {"text", func(context.Context) (string, error) { return "Text in clipboard sample", nil }, "Text in clipboard sample"}, {"error", func(context.Context) (string, error) { return "", errors.New("unavailable") }, "Error accessing clipboard"}, } { t.Run(test.name, func(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) requests := make(chan struct{}, 1) speech := &fakeSpeechQueue{spoken: make(chan string, 1), interrupt: make(chan struct{}, 1)} done := runClipboardWorker(ctx, requests, speech, test.read) requests <- struct{}{} select { case got := <-speech.spoken: if got != test.wantText { t.Fatalf("speech = %q, want %q", got, test.wantText) } case <-time.After(time.Second): t.Fatal("clipboard announcement missing") } if len(speech.interrupt) != 1 { t.Fatal("clipboard announcement did not interrupt prior speech") } cancel() select { case <-done: case <-time.After(time.Second): t.Fatal("clipboard worker did not stop") } }) } }