aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test-music-config--add-dired-selection.el64
-rw-r--r--tests/test-music-config--after-playlist-clear.el25
2 files changed, 89 insertions, 0 deletions
diff --git a/tests/test-music-config--add-dired-selection.el b/tests/test-music-config--add-dired-selection.el
new file mode 100644
index 00000000..9380409c
--- /dev/null
+++ b/tests/test-music-config--add-dired-selection.el
@@ -0,0 +1,64 @@
+;;; test-music-config--add-dired-selection.el --- Tests for dired add command -*- coding: utf-8; lexical-binding: t; -*-
+;;
+;; Author: Craig Jennings <c@cjennings.net>
+;;
+;;; Commentary:
+;; Unit tests for cj/music-add-dired-selection.
+;;
+;; Test organization:
+;; - Normal Cases: marked files (no region) are all queued
+;; - Boundary Cases: no marks falls back to the file at point
+;; - Error Cases: outside dired signals a user-error
+;;
+;;; Code:
+
+(require 'ert)
+(require 'cl-lib)
+
+;; Stub missing dependencies before loading music-config
+(defvar-keymap cj/custom-keymap
+ :doc "Stub keymap for testing")
+
+;; Add EMMS elpa directory to load path for batch testing
+(let ((emms-dir (car (file-expand-wildcards
+ (expand-file-name "elpa/emms-*" user-emacs-directory)))))
+ (when emms-dir
+ (add-to-list 'load-path emms-dir)))
+
+(require 'emms)
+(require 'music-config)
+
+(defun test-add-dired--run (marked)
+ "Run the command with MARKED as dired's marked-file answer; return added files."
+ (let (added)
+ (cl-letf (((symbol-function 'derived-mode-p) (lambda (&rest _) t))
+ ((symbol-function 'cj/music--ensure-playlist-buffer) (lambda () nil))
+ ((symbol-function 'dired-get-marked-files)
+ (lambda (&rest _) marked))
+ ((symbol-function 'file-directory-p) (lambda (_f) nil))
+ ((symbol-function 'cj/music--valid-file-p) (lambda (_f) t))
+ ((symbol-function 'emms-add-file) (lambda (f) (push f added)))
+ ((symbol-function 'message) (lambda (&rest _) nil)))
+ (cj/music-add-dired-selection)
+ (nreverse added))))
+
+(ert-deftest test-music-add-dired-selection-queues-all-marked-files ()
+ "Normal: files marked with m (no region) are all queued, not just point.
+The old gate ran dired-get-marked-files only under use-region-p, so marks
+without a region fell to the single-file branch and silently dropped all
+but the point file."
+ (should (equal (test-add-dired--run '("/tmp/a.mp3" "/tmp/b.mp3" "/tmp/c.mp3"))
+ '("/tmp/a.mp3" "/tmp/b.mp3" "/tmp/c.mp3"))))
+
+(ert-deftest test-music-add-dired-selection-point-file-when-no-marks ()
+ "Boundary: with no marks, dired-get-marked-files returns the point file."
+ (should (equal (test-add-dired--run '("/tmp/only.mp3"))
+ '("/tmp/only.mp3"))))
+
+(ert-deftest test-music-add-dired-selection-errors-outside-dired ()
+ "Error: outside a dired buffer the command signals a user-error."
+ (cl-letf (((symbol-function 'derived-mode-p) (lambda (&rest _) nil)))
+ (should-error (cj/music-add-dired-selection) :type 'user-error)))
+
+(provide 'test-music-config--add-dired-selection)
+;;; test-music-config--add-dired-selection.el ends here
diff --git a/tests/test-music-config--after-playlist-clear.el b/tests/test-music-config--after-playlist-clear.el
index c23e2b5b..42dcf0e3 100644
--- a/tests/test-music-config--after-playlist-clear.el
+++ b/tests/test-music-config--after-playlist-clear.el
@@ -112,5 +112,30 @@
(progn (cj/music--after-playlist-clear) nil)
(error err)))))
+(ert-deftest test-music-header-toggle-advice-is-named-and-installed ()
+ "Normal: the header-refresh toggle advice is a named, removable function.
+An anonymous lambda can't be advice-removed and stacks a copy on every
+:config reload, firing the header refresh N times per toggle."
+ (should (fboundp 'cj/music--refresh-header-after-toggle))
+ (dolist (fn '(emms-toggle-repeat-playlist
+ emms-toggle-repeat-track
+ emms-toggle-random-playlist
+ cj/music-toggle-consume))
+ (should (advice-member-p #'cj/music--refresh-header-after-toggle fn))))
+
+(ert-deftest test-music-header-toggle-advice-does-not-stack ()
+ "Boundary: re-running the install (a :config reload) keeps one advice copy."
+ (dolist (fn '(emms-toggle-repeat-playlist emms-toggle-repeat-track))
+ (advice-remove fn #'cj/music--refresh-header-after-toggle)
+ (advice-add fn :after #'cj/music--refresh-header-after-toggle)
+ (advice-remove fn #'cj/music--refresh-header-after-toggle)
+ (advice-add fn :after #'cj/music--refresh-header-after-toggle)
+ (let ((count 0))
+ (advice-mapc (lambda (f _props)
+ (when (eq f 'cj/music--refresh-header-after-toggle)
+ (setq count (1+ count))))
+ fn)
+ (should (= count 1)))))
+
(provide 'test-music-config--after-playlist-clear)
;;; test-music-config--after-playlist-clear.el ends here