unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
blob 5a9ad0ff5ba818825f2a7e8c8cafa20092854d39 4402 bytes (raw)
name: test/lisp/erc/erc-desktop-notifications-tests.el 	 # note: path name is non-authoritative(*)

  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
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
 
;;; erc-desktop-notifications-tests.el --- Notifications tests  -*- lexical-binding:t -*-

;; Copyright (C) 2024 Free Software Foundation, Inc.

;; This file is part of GNU Emacs.
;;
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published
;; by the Free Software Foundation, either version 3 of the License,
;; or (at your option) any later version.
;;
;; GNU Emacs is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;; General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:
;;; Code:
(require 'erc-desktop-notifications)

(require 'ert-x)
(eval-and-compile
  (let ((load-path (cons (ert-resource-directory) load-path)))
    (require 'erc-tests-common)))

(defun erc-desktop-notifications-tests--perform (test)
  (erc-tests-common-make-server-buf)
  (erc-notifications-mode +1)
  (setq erc-server-current-nick "tester")

  (cl-letf* ((calls nil)
             ((frame-parameter nil 'last-focus-update)
              t)
             ((symbol-function 'erc-notifications-notify)
              (lambda (&rest r) (push r calls))))
    (with-current-buffer (erc--open-target "#chan")
      (funcall test (lambda () (prog1 calls (setq calls nil))))))

  (when noninteractive
    (erc-notifications-mode -1)
    (erc-tests-common-kill-buffers)))

(defun erc-desktop-notifications-tests--populate-chan (test)
  (erc-desktop-notifications-tests--perform
   (lambda (check)
     (erc-tests-common-add-cmem "bob")
     (erc-tests-common-add-cmem "alice")

     (erc-tests-common-simulate-line
      ":irc.foonet.org 353 tester = #chan :alice bob tester")
     (erc-tests-common-simulate-line
      ":irc.foonet.org 366 tester #chan :End of NAMES list")
     (erc-tests-common-simulate-privmsg "bob" "hi tester")

     (should (equal (current-buffer) (get-buffer "#chan")))
     (should (not (eq (current-buffer) (window-buffer)))) ; *ert* or *scratch*
     (funcall test check))))

(ert-deftest erc-notifications-focused-contexts/default ()
  (should (equal erc-notifications-focused-contexts '(query mention)))

  (erc-desktop-notifications-tests--populate-chan
   (lambda (check)

     ;; A private query triggers a notification.
     (erc-tests-common-simulate-line ":bob!~bob@fsf.org PRIVMSG tester yo")
     (should (eq (current-buffer) (get-buffer "bob")))

     ;; A NOTICE command doesn't trigger a notification because it's
     ;; absent from `erc-desktop-notifications-match-query-commands'.
     (erc-tests-common-simulate-line ":irc.foonet.org NOTICE tester nope")

     (should (equal (funcall check)
                    '(("bob" "yo")
                      ("bob" "hi tester\n"))))

     ;; Setting the window to the buffer where insertions are happening
     ;; makes no difference: notifications are still sent.
     (erc-tests-common-simulate-line ":bob!~bob@fsf.org PRIVMSG tester ho")

     (set-window-buffer nil (set-buffer "#chan"))
     (erc-tests-common-simulate-privmsg "alice" "hi tester")

     (should (equal (funcall check)
                    '(("alice" "hi tester\n")
                      ("bob" "ho")))))))

(ert-deftest erc-notifications-focused-contexts/unselected ()
  (should (equal erc-notifications-focused-contexts '(query mention)))

  (let ((erc-notifications-focused-contexts))

    (erc-desktop-notifications-tests--populate-chan
     (lambda (check)
       (should (equal (funcall check) '(("bob" "hi tester\n"))))

       ;; Buffer #chan is current and displayed in the selected window,
       ;; so no notification is sent.
       (set-window-buffer nil "#chan") ; #chan
       (erc-tests-common-simulate-privmsg "alice" "hi tester")

       ;; A new query comes in for a buffer that doesn't exist.  The
       ;; option `erc-receive-query-display' tells ERC to switch to that
       ;; buffer and show it before insertion.  Therefore, no
       ;; notification is sent.
       (let ((erc-receive-query-display 'buffer))
         (erc-tests-common-simulate-line
          ":bob!~bob@fsf.org PRIVMSG tester yo"))

       (should-not (funcall check))))))

;;; erc-desktop-notifications-tests.el ends here

debug log:

solving 5a9ad0ff5ba ...
found 5a9ad0ff5ba in https://yhetil.org/emacs-bugs/877c9v4u97.fsf__36819.6135548473$1729900311$gmane$org@neverwas.me/ ||
	https://yhetil.org/emacs-bugs/87y12rifv2.fsf__34989.0912578971$1728872725$gmane$org@neverwas.me/

applying [1/1] https://yhetil.org/emacs-bugs/877c9v4u97.fsf__36819.6135548473$1729900311$gmane$org@neverwas.me/
diff --git a/test/lisp/erc/erc-desktop-notifications-tests.el b/test/lisp/erc/erc-desktop-notifications-tests.el
new file mode 100644
index 00000000000..5a9ad0ff5ba

Checking patch test/lisp/erc/erc-desktop-notifications-tests.el...
Applied patch test/lisp/erc/erc-desktop-notifications-tests.el cleanly.

skipping https://yhetil.org/emacs-bugs/87y12rifv2.fsf__34989.0912578971$1728872725$gmane$org@neverwas.me/ for 5a9ad0ff5ba
index at:
100644 5a9ad0ff5ba818825f2a7e8c8cafa20092854d39	test/lisp/erc/erc-desktop-notifications-tests.el

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).