App-TimeTracker
view release on metacpan or search on metacpan
t/Command/core.t view on Meta::CPAN
$now->set_time_zone('local');
my $basetf = $now->ymd('') . '-';
my $tracker_dir = $home->subdir( $now->year, sprintf( "%02d", $now->month ) );
{ # init
@ARGV = ('init');
my $class = $p->setup_class( {} );
file_exists_ok( $home->file('projects.json') );
file_exists_ok( $home->file('tracker.json') );
file_not_exists_ok( $tmp->file( 'some_project', '.tracker.json' ) );
file_not_exists_ok( $tmp->file( 'other_project', '.tracker.json' ) );
$p->_build_home($home);
my $t = $class->name->new( home => $home, config => {}, _current_project => 'some_project' );
trap { $t->cmd_init( $tmp->subdir('some_project') ) };
is( $trap->stdout, "Set up this directory for time-tracking via file .tracker.json\n",
'init: output' );
file_exists_ok( $home->file('projects.json') );
file_exists_ok( $home->file('tracker.json') );
file_exists_ok( $tmp->file( 'some_project', '.tracker.json' ) );
}
{ # init (setting project name)
file_not_exists_ok( $tmp->file( 'project_name_auto', '.tracker.json' ) );
file_not_exists_ok( $tmp->file( 'project_name_custom', '.tracker.json' ) );
@ARGV = ('init');
my $class = $p->setup_class( {} );
{
my $p = App::TimeTracker::Proto->new( home => $home );
# _current_project not set
my $t = $class->name->new( home => $home, config => {} );
trap { $t->cmd_init( $tmp->subdir('project_name_auto') ) };
t/Command/core.t view on Meta::CPAN
cmp_deeply $projects_data, $tracker_files, 'after loading subproj1 project';
}
}
my $c1 = $p->load_config( $tmp->subdir(qw(some_project)) );
{ # start
@ARGV = ('start');
my $class = $p->setup_class($c1);
file_not_exists_ok( $tracker_dir->file( $basetf . '140000_some_project.trc' ),
'tracker file does not exist yet' );
my $t = $class->name->new(
home => $home,
config => $c1,
_current_project => 'some_project',
at => '14:00'
);
trap { $t->cmd_start };
is( $trap->stdout, "Started working on some_project at 14:00:00\n", 'start: output' );
file_not_empty_ok( $tracker_dir->file( $basetf . '140000_some_project.trc' ),
'tracker file exists' );
}
{ # current
# # TODO: need to monkey-patch $class->now to return a mocked value
@ARGV = ('current');
my $class = $p->setup_class($c1);
my $t = $class->name->new( home => $home, config => $c1, _current_project => 'some_project' );
trap { $t->cmd_current };
t/Command/core.t view on Meta::CPAN
}
{ # append
@ARGV = ('append');
my $class = $p->setup_class($c1);
my $t = $class->name->new( home => $home, config => $c1, _current_project => 'some_project' );
trap { $t->cmd_append };
is( $trap->stdout, "Started working on some_project at 14:15:00\n", 'stop: output' );
my $trc = $tracker_dir->file( $basetf . '141500_some_project.trc' );
file_not_empty_ok( $trc, 'tracker file exists' );
my $task = App::TimeTracker::Data::Task->load( $trc->stringify );
is( $task->stop, undef, 'task stop not set' );
}
{ # init other project
file_not_exists_ok( $tmp->file( 'other_project', '.tracker.json' ) );
@ARGV = ('init');
my $class = $p->setup_class( {} );
my $t = $class->name->new( home => $home, config => {}, _current_project => 'other_project' );
trap { $t->cmd_init( $tmp->subdir('other_project') ) };
is( $trap->stdout, "Set up this directory for time-tracking via file .tracker.json\n",
'init: output' );
file_exists_ok( $tmp->file( 'other_project', '.tracker.json' ) );
}
my $c2 = $p->load_config( $tmp->subdir(qw(other_project)) );
{ # start other project
@ARGV = ('start');
my $class = $p->setup_class($c2);
my $trc = $tracker_dir->file( $basetf . '143000_other_project.trc' );
file_not_exists_ok( $trc, 'tracker file does not exist yet' );
my $t = $class->name->new(
home => $home,
config => $c2,
_current_project => 'other_project',
at => '14:30'
);
trap { $t->cmd_start };
is( $trap->stdout,
"Worked 00:15:00 on some_project\nStarted working on other_project at 14:30:00\n",
'start: output'
);
file_not_empty_ok( $trc, 'tracker file exists' );
my $task = App::TimeTracker::Data::Task->load(
$tracker_dir->file( $basetf . '141500_some_project.trc' )->stringify );
is( $task->seconds, 15 * 60, 'prev task seconds' );
is( $task->duration, '00:15:00', 'prev task duration' );
}
{ # stop it
@ARGV = ('stop');
my $class = $p->setup_class($c1);
t/Command/rt_73859_daychange.t view on Meta::CPAN
@ARGV = ('start');
my $class = $p->setup_class($c);
my $t = $class->name->new(
home => $home,
config => $c,
_current_project => 'rt73859',
at => '23:30'
);
trap { $t->cmd_start };
is( $trap->stdout, "Started working on rt73859 at 23:30:00\n", 'start: output' );
file_not_empty_ok( $tracker_dir->file('20120109-233000_rt73859.trc'), 'tracker file exists' );
}
{ # stop
my $test_date = DateTime->new(
year => 2012,
month => 1,
day => 10,
hour => '00',
minute => 3,
time_zone => 'local'
t/Command/rt_73859_daychange.t view on Meta::CPAN
time_zone => 'local'
);
Test::MockTime::set_fixed_time( $test_date->epoch );
@ARGV = ('start');
my $class = $p->setup_class($c);
my $t = $class->name->new( home => $home, config => $c, _current_project => 'rt73859' );
trap { $t->cmd_start };
is( $trap->stdout, "Started working on rt73859 at 23:30:00\n", 'start: output' );
file_not_empty_ok( $tracker_dir->file('20120108-233000_rt73859.trc'), 'tracker file exists' );
}
{ # stop
my $test_date = DateTime->new(
year => 2012,
month => 1,
day => 8,
hour => 23,
minute => 45,
time_zone => 'local'
t/Command/rt_73859_daychange.t view on Meta::CPAN
config => $c,
_current_project => 'rt73859',
at => '0:30'
);
trap { $t->cmd_stop };
like( $trap->stdout, qr/This makes no sense/, 'stop: aborted output' );
my $task = App::TimeTracker::Data::Task->load(
$tracker_dir->file('20120108-233000_rt73859.trc')->stringify );
is( $task->stop, undef, 'task: no stop time' );
file_not_empty_ok( $home->file('current'), '"current" file still exists' );
}
{ # stop again, with long --at
my $test_date = DateTime->new(
year => 2012,
month => 1,
day => 8,
hour => 23,
minute => 45,
time_zone => 'local'
t/Command/rt_73859_daychange.t view on Meta::CPAN
at => '2012-01-09 00:30'
);
trap { $t->cmd_stop };
is( $trap->stdout, "Worked 01:00:00 on rt73859\n", 'stop: output' );
my $task = App::TimeTracker::Data::Task->load(
$tracker_dir->file('20120108-233000_rt73859.trc')->stringify );
is( $task->seconds, 60 * 60, 'task seconds' );
is( $task->duration, '01:00:00', 'task duration' );
file_not_exists_ok( $home->file('current'), '"current" file is gone now' );
}
done_testing();
( run in 0.750 second using v1.01-cache-2.11-cpan-cc502c75498 )