oficina / calendar Public

Clone
git clone https://amadan.net/oficina/calendar

Plain git — no account needed to clone.

Download

Download this file

1package calendartest
2
3import (
4 "regexp"
5 "testing"
6)
7
8// The view switcher keeps the date you were looking at, through Month too.
9// A month URL names only the month, so the switcher carries the day as
10// ?date= and Month's Day and Week tabs go back to it, not to the 1st.
11func TestViewTabsKeepTheSelectedDateThroughMonth(t *testing.T) {
12 app, session := signedIn(t, "someone@example.com")
13 h := app.Handler()
14 tab := func(path, label string) string {
15 t.Helper()
16 rec := getAs(t, h, session, path)
17 if rec.Code != 200 {
18 t.Fatalf("GET %s: %d", path, rec.Code)
19 }
20 m := regexp.MustCompile(`<a cal-tab="` + label + `" href="([^"]*)"`).FindStringSubmatch(rec.Body.String())
21 if m == nil {
22 t.Fatalf("GET %s: no %s tab", path, label)
23 }
24 return m[1]
25 }
26 for _, c := range []struct{ path, label, want string }{
27 {"/day/2026-09-24", "Month", "/month/2026-09?date=2026-09-24"},
28 {"/week/2026-09-24", "Month", "/month/2026-09?date=2026-09-21"},
29 {"/agenda?from=2026-09-24", "Month", "/month/2026-09?date=2026-09-24"},
30 {"/month/2026-09?date=2026-09-24", "Day", "/day/2026-09-24"},
31 {"/month/2026-09?date=2026-09-24", "Week", "/week/2026-09-24"},
32 {"/month/2026-09?date=2026-09-24", "Agenda", "/agenda?from=2026-09-24"},
33 // A date outside the month, or none, falls back to the 1st (this
34 // month is not the current one, where it would be today).
35 {"/month/2026-09?date=2026-10-02", "Day", "/day/2026-09-01"},
36 {"/month/2020-02", "Week", "/week/2020-02-01"},
37 } {
38 if got := tab(c.path, c.label); got != c.want {
39 t.Errorf("%s: %s tab = %s, want %s", c.path, c.label, got, c.want)
40 }
41 }
42}
43