summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-04-04 13:26:10 -0500
committerCraig Jennings <c@cjennings.net>2026-04-04 13:26:10 -0500
commitde99a2930bbe65d7c2ea04656caa18823068c182 (patch)
tree14c2300f48fe4ef0a29b0d3327e45a691e5672bb /tests
parent752e2f825b1ee3eb513e27f2c03bcaef30eec767 (diff)
downloademacs-wttrin-de99a2930bbe65d7c2ea04656caa18823068c182.tar.gz
emacs-wttrin-de99a2930bbe65d7c2ea04656caa18823068c182.zip
fix: emoji dimming can disagree with tooltip staleness
The emoji face (dimmed/normal) was frozen at the last update-display call, but the tooltip computes staleness dynamically. Between refreshes, data could cross the stale threshold — tooltip says "Stale" while the emoji is still normal. Track the rendered staleness state. When the tooltip detects a transition, trigger a re-render so the emoji dimming matches.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-wttrin--mode-line-update-display.el26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/test-wttrin--mode-line-update-display.el b/tests/test-wttrin--mode-line-update-display.el
index 81fbded..0635b5f 100644
--- a/tests/test-wttrin--mode-line-update-display.el
+++ b/tests/test-wttrin--mode-line-update-display.el
@@ -210,6 +210,32 @@
(should-not wttrin-mode-line-string))
(test-wttrin--mode-line-update-display-teardown)))
+(ert-deftest test-wttrin--mode-line-update-display-stale-emoji-dims-on-hover-transition ()
+ "When data crosses the stale threshold between refreshes, hovering should
+trigger an emoji re-render so dimming matches the tooltip's staleness state."
+ (test-wttrin--mode-line-update-display-setup)
+ (unwind-protect
+ (let ((wttrin-mode-line-refresh-interval 900)
+ (wttrin-mode-line-emoji-font nil))
+ ;; Initial render: data is fresh (age=200, threshold=1800)
+ (cl-letf (((symbol-function 'float-time) (lambda () 1200.0)))
+ (setq wttrin--mode-line-cache (cons 1000.0 "Paris: X +61°F Clear"))
+ (wttrin--mode-line-update-display)
+ ;; Emoji should NOT be dimmed
+ (let ((face (get-text-property 1 'face wttrin-mode-line-string)))
+ (should-not (and face (equal (plist-get face :foreground) "gray60")))))
+
+ ;; Time passes: data is now stale (age=2001, threshold=1800)
+ ;; Invoke the tooltip (simulating a hover) — this should trigger a re-render
+ (cl-letf (((symbol-function 'float-time) (lambda () 3001.0)))
+ (let ((help-echo-fn (get-text-property 0 'help-echo wttrin-mode-line-string)))
+ (funcall help-echo-fn nil nil nil))
+ ;; After hover detected staleness transition, emoji should now be dimmed
+ (let ((face (get-text-property 1 'face wttrin-mode-line-string)))
+ (should face)
+ (should (equal (plist-get face :foreground) "gray60")))))
+ (test-wttrin--mode-line-update-display-teardown)))
+
;;; --------------------------------------------------------------------------
;;; wttrin--mode-line-fetch-weather
;;; --------------------------------------------------------------------------