fix Select today in Logbook by default

Commit
d313467dec240499ad4d8a7cac940f132102f48e
Author
Marius Peter <dev@marius-peter.com>
Author date
Committer
Marius Peter <dev@marius-peter.com>
Committer date
Changed files
lib/web/handlers_logbook.ml
index 3d712076..23179cc9 100644..100644
@@ -351,8 +351,16 @@
351 351 let clamp lo hi v = max lo (min hi v) in
352 352 let year = query_int "year" (now_tm.Unix.tm_year + 1900) in
353 353 let month = clamp 1 12 (query_int "month" (now_tm.Unix.tm_mon + 1)) in
354 Added: let default_day =
355 Added: if
356 Added: Option.is_none (Dream.query request "day")
357 Added: && Option.is_none (Dream.query request "year")
358 Added: && Option.is_none (Dream.query request "month")
359 Added: then now_tm.Unix.tm_mday
360 Added: else 0
361 Added: in
354 362 let selected_date_number =
355 Removed: match query_int "day" 0 with
363 Added: match query_int "day" default_day with
356 364 | day when day >= 1 && day <= Calendar.days_in_month ~year ~month ->
357 365 Some day
358 366 | _ -> None
test/web/logbook.ml
index c1df6d73..8ef3100a 100644..100644
@@ -34,6 +34,23 @@
34 34 Alcotest.(check int)
35 35 "the feedback modal stays available" 200
36 36 (status (get c "/logbook?feedback=start")) );
37 Added: ( "the Logbook selects today by default",
38 Added: `Quick,
39 Added: fun () ->
40 Added: let c, now, _repo = clocked_client () in
41 Added: now := day 10;
42 Added: let _ = sign_in_new c in
43 Added: let page = body (get c "/logbook") in
44 Added: Alcotest.(check bool)
45 Added: "today is the selected day" true
46 Added: (Option.is_some
47 Added: (index_from ~needle:"aria-label=\"11: today\"" page 0));
48 Added: Alcotest.(check bool)
49 Added: "today's empty panel is displayed" true
50 Added: (Option.is_some
51 Added: (index_from
52 Added: ~needle:"No workout was recorded or planned on this day."
53 Added: page 0)) );
37 54 ( "the calendar marks the next routine workout after recovery",
38 55 `Quick,
39 56 fun () ->