aboutsummaryrefslogtreecommitdiff
path: root/tests/test-wttrin-mode-line-click.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-click.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-click.el')
-rw-r--r--tests/test-wttrin-mode-line-click.el69
1 files changed, 69 insertions, 0 deletions
diff --git a/tests/test-wttrin-mode-line-click.el b/tests/test-wttrin-mode-line-click.el
new file mode 100644
index 0000000..fccd45e
--- /dev/null
+++ b/tests/test-wttrin-mode-line-click.el
@@ -0,0 +1,69 @@
+;;; test-wttrin-mode-line-click.el --- Tests for wttrin-mode-line-click -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2025 Craig Jennings
+
+;;; Commentary:
+
+;; Unit tests for wttrin-mode-line-click function.
+;; Tests the left-click handler for the mode-line weather widget.
+
+;;; Code:
+
+(require 'ert)
+(require 'wttrin)
+(require 'testutil-wttrin)
+
+;;; Setup and Teardown
+
+(defun test-wttrin-mode-line-click-setup ()
+ "Setup for mode-line-click tests."
+ (testutil-wttrin-setup))
+
+(defun test-wttrin-mode-line-click-teardown ()
+ "Teardown for mode-line-click tests."
+ (testutil-wttrin-teardown)
+ (when (get-buffer "*wttr.in*")
+ (kill-buffer "*wttr.in*")))
+
+;;; Normal Cases
+
+(ert-deftest test-wttrin-mode-line-click-normal-opens-weather-for-favorite ()
+ "Clicking the mode-line widget should open weather for the favorite location."
+ (test-wttrin-mode-line-click-setup)
+ (unwind-protect
+ (let ((wttrin-favorite-location "New Orleans, LA")
+ (opened-location nil))
+ (cl-letf (((symbol-function 'wttrin)
+ (lambda (location) (setq opened-location location))))
+ (wttrin-mode-line-click)
+ (should (equal opened-location "New Orleans, LA"))))
+ (test-wttrin-mode-line-click-teardown)))
+
+(ert-deftest test-wttrin-mode-line-click-normal-passes-exact-location-string ()
+ "The exact favorite location string should be passed to wttrin, not modified."
+ (test-wttrin-mode-line-click-setup)
+ (unwind-protect
+ (let ((wttrin-favorite-location "São Paulo, BR")
+ (opened-location nil))
+ (cl-letf (((symbol-function 'wttrin)
+ (lambda (location) (setq opened-location location))))
+ (wttrin-mode-line-click)
+ (should (equal opened-location "São Paulo, BR"))))
+ (test-wttrin-mode-line-click-teardown)))
+
+;;; Boundary Cases
+
+(ert-deftest test-wttrin-mode-line-click-boundary-nil-location-is-noop ()
+ "When no favorite location is configured, clicking should do nothing."
+ (test-wttrin-mode-line-click-setup)
+ (unwind-protect
+ (let ((wttrin-favorite-location nil)
+ (wttrin-called nil))
+ (cl-letf (((symbol-function 'wttrin)
+ (lambda (_location) (setq wttrin-called t))))
+ (wttrin-mode-line-click)
+ (should-not wttrin-called)))
+ (test-wttrin-mode-line-click-teardown)))
+
+(provide 'test-wttrin-mode-line-click)
+;;; test-wttrin-mode-line-click.el ends here