summaryrefslogtreecommitdiff
path: root/internal/server/handlers/handlers_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/server/handlers/handlers_test.go')
-rw-r--r--internal/server/handlers/handlers_test.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/internal/server/handlers/handlers_test.go b/internal/server/handlers/handlers_test.go
index b2ae43e..75d25a2 100644
--- a/internal/server/handlers/handlers_test.go
+++ b/internal/server/handlers/handlers_test.go
@@ -37,6 +37,9 @@ func TestRoutes(t *testing.T) {
want int
}{
{"home", http.MethodGet, "/", http.StatusOK},
+ {"stylesheet", http.MethodGet, "/css/style.css", http.StatusOK},
+ {"missing stylesheet", http.MethodGet, "/css/nope.css", http.StatusNotFound},
+ {"templates not served", http.MethodGet, "/templates/index.html", http.StatusNotFound},
{"unknown path", http.MethodGet, "/nonsense", http.StatusNotFound},
{"wrong method on home", http.MethodPost, "/", http.StatusMethodNotAllowed},
}
@@ -51,6 +54,35 @@ func TestRoutes(t *testing.T) {
}
}
+func TestStylesheetIsServed(t *testing.T) {
+ mux := Routes(newTestConfig())
+
+ rec := get(t, mux, http.MethodGet, "/css/style.css")
+ if rec.Code != http.StatusOK {
+ t.Fatalf("got status %d, want 200", rec.Code)
+ }
+
+ if ct := rec.Header().Get("Content-Type"); !strings.HasPrefix(ct, "text/css") {
+ t.Errorf("got Content-Type %q, want text/css", ct)
+ }
+ if rec.Body.Len() == 0 {
+ t.Error("stylesheet served empty")
+ }
+}
+
+func TestHomeLinksServedStylesheet(t *testing.T) {
+ mux := Routes(newTestConfig())
+
+ body := get(t, mux, http.MethodGet, "/").Body.String()
+ if !strings.Contains(body, `href="/css/style.css"`) {
+ t.Fatalf("home does not link the stylesheet, got:\n%s", body)
+ }
+
+ if code := get(t, mux, http.MethodGet, "/css/style.css").Code; code != http.StatusOK {
+ t.Errorf("linked stylesheet returned %d, want 200", code)
+ }
+}
+
func TestHomeRendersInstanceName(t *testing.T) {
cfg := newTestConfig()
cfg.Instance.Name = "Prodavnica123"