aboutsummaryrefslogtreecommitdiff
path: root/tests/test-wttrin-mode-line-force-refresh.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-04-04 12:26:16 -0500
committerCraig Jennings <c@cjennings.net>2026-04-04 12:26:16 -0500
commitea5636c51361b86d132d647ee3548d208394878e (patch)
treea60ab847c7324417ca7de46e73d370ba2af90d05 /tests/test-wttrin-mode-line-force-refresh.el
parentb74b98f177d92d50ddbede900ba41212e07c5f63 (diff)
downloademacs-wttrin-ea5636c51361b86d132d647ee3548d208394878e.tar.gz
emacs-wttrin-ea5636c51361b86d132d647ee3548d208394878e.zip
test: add 50 tests for untested functions; fix nil crash in save-debug-data
Add 11 new test files covering wttrin--save-debug-data, wttrin--buffer-cache-refresh, wttrin--mode-line-stop, wttrin--mode-line-start, wttrin-query, wttrin-requery-force, wttrin-mode-line-click, wttrin-mode-line-force-refresh, wttrin-fetch-raw-string, wttrin-clear-cache, and wttrin-requery. Fix bug in wttrin--save-debug-data where nil raw-string caused (insert nil) crash — reachable when debug mode is on and fetch fails. Refactor wttrin-requery: extract wttrin--requery-location so the core kill-buffer-and-query logic is testable without mocking completing-read. 267 tests total (was 217), all passing.
Diffstat (limited to 'tests/test-wttrin-mode-line-force-refresh.el')
-rw-r--r--tests/test-wttrin-mode-line-force-refresh.el71
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