1package main23import (4 "io"5 "net/http"6 "net/http/httptest"7 "strings"8 "testing"910 "github.com/FelineStateMachine/atlas/internal/bundle/bundletest"11)1213func testServer(t *testing.T) (*server, string) {14 t.Helper()15 dir := t.TempDir()16 install(t, dir, "hollowmere-jan.atlas", bundletest.Spec{17 Slug: "hollowmere", Title: "Hollowmere", CreatedAt: "2026-01-01T00:00:00Z",18 })19 install(t, dir, "hollowmere-feb.atlas", bundletest.Spec{20 Slug: "hollowmere", Title: "Hollowmere", CreatedAt: "2026-02-01T00:00:00Z",21 Worlds: []bundletest.WorldSpec{{22 Slug: "overworld",23 Pins: []bundletest.Pin{{Title: "Gate"}, {Title: "Well"}},24 Merged: fixtureMerged(),25 }},26 })27 return newServer(&library{dir: dir}, &workshop{bundles: dir}), dir28}2930func newTestSite(t *testing.T, s *server) *httptest.Server {31 t.Helper()32 ts := httptest.NewServer(s.routes())33 t.Cleanup(ts.Close)34 return ts35}3637func get(t *testing.T, ts *httptest.Server, path string) (int, string) {38 t.Helper()39 response, err := ts.Client().Get(ts.URL + path)40 if err != nil {41 t.Fatal(err)42 }43 defer response.Body.Close()44 body, err := io.ReadAll(response.Body)45 if err != nil {46 t.Fatal(err)47 }48 return response.StatusCode, string(body)49}5051func TestPages(t *testing.T) {52 server, _ := testServer(t)53 ts := newTestSite(t, server)5455 status, body := get(t, ts, "/")56 if status != http.StatusOK {57 t.Fatalf("collection answered %d", status)58 }59 for _, want := range []string{"Hollowmere", "hollowmere", "ign-wiki"} {60 if !strings.Contains(body, want) {61 t.Errorf("collection page misses %q", want)62 }63 }6465 status, body = get(t, ts, "/volume/hollowmere")66 if status != http.StatusOK {67 t.Fatalf("volume page answered %d", status)68 }69 for _, want := range []string{70 "hollowmere-feb.atlas", "hollowmere-jan.atlas", "serving",71 "annotation", "cartography", "structure", "Old Well", "name 200px away",72 } {73 if !strings.Contains(body, want) {74 t.Errorf("volume page misses %q", want)75 }76 }77 // The serving mark belongs to the newer build alone.78 if strings.Index(body, "hollowmere-feb.atlas") > strings.Index(body, "hollowmere-jan.atlas") {79 t.Error("builds are not newest first")80 }8182 if status, _ := get(t, ts, "/volume/nowhere"); status != http.StatusNotFound {83 t.Errorf("unknown game answered %d", status)84 }85 if status, _ := get(t, ts, "/static/style.css"); status != http.StatusOK {86 t.Errorf("stylesheet answered %d", status)87 }8889 status, body = get(t, ts, "/sources")90 if status != http.StatusOK {91 t.Fatalf("sources page answered %d", status)92 }93 for _, want := range []string{94 "MapGenie", "IGN Wiki", "Piggyback", "Referer",95 "raster", "icons", "locations", "metadata",96 "Rebuild pyramids", "Recompose bundles",97 } {98 if !strings.Contains(body, want) {99 t.Errorf("sources page misses %q", want)100 }101 }102}