diff options
| author | Craig Jennings <c@cjennings.net> | 2026-06-25 01:10:49 -0400 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-06-25 01:10:49 -0400 |
| commit | 4266923daf6f137fbe2897334b7669f7fb4633c8 (patch) | |
| tree | 42144ed5202f4c19e6f774cbc3688b0273777b7a /tests | |
| parent | efd3cdce5b3aebfdb3e02460d1ec0434cef85949 (diff) | |
| download | emacs-wttrin-4266923daf6f137fbe2897334b7669f7fb4633c8.tar.gz emacs-wttrin-4266923daf6f137fbe2897334b7669f7fb4633c8.zip | |
fix: refresh mode-line weather when the default location changes
Pressing d to promote a displayed location to the favorite changed wttrin-favorite-location but left the mode-line untouched. Its cache still held the old location's weather. The next scheduled refetch could be up to an hour away, so the hover tooltip kept showing the previous default.
wttrin--set-favorite-location now detects a real change and, when the mode-line is active, clears the stale cache and fetches the new location at once via a new wttrin--mode-line-refresh-now helper. The tooltip switches within seconds instead of waiting for the timer.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test-wttrin-make-default.el | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/test-wttrin-make-default.el b/tests/test-wttrin-make-default.el index c6f845b..623200c 100644 --- a/tests/test-wttrin-make-default.el +++ b/tests/test-wttrin-make-default.el @@ -61,6 +61,51 @@ unbound); persistence is left to `wttrin--savehist-register'." (should (memq 'wttrin-favorite-location savehist-additional-variables)))) ;;; -------------------------------------------------------------------------- +;;; mode-line refresh when the favorite changes +;;; -------------------------------------------------------------------------- + +;;; Normal Cases + +(ert-deftest test-wttrin--set-favorite-location-normal-mode-line-on-refreshes () + "Normal: changing the favorite while the mode-line is active clears the +stale cache and fetches fresh weather for the new location immediately." + (let ((wttrin-favorite-location "Oslo, NO") + (wttrin-mode-line-mode t) + (wttrin--mode-line-cache (cons 0.0 "Oslo, NO: sun")) + (fetched nil)) + (cl-letf (((symbol-function 'wttrin--mode-line-fetch-weather) + (lambda () (setq fetched t))) + ((symbol-function 'wttrin--mode-line-set-placeholder) + (lambda () nil))) + (wttrin--set-favorite-location "Paris, FR") + (should (null wttrin--mode-line-cache)) + (should fetched)))) + +;;; Boundary Cases + +(ert-deftest test-wttrin--set-favorite-location-boundary-mode-line-off-no-fetch () + "Boundary: with the mode-line inactive, changing the favorite does not fetch." + (let ((wttrin-favorite-location "Oslo, NO") + (wttrin-mode-line-mode nil) + (fetched nil)) + (cl-letf (((symbol-function 'wttrin--mode-line-fetch-weather) + (lambda () (setq fetched t)))) + (wttrin--set-favorite-location "Paris, FR") + (should-not fetched)))) + +(ert-deftest test-wttrin--set-favorite-location-boundary-unchanged-no-fetch () + "Boundary: re-promoting the current favorite does not refetch the mode-line." + (let ((wttrin-favorite-location "Paris, FR") + (wttrin-mode-line-mode t) + (fetched nil)) + (cl-letf (((symbol-function 'wttrin--mode-line-fetch-weather) + (lambda () (setq fetched t))) + ((symbol-function 'wttrin--mode-line-set-placeholder) + (lambda () nil))) + (wttrin--set-favorite-location "Paris, FR") + (should-not fetched)))) + +;;; -------------------------------------------------------------------------- ;;; wttrin-make-default ;;; -------------------------------------------------------------------------- |
