summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-11 17:17:54 -0500
committerCraig Jennings <c@cjennings.net>2026-05-11 17:17:54 -0500
commitbbd1b73cbaf1716734b1193467564a0c7122dec7 (patch)
treea229758b212f324c4a2e4d8102c60e6503dedee0 /tests
parenteddc103fd251e324f8bd5c9000ed8d29cb59c602 (diff)
downloaddotemacs-bbd1b73cbaf1716734b1193467564a0c7122dec7.tar.gz
dotemacs-bbd1b73cbaf1716734b1193467564a0c7122dec7.zip
fix(slack): harden and curate the C-; S ! reaction workflow
Two problems with `C-; S !'. First, emacs-slack's `slack-reaction-echo-description' runs in a buffer-local `post-command-hook' and can error on every keystroke when a reaction widget's text properties are malformed, which makes it hard to leave the Slack buffer or recover with C-g. It's now wrapped in `condition-case' that, on error, removes the hook from that buffer's local `post-command-hook' and messages once. Second, without emojify the upstream reaction picker is a flat completing-read over 1600+ names. `cj/slack-message-add-reaction' now offers a curated common list (`thumbsup', `pray', `eyes', `white_check_mark', `heart', `joy', `thinking_face', `rocket', `tada') with "Other..." delegating back to `slack-message-reaction-input' for the full set. Tests cover the hook hardening, the curated picker, and the `C-; S !' rebinding.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-slack-config-reactions.el91
1 files changed, 91 insertions, 0 deletions
diff --git a/tests/test-slack-config-reactions.el b/tests/test-slack-config-reactions.el
new file mode 100644
index 00000000..a5755a49
--- /dev/null
+++ b/tests/test-slack-config-reactions.el
@@ -0,0 +1,91 @@
+;;; test-slack-config-reactions.el --- Tests for Slack reaction helpers -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; Tests for local Slack reaction workflow hardening and shortlist selection.
+
+;;; Code:
+
+(require 'ert)
+(require 'cl-lib)
+
+(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
+(require 'slack-config)
+
+(defvar slack-current-buffer)
+
+(ert-deftest test-slack-config-reaction-echo-error-removes-local-hook ()
+ "Error: malformed reaction hover errors remove the local post-command hook."
+ (with-temp-buffer
+ (add-hook 'post-command-hook #'slack-reaction-echo-description nil t)
+ (cl-letf (((symbol-function 'message) (lambda (&rest _args) nil)))
+ (cj/slack--safe-reaction-echo-description
+ (lambda (&rest _args) (error "bad reaction"))))
+ (should-not (memq #'slack-reaction-echo-description post-command-hook))))
+
+(ert-deftest test-slack-config-reaction-echo-success-keeps-local-hook ()
+ "Normal: successful reaction hover leaves the local hook installed."
+ (with-temp-buffer
+ (add-hook 'post-command-hook #'slack-reaction-echo-description nil t)
+ (cj/slack--safe-reaction-echo-description (lambda (&rest _args) :ok))
+ (should (memq #'slack-reaction-echo-description post-command-hook))))
+
+(ert-deftest test-slack-config-reaction-candidates-include-common-and-fallback ()
+ "Normal: common reaction candidates include frequent choices and Other."
+ (let ((candidates (cj/slack--reaction-candidates)))
+ (should (member '("Other..." . :other) candidates))
+ (should (cl-some (lambda (candidate)
+ (and (string-match-p "thumbsup" (car candidate))
+ (equal "thumbsup" (cdr candidate))))
+ candidates))
+ (should (cl-some (lambda (candidate)
+ (and (string-match-p "pray" (car candidate))
+ (equal "pray" (cdr candidate))))
+ candidates))))
+
+(ert-deftest test-slack-config-select-reaction-common-choice ()
+ "Normal: selecting a common display candidate returns its Slack emoji name."
+ (let* ((candidates (cj/slack--reaction-candidates))
+ (choice (car (cl-find-if (lambda (candidate)
+ (equal "pray" (cdr candidate)))
+ candidates))))
+ (cl-letf (((symbol-function 'completing-read)
+ (lambda (&rest _args) choice)))
+ (should (equal "pray" (cj/slack-select-reaction :team))))))
+
+(ert-deftest test-slack-config-select-reaction-other-falls-back-to-upstream ()
+ "Boundary: Other delegates to emacs-slack's full emoji input."
+ (cl-letf (((symbol-function 'completing-read)
+ (lambda (&rest _args) "Other..."))
+ ((symbol-function 'slack-message-reaction-input)
+ (lambda (team)
+ (should (eq team :team))
+ "custom_emoji")))
+ (should (equal "custom_emoji" (cj/slack-select-reaction :team)))))
+
+(ert-deftest test-slack-config-reaction-key-uses-local-command ()
+ "Normal: C-; S ! uses the local safer reaction command."
+ (should (eq (keymap-lookup cj/slack-keymap "!")
+ #'cj/slack-message-add-reaction)))
+
+(ert-deftest test-slack-config-message-add-reaction-dispatches-selected-reaction ()
+ "Normal: local reaction command sends selected reaction to Slack."
+ (let ((slack-current-buffer :buffer)
+ called)
+ (cl-letf (((symbol-function 'slack-buffer-team)
+ (lambda (buffer)
+ (should (eq buffer :buffer))
+ :team))
+ ((symbol-function 'cj/slack-select-reaction)
+ (lambda (team)
+ (should (eq team :team))
+ "pray"))
+ ((symbol-function 'slack-get-ts)
+ (lambda () "123.456"))
+ ((symbol-function 'slack-buffer-add-reaction-to-message)
+ (lambda (buffer reaction ts)
+ (setq called (list buffer reaction ts)))))
+ (cj/slack-message-add-reaction)
+ (should (equal called '(:buffer "pray" "123.456"))))))
+
+(provide 'test-slack-config-reactions)
+;;; test-slack-config-reactions.el ends here