2012-05-25 01:32:05 +02:00
|
|
|
(eval-when-compile (require 'cl))
|
|
|
|
(require 'ert)
|
|
|
|
|
|
|
|
(require 'ein-notification)
|
|
|
|
|
2012-09-02 06:14:54 +02:00
|
|
|
(defun ein:testing-notification-tab-mock ()
|
|
|
|
(make-instance 'ein:notification-tab
|
|
|
|
:get-list (lambda () '(a b c))
|
|
|
|
:get-current (lambda () 'a)
|
|
|
|
:get-name #'ignore))
|
|
|
|
|
2012-09-02 06:18:34 +02:00
|
|
|
(ert-deftest ein:header-line-normal ()
|
|
|
|
(let* ((ein:%notification% (ein:notification "NotificationTest"))
|
|
|
|
(kernel (oref ein:%notification% :kernel)))
|
|
|
|
(oset ein:%notification% :tab (ein:testing-notification-tab-mock))
|
|
|
|
(should (equal (ein:header-line)
|
|
|
|
"IP[y]: [1] 2 3 "))))
|
|
|
|
|
2012-09-02 06:19:57 +02:00
|
|
|
(ert-deftest ein:header-line-kernel-status-busy ()
|
2012-08-18 23:05:47 +02:00
|
|
|
(let* ((ein:%notification% (ein:notification "NotificationTest"))
|
|
|
|
(kernel (oref ein:%notification% :kernel)))
|
2012-09-02 06:14:54 +02:00
|
|
|
(oset ein:%notification% :tab (ein:testing-notification-tab-mock))
|
2012-05-25 01:32:05 +02:00
|
|
|
(ein:notification-status-set kernel
|
2012-06-06 21:03:54 +02:00
|
|
|
'status_busy.Kernel)
|
2012-09-02 06:14:54 +02:00
|
|
|
(should (equal (ein:header-line)
|
|
|
|
"IP[y]: Kernel is busy... | [1] 2 3 "))))
|
2012-05-25 01:32:05 +02:00
|
|
|
|
2012-09-02 06:19:57 +02:00
|
|
|
(ert-deftest ein:header-line-notebook-status-busy ()
|
2012-08-18 23:05:47 +02:00
|
|
|
(let* ((ein:%notification% (ein:notification "NotificationTest"))
|
|
|
|
(notebook (oref ein:%notification% :notebook)))
|
2012-09-02 06:14:54 +02:00
|
|
|
(oset ein:%notification% :tab (ein:testing-notification-tab-mock))
|
2012-05-25 01:32:05 +02:00
|
|
|
(ein:notification-status-set notebook
|
2012-06-06 21:03:54 +02:00
|
|
|
'notebook_saved.Notebook)
|
2012-09-02 06:14:54 +02:00
|
|
|
(should (equal (ein:header-line)
|
|
|
|
"IP[y]: Notebook is saved | [1] 2 3 "))))
|
2012-05-25 01:32:05 +02:00
|
|
|
|
2012-09-02 06:19:57 +02:00
|
|
|
(ert-deftest ein:header-line-notebook-complex ()
|
2012-08-18 23:05:47 +02:00
|
|
|
(let* ((ein:%notification% (ein:notification "NotificationTest"))
|
|
|
|
(kernel (oref ein:%notification% :kernel))
|
|
|
|
(notebook (oref ein:%notification% :notebook)))
|
2012-09-02 06:14:54 +02:00
|
|
|
(oset ein:%notification% :tab (ein:testing-notification-tab-mock))
|
2012-05-25 01:32:05 +02:00
|
|
|
(ein:notification-status-set kernel
|
2012-06-06 21:03:54 +02:00
|
|
|
'status_dead.Kernel)
|
2012-05-25 01:32:05 +02:00
|
|
|
(ein:notification-status-set notebook
|
2012-06-06 21:03:54 +02:00
|
|
|
'notebook_saving.Notebook)
|
2012-05-25 01:32:05 +02:00
|
|
|
(should (equal
|
|
|
|
(ein:header-line)
|
2012-09-02 06:14:54 +02:00
|
|
|
(concat "IP[y]: Saving Notebook... | "
|
|
|
|
"Kernel is dead. Need restart. | "
|
|
|
|
"[1] 2 3 ")))))
|
2012-05-25 01:48:29 +02:00
|
|
|
|
2012-09-02 06:19:57 +02:00
|
|
|
(ert-deftest ein:notification-and-events ()
|
2012-05-25 01:48:29 +02:00
|
|
|
(let* ((notification (ein:notification "NotificationTest"))
|
|
|
|
(kernel (oref notification :kernel))
|
|
|
|
(notebook (oref notification :notebook))
|
2012-08-19 12:37:56 +02:00
|
|
|
(events (ein:events-new)))
|
2012-05-25 01:48:29 +02:00
|
|
|
(ein:notification-bind-events notification events)
|
2012-05-25 03:03:57 +02:00
|
|
|
(should (= (hash-table-count (oref events :callbacks)) 7))
|
2012-05-25 01:48:29 +02:00
|
|
|
(should (equal (oref kernel :status) nil))
|
|
|
|
(loop for et in (mapcar #'car (oref kernel :s2m))
|
|
|
|
do (ein:events-trigger events et)
|
|
|
|
do (should (equal (oref kernel :status) et))
|
|
|
|
do (should (equal (oref notebook :status) nil)))
|
|
|
|
(loop for et in (mapcar #'car (oref notebook :s2m))
|
|
|
|
do (ein:events-trigger events et)
|
2012-06-06 21:03:54 +02:00
|
|
|
do (should (equal (oref kernel :status) 'status_dead.Kernel))
|
2012-05-25 01:48:29 +02:00
|
|
|
do (should (equal (oref notebook :status) et)))))
|