From ea5636c51361b86d132d647ee3548d208394878e Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sat, 4 Apr 2026 12:26:16 -0500 Subject: test: add 50 tests for untested functions; fix nil crash in save-debug-data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- tests/test-wttrin-mode-line-click.el | 69 ++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 tests/test-wttrin-mode-line-click.el (limited to 'tests/test-wttrin-mode-line-click.el') 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 -- cgit v1.2.3