diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-05 14:49:14 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-05 14:49:14 -0500 |
| commit | 14d75bc5c9a35e26f80944010a494d9589c26c2f (patch) | |
| tree | 89a38a9facd38af5b22a70144e7a991c71d17ac9 /tests | |
| parent | 22af1d98bcfe8dc970ee134f50d00c3ed31efe79 (diff) | |
| download | org-drill-14d75bc5c9a35e26f80944010a494d9589c26c2f.tar.gz org-drill-14d75bc5c9a35e26f80944010a494d9589c26c2f.zip | |
test: cover org-drill-presentation-prompt-in-buffer
I extended the presentation-prompt tests with cases for the in-buffer
variant: default prompt assembled when none is supplied, explicit
prompt fed straight through, drill-answer cleared on entry, and the
session's exit-kind flowing back to the caller after recursive-edit
returns. Recursive-edit, display-buffer, and the timer are all mocked.
Coverage moved from 93.2% to 94.4%.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test-org-drill-presentation-prompt.el | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/test-org-drill-presentation-prompt.el b/tests/test-org-drill-presentation-prompt.el index 9518457..2c81623 100644 --- a/tests/test-org-drill-presentation-prompt.el +++ b/tests/test-org-drill-presentation-prompt.el @@ -120,6 +120,67 @@ goes to the in-buffer variant." (should-not mini-called) (should buffer-called))))) +;;;; org-drill-presentation-prompt-in-buffer + +(defmacro with-mocked-in-buffer-deps (&rest body) + (declare (indent 0)) + `(cl-letf (((symbol-function 'run-with-idle-timer) + (lambda (&rest _) 'fake-timer)) + ((symbol-function 'cancel-timer) #'ignore) + ((symbol-function 'recursive-edit) #'ignore) + ((symbol-function 'select-window) #'ignore) + ((symbol-function 'display-buffer) + (lambda (buf &rest _) + (or (get-buffer-window buf) + (selected-window)))) + ((symbol-function 'org-drill--make-minibuffer-prompt) + (lambda (_s p) p))) + ,@body)) + +(ert-deftest test-presentation-prompt-in-buffer-uses-default-prompt-when-nil () + "When PROMPT is nil, `prompt-in-buffer' assembles a default prompt that +mentions the response keys." + (let ((seen-prompt nil)) + (with-mocked-in-buffer-deps + (cl-letf (((symbol-function 'org-drill--maybe-prepend-leech-warning) + (lambda (p) (setq seen-prompt p) p))) + (with-fresh-drill-entry + (org-drill-presentation-prompt-in-buffer (org-drill-session))))) + (should (string-match-p "Type answer" seen-prompt)))) + +(ert-deftest test-presentation-prompt-in-buffer-with-explicit-prompt () + "When PROMPT is supplied, that string is the one fed to the leech-warning prepass." + (let ((seen-prompt nil)) + (with-mocked-in-buffer-deps + (cl-letf (((symbol-function 'org-drill--maybe-prepend-leech-warning) + (lambda (p) (setq seen-prompt p) p))) + (with-fresh-drill-entry + (org-drill-presentation-prompt-in-buffer (org-drill-session) "EXPLICIT-P")))) + (should (equal "EXPLICIT-P" seen-prompt)))) + +(ert-deftest test-presentation-prompt-in-buffer-clears-drill-answer () + "Calling the prompt resets the session's drill-answer slot." + (let ((session (org-drill-session))) + (oset session drill-answer "stale") + (with-mocked-in-buffer-deps + (cl-letf (((symbol-function 'org-drill--maybe-prepend-leech-warning) + (lambda (p) p))) + (with-fresh-drill-entry + (org-drill-presentation-prompt-in-buffer session "p")))) + (should (null (oref session drill-answer))))) + +(ert-deftest test-presentation-prompt-in-buffer-returns-exit-kind () + "The function returns the session's exit-kind set by recursive-edit." + (let ((session (org-drill-session))) + (with-mocked-in-buffer-deps + (cl-letf (((symbol-function 'recursive-edit) + (lambda () (oset session exit-kind 'mock-result))) + ((symbol-function 'org-drill--maybe-prepend-leech-warning) + (lambda (p) p))) + (with-fresh-drill-entry + (let ((result (org-drill-presentation-prompt-in-buffer session "p"))) + (should (eq 'mock-result result)))))))) + (provide 'test-org-drill-presentation-prompt) ;;; test-org-drill-presentation-prompt.el ends here |
