nag/test/tag.bats

111 lines
2.6 KiB
Bash

#!/usr/bin/env bats
load test_helper
@test "tag adds a single tag to an alarm" {
run_nag at "tomorrow 3pm" "test alarm"
run_nag tag 1 work
[ "${status}" -eq 0 ]
local _tags
_tags="$(cut -f2 "${NAG_DIR}/alarms")"
[ "${_tags}" = "work" ]
}
@test "tag adds multiple tags to an alarm" {
run_nag at "tomorrow 3pm" "test alarm"
run_nag tag 1 work meetings
[ "${status}" -eq 0 ]
local _tags
_tags="$(cut -f2 "${NAG_DIR}/alarms")"
[ "${_tags}" = "work,meetings" ]
}
@test "tag merges with existing tags without duplicates" {
run_nag at "tomorrow 3pm" "test alarm"
run_nag tag 1 work
run_nag tag 1 meetings work
[ "${status}" -eq 0 ]
local _tags
_tags="$(cut -f2 "${NAG_DIR}/alarms")"
[ "${_tags}" = "work,meetings" ]
}
@test "tag rejects pure integer tag names" {
run_nag at "tomorrow 3pm" "test alarm"
run_nag tag 1 123
[ "${status}" -eq 1 ]
}
@test "tag with nonexistent ID fails" {
run_nag tag 99 work
[ "${status}" -eq 1 ]
}
@test "tag without arguments fails" {
run_nag tag
[ "${status}" -eq 1 ]
}
@test "tag with non-numeric arg lists matching alarms" {
run_nag at "tomorrow 3pm" "work task"
run_nag tag 1 work
run_nag at "tomorrow 4pm" "personal task"
run_nag tag work
[ "${status}" -eq 0 ]
[[ "${output}" =~ "work task" ]]
[[ ! "${output}" =~ "personal task" ]]
}
@test "tag list shows no matches message" {
run_nag at "tomorrow 3pm" "test alarm"
run_nag tag nonexistent
[ "${status}" -eq 0 ]
[[ "${output}" =~ "No alarms tagged" ]]
}
@test "untag removes a tag from an alarm" {
run_nag at "tomorrow 3pm" "test alarm"
run_nag tag 1 work meetings
run_nag untag 1 work
[ "${status}" -eq 0 ]
local _tags
_tags="$(cut -f2 "${NAG_DIR}/alarms")"
[ "${_tags}" = "meetings" ]
}
@test "untag removes the last tag leaving empty field" {
run_nag at "tomorrow 3pm" "test alarm"
run_nag tag 1 work
run_nag untag 1 work
[ "${status}" -eq 0 ]
local _tags
_tags="$(cut -f2 "${NAG_DIR}/alarms")"
[ "${_tags}" = "" ]
}
@test "untag with nonexistent tag fails" {
run_nag at "tomorrow 3pm" "test alarm"
run_nag tag 1 work
run_nag untag 1 meetings
[ "${status}" -eq 1 ]
}
@test "untag with nonexistent ID fails" {
run_nag untag 99 work
[ "${status}" -eq 1 ]
}
@test "untag removes multiple tags at once" {
run_nag at "tomorrow 3pm" "test alarm"
run_nag tag 1 work meetings personal
run_nag untag 1 work personal
[ "${status}" -eq 0 ]
local _tags
_tags="$(cut -f2 "${NAG_DIR}/alarms")"
[ "${_tags}" = "meetings" ]
}
@test "untag without arguments fails" {
run_nag untag
[ "${status}" -eq 1 ]
}