clone

a self-hosted multitenant nostr relay with sites, file storage, git hosting, and inbox and outbox delivery

feat/tinyagent
tinyrelay / tinyclient / social_navigation_test.go
social_navigation_test.go 1.7K
1package tinyclient23import (4 "net/http"5 "net/http/httptest"6 "net/url"7 "strings"8 "testing"910 "github.com/FelineStateMachine/tinyrelay/internal/policy"11)1213func TestSocialNavigationSharesOneRail(t *testing.T) {14 for _, kind := range []string{"feed", "notes", "posts", "photos", "videos", "podcasts"} {15 t.Run(kind, func(t *testing.T) {16 b := &socialBackend{fakeBackend: fakeBackend{policy: policy.Defaults(strings.Repeat("a", 64))}}17 a, err := New(b, Options{})18 if err != nil {19 t.Fatal(err)20 }21 r := httptest.NewRecorder()22 a.ServeHTTP(r, httptest.NewRequest(http.MethodGet, "/social?kind="+kind, nil))23 body := r.Body.String()24 for _, marker := range []string{`aria-label="Social"`, ">/feed</a>", ">/notes</a>", ">/posts</a>", ">/photos</a>", ">/videos</a>", ">/podcasts</a>", `href="/social/profile"`, `href="/social/profile?author=`} {25 if !strings.Contains(body, marker) {26 t.Errorf("missing %q", marker)27 }28 }29 if r.Code != http.StatusOK || strings.Contains(body, "class=") || strings.Contains(body, "\u00b7") {30 t.Fatalf("invalid social page: status=%d", r.Code)31 }32 if !strings.Contains(body, `aria-current="page">/`+kind+`</a>`) {33 t.Fatal("selected social view is missing")34 }35 })36 }37}3839func TestSocialViewAliasesAndMobileTitle(t *testing.T) {40 for _, query := range []url.Values{{"kind": {"articles"}}, {"kinds": {"30023"}}} {41 view := socialView(query)42 if view.Key != "posts" || view.Label != "Posts" {43 t.Fatalf("article alias = %+v", view)44 }45 }46 header := mobileHeader(PageData{Tab: "social", Path: "/social", Query: url.Values{"kind": {"photos"}}, Slug: "tiny"})47 if header.Title != "Photos" || header.Subtitle != "Social" || header.BackURL != "/social" {48 t.Fatalf("category mobile header = %+v", header)49 }50}