Add test for MacOSX notifications

This commit is contained in:
Michael Aquilina 2019-07-15 17:04:56 +01:00
parent 241f33ba26
commit 41117d1b45
No known key found for this signature in database
GPG key ID: 636066730B056BD1
2 changed files with 27 additions and 6 deletions

View file

@ -23,7 +23,7 @@ function _auto_notify_message() {
text="$(echo -e "\"$command\" has completed\n(Total time: $elapsed seconds)")"
platform="$(uname)"
if [[ "$platform" = "Linux" ]]; then
if [[ "$platform" == "Linux" ]]; then
notify-send "$text"
elif [[ "$platform" == "Darwin" ]]; then
osascript -e "display notification \"$text\" with title \"Command Completed\""
@ -75,4 +75,5 @@ function enable_auto_notify() {
}
autoload -Uz add-zsh-hook
enable_auto_notify

View file

@ -4,19 +4,19 @@
load "../auto-notify.plugin.zsh"
function notify-send {
echo "Notification: $@"
echo - "Notification: $@"
}
function uname {
echo "Linux"
echo - "Linux"
}
# Mock date function to return a frozen timestamp
function date {
if [[ "$1" == +"%s" ]]; then
echo "11100"
echo - "11100"
else
date "$@"
date - "$@"
fi
}
}
@ -85,13 +85,33 @@
assert "$lines[2]" same_as "(Total time: 20 seconds)"
}
@test 'auto-notify-send sends notification on MacOSX' {
AUTO_COMMAND="f bar -r"
AUTO_COMMAND_FULL="foo bar -r"
AUTO_COMMAND_START=11080
function uname {
echo - "Darwin"
}
function osascript {
echo - $@
}
run _auto_notify_send
assert $state equals 0
assert "$lines[1]" same_as "-e display notification \"\"f bar -r\" has completed"
assert "$lines[2]" same_as "(Total time: 20 seconds)\" with title \"Command Completed\""
}
@test 'auto-notify-send sends warning on unsupported platform' {
AUTO_COMMAND="f bar -r"
AUTO_COMMAND_FULL="foo bar -r"
AUTO_COMMAND_START=11080
function uname {
echo "Hal9000"
echo - "Hal9000"
}
run _auto_notify_send