|
|
@@ -1,4 +1,4 @@
|
|
|
-;;; xwidget-plus-follow-link-test.el -- xwwp follow link test suite -*- lexical-binding: t; -*-
|
|
|
+;;; xwwp-follow-link-test.el -- xwwp follow link test suite -*- lexical-binding: t; -*-
|
|
|
|
|
|
;; Copyright (C) 2020 Damien Merenne <dam@cosinux.org>
|
|
|
|
|
|
@@ -21,14 +21,18 @@
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
+(require 'cl-lib)
|
|
|
(require 'test-helper)
|
|
|
(require 'with-simulated-input)
|
|
|
-(require 'xwidget-plus-follow-link)
|
|
|
+(require 'xwwp-follow-link)
|
|
|
+(require 'xwwp-follow-link-ido)
|
|
|
+(require 'xwwp-follow-link-ivy)
|
|
|
+(require 'xwwp-follow-link-helm)
|
|
|
|
|
|
(setq completing-read-function #'completing-read-default)
|
|
|
|
|
|
;; Some usefull javascript
|
|
|
-(xwidget-plus-js-def test element-classes (selector)
|
|
|
+(xwwp-js-def test element-classes (selector)
|
|
|
"Fetch the list of css class for element matching SELECTOR.""
|
|
|
map = Array.prototype.map;
|
|
|
r = {};
|
|
|
@@ -40,70 +44,71 @@ document.querySelectorAll(selector).forEach(l => {
|
|
|
return r;
|
|
|
")
|
|
|
|
|
|
-(xwidget-plus-js-def test current-location ()
|
|
|
+(xwwp-js-def test current-location ()
|
|
|
"Fetch the current url.""
|
|
|
return '' + window.location;
|
|
|
")
|
|
|
|
|
|
;; A mocked backend class that doesn't interactively read anything.
|
|
|
-(defclass xwidget-plus-completion-backend-test (xwidget-plus-completion-backend)
|
|
|
+(defclass xwwp-follow-link-completion-backend-test (xwwp-follow-link-completion-backend)
|
|
|
((candidates-mock :initarg :candidates-mock)
|
|
|
(selected-mock :initarg :selected-mock)
|
|
|
(action-fn)
|
|
|
(classes)
|
|
|
(location)))
|
|
|
|
|
|
-(defun xwidget-plus-update-fn-callback (result)
|
|
|
+(defun xwwp-update-fn-callback (result)
|
|
|
"Called after updating candidates with the css classes in RESULT."
|
|
|
- (let ((backend xwidget-plus-follow-link-completion-backend-instance))
|
|
|
+ (let ((backend xwwp-follow-link-completion-backend-instance))
|
|
|
;; Store the results.
|
|
|
(oset backend classes (seq-map #'identity result))
|
|
|
;; Trigger the action function with the mocked selected link
|
|
|
(funcall (oref backend action-fn) (oref backend selected-mock))
|
|
|
- (xwidget-plus-event-dispatch)))
|
|
|
+ (xwwp-event-dispatch)))
|
|
|
|
|
|
-(defun xwidget-plus-location-callback (result)
|
|
|
+(defun xwwp-location-callback (result)
|
|
|
"Called after updating candidates with the css classes in RESULT."
|
|
|
- (let ((backend xwidget-plus-follow-link-completion-backend-instance))
|
|
|
+ (let ((backend xwwp-follow-link-completion-backend-instance))
|
|
|
;; Store the results.
|
|
|
(oset backend location result)))
|
|
|
|
|
|
-(cl-defmethod xwidget-plus-follow-link-candidates ((backend xwidget-plus-completion-backend-test))
|
|
|
+(cl-defmethod xwwp-follow-link-candidates ((backend xwwp-follow-link-completion-backend-test))
|
|
|
"Return the list of BACKEND mocked candidates."
|
|
|
(oref backend candidates-mock))
|
|
|
|
|
|
-(cl-defmethod xwidget-plus-follow-link-read ((backend xwidget-plus-completion-backend-test) _ _ action-fn update-fn)
|
|
|
+(cl-defmethod xwwp-follow-link-read ((backend xwwp-follow-link-completion-backend-test) _ _ action-fn update-fn)
|
|
|
"Store ACTION-FN in BACKEND, call the UPDATE-FN, and fetch the link element classes."
|
|
|
;; Stoire action so that we can call it after having fetch the css classes.
|
|
|
(oset backend action-fn action-fn)
|
|
|
;; Trigger the javascript update.
|
|
|
(funcall update-fn)
|
|
|
;; Fetch css classes.
|
|
|
- (xwidget-plus-js-inject (xwidget-webkit-current-session) 'test)
|
|
|
- (xwidget-plus-test-element-classes (xwidget-webkit-current-session) "a" #'xwidget-plus-update-fn-callback)
|
|
|
- (xwidget-plus-event-dispatch))
|
|
|
+ (xwwp-js-inject (xwidget-webkit-current-session) 'test)
|
|
|
+ (xwwp-test-element-classes (xwidget-webkit-current-session) "a" #'xwwp-update-fn-callback)
|
|
|
+ (xwwp-event-dispatch))
|
|
|
|
|
|
-(cl-defmethod backend-test-link-classes ((backend xwidget-plus-completion-backend-test) link-id)
|
|
|
+(cl-defmethod backend-test-link-classes ((backend xwwp-follow-link-completion-backend-test) link-id)
|
|
|
"Return test BACKEND css class names for LINK-ID."
|
|
|
(cdr (assoc link-id (oref backend classes))))
|
|
|
|
|
|
(defmacro with-backend (backend &rest body)
|
|
|
"Run BODY with the specified BACKEND."
|
|
|
(declare (indent 1))
|
|
|
- `(let* ((backend (,(intern (concat "xwidget-plus-completion-backend-" (symbol-name backend)))))
|
|
|
- (xwidget-plus-follow-link-completion-backend-instance backend))
|
|
|
+ `(let* ((backend (,(intern (concat "xwwp-follow-link-completion-backend-" (symbol-name backend)))))
|
|
|
+ (xwwp-follow-link-completion-backend-instance backend))
|
|
|
,@body))
|
|
|
|
|
|
|
|
|
(defmacro with-test-backend-browse (candidates selected url &rest body)
|
|
|
"Run BODY with the specified BACKEND mocking CANDIDATES and SELECTED while browsing URL."
|
|
|
(declare (indent 3))
|
|
|
- `(let* ((xwidget-plus-completion-system (lambda () (xwidget-plus-completion-backend-test :candidates-mock ,candidates
|
|
|
- :selected-mock ,selected))))
|
|
|
+ `(let* ((xwwp-follow-link-completion-system
|
|
|
+ (lambda () (xwwp-follow-link-completion-backend-test :candidates-mock ,candidates
|
|
|
+ :selected-mock ,selected))))
|
|
|
(with-browse ,url
|
|
|
,@body)))
|
|
|
|
|
|
-(ert-deftest test-xwidget-plus-follow-link-prepare-links ()
|
|
|
+(ert-deftest test-xwwp-follow-link-prepare-links ()
|
|
|
(let ((links '(("3" . "Functions")
|
|
|
("1" . "Function Cells")
|
|
|
("12" . "Structures")
|
|
|
@@ -114,41 +119,41 @@ return '' + window.location;
|
|
|
("Functions" . 3)
|
|
|
("Declare Form" . 9)
|
|
|
("Structures" . 12))
|
|
|
- (xwidget-plus-follow-link-prepare-links links)))))
|
|
|
+ (xwwp-follow-link-prepare-links links)))))
|
|
|
|
|
|
-(ert-deftest test-xwidget-plus-follow-link-highlight ()
|
|
|
+(ert-deftest test-xwwp-follow-link-highlight ()
|
|
|
(with-test-backend-browse '(0 0 1) 0 "links.html"
|
|
|
- (xwidget-plus-follow-link)
|
|
|
- (xwidget-plus-event-loop)
|
|
|
- (let ((backend xwidget-plus-follow-link-completion-backend-instance))
|
|
|
- (xwidget-plus-js-inject xwidget 'test)
|
|
|
- (xwidget-plus-test-current-location xwidget #'xwidget-plus-location-callback)
|
|
|
- (xwidget-plus-event-dispatch)
|
|
|
+ (xwwp-follow-link)
|
|
|
+ (xwwp-event-loop)
|
|
|
+ (let ((backend xwwp-follow-link-completion-backend-instance))
|
|
|
+ (xwwp-js-inject xwidget 'test)
|
|
|
+ (xwwp-test-current-location xwidget #'xwwp-location-callback)
|
|
|
+ (xwwp-event-dispatch)
|
|
|
(should (string= "test-1.html" (file-name-nondirectory (oref backend location))))
|
|
|
- (should (equal (backend-test-link-classes backend "test-1") '["xwidget-plus-follow-link-selected"]))
|
|
|
- (should (equal (backend-test-link-classes backend "test-2") '["xwidget-plus-follow-link-candidate"]))))
|
|
|
+ (should (equal (backend-test-link-classes backend "test-1") '["xwwp-follow-link-selected"]))
|
|
|
+ (should (equal (backend-test-link-classes backend "test-2") '["xwwp-follow-link-candidate"]))))
|
|
|
(with-test-backend-browse '(1 0 1) 1 "links.html"
|
|
|
- (xwidget-plus-follow-link)
|
|
|
- (xwidget-plus-event-loop)
|
|
|
- (let ((backend xwidget-plus-follow-link-completion-backend-instance))
|
|
|
- (xwidget-plus-js-inject xwidget 'test)
|
|
|
- (xwidget-plus-test-current-location xwidget #'xwidget-plus-location-callback)
|
|
|
- (xwidget-plus-event-dispatch)
|
|
|
+ (xwwp-follow-link)
|
|
|
+ (xwwp-event-loop)
|
|
|
+ (let ((backend xwwp-follow-link-completion-backend-instance))
|
|
|
+ (xwwp-js-inject xwidget 'test)
|
|
|
+ (xwwp-test-current-location xwidget #'xwwp-location-callback)
|
|
|
+ (xwwp-event-dispatch)
|
|
|
(should (string= "test-2.html" (file-name-nondirectory (oref backend location))))
|
|
|
- (should (equal (backend-test-link-classes backend "test-1") '["xwidget-plus-follow-link-candidate"]))
|
|
|
- (should (equal (backend-test-link-classes backend "test-2") '["xwidget-plus-follow-link-selected"])))))
|
|
|
+ (should (equal (backend-test-link-classes backend "test-1") '["xwwp-follow-link-candidate"]))
|
|
|
+ (should (equal (backend-test-link-classes backend "test-2") '["xwwp-follow-link-selected"])))))
|
|
|
|
|
|
-(ert-deftest test-xwidget-plus-follow-link-highlight-no-candidates ()
|
|
|
+(ert-deftest test-xwwp-follow-link-highlight-no-candidates ()
|
|
|
(with-test-backend-browse '(1) 1 "links.html"
|
|
|
- (xwidget-plus-follow-link)
|
|
|
- (xwidget-plus-event-loop)
|
|
|
- (let ((backend xwidget-plus-follow-link-completion-backend-instance))
|
|
|
- (xwidget-plus-js-inject xwidget 'test)
|
|
|
- (xwidget-plus-test-current-location xwidget #'xwidget-plus-location-callback)
|
|
|
- (xwidget-plus-event-dispatch)
|
|
|
+ (xwwp-follow-link)
|
|
|
+ (xwwp-event-loop)
|
|
|
+ (let ((backend xwwp-follow-link-completion-backend-instance))
|
|
|
+ (xwwp-js-inject xwidget 'test)
|
|
|
+ (xwwp-test-current-location xwidget #'xwwp-location-callback)
|
|
|
+ (xwwp-event-dispatch)
|
|
|
(should (string= "test-2.html" (file-name-nondirectory (oref backend location))))
|
|
|
(should (equal (backend-test-link-classes backend "test-1") '[]))
|
|
|
- (should (equal (backend-test-link-classes backend "test-2") '["xwidget-plus-follow-link-selected"])))))
|
|
|
+ (should (equal (backend-test-link-classes backend "test-2") '["xwwp-follow-link-selected"])))))
|
|
|
|
|
|
(defmacro with-read-fixtures (backend &rest body)
|
|
|
(declare (indent 1))
|
|
|
@@ -160,76 +165,77 @@ return '' + window.location;
|
|
|
(with-browse "links.html"
|
|
|
,@body))))
|
|
|
|
|
|
-(ert-deftest test-xwidget-plus-follow-link-read-default ()
|
|
|
+(ert-deftest test-xwwp-follow-link-read-default ()
|
|
|
(with-read-fixtures default
|
|
|
(with-simulated-input "test SPC 2 RET"
|
|
|
- (xwidget-plus-follow-link-read backend "Test: " links action update)
|
|
|
+ (xwwp-follow-link-read backend "Test: " links action update)
|
|
|
(should (= 1 link)))))
|
|
|
|
|
|
-(ert-deftest test-xwidget-plus-follow-link-read-ido ()
|
|
|
+(ert-deftest test-xwwp-follow-link-read-ido ()
|
|
|
(require 'ido)
|
|
|
(with-read-fixtures ido
|
|
|
(with-simulated-input "2 RET"
|
|
|
- (xwidget-plus-follow-link-read backend "Test: " links action update)
|
|
|
+ (xwwp-follow-link-read backend "Test: " links action update)
|
|
|
(should (= 1 link)))))
|
|
|
|
|
|
-(ert-deftest test-xwidget-plus-follow-link-read-ivy ()
|
|
|
+(ert-deftest test-xwwp-follow-link-read-ivy ()
|
|
|
(require 'ivy)
|
|
|
(with-read-fixtures ivy
|
|
|
(with-simulated-input "2 RET"
|
|
|
- (xwidget-plus-follow-link-read backend "Test: " links action update)
|
|
|
+ (xwwp-follow-link-read backend "Test: " links action update)
|
|
|
(should (= 1 link)))))
|
|
|
|
|
|
-(ert-deftest test-xwidget-plus-follow-link-read-helm ()
|
|
|
+(ert-deftest test-xwwp-follow-link-read-helm ()
|
|
|
(require 'helm)
|
|
|
(with-read-fixtures helm
|
|
|
(with-simulated-input '("2" (wsi-simulate-idle-time 0.1) "RET")
|
|
|
- (xwidget-plus-follow-link-read backend "Test: " links action update)
|
|
|
+ (xwwp-follow-link-read backend "Test: " links action update)
|
|
|
(should (= 1 link)))))
|
|
|
|
|
|
(defmacro with-feature (feature &rest body)
|
|
|
(declare (indent 1))
|
|
|
- `(progn (when (featurep 'ido) (unload-feature 'ido t))
|
|
|
- (when (featurep 'ivy) (unload-feature 'ivy t))
|
|
|
- (when (featurep 'helm) (unload-feature 'helm t))
|
|
|
- (when ,feature (require ,feature))
|
|
|
- ,@body))
|
|
|
+ (let ((fsym (intern (concat "xwwp-follow-link-" (symbol-name feature)))))
|
|
|
+ `(cl-letf (((symbol-function 'require) (lambda (f &optional filename no-errors) (eq (quote ,fsym) f))))
|
|
|
+ ,@body)))
|
|
|
|
|
|
-(ert-deftest test-xwidget-plus-follow-link-make-backend-use-feature ()
|
|
|
+(ert-deftest test-xwwp-follow-link-make-backend-use-feature ()
|
|
|
(with-feature nil
|
|
|
- (should (eq #'xwidget-plus-completion-backend-default (xwidget-plus-follow-link-make-backend))))
|
|
|
- (with-feature 'ido
|
|
|
- (should (eq #'xwidget-plus-completion-backend-ido (xwidget-plus-follow-link-make-backend))))
|
|
|
- (with-feature 'ivy
|
|
|
- (should (eq #'xwidget-plus-completion-backend-ivy (xwidget-plus-follow-link-make-backend))))
|
|
|
- (with-feature 'helm
|
|
|
- (should (eq #'xwidget-plus-completion-backend-helm (xwidget-plus-follow-link-make-backend)))))
|
|
|
-
|
|
|
-(ert-deftest test-xwidget-plus-follow-link-make-backend-use-custom ()
|
|
|
- (let ((xwidget-plus-completion-system 'default))
|
|
|
+ (should (eq #'xwwp-follow-link-completion-backend-default (xwwp-follow-link-make-backend))))
|
|
|
+ (with-feature ido
|
|
|
+ (should (eq #'xwwp-follow-link-completion-backend-ido (xwwp-follow-link-make-backend))))
|
|
|
+ (with-feature ivy
|
|
|
+ (should (eq #'xwwp-follow-link-completion-backend-ivy (xwwp-follow-link-make-backend))))
|
|
|
+ (with-feature helm
|
|
|
+ (should (eq #'xwwp-follow-link-completion-backend-helm (xwwp-follow-link-make-backend)))))
|
|
|
+
|
|
|
+(ert-deftest test-xwwp-follow-link-make-backend-use-custom ()
|
|
|
+ (let ((xwwp-follow-link-completion-system 'default))
|
|
|
(with-feature nil
|
|
|
- (should (eq #'xwidget-plus-completion-backend-default (xwidget-plus-follow-link-make-backend)))))
|
|
|
- (let ((xwidget-plus-completion-system 'ido))
|
|
|
- (should (eq #'xwidget-plus-completion-backend-ido (xwidget-plus-follow-link-make-backend))))
|
|
|
- (let ((xwidget-plus-completion-system 'ivy))
|
|
|
- (should (eq #'xwidget-plus-completion-backend-ivy (xwidget-plus-follow-link-make-backend))))
|
|
|
- (let ((xwidget-plus-completion-system 'helm))
|
|
|
- (should (eq #'xwidget-plus-completion-backend-helm (xwidget-plus-follow-link-make-backend))))
|
|
|
- (let ((xwidget-plus-completion-system #'identity))
|
|
|
- (should (eq #'identity (xwidget-plus-follow-link-make-backend)))))
|
|
|
+ (should (eq #'xwwp-follow-link-completion-backend-default (xwwp-follow-link-make-backend)))))
|
|
|
+ (let ((xwwp-follow-link-completion-system 'ido))
|
|
|
+ (with-feature ido
|
|
|
+ (should (eq #'xwwp-follow-link-completion-backend-ido (xwwp-follow-link-make-backend)))))
|
|
|
+ (let ((xwwp-follow-link-completion-system 'ivy))
|
|
|
+ (with-feature ivy
|
|
|
+ (should (eq #'xwwp-follow-link-completion-backend-ivy (xwwp-follow-link-make-backend)))))
|
|
|
+ (let ((xwwp-follow-link-completion-system 'helm))
|
|
|
+ (with-feature helm
|
|
|
+ (should (eq #'xwwp-follow-link-completion-backend-helm (xwwp-follow-link-make-backend)))))
|
|
|
+ (let ((xwwp-follow-link-completion-system #'identity))
|
|
|
+ (should (eq #'identity (xwwp-follow-link-make-backend)))))
|
|
|
|
|
|
;; Local Variables:
|
|
|
;; eval: (mmm-mode)
|
|
|
;; eval: (mmm-add-group 'elisp-js '((elisp-rawjs :submode js-mode
|
|
|
;; :face mmm-code-submode-face
|
|
|
;; :delimiter-mode nil
|
|
|
-;; :front "xwidget-plus--js \"" :back "\" js--")
|
|
|
+;; :front "xwwp--js \"" :back "\" js--")
|
|
|
;; (elisp-defjs :submode js-mode
|
|
|
;; :face mmm-code-submode-face
|
|
|
;; :delimiter-mode nil
|
|
|
-;; :front "xwidget-plus-js-def .*\n.*\"\"\n" :back "\")\n")))
|
|
|
+;; :front "xwwp-js-def .*\n.*\"\"\n" :back "\")\n")))
|
|
|
;; mmm-classes: elisp-js
|
|
|
;; End:
|
|
|
|
|
|
-(provide 'xwidget-plus-follow-link-test)
|
|
|
-;;; xwidget-plus-follow-link-test.el ends here
|
|
|
+(provide 'xwwp-follow-link-test)
|
|
|
+;;; xwwp-follow-link-test.el ends here
|