diff options
Diffstat (limited to 'tests/test-wttrin-mode-line-click.el')
| -rw-r--r-- | tests/test-wttrin-mode-line-click.el | 69 |
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 |
