- Razbijen monolitni server_test.go na fokusirane test fajlove: api_test.go, dashboard_test.go, docs_test.go, search_test.go, submit_test.go, task_detail_test.go, console_test.go, sse_test.go, timestamp_test.go, ui_test.go, test_helpers_test.go - Dodat logs.go handler (handleLogsTail) koji je nedostajao - Dodat LogFile u config - Fix konzola: prompt se šalje preko fajla umesto direktno u PTY - 192 testova prolazi Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
118 lines
2.7 KiB
Go
118 lines
2.7 KiB
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
func TestSearch_FindsTask(t *testing.T) {
|
|
srv := setupTestServer(t)
|
|
|
|
req := httptest.NewRequest(http.MethodGet, "/search?q=Prvi", nil)
|
|
w := httptest.NewRecorder()
|
|
srv.Router.ServeHTTP(w, req)
|
|
|
|
if w.Code != http.StatusOK {
|
|
t.Fatalf("expected 200, got %d", w.Code)
|
|
}
|
|
|
|
body := w.Body.String()
|
|
if !containsStr(body, "T01") {
|
|
t.Error("expected T01 in search results for 'Prvi'")
|
|
}
|
|
}
|
|
|
|
func TestSearch_FindsTaskByID(t *testing.T) {
|
|
srv := setupTestServer(t)
|
|
|
|
req := httptest.NewRequest(http.MethodGet, "/search?q=T08", nil)
|
|
w := httptest.NewRecorder()
|
|
srv.Router.ServeHTTP(w, req)
|
|
|
|
body := w.Body.String()
|
|
if !containsStr(body, "T08") {
|
|
t.Error("expected T08 in search results")
|
|
}
|
|
}
|
|
|
|
func TestSearch_FindsDocument(t *testing.T) {
|
|
srv := setupTestServer(t)
|
|
|
|
req := httptest.NewRequest(http.MethodGet, "/search?q=checker", nil)
|
|
w := httptest.NewRecorder()
|
|
srv.Router.ServeHTTP(w, req)
|
|
|
|
body := w.Body.String()
|
|
if !containsStr(body, "checker/CLAUDE.md") {
|
|
t.Error("expected checker CLAUDE.md in search results")
|
|
}
|
|
}
|
|
|
|
func TestSearch_FindsReport(t *testing.T) {
|
|
srv := setupTestServer(t)
|
|
|
|
req := httptest.NewRequest(http.MethodGet, "/search?q=prolaze", nil)
|
|
w := httptest.NewRecorder()
|
|
srv.Router.ServeHTTP(w, req)
|
|
|
|
body := w.Body.String()
|
|
if !containsStr(body, "T01-report.md") {
|
|
t.Error("expected T01 report in search results")
|
|
}
|
|
}
|
|
|
|
func TestSearch_EmptyQuery(t *testing.T) {
|
|
srv := setupTestServer(t)
|
|
|
|
req := httptest.NewRequest(http.MethodGet, "/search?q=", nil)
|
|
w := httptest.NewRecorder()
|
|
srv.Router.ServeHTTP(w, req)
|
|
|
|
if w.Code != http.StatusOK {
|
|
t.Fatalf("expected 200, got %d", w.Code)
|
|
}
|
|
if w.Body.Len() != 0 {
|
|
t.Errorf("expected empty response for empty query, got %d bytes", w.Body.Len())
|
|
}
|
|
}
|
|
|
|
func TestSearch_NoResults(t *testing.T) {
|
|
srv := setupTestServer(t)
|
|
|
|
req := httptest.NewRequest(http.MethodGet, "/search?q=xyznepostoji", nil)
|
|
w := httptest.NewRecorder()
|
|
srv.Router.ServeHTTP(w, req)
|
|
|
|
body := w.Body.String()
|
|
if !containsStr(body, "Nema rezultata") {
|
|
t.Error("expected 'Nema rezultata' message")
|
|
}
|
|
}
|
|
|
|
func TestSearch_CaseInsensitive(t *testing.T) {
|
|
srv := setupTestServer(t)
|
|
|
|
req := httptest.NewRequest(http.MethodGet, "/search?q=CODER", nil)
|
|
w := httptest.NewRecorder()
|
|
srv.Router.ServeHTTP(w, req)
|
|
|
|
body := w.Body.String()
|
|
if !containsStr(body, "coder") {
|
|
t.Error("expected case-insensitive match for 'CODER'")
|
|
}
|
|
}
|
|
|
|
func TestSearch_HasSnippet(t *testing.T) {
|
|
srv := setupTestServer(t)
|
|
|
|
req := httptest.NewRequest(http.MethodGet, "/search?q=kodiranja", nil)
|
|
w := httptest.NewRecorder()
|
|
srv.Router.ServeHTTP(w, req)
|
|
|
|
body := w.Body.String()
|
|
if !containsStr(body, "kodiranja") {
|
|
t.Error("expected snippet with 'kodiranja' text")
|
|
}
|
|
}
|