summaryrefslogtreecommitdiff
path: root/test/lisp/erc/erc-scenarios-join-display-context.el
blob: 84297de7acd7e2eabf6edb9462c7c3b4cae1658a (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
;;; erc-scenarios-join-display-context.el --- buffer-display autojoin ctx -*- lexical-binding: t -*-

;; Copyright (C) 2023-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 'ert-x)
(eval-and-compile
  (let ((load-path (cons (ert-resource-directory) load-path)))
    (require 'erc-scenarios-common)))

(ert-deftest erc-scenarios-join-display-context--errors ()
  :tags '(:expensive-test)
  (erc-scenarios-common-with-cleanup
      ((erc-scenarios-common-dialog "join/buffer-display")
       (erc-server-flood-penalty 0.1)
       (dumb-server (erc-d-run "localhost" t 'mode-context))
       (port (process-contact dumb-server :service))
       (erc-buffer-display (lambda (buf action)
                             (when (equal
                                    (alist-get 'erc-autojoin-mode action)
                                    "#chan")
                               (pop-to-buffer buf))))
       (erc-autojoin-channels-alist '((foonet "#chan" "#spam" "#foo")))
       (expect (erc-d-t-make-expecter)))

    (ert-info ("Connect without password")
      (with-current-buffer (erc :server "127.0.0.1"
                                :port port
                                :nick "tester"
                                :full-name "tester")
        (should (string= (buffer-name) (format "127.0.0.1:%d" port)))
        ;; FIXME test for effect rather than inspecting interval variables.
        (erc-d-t-wait-for 10 (equal erc-join--requested-channels
                                    '("#foo" "#spam" "#chan")))
        (funcall expect 10 "Max occupancy for channel #spam exceeded")
        (funcall expect 10 "Channel #foo is invitation only")))

    (ert-info ("New #chan buffer displayed in new window")
      (with-current-buffer (erc-d-t-wait-for 10 (get-buffer "#chan"))
        (should (eq (window-buffer) (current-buffer)))
        (funcall expect 10 "#chan was created on")))

    ;; FIXME find a less dishonest way to do this than inspecting
    ;; interval variables.
    (ert-info ("Ensure channels no longer tracked")
      (should-not erc-join--requested-channels))))

;;; erc-scenarios-join-display-context.el ends here