aboutsummaryrefslogtreecommitdiffstats
path: root/internal/web/web_test.go
diff options
context:
space:
mode:
authorgrm <grm@eyesin.space>2026-09-12 12:33:57 +0300
committergrm <grm@eyesin.space>2026-09-12 12:33:57 +0300
commitdd13e4b73a105ee416b6cfd8eb19b217622c0031 (patch)
tree93ce503a09b99115efeeee6cd1a85781c1674b02 /internal/web/web_test.go
parent2b450b66fee4906e746f6e04a6d07a72ff2faf64 (diff)
downloadblogspace-dd13e4b73a105ee416b6cfd8eb19b217622c0031.tar.gz
blogspace-dd13e4b73a105ee416b6cfd8eb19b217622c0031.tar.bz2
blogspace-dd13e4b73a105ee416b6cfd8eb19b217622c0031.zip
Add announcements: blog-wide notices on every page and post
A blog can have any number of announcements ("sections" in the schema): a book club's next meeting, this month's pick, a holiday closure. Each has a placement (above or below the posts, or under the menu when the menu is a left sidebar), a look (highlighted, warning, plain), an order, and an on/off switch so recurring notices can be kept around while hidden. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Sd8UPWrvyYCLj97JexNw3A
Diffstat (limited to 'internal/web/web_test.go')
-rw-r--r--internal/web/web_test.go21
1 files changed, 19 insertions, 2 deletions
diff --git a/internal/web/web_test.go b/internal/web/web_test.go
index 6c8072e..002f18a 100644
--- a/internal/web/web_test.go
+++ b/internal/web/web_test.go
@@ -50,7 +50,7 @@ func TestHostRoutingWithoutDB(t *testing.T) {
func TestRootRoutePrecedence(t *testing.T) {
cfg := &config.Config{BaseDomain: "example.com", JWTSecret: []byte("x"), MaxUploadBytes: 1 << 20}
s := NewServer(cfg, nil)
- for path, want := range map[string]int{"/webadmin": 200, "/healthz": 200, "/dashboard": 303, "/admin/": 303, "/b/alice/posts": 303, "/account/password": 303} {
+ for path, want := range map[string]int{"/webadmin": 200, "/healthz": 200, "/dashboard": 303, "/admin/": 303, "/b/alice/posts": 303, "/b/alice/announcements": 303, "/account/password": 303} {
rec := httptest.NewRecorder()
req := httptest.NewRequest("GET", path, nil)
req.Host = "example.com"
@@ -86,7 +86,7 @@ func TestAllTemplatesParse(t *testing.T) {
tpl := newTemplates(false, funcs)
for _, name := range []string{"auth/login.html", "dashboard/overview.html", "dashboard/pages.html", "dashboard/page_form.html",
"dashboard/posts.html", "dashboard/post_form.html", "dashboard/design.html", "dashboard/images.html", "dashboard/settings.html",
- "dashboard/password.html", "dashboard/confirm.html", "admin/index.html", "admin/new_user.html", "admin/delete_user.html",
+ "dashboard/password.html", "dashboard/confirm.html", "dashboard/sections.html", "dashboard/section_form.html", "admin/index.html", "admin/new_user.html", "admin/delete_user.html",
"blog/page.html", "blog/post.html", "blog/404.html"} {
if _, err := tpl.get(name); err != nil {
t.Errorf("%s: %v", name, err)
@@ -120,3 +120,20 @@ func TestAppendImageMD(t *testing.T) {
t.Errorf("nil image should not change the body: %q", got)
}
}
+
+func TestSplitSections(t *testing.T) {
+ secs := []store.Section{{ID: 1, Placement: "above"}, {ID: 2, Placement: "below"}, {ID: 3, Placement: "sidebar"}}
+ above, below, sidebar := splitSections(secs, true)
+ if len(above) != 1 || len(below) != 1 || len(sidebar) != 1 || sidebar[0].ID != 3 {
+ t.Errorf("with sidebar: %v %v %v", above, below, sidebar)
+ }
+ above, _, sidebar = splitSections(secs, false)
+ if len(above) != 2 || len(sidebar) != 0 || above[1].ID != 3 { // sidebar falls back to above, keeping order
+ t.Errorf("without sidebar: %v %v", above, sidebar)
+ }
+ sec := &store.Section{Placement: "footer", Style: "<script>"}
+ normalizeSection(sec)
+ if sec.Placement != "above" || sec.Style != "note" {
+ t.Errorf("normalize: %+v", sec)
+ }
+}