From 4d396a3582b009c03b9c903549b1e9312f8707d1 Mon Sep 17 00:00:00 2001
From: Sulthan Zaki
Nothing new. Every series is caught up to its latest chapter.
+{{else if eq .Tab "archived"}} +Nothing archived. Shelve a series to park it here — it keeps getting checked for new chapters.
+{{else if eq .Tab "finished"}} +Nothing finished yet.
{{else}}Nothing here yet. Bookmarks appear once the userscript records a chapter. diff --git a/backend/web_test.go b/backend/web_test.go index 315c07f..edbf541 100644 --- a/backend/web_test.go +++ b/backend/web_test.go @@ -308,8 +308,8 @@ func TestCardHxTargetIsValidSelectorForColonKey(t *testing.T) { body := rr.Body.String() want := `hx-target="[id='card-asura:solo']"` - if strings.Count(body, want) != 3 { - t.Fatalf("body has %d occurrences of %s, want 3 (favorite button, delete button, chapter form)", + if strings.Count(body, want) != 5 { + t.Fatalf("body has %d occurrences of %s, want 5 (favorite, archive, finish, delete buttons, chapter form)", strings.Count(body, want), want) } if strings.Contains(body, `hx-target="#card-asura:solo"`) { @@ -675,3 +675,58 @@ func TestUIStatusDoesNotReorderList(t *testing.T) { t.Fatalf("UpdatedAt moved %d -> %d", before.UpdatedAt, after.UpdatedAt) } } + +func TestCardShowsStatusControls(t *testing.T) { + cfg := webConfig() + srv, store := newWebTestServer(t, cfg) + seedStatusRows(t, store) + + cases := []struct { + tab string + want, dontWant []string + }{ + // A series being read can be shelved or completed, not restored. + {"all", []string{`hx-vals='{"status":"archived"}'`, `hx-vals='{"status":"finished"}'`}, nil}, + // An archived one can come back or be completed. + {"archived", []string{`hx-vals='{"status":"reading"}'`, `hx-vals='{"status":"finished"}'`}, nil}, + // A finished one can only come back. + {"finished", []string{`hx-vals='{"status":"reading"}'`}, []string{`hx-vals='{"status":"finished"}'`}}, + } + for _, tc := range cases { + t.Run(tc.tab, func(t *testing.T) { + req := httptest.NewRequest(http.MethodGet, "/ui/list?tab="+tc.tab, nil) + req.AddCookie(sessionCookie(t, cfg)) + rr := httptest.NewRecorder() + srv.ServeHTTP(rr, req) + + body := rr.Body.String() + for _, w := range tc.want { + if !strings.Contains(body, w) { + t.Fatalf("tab %s missing control %s", tc.tab, w) + } + } + for _, d := range tc.dontWant { + if strings.Contains(body, d) { + t.Fatalf("tab %s offered %s", tc.tab, d) + } + } + }) + } +} + +func TestAppRendersNewTabs(t *testing.T) { + cfg := webConfig() + srv, store := newWebTestServer(t, cfg) + seedStatusRows(t, store) + + req := httptest.NewRequest(http.MethodGet, "/", nil) + req.AddCookie(sessionCookie(t, cfg)) + rr := httptest.NewRecorder() + srv.ServeHTTP(rr, req) + + for _, want := range []string{`href="/?tab=archived"`, `href="/?tab=finished"`} { + if !strings.Contains(rr.Body.String(), want) { + t.Fatalf("app page missing %s", want) + } + } +}