blob: 3858050ac072227f646c2aa4af872a0766d86250 (
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
|
;;; test-wttrin-mode-line-force-refresh.el --- Tests for wttrin-mode-line-force-refresh -*- lexical-binding: t; -*-
;; Copyright (C) 2025-2026 Craig Jennings
;;; Commentary:
;; Unit tests for wttrin-mode-line-force-refresh function.
;; Tests the right-click handler that force-refreshes mode-line weather.
;;; Code:
(require 'ert)
(require 'wttrin)
(require 'testutil-wttrin)
;;; Setup and Teardown
(defun test-wttrin-mode-line-force-refresh-setup ()
"Setup for mode-line-force-refresh tests."
(testutil-wttrin-setup)
(setq wttrin-mode-line-string nil)
(setq wttrin--mode-line-cache nil))
(defun test-wttrin-mode-line-force-refresh-teardown ()
"Teardown for mode-line-force-refresh tests."
(testutil-wttrin-teardown)
(setq wttrin-mode-line-string nil)
(setq wttrin--mode-line-cache nil))
;;; Normal Cases
(ert-deftest test-wttrin-mode-line-force-refresh-normal-calls-fetch ()
"Right-click should trigger a weather fetch."
(test-wttrin-mode-line-force-refresh-setup)
(unwind-protect
(let ((wttrin-favorite-location "Paris")
(fetch-called nil))
(cl-letf (((symbol-function 'wttrin--mode-line-fetch-weather)
(lambda () (setq fetch-called t))))
(wttrin-mode-line-force-refresh)
(should fetch-called)))
(test-wttrin-mode-line-force-refresh-teardown)))
(ert-deftest test-wttrin-mode-line-force-refresh-normal-sets-force-flag ()
"The fetch should run with force-refresh bound to t to bypass cache."
(test-wttrin-mode-line-force-refresh-setup)
(unwind-protect
(let ((wttrin-favorite-location "Paris")
(force-flag-during-fetch nil))
(cl-letf (((symbol-function 'wttrin--mode-line-fetch-weather)
(lambda () (setq force-flag-during-fetch wttrin--force-refresh))))
(wttrin-mode-line-force-refresh)
(should force-flag-during-fetch)))
(test-wttrin-mode-line-force-refresh-teardown)))
;;; Boundary Cases
(ert-deftest test-wttrin-mode-line-force-refresh-boundary-nil-location-is-noop ()
"When no favorite location is set, right-click should do nothing."
(test-wttrin-mode-line-force-refresh-setup)
(unwind-protect
(let ((wttrin-favorite-location nil)
(fetch-called nil))
(cl-letf (((symbol-function 'wttrin--mode-line-fetch-weather)
(lambda () (setq fetch-called t))))
(wttrin-mode-line-force-refresh)
(should-not fetch-called)))
(test-wttrin-mode-line-force-refresh-teardown)))
(provide 'test-wttrin-mode-line-force-refresh)
;;; test-wttrin-mode-line-force-refresh.el ends here
|