claude-web-chat/projects_test.go
djuka 3283888738
All checks were successful
Tests / unit-tests (push) Successful in 51s
Inicijalna implementacija Claude Web Chat (Faza 1 - CLI mod)
- Login sa session cookie autentifikacijom
- Lista projekata iz filesystem-a
- Chat sa Claude CLI preko WebSocket-a
- Streaming NDJSON parsiranje iz CLI stdout-a
- Sesija zivi nezavisno od browsera (reconnect replay)
- Sidebar sa .md fajlovima i markdown renderovanjem
- Dark tema, htmx + Go templates
- 47 unit testova

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 05:03:40 +00:00

100 lines
2.4 KiB
Go

package main
import (
"os"
"path/filepath"
"testing"
)
func TestListProjects(t *testing.T) {
dir := t.TempDir()
// Create test projects
os.MkdirAll(filepath.Join(dir, "alpha"), 0755)
os.MkdirAll(filepath.Join(dir, "beta"), 0755)
os.MkdirAll(filepath.Join(dir, ".hidden"), 0755)
os.WriteFile(filepath.Join(dir, "file.txt"), []byte("not a dir"), 0644)
// Add README to alpha
os.WriteFile(filepath.Join(dir, "alpha", "README.md"), []byte("# Alpha Project\nSome description"), 0644)
t.Run("lists directories only", func(t *testing.T) {
projects, err := ListProjects(dir)
if err != nil {
t.Fatalf("ListProjects: %v", err)
}
if len(projects) != 2 {
t.Fatalf("got %d projects, want 2", len(projects))
}
})
t.Run("sorted alphabetically", func(t *testing.T) {
projects, err := ListProjects(dir)
if err != nil {
t.Fatalf("ListProjects: %v", err)
}
if projects[0].Name != "alpha" {
t.Errorf("first = %q, want alpha", projects[0].Name)
}
if projects[1].Name != "beta" {
t.Errorf("second = %q, want beta", projects[1].Name)
}
})
t.Run("reads README description", func(t *testing.T) {
projects, err := ListProjects(dir)
if err != nil {
t.Fatalf("ListProjects: %v", err)
}
if !projects[0].HasReadme {
t.Error("alpha should have HasReadme=true")
}
if projects[0].Description != "Alpha Project" {
t.Errorf("description = %q, want 'Alpha Project'", projects[0].Description)
}
})
t.Run("no README", func(t *testing.T) {
projects, err := ListProjects(dir)
if err != nil {
t.Fatalf("ListProjects: %v", err)
}
if projects[1].HasReadme {
t.Error("beta should have HasReadme=false")
}
if projects[1].Description != "" {
t.Errorf("description = %q, want empty", projects[1].Description)
}
})
t.Run("excludes hidden dirs", func(t *testing.T) {
projects, err := ListProjects(dir)
if err != nil {
t.Fatalf("ListProjects: %v", err)
}
for _, p := range projects {
if p.Name == ".hidden" {
t.Error("should not include hidden directories")
}
}
})
t.Run("nonexistent directory", func(t *testing.T) {
_, err := ListProjects("/nonexistent/path")
if err == nil {
t.Fatal("expected error for nonexistent dir")
}
})
t.Run("empty directory", func(t *testing.T) {
emptyDir := t.TempDir()
projects, err := ListProjects(emptyDir)
if err != nil {
t.Fatalf("ListProjects: %v", err)
}
if len(projects) != 0 {
t.Errorf("got %d projects, want 0", len(projects))
}
})
}