diff options
Diffstat (limited to 'tests/test-wttrin-mode-line-force-refresh.el')
| -rw-r--r-- | tests/test-wttrin-mode-line-force-refresh.el | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/test-wttrin-mode-line-force-refresh.el b/tests/test-wttrin-mode-line-force-refresh.el new file mode 100644 index 0000000..2275cee --- /dev/null +++ b/tests/test-wttrin-mode-line-force-refresh.el @@ -0,0 +1,71 @@ +;;; test-wttrin-mode-line-force-refresh.el --- Tests for wttrin-mode-line-force-refresh -*- lexical-binding: t; -*- + +;; Copyright (C) 2025 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 |
