test-org-attach.el 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. ;;; test-org-attach.el --- tests for org-attach.el -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2017
  3. ;; Author: Marco Wahl
  4. ;; Keywords: internal
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;;
  17. ;;; Code:
  18. (require 'org-test)
  19. (require 'org-attach)
  20. (ert-deftest test-org-attach/dired-attach-to-next-best-subtree/1 ()
  21. "Attach file at point in dired to subtree."
  22. (should
  23. (let ((a-filename (make-temp-file "a"))) ; file is an attach candidate.
  24. (unwind-protect
  25. (org-test-with-temp-text-in-file
  26. "* foo :foo:"
  27. (split-window)
  28. (dired temporary-file-directory)
  29. (assert (eq 'dired-mode major-mode))
  30. (revert-buffer)
  31. (dired-goto-file a-filename)
  32. ; action
  33. (call-interactively #'org-attach-dired-to-subtree)
  34. ; check
  35. (delete-window)
  36. (assert (eq 'org-mode major-mode))
  37. (beginning-of-buffer)
  38. (search-forward "* foo")
  39. ; expectation. tag ATTACH has been appended.
  40. (reduce (lambda (x y) (or x y))
  41. (mapcar (lambda (x) (string-equal "ATTACH" x))
  42. (plist-get
  43. (plist-get
  44. (org-element-at-point) 'headline) :tags))))
  45. (delete-file a-filename)))))
  46. (ert-deftest test-org-attach/dired-attach-to-next-best-subtree/2 ()
  47. "Attach 2 marked files."
  48. (should
  49. (let ((a-filename (make-temp-file "a"))
  50. (b-filename (make-temp-file "b"))) ; attach candidates.
  51. (unwind-protect
  52. (org-test-with-temp-text-in-file
  53. "* foo"
  54. (split-window)
  55. (dired temporary-file-directory)
  56. (assert (eq 'dired-mode major-mode))
  57. (revert-buffer)
  58. (dired-goto-file a-filename)
  59. (dired-mark 1)
  60. (dired-goto-file b-filename)
  61. (dired-mark 1)
  62. ; action
  63. (call-interactively #'org-attach-dired-to-subtree)
  64. ; check
  65. (delete-window)
  66. (assert (eq 'org-mode major-mode))
  67. (beginning-of-buffer)
  68. (search-forward "* foo")
  69. (and (file-exists-p (concat (org-attach-dir) "/"
  70. (file-name-nondirectory a-filename)))
  71. (file-exists-p (concat (org-attach-dir) "/"
  72. (file-name-nondirectory b-filename)))))
  73. (delete-file a-filename)
  74. (delete-file b-filename)))))
  75. (provide 'test-org-attach)
  76. ;;; test-org-attach.el ends here