fix: snooze and unsnooze always resolve targets to alarm IDs
This commit is contained in:
parent
ed10ae8842
commit
a2c3755635
2 changed files with 156 additions and 65 deletions
|
|
@ -27,31 +27,36 @@ load test_helper
|
|||
[ "${status}" -eq 1 ]
|
||||
}
|
||||
|
||||
@test "snooze all creates global entry" {
|
||||
@test "snooze all creates entries for all alarm IDs" {
|
||||
run_nag at "tomorrow 3pm" "first"
|
||||
run_nag at "tomorrow 4pm" "second"
|
||||
run_nag snooze all
|
||||
[ "${status}" -eq 0 ]
|
||||
[[ "${output}" =~ "Snoozed all." ]]
|
||||
[[ "${output}" =~ "Snoozed [1]" ]]
|
||||
[[ "${output}" =~ "Snoozed [2]" ]]
|
||||
[ -f "${NAG_DIR}/snoozed" ]
|
||||
grep -q "^\*$" "${NAG_DIR}/snoozed"
|
||||
grep -q "^1$" "${NAG_DIR}/snoozed"
|
||||
grep -q "^2$" "${NAG_DIR}/snoozed"
|
||||
}
|
||||
|
||||
@test "snooze all with duration sets expiry" {
|
||||
@test "snooze all with duration sets expiry for each alarm" {
|
||||
run_nag at "tomorrow 3pm" "first"
|
||||
run_nag at "tomorrow 4pm" "second"
|
||||
run_nag snooze all "tomorrow"
|
||||
[ "${status}" -eq 0 ]
|
||||
[[ "${output}" =~ "Snoozed all" ]]
|
||||
[[ "${output}" =~ "until" ]]
|
||||
local _line
|
||||
_line="$(cat "${NAG_DIR}/snoozed")"
|
||||
[[ "${_line}" == \*$'\t'* ]]
|
||||
grep -q "^1"$'\t' "${NAG_DIR}/snoozed"
|
||||
grep -q "^2"$'\t' "${NAG_DIR}/snoozed"
|
||||
}
|
||||
|
||||
@test "snooze by tag creates entry in snoozed file" {
|
||||
@test "snooze by tag creates entries for matching alarm IDs" {
|
||||
run_nag at "tomorrow 3pm" "work task"
|
||||
run_nag tag 1 work
|
||||
run_nag snooze work
|
||||
[ "${status}" -eq 0 ]
|
||||
[[ "${output}" =~ "Snoozed [work]" ]]
|
||||
grep -q "^work$" "${NAG_DIR}/snoozed"
|
||||
[[ "${output}" =~ "Snoozed [1]" ]]
|
||||
grep -q "^1$" "${NAG_DIR}/snoozed"
|
||||
! grep -q "^work" "${NAG_DIR}/snoozed"
|
||||
}
|
||||
|
||||
@test "snooze by tag requires -f" {
|
||||
|
|
@ -80,16 +85,15 @@ load test_helper
|
|||
[[ "${_line}" == 1$'\t'* ]]
|
||||
}
|
||||
|
||||
@test "snooze by tag with duration sets expiry" {
|
||||
@test "snooze by tag with duration sets expiry for matching IDs" {
|
||||
run_nag at "tomorrow 3pm" "work task"
|
||||
run_nag tag 1 work
|
||||
run_nag snooze work "tomorrow"
|
||||
[ "${status}" -eq 0 ]
|
||||
[[ "${output}" =~ "Snoozed [work]" ]]
|
||||
[[ "${output}" =~ "Snoozed [1]" ]]
|
||||
[[ "${output}" =~ "until" ]]
|
||||
local _line
|
||||
_line="$(cat "${NAG_DIR}/snoozed")"
|
||||
[[ "${_line}" == work$'\t'* ]]
|
||||
grep -q "^1"$'\t' "${NAG_DIR}/snoozed"
|
||||
! grep -q "^work" "${NAG_DIR}/snoozed"
|
||||
}
|
||||
|
||||
@test "unsnooze by ID removes entry from snoozed file" {
|
||||
|
|
@ -102,6 +106,7 @@ load test_helper
|
|||
}
|
||||
|
||||
@test "unsnooze all removes snoozed file" {
|
||||
run_nag at "tomorrow 3pm" "test alarm"
|
||||
run_nag snooze all
|
||||
run_nag unsnooze all
|
||||
[ "${status}" -eq 0 ]
|
||||
|
|
@ -120,14 +125,14 @@ load test_helper
|
|||
[ "${status}" -eq 1 ]
|
||||
}
|
||||
|
||||
@test "unsnooze by tag removes tag entry" {
|
||||
@test "unsnooze by tag removes snoozed entries for matching alarms" {
|
||||
run_nag at "tomorrow 3pm" "work task"
|
||||
run_nag tag 1 work
|
||||
run_nag snooze work
|
||||
run_nag unsnooze work
|
||||
[ "${status}" -eq 0 ]
|
||||
[[ "${output}" =~ "Unsnoozed [work]" ]]
|
||||
! grep -q "^work" "${NAG_DIR}/snoozed" 2>/dev/null
|
||||
[[ "${output}" =~ "Unsnoozed [1]" ]]
|
||||
! grep -q "^1" "${NAG_DIR}/snoozed" 2>/dev/null
|
||||
}
|
||||
|
||||
@test "unsnooze by tag requires -f" {
|
||||
|
|
@ -145,10 +150,40 @@ load test_helper
|
|||
[ "${status}" -eq 1 ]
|
||||
}
|
||||
|
||||
@test "unsnooze tag that is not snoozed fails" {
|
||||
@test "unsnooze tag with no snoozed alarms fails" {
|
||||
run_nag at "tomorrow 3pm" "work task"
|
||||
run_nag tag 1 work
|
||||
run "${_NAG}" -f unsnooze work
|
||||
[ "${status}" -eq 1 ]
|
||||
[[ "${output}" =~ "not snoozed" ]]
|
||||
}
|
||||
|
||||
@test "snooze replaces existing entry instead of duplicating" {
|
||||
run_nag at "tomorrow 3pm" "take a break"
|
||||
run_nag snooze 1
|
||||
run_nag snooze 1
|
||||
[ "${status}" -eq 0 ]
|
||||
[ "$(grep -c "^1" "${NAG_DIR}/snoozed")" -eq 1 ]
|
||||
}
|
||||
|
||||
@test "snooze by tag does not duplicate already-snoozed IDs" {
|
||||
run_nag at "tomorrow 3pm" "work task"
|
||||
run_nag tag 1 work
|
||||
run_nag snooze 1
|
||||
run_nag snooze work
|
||||
[ "${status}" -eq 0 ]
|
||||
[ "$(grep -c "^1" "${NAG_DIR}/snoozed")" -eq 1 ]
|
||||
}
|
||||
|
||||
@test "unsnooze by tag removes ID-snoozed alarms with that tag" {
|
||||
run_nag at "tomorrow 3pm" "work task"
|
||||
run_nag tag 1 work
|
||||
run_nag snooze 1
|
||||
run_nag snooze work
|
||||
run_nag unsnooze work
|
||||
[ "${status}" -eq 0 ]
|
||||
# Alarm should be fully unsnoozed, no entries left
|
||||
if [ -f "${NAG_DIR}/snoozed" ]; then
|
||||
[ ! -s "${NAG_DIR}/snoozed" ] || ! grep -q "^1" "${NAG_DIR}/snoozed"
|
||||
fi
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue