a love letter to tangled (android, iOS, and a search API)
1package view
2
3import (
4 "net/http"
5 "net/http/httptest"
6 "strings"
7 "testing"
8)
9
10func TestHandlerRendersSearchHome(t *testing.T) {
11 req := httptest.NewRequest(http.MethodGet, "/", nil)
12 rec := httptest.NewRecorder()
13
14 Handler().ServeHTTP(rec, req)
15
16 if rec.Code != http.StatusOK {
17 t.Fatalf("expected status 200, got %d", rec.Code)
18 }
19
20 body := rec.Body.String()
21 if !strings.Contains(body, "Search Tangled") {
22 t.Fatalf("expected search home content, got body %q", body)
23 }
24 if !strings.Contains(body, "GET /actors/desertthunder.dev") {
25 t.Fatalf("expected search empty state example, got body %q", body)
26 }
27 if strings.Contains(body, "Health Endpoints") {
28 t.Fatalf("expected search home page, got health page content")
29 }
30}
31
32func TestHandlerRendersDocsIndex(t *testing.T) {
33 req := httptest.NewRequest(http.MethodGet, "/docs", nil)
34 rec := httptest.NewRecorder()
35
36 Handler().ServeHTTP(rec, req)
37
38 if rec.Code != http.StatusOK {
39 t.Fatalf("expected status 200, got %d", rec.Code)
40 }
41
42 body := rec.Body.String()
43 if !strings.Contains(body, "API Documentation") {
44 t.Fatalf("expected docs page content, got body %q", body)
45 }
46 if strings.Contains(body, "template error") {
47 t.Fatalf("expected docs page render, got template error")
48 }
49}