feat: Audio Preview Player — browse and play WAV samples via Web Audio API
Issue: #9 Backend: - GET /api/list-wavs?dir=<path> — lists .wav files in a directory - GET /wavs/<file> — static file serving from ./output/wavs Web UI: - WAV Browser section with path input + Browse button - AudioContext-based playback (zero deps) — progress bar, time display - WAV file grid with Play buttons, active item highlighting Tests: - 3 new tests for handleListWavs (wav files, empty dir, nonexistent dir) - Fix TestFindAkaiutil: add t.Chdir(tmp) so relative path lookups don't accidentally find the repo's third_party/akaiutil/akaiutil binary
This commit is contained in:
@@ -442,4 +442,68 @@ func TestHandleAPIExtract_ExtractISOError(t *testing.T) {
|
||||
if !strings.Contains(msg, "FAIL bad.iso") {
|
||||
t.Errorf("expected FAIL message, got: %s", msg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleListWavs_ReturnsWavFiles(t *testing.T) {
|
||||
tmp := t.TempDir()
|
||||
wavDir := filepath.Join(tmp, "wavs")
|
||||
if err := os.MkdirAll(wavDir, 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, name := range []string{"kick.wav", "snare.wav", "hihat.wav"} {
|
||||
fd, _ := os.Create(filepath.Join(wavDir, name))
|
||||
_ = fd.Close()
|
||||
}
|
||||
fd, _ := os.Create(filepath.Join(wavDir, "readme.txt"))
|
||||
_ = fd.Close()
|
||||
|
||||
req := httptest.NewRequest("GET", "/api/list-wavs?dir="+wavDir, nil)
|
||||
rr := httptest.NewRecorder()
|
||||
handleListWavs(rr, req)
|
||||
|
||||
if rr.Code != http.StatusOK {
|
||||
t.Errorf("expected 200, got %d", rr.Code)
|
||||
}
|
||||
var files []string
|
||||
if err := json.Unmarshal(rr.Body.Bytes(), &files); err != nil {
|
||||
t.Fatalf("invalid JSON: %v", err)
|
||||
}
|
||||
if len(files) != 3 {
|
||||
t.Errorf("expected 3 wav files, got %d: %v", len(files), files)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleListWavs_EmptyDir(t *testing.T) {
|
||||
tmp := t.TempDir()
|
||||
req := httptest.NewRequest("GET", "/api/list-wavs?dir="+tmp, nil)
|
||||
rr := httptest.NewRecorder()
|
||||
handleListWavs(rr, req)
|
||||
|
||||
if rr.Code != http.StatusOK {
|
||||
t.Errorf("expected 200, got %d", rr.Code)
|
||||
}
|
||||
var files []string
|
||||
if err := json.Unmarshal(rr.Body.Bytes(), &files); err != nil {
|
||||
t.Fatalf("invalid JSON: %v", err)
|
||||
}
|
||||
if len(files) != 0 {
|
||||
t.Errorf("expected 0 files, got %d", len(files))
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleListWavs_NonExistentDir(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/api/list-wavs?dir=/nonexistent/wavs", nil)
|
||||
rr := httptest.NewRecorder()
|
||||
handleListWavs(rr, req)
|
||||
|
||||
if rr.Code != http.StatusOK {
|
||||
t.Errorf("expected 200, got %d", rr.Code)
|
||||
}
|
||||
var resp map[string]any
|
||||
if err := json.Unmarshal(rr.Body.Bytes(), &resp); err != nil {
|
||||
t.Fatalf("invalid JSON: %v", err)
|
||||
}
|
||||
if _, ok := resp["error"]; !ok {
|
||||
t.Error("expected error for nonexistent dir")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user