summaryrefslogtreecommitdiff
path: root/tests/test-wttrin-clear-cache.el
blob: 8185c5f651f27c6f5b109867b9c987dfdad89519 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
;;; test-wttrin-clear-cache.el --- Tests for wttrin-clear-cache -*- lexical-binding: t; -*-

;; Copyright (C) 2025-2026 Craig Jennings

;;; Commentary:

;; Unit tests for wttrin-clear-cache function.
;; Tests the interactive command that clears all cached weather data.

;;; Code:

(require 'ert)
(require 'wttrin)
(require 'testutil-wttrin)

;;; Setup and Teardown

(defun test-wttrin-clear-cache-setup ()
  "Setup for clear-cache tests."
  (testutil-wttrin-setup))

(defun test-wttrin-clear-cache-teardown ()
  "Teardown for clear-cache tests."
  (testutil-wttrin-teardown))

;;; Normal Cases

(ert-deftest test-wttrin-clear-cache-normal-empties-all-entries ()
  "Clearing the cache should remove all stored weather entries."
  (test-wttrin-clear-cache-setup)
  (unwind-protect
      (progn
        ;; Populate cache with several entries
        (testutil-wttrin-add-to-cache "Paris" "data1")
        (testutil-wttrin-add-to-cache "London" "data2")
        (testutil-wttrin-add-to-cache "Tokyo" "data3")
        (should (= 3 (testutil-wttrin-cache-size)))
        (wttrin-clear-cache)
        (should (= 0 (testutil-wttrin-cache-size))))
    (test-wttrin-clear-cache-teardown)))

(ert-deftest test-wttrin-clear-cache-normal-shows-confirmation ()
  "User should be told the cache was cleared."
  (test-wttrin-clear-cache-setup)
  (unwind-protect
      (let ((displayed-message nil))
        (cl-letf (((symbol-function 'message)
                   (lambda (fmt &rest args)
                     (setq displayed-message (apply #'format fmt args)))))
          (wttrin-clear-cache)
          (should displayed-message)
          (should (string-match-p "cache cleared" displayed-message))))
    (test-wttrin-clear-cache-teardown)))

;;; Boundary Cases

(ert-deftest test-wttrin-clear-cache-boundary-already-empty ()
  "Clearing an already empty cache should not error."
  (test-wttrin-clear-cache-setup)
  (unwind-protect
      (progn
        (should (= 0 (testutil-wttrin-cache-size)))
        ;; Should not error
        (wttrin-clear-cache)
        (should (= 0 (testutil-wttrin-cache-size))))
    (test-wttrin-clear-cache-teardown)))

(provide 'test-wttrin-clear-cache)
;;; test-wttrin-clear-cache.el ends here