aboutsummaryrefslogtreecommitdiff
path: root/tests/test-chime-format-event-for-tooltip.el
blob: a9a53a51159aad08c42a2d78cb780650c8930347 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
;;; test-chime-format-event-for-tooltip.el --- Tests for chime--format-event-for-tooltip -*- lexical-binding: t; -*-

;; Copyright (C) 2024 Craig Jennings

;; Author: Craig Jennings <c@cjennings.net>

;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; Unit tests for chime--format-event-for-tooltip function.
;; Tests cover normal cases, boundary cases, and error cases.

;;; Code:

;; Initialize package system for batch mode
(when noninteractive
  (package-initialize))

(require 'ert)

;; Load dependencies required by chime
(require 'dash)
(require 'alert)
(require 'async)
(require 'org-agenda)

;; Load chime from parent directory
(load (expand-file-name "../chime.el") nil t)

;; Load test utilities
(require 'testutil-general (expand-file-name "testutil-general.el"))
(require 'testutil-time (expand-file-name "testutil-time.el"))

;;; Setup and Teardown

(defun test-chime-format-event-for-tooltip-setup ()
  "Setup function run before each test."
  (chime-create-test-base-dir))

(defun test-chime-format-event-for-tooltip-teardown ()
  "Teardown function run after each test."
  (chime-delete-test-base-dir))

;;; Normal Cases

(ert-deftest test-chime-format-event-for-tooltip-normal-minutes ()
  "Test formatting event with minutes until event.

REFACTORED: Uses dynamic timestamps"
  (test-chime-format-event-for-tooltip-setup)
  (unwind-protect
      (let* ((time (test-time-tomorrow-at 14 10))
             (timestamp (test-timestamp-string time))
             (result (chime--format-event-for-tooltip
                      timestamp
                      10
                      "Team Meeting")))
        (should (stringp result))
        (should (string-match-p "Team Meeting" result))
        (should (string-match-p "02:10 PM" result))
        (should (string-match-p "10 minutes" result)))
    (test-chime-format-event-for-tooltip-teardown)))

(ert-deftest test-chime-format-event-for-tooltip-normal-hours ()
  "Test formatting event with hours until event.

REFACTORED: Uses dynamic timestamps"
  (test-chime-format-event-for-tooltip-setup)
  (unwind-protect
      (let* ((time (test-time-tomorrow-at 15 30))
             (timestamp (test-timestamp-string time))
             (result (chime--format-event-for-tooltip
                      timestamp
                      90
                      "Afternoon Meeting")))
        (should (stringp result))
        (should (string-match-p "Afternoon Meeting" result))
        (should (string-match-p "03:30 PM" result))
        (should (string-match-p "1 hour" result)))
    (test-chime-format-event-for-tooltip-teardown)))

(ert-deftest test-chime-format-event-for-tooltip-normal-multiple-hours ()
  "Test formatting event with multiple hours until event.

REFACTORED: Uses dynamic timestamps"
  (test-chime-format-event-for-tooltip-setup)
  (unwind-protect
      (let* ((time (test-time-tomorrow-at 17 0))
             (timestamp (test-timestamp-string time))
             (result (chime--format-event-for-tooltip
                      timestamp
                      300
                      "End of Day Review")))
        (should (stringp result))
        (should (string-match-p "End of Day Review" result))
        (should (string-match-p "05:00 PM" result))
        (should (string-match-p "5 hours" result)))
    (test-chime-format-event-for-tooltip-teardown)))

;;; Boundary Cases

(ert-deftest test-chime-format-event-for-tooltip-boundary-exactly-one-day ()
  "Test formatting event exactly 1 day away (1440 minutes).

REFACTORED: Uses dynamic timestamps"
  (test-chime-format-event-for-tooltip-setup)
  (unwind-protect
      (let* ((time (test-time-days-from-now 1 9 0))
             (timestamp (test-timestamp-string time))
             (result (chime--format-event-for-tooltip
                      timestamp
                      1440
                      "Tomorrow Event")))
        (should (stringp result))
        (should (string-match-p "Tomorrow Event" result))
        (should (string-match-p "09:00 AM" result))
        (should (string-match-p "in 1 day" result)))
    (test-chime-format-event-for-tooltip-teardown)))

(ert-deftest test-chime-format-event-for-tooltip-boundary-multiple-days ()
  "Test formatting event multiple days away.

REFACTORED: Uses dynamic timestamps"
  (test-chime-format-event-for-tooltip-setup)
  (unwind-protect
      (let* ((time (test-time-days-from-now 3 10 0))
             (timestamp (test-timestamp-string time))
             (result (chime--format-event-for-tooltip
                      timestamp
                      4320  ; 3 days
                      "Future Meeting")))
        (should (stringp result))
        (should (string-match-p "Future Meeting" result))
        (should (string-match-p "10:00 AM" result))
        (should (string-match-p "in 3 days" result)))
    (test-chime-format-event-for-tooltip-teardown)))

(ert-deftest test-chime-format-event-for-tooltip-boundary-just-under-one-day ()
  "Test formatting event just under 1 day away (1439 minutes).

REFACTORED: Uses dynamic timestamps"
  (test-chime-format-event-for-tooltip-setup)
  (unwind-protect
      (let* ((time (test-time-tomorrow-at 8 59))
             (timestamp (test-timestamp-string time))
             (result (chime--format-event-for-tooltip
                      timestamp
                      1439
                      "Almost Tomorrow")))
        (should (stringp result))
        (should (string-match-p "Almost Tomorrow" result))
        (should (string-match-p "08:59 AM" result))
        ;; Should show hours/minutes, not days
        (should (string-match-p "23 hours" result)))
    (test-chime-format-event-for-tooltip-teardown)))

(ert-deftest test-chime-format-event-for-tooltip-boundary-zero-minutes ()
  "Test formatting event happening right now (0 minutes).

REFACTORED: Uses dynamic timestamps"
  (test-chime-format-event-for-tooltip-setup)
  (unwind-protect
      (let* ((time (test-time-today-at 14 0))
             (timestamp (test-timestamp-string time))
             (result (chime--format-event-for-tooltip
                      timestamp
                      0
                      "Current Event")))
        (should (stringp result))
        (should (string-match-p "Current Event" result))
        (should (string-match-p "02:00 PM" result))
        (should (string-match-p "right now" result)))
    (test-chime-format-event-for-tooltip-teardown)))

(ert-deftest test-chime-format-event-for-tooltip-boundary-one-minute ()
  "Test formatting event 1 minute away.

REFACTORED: Uses dynamic timestamps"
  (test-chime-format-event-for-tooltip-setup)
  (unwind-protect
      (let* ((time (test-time-today-at 14 1))
             (timestamp (test-timestamp-string time))
             (result (chime--format-event-for-tooltip
                      timestamp
                      1
                      "Imminent Event")))
        (should (stringp result))
        (should (string-match-p "Imminent Event" result))
        (should (string-match-p "02:01 PM" result))
        (should (string-match-p "1 minute" result)))
    (test-chime-format-event-for-tooltip-teardown)))

(ert-deftest test-chime-format-event-for-tooltip-boundary-long-title ()
  "Test formatting event with very long title.

REFACTORED: Uses dynamic timestamps"
  (test-chime-format-event-for-tooltip-setup)
  (unwind-protect
      (let* ((time (test-time-today-at 14 10))
             (timestamp (test-timestamp-string time))
             (long-title (make-string 200 ?x))
             (result (chime--format-event-for-tooltip
                      timestamp
                      10
                      long-title)))
        (should (stringp result))
        (should (string-match-p long-title result)))
    (test-chime-format-event-for-tooltip-teardown)))

;;; Error Cases

(ert-deftest test-chime-format-event-for-tooltip-error-nil-title ()
  "Test formatting with nil title doesn't crash.

REFACTORED: Uses dynamic timestamps"
  (test-chime-format-event-for-tooltip-setup)
  (unwind-protect
      (let* ((time (test-time-today-at 14 10))
             (timestamp (test-timestamp-string time)))
        ;; Should not crash with nil title
        (should-not (condition-case nil
                        (progn
                          (chime--format-event-for-tooltip
                           timestamp
                           10
                           nil)
                          nil)
                      (error t))))
    (test-chime-format-event-for-tooltip-teardown)))

(ert-deftest test-chime-format-event-for-tooltip-error-empty-title ()
  "Test formatting with empty title.

REFACTORED: Uses dynamic timestamps"
  (test-chime-format-event-for-tooltip-setup)
  (unwind-protect
      (let* ((time (test-time-today-at 14 10))
             (timestamp (test-timestamp-string time))
             (result (chime--format-event-for-tooltip
                      timestamp
                      10
                      "")))
        (should (stringp result))
        (should (string-match-p "02:10 PM" result)))
    (test-chime-format-event-for-tooltip-teardown)))

(provide 'test-chime-format-event-for-tooltip)
;;; test-chime-format-event-for-tooltip.el ends here