|
| 1 | +;;; magit-standup-test.el --- Tests for magit-standup -*- lexical-binding: t; -*- |
| 2 | + |
| 3 | +;;; Commentary: |
| 4 | + |
| 5 | +;; Buttercup tests for magit-standup. |
| 6 | + |
| 7 | +;;; Code: |
| 8 | + |
| 9 | +(require 'buttercup) |
| 10 | +(require 'magit-standup) |
| 11 | + |
| 12 | +(describe "magit-standup--since-date" |
| 13 | + (it "looks back 3 days on Monday (to Friday)" |
| 14 | + ;; Monday 2026-01-05 12:00:00 UTC — %u = 1 |
| 15 | + (let ((magit-standup-since-days-ago nil)) |
| 16 | + (cl-letf (((symbol-function 'current-time) |
| 17 | + (lambda () (encode-time 0 0 12 5 1 2026)))) |
| 18 | + (expect (magit-standup--since-date) :to-equal "2026-01-02")))) |
| 19 | + |
| 20 | + (it "looks back 1 day on Tuesday" |
| 21 | + ;; Tuesday 2026-01-06 12:00:00 UTC — %u = 2 |
| 22 | + (let ((magit-standup-since-days-ago nil)) |
| 23 | + (cl-letf (((symbol-function 'current-time) |
| 24 | + (lambda () (encode-time 0 0 12 6 1 2026)))) |
| 25 | + (expect (magit-standup--since-date) :to-equal "2026-01-05")))) |
| 26 | + |
| 27 | + (it "looks back 1 day on Wednesday" |
| 28 | + ;; Wednesday 2026-01-07 12:00:00 UTC — %u = 3 |
| 29 | + (let ((magit-standup-since-days-ago nil)) |
| 30 | + (cl-letf (((symbol-function 'current-time) |
| 31 | + (lambda () (encode-time 0 0 12 7 1 2026)))) |
| 32 | + (expect (magit-standup--since-date) :to-equal "2026-01-06")))) |
| 33 | + |
| 34 | + (it "looks back to Friday on Saturday (1 day)" |
| 35 | + ;; Saturday 2026-01-10 12:00:00 UTC — %u = 6 |
| 36 | + (let ((magit-standup-since-days-ago nil)) |
| 37 | + (cl-letf (((symbol-function 'current-time) |
| 38 | + (lambda () (encode-time 0 0 12 10 1 2026)))) |
| 39 | + (expect (magit-standup--since-date) :to-equal "2026-01-09")))) |
| 40 | + |
| 41 | + (it "looks back to Friday on Sunday (2 days)" |
| 42 | + ;; Sunday 2026-01-11 12:00:00 UTC — %u = 7 |
| 43 | + (let ((magit-standup-since-days-ago nil)) |
| 44 | + (cl-letf (((symbol-function 'current-time) |
| 45 | + (lambda () (encode-time 0 0 12 11 1 2026)))) |
| 46 | + (expect (magit-standup--since-date) :to-equal "2026-01-09")))) |
| 47 | + |
| 48 | + (it "uses custom override when magit-standup-since-days-ago is set" |
| 49 | + ;; Wednesday 2026-01-07 — would normally be 1 day back |
| 50 | + (let ((magit-standup-since-days-ago 7)) |
| 51 | + (cl-letf (((symbol-function 'current-time) |
| 52 | + (lambda () (encode-time 0 0 12 7 1 2026)))) |
| 53 | + (expect (magit-standup--since-date) :to-equal "2025-12-31"))))) |
| 54 | + |
| 55 | +(describe "magit-standup--format-org" |
| 56 | + (it "formats repo with commits as org headings" |
| 57 | + (expect (magit-standup--format-org |
| 58 | + '(("my-repo" . ("abc123 Fix bug" |
| 59 | + "def456 Add feature")))) |
| 60 | + :to-equal |
| 61 | + "* my-repo\n- abc123 Fix bug\n- def456 Add feature\n")) |
| 62 | + |
| 63 | + (it "shows placeholder when repo has no commits" |
| 64 | + (expect (magit-standup--format-org |
| 65 | + '(("empty-repo"))) |
| 66 | + :to-equal |
| 67 | + "* empty-repo\n- (no commits)\n")) |
| 68 | + |
| 69 | + (it "separates multiple repos with blank lines" |
| 70 | + (expect (magit-standup--format-org |
| 71 | + '(("repo-a" . ("abc Fix thing")) |
| 72 | + ("repo-b" . ("def Other thing")))) |
| 73 | + :to-equal |
| 74 | + (concat "* repo-a\n- abc Fix thing\n" |
| 75 | + "\n" |
| 76 | + "* repo-b\n- def Other thing\n")))) |
| 77 | + |
| 78 | +;;; magit-standup-test.el ends here |
0 commit comments