diff --git a/test-hooks.sh b/test-hooks.sh deleted file mode 100755 index 1085a19..0000000 --- a/test-hooks.sh +++ /dev/null @@ -1,66 +0,0 @@ -#!/bin/sh -testdir=/tmp/timew-hook-test -rm -r $testdir -export TIMEWARRIORDB=$testdir/timew -export TASKDATA=$testdir/task -export TASKRC=$TASKDATA/taskrc -hooksdir=$TASKDATA/hooks -mkdir -p $hooksdir -cp ./*.timewarrior $hooksdir -( timew :quiet :yes && echo yes | task ) >/dev/null 2>&1 - -set -e -highlight() { echo "$@"; } -verbose=$(test "$1" = "v" && echo "true" || echo "false") -debug() { $verbose && $@ || true; } -if test "$1" = "q" -then task() { command task "$@" 2>/dev/null; } -else $verbose || task() { command task "$@" 3>&1 1>&2 2>&3 3>&- | (grep -v "override:" || true); } -fi -checkdom() { - test "$(timew get dom.$1)" = "$2" -} - -highlight A new task is started with correct time -task add test +t1 start:2020-04-04 entry:2020-04-03 -debug task 1 info -checkdom active.start "2020-04-04T00:00:00" - -highlight Modify start time -task 1 modify start:2020-04-05T12:00 -debug timew -checkdom active.start "2020-04-05T12:00:00" - -highlight Modify tags -task 1 modify +t2 project:testing -checkdom tag.count 4 - -checkcur() { - checkdom tracked.count 1 - checkdom tag.count 4 - checkdom active.tag.count 4 - checkdom active.start "2020-04-05T12:00:00" -} - -highlight Modify start time of second task -task add test2 +t3 entry:2020-04-03 -task 2 modify start:2020-04-06 -checkcur - -highlight Modify tags of second now started task -task 2 modify +t3 -debug timew -checkcur - -highlight Stop second task -task 2 stop -checkcur - -highlight Switch active task and don\'t override previous interval -task 1 stop -timew modify end @1 2020-04-07T00:00 -#Automatically correct overlap, needs support in timew core -#task 2 modify start:today -! task 2 modify start:2020-04-05T00:00 -task 2 modify start:2020-04-07 -checkdom active.tag.count 2 diff --git a/test/test_on-modify_e2e.py b/test/test_on-modify_e2e.py index b1ab752..37d4693 100755 --- a/test/test_on-modify_e2e.py +++ b/test/test_on-modify_e2e.py @@ -201,3 +201,89 @@ def test_hook_should_process_stop(self): j = self.timew.export() self.assertEqual(len(j), 1) self.assertClosedInterval(j[0], expectedTags=["Foo"]) + + def test_a_new_task_is_started_with_correct_time(self): + """A new task is started with correct time""" + self.task.activate_hooks() + self.task("add test +t1 start:2020-04-04 entry:2020-04-03") + + dom = self.timew("get dom.active.start") + self.assertEqual(dom, "2020-04-04T00:00:00") + + def test_modify_start_time(self): + """Modify start time""" + self.task.deactivate_hooks() + self.task("add test +t1 start:2020-04-04 entry:2020-04-03") + self.task.activate_hooks() + self.task("1 modify start:2020-04-05T12:00") + + dom = self.timew("get dom.active.start") + self.assertEqual(dom, "2020-04-05T12:00:00") + + def test_modify_tags(self): + """Modify tags""" + self.task.deactivate_hooks() + self.task("add test +t1 start:2020-04-04 entry:2020-04-03") + self.task("1 modify start:2020-04-05T12:00") + self.task.activate_hooks() + self.task("1 modify +t2 project:testing") + + dom = self.timew("get dom.tag.count") + self.assertEqual(dom, 4) + + def test_modify_start_time_of_second_task(self): + """Modify start time of second task""" + self.task.deactivate_hooks() + self.task("add test +t1 start:2020-04-04 entry:2020-04-03") + self.task("1 modify start:2020-04-05T12:00") + self.task.activate_hooks() + self.task("add test2 +t3 entry:2020-04-03") + self.task("2 modify start:2020-04-06") + + j = self.timew.export() + self.assertEqual(len(j), 1) + self.assertClosedInterval(j[0], expectedTags=["Foo"]) + + def test_modify_tags_of_second_now_started_task(self): + """Modify tags of second now started task""" + self.task.deactivate_hooks() + self.task("add test +t1 start:2020-04-04 entry:2020-04-03") + self.task("1 modify start:2020-04-05T12:00") + self.task("add test2 +t3 entry:2020-04-03") + self.task.activate_hooks() + self.task("2 modify +t3") + + j = self.timew.export() + self.assertEqual(len(j), 1) + self.assertClosedInterval(j[0], expectedTags=["Foo"]) + + def test_stop_second_task(self): + """Stop second task""" + self.task.deactivate_hooks() + self.task("add test +t1 start:2020-04-04 entry:2020-04-03") + self.task("1 modify start:2020-04-05T12:00") + self.task("add test2 +t3 entry:2020-04-03") + self.task.activate_hooks() + self.task("2 stop") + + j = self.timew.export() + self.assertEqual(len(j), 1) + self.assertClosedInterval(j[0], expectedTags=["Foo"]) + + def test_switch_active_task_and_dont_override_previous_interval(self): + """Switch active task and don\'t override previous interval""" + self.task.deactivate_hooks() + self.task("add test +t1 start:2020-04-04 entry:2020-04-03") + self.task("1 modify start:2020-04-05T12:00") + self.task("add test2 +t3 entry:2020-04-03") + self.task("2 stop") + self.task.activate_hooks() + self.task('1 stop') + self.timew("modify end @1 2020-04-07T00:00") + # Automatically correct overlap, needs support in timew core + # task 2 modify start:today + self.task.runError("2 modify start:2020-04-05T00:00") + self.task("2 modify start:2020-04-07") + + dom = self.timew("get dom.active.tag.count") + self.assertEqual(dom, "2")