|
| 1 | +;;; dashboard-project-status-test.el --- Tests for dashboard-project-status -*- lexical-binding: t; -*- |
| 2 | + |
| 3 | +;; Author: Jason Duncan <[email protected]> |
| 4 | + |
| 5 | +;;; Code: |
| 6 | + |
| 7 | +(require 'cl) |
| 8 | + |
| 9 | +(expectations |
| 10 | + (desc "dashboard-project-status without UPDATE value") |
| 11 | + (expect (not-called git-run) |
| 12 | + (stub dashboard-project-status-insert-heading) |
| 13 | + (stub dashboard-project-status-insert-body) |
| 14 | + (funcall (dashboard-project-status "foo") nil)) |
| 15 | + (desc "dashboard-project-status with non-nil UPDATE value") |
| 16 | + (expect (mock (git-run "remote" "update") => nil) |
| 17 | + (stub dashboard-project-status-insert-heading) |
| 18 | + (stub dashboard-project-status-insert-body) |
| 19 | + (funcall (dashboard-project-status "foo" t) nil)) |
| 20 | + (desc "dashboard-project-status inserts a heading") |
| 21 | + (expect (mock (dashboard-project-status-insert-heading) => nil) |
| 22 | + (stub dashboard-project-status-insert-body) |
| 23 | + (funcall (dashboard-project-status "foo") nil)) |
| 24 | + (desc "dashboard-project-status inserts a body") |
| 25 | + (expect (mock (dashboard-project-status-insert-body) => nil) |
| 26 | + (stub dashboard-project-status-insert-heading) |
| 27 | + (funcall (dashboard-project-status "foo") nil)) |
| 28 | + (desc "dashboard-project-status-insert-heading when magit is present inserts status text") |
| 29 | + ;; the blank in the middle is where the widget should go, |
| 30 | + ;; but I cannot as yet figure out a way to test that |
| 31 | + (expect "Project is up-to-date." |
| 32 | + (stub dashboard-project-status-git-local-is-behind?) |
| 33 | + (stub widget-create) |
| 34 | + (with-temp-buffer |
| 35 | + (let ((git-repo "foo")) |
| 36 | + (mocklet (((functionp 'magit-status) => t)) |
| 37 | + (dashboard-project-status-insert-heading))) |
| 38 | + (buffer-string))) |
| 39 | + (desc "dashboard-project-status-insert-heading when magit is not present only inserts text") |
| 40 | + (expect "Project foo is up-to-date." |
| 41 | + (stub dashboard-project-status-git-local-is-behind?) |
| 42 | + (with-temp-buffer |
| 43 | + (let ((git-repo "foo")) |
| 44 | + (mocklet (((functionp 'magit-status))) |
| 45 | + (dashboard-project-status-insert-heading))) |
| 46 | + (buffer-string))) |
| 47 | + (desc "dashboard-project-status-insert-body inserts nothing when no items") |
| 48 | + (expect "" |
| 49 | + (stub git-untracked-files) |
| 50 | + (stub dashboard-project-status-git-unstaged-files) |
| 51 | + (stub git-staged-files) |
| 52 | + (with-temp-buffer |
| 53 | + (dashboard-project-status-insert-body) |
| 54 | + (buffer-string))) |
| 55 | + (desc "dashboard-project-status-insert-body inserts untracked files") |
| 56 | + (expect (concat "\nUntracked Files:" |
| 57 | + "\n " |
| 58 | + (abbreviate-file-name |
| 59 | + (expand-file-name |
| 60 | + (concat (file-name-as-directory "foo") "foo"))) |
| 61 | + "\n " |
| 62 | + (abbreviate-file-name |
| 63 | + (expand-file-name |
| 64 | + (concat (file-name-as-directory "foo") "bar")))) |
| 65 | + (stub git-untracked-files => '("foo" "bar")) |
| 66 | + (stub dashboard-project-status-git-unstaged-files) |
| 67 | + (stub git-staged-files) |
| 68 | + (with-temp-buffer |
| 69 | + (let ((git-repo "foo")) |
| 70 | + (flet ((widget-create (&rest args) |
| 71 | + (insert (car (last args))))) |
| 72 | + (dashboard-project-status-insert-body))) |
| 73 | + (buffer-string))) |
| 74 | + (desc "dashboard-project-status-insert-body inserts unstaged files") |
| 75 | + (expect (concat "\nUnstaged Files:" |
| 76 | + "\n " |
| 77 | + (abbreviate-file-name |
| 78 | + (expand-file-name |
| 79 | + (concat (file-name-as-directory "foo") "foo"))) |
| 80 | + "\n " |
| 81 | + (abbreviate-file-name |
| 82 | + (expand-file-name |
| 83 | + (concat (file-name-as-directory "foo") "bar")))) |
| 84 | + (stub git-untracked-files) |
| 85 | + (stub dashboard-project-status-git-unstaged-files => '("foo" "bar")) |
| 86 | + (stub git-staged-files) |
| 87 | + (with-temp-buffer |
| 88 | + (let ((git-repo "foo")) |
| 89 | + (flet ((widget-create (&rest args) |
| 90 | + (insert (car (last args))))) |
| 91 | + (dashboard-project-status-insert-body))) |
| 92 | + (buffer-string))) |
| 93 | + (desc "dashboard-project-status-insert-body inserts staged files") |
| 94 | + (expect (concat "\nStaged Files:" |
| 95 | + "\n " |
| 96 | + (abbreviate-file-name |
| 97 | + (expand-file-name |
| 98 | + (concat (file-name-as-directory "foo") "foo"))) |
| 99 | + "\n " |
| 100 | + (abbreviate-file-name |
| 101 | + (expand-file-name |
| 102 | + (concat (file-name-as-directory "foo") "bar")))) |
| 103 | + (stub git-untracked-files) |
| 104 | + (stub dashboard-project-status-git-unstaged-files) |
| 105 | + (stub git-staged-files => '("foo" "bar")) |
| 106 | + (with-temp-buffer |
| 107 | + (let ((git-repo "foo")) |
| 108 | + (flet ((widget-create (&rest args) |
| 109 | + (insert (car (last args))))) |
| 110 | + (dashboard-project-status-insert-body))) |
| 111 | + (buffer-string))) |
| 112 | + ) |
0 commit comments