aboutsummaryrefslogtreecommitdiff
path: root/tests/test-wttrin--update-layout.el
blob: b8df6657be45fc9e4fa71277712d9df03a0ee94d (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
;;; test-wttrin--update-layout.el --- Auto-fit gating -*- lexical-binding: t; -*-

;; Copyright (C) 2024-2026 Craig Jennings

;;; Commentary:
;; Auto-fit must not size the transient "Loading..." placeholder to fill the
;; window; it runs only once real weather has rendered.

;;; Code:

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

(ert-deftest test-wttrin--update-layout-error-skips-fit-on-placeholder ()
  "Error: with auto-fit on, the loading placeholder (weather not rendered) is
not auto-fitted; the fit runs only after weather renders."
  (let ((buf (get-buffer-create "*wttrin-layout-test*"))
        (fit-calls 0))
    (unwind-protect
        (save-window-excursion
          (cl-letf (((symbol-function 'wttrin--apply-fit-font)
                     (lambda (&rest _) (setq fit-calls (1+ fit-calls))))
                    ((symbol-function 'wttrin--center-buffer) #'ignore))
            (with-current-buffer buf (insert "Loading..."))
            (set-window-buffer (selected-window) buf)
            (with-current-buffer buf
              (let ((wttrin-auto-fit-font t))
                (setq-local wttrin--weather-rendered nil)
                (wttrin--update-layout)
                (should (= 0 fit-calls))
                (setq-local wttrin--weather-rendered t)
                (wttrin--update-layout)
                (should (= 1 fit-calls))))))
      (kill-buffer buf))))

(provide 'test-wttrin--update-layout)
;;; test-wttrin--update-layout.el ends here