aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPaul Pogonyshev <pogonyshev@gmail.com>2023-09-24 23:03:14 +0200
committerJonas Bernoulli <jonas@bernoul.li>2023-10-15 21:49:44 +0200
commit703410039cf28e6bba4949853d010e897d972356 (patch)
tree2e22781cc7b9bccd88c8c98d0b8f5e04c15e4e42 /test
parentc6a62accc5ed4bbdae4e1dc2060210ecfc4cdb8a (diff)
test: Assert that certain text is visible
Basic UI tests; would catch the bug in commit 1ab107a7.
Diffstat (limited to 'test')
-rw-r--r--test/magit-tests.el34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/magit-tests.el b/test/magit-tests.el
index 57797f3..f2d67f8 100644
--- a/test/magit-tests.el
+++ b/test/magit-tests.el
@@ -59,6 +59,20 @@
(declare (indent 1) (debug t))
`(magit-with-test-directory (magit-test-init-repo "." "--bare") ,@body))
+(defun magit-test-visible-text (&optional raw)
+ (save-excursion
+ (let (chunks)
+ (goto-char (point-min))
+ (while (let ((to (next-single-char-property-change (point) 'invisible)))
+ (unless (invisible-p (point))
+ (push (buffer-substring-no-properties (point) to) chunks))
+ (goto-char to)
+ (< (point) (point-max))))
+ (let ((result (mapconcat #'identity (nreverse chunks) nil)))
+ (unless raw
+ (setq result (string-trim result)))
+ result))))
+
;;; Git
(ert-deftest magit--with-safe-default-directory ()
@@ -401,6 +415,26 @@ Enter passphrase for key '/home/user/.ssh/id_rsa': "
'(unpushed . "@{upstream}..")
(magit-rev-parse "--short" "master")))))
+(ert-deftest magit-status:section-commands ()
+ (magit-with-test-repository
+ (magit-git "commit" "-m" "dummy" "--allow-empty")
+ (with-current-buffer (magit-status-setup-buffer)
+ (magit-section-show-level-1-all)
+ (should (string-match-p
+ "\\`Head:[[:space:]]+master dummy\n\nRecent commits\\'"
+ (magit-test-visible-text)))
+ (magit-section-show-level-2-all)
+ (should (string-match-p
+ "\\`Head:[[:space:]]+master dummy\n
+Recent commits\n[[:xdigit:]]\\{7,\\} master dummy\\'"
+ (magit-test-visible-text)))
+ (goto-char (point-min))
+ (search-forward "Recent")
+ (magit-section-show-level-1)
+ (should (string-match-p
+ "\\`Head:[[:space:]]+master dummy\n\nRecent commits\\'"
+ (magit-test-visible-text))))))
+
;;; libgit
(ert-deftest magit-in-bare-repo ()