From dd16641400e49f94f480db8c3e62e0760065e6d8 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 14 May 2012 17:11:51 +0100 Subject: basic dashbaord tests --- t/app/controller/dashboard.t | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 t/app/controller/dashboard.t (limited to 't/app/controller/dashboard.t') diff --git a/t/app/controller/dashboard.t b/t/app/controller/dashboard.t new file mode 100644 index 000000000..b96196d21 --- /dev/null +++ b/t/app/controller/dashboard.t @@ -0,0 +1,42 @@ +use strict; +use warnings; +use Test::More; + +use FixMyStreet::TestMech; + +my $mech = FixMyStreet::TestMech->new; + +my $test_user = 'council_user@example.com'; +my $test_pass = 'password'; +my $test_council = 2651; + +$mech->delete_user( $test_user ); +my $user = FixMyStreet::App->model('DB::User')->create( { + email => $test_user, + password => $test_pass, +} ); + +$mech->not_logged_in_ok; +$mech->get_ok('/dashboard'); + +$mech->content_contains( 'sign in' ); + +$mech->submit_form( + with_fields => { email => $test_user, password_sign_in => $test_pass } +); + +is $mech->status, '404', 'If not council user get 404'; + +$user->from_council( $test_council ); +$user->update; + +$mech->log_out_ok; +$mech->get_ok('/dashboard'); +$mech->submit_form_ok( { + with_fields => { email => $test_user, password_sign_in => $test_pass } +} ); + +$mech->content_contains( 'Summary Statistics' ); +$mech->content_contains( 'Edinburgh' ); + +done_testing; -- cgit v1.2.3 From 4268024f74085b25a985fdfde431cd9b17e4cffb Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 14 May 2012 18:06:32 +0100 Subject: add council name to dashboard --- t/app/controller/dashboard.t | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 't/app/controller/dashboard.t') diff --git a/t/app/controller/dashboard.t b/t/app/controller/dashboard.t index b96196d21..788b41dbe 100644 --- a/t/app/controller/dashboard.t +++ b/t/app/controller/dashboard.t @@ -36,7 +36,6 @@ $mech->submit_form_ok( { with_fields => { email => $test_user, password_sign_in => $test_pass } } ); -$mech->content_contains( 'Summary Statistics' ); -$mech->content_contains( 'Edinburgh' ); +$mech->content_contains( 'Summary Statistics for City of Edinburgh' ); done_testing; -- cgit v1.2.3 From c12c7836af432302fe3805e6081df3182f0bc2b6 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 14 May 2012 19:15:49 +0100 Subject: add in some basic tests of data --- t/app/controller/dashboard.t | 45 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 't/app/controller/dashboard.t') diff --git a/t/app/controller/dashboard.t b/t/app/controller/dashboard.t index 788b41dbe..eccbc0cde 100644 --- a/t/app/controller/dashboard.t +++ b/t/app/controller/dashboard.t @@ -3,6 +3,7 @@ use warnings; use Test::More; use FixMyStreet::TestMech; +use Web::Scraper; my $mech = FixMyStreet::TestMech->new; @@ -38,4 +39,48 @@ $mech->submit_form_ok( { $mech->content_contains( 'Summary Statistics for City of Edinburgh' ); +FixMyStreet::App->model('DB::Contact')->search( { area_id => $test_council } ) + ->delete; + +my $eight_weeks_ago = DateTime->now->subtract( weeks => 8 ); + +FixMyStreet::App->model('DB::Problem')->search( { council => $test_council } ) + ->update( { confirmed => $eight_weeks_ago } ); + +my @cats = qw( Grafitti Litter Potholes ); +for my $contact ( @cats ) { + FixMyStreet::App->model('DB::Contact')->create( + { + area_id => $test_council, + category => $contact, + email => "$contact\@example.org", + confirmed => 1, + whenedited => DateTime->now, + deleted => 0, + editor => 'test', + note => 'test', + } + ); +} + +$mech->get_ok('/dashboard'); + +my $categories = scraper { + process "select[name=category] > option", 'cats[]' => 'TEXT', + process "select[name=ward] > option", 'wards[]' => 'TEXT', + process "table[id=overview] > tr", 'rows[]' => scraper { + process 'td', 'cols[]' => 'TEXT' + } +}; + +my $expected_cats = [ 'All', '-- Pick a category --', @cats, 'Other' ]; +my $res = $categories->scrape( $mech->content ); +is_deeply( $res->{cats}, $expected_cats, 'correct list of categories' ); + +foreach my $row ( @{ $res->{rows} }[1 .. 11] ) { + foreach my $col ( @{ $row->{cols} } ) { + is $col, 0; + } +} + done_testing; -- cgit v1.2.3 From 8a6bcedac3697e2c1c07c27bc0b42224b8f5ba16 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Tue, 15 May 2012 10:56:30 +0100 Subject: check one report included in figures --- t/app/controller/dashboard.t | 51 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) (limited to 't/app/controller/dashboard.t') diff --git a/t/app/controller/dashboard.t b/t/app/controller/dashboard.t index eccbc0cde..93aee9a72 100644 --- a/t/app/controller/dashboard.t +++ b/t/app/controller/dashboard.t @@ -10,6 +10,7 @@ my $mech = FixMyStreet::TestMech->new; my $test_user = 'council_user@example.com'; my $test_pass = 'password'; my $test_council = 2651; +my $test_ward = 20723; $mech->delete_user( $test_user ); my $user = FixMyStreet::App->model('DB::User')->create( { @@ -17,6 +18,10 @@ my $user = FixMyStreet::App->model('DB::User')->create( { password => $test_pass, } ); +my $p_user = FixMyStreet::App->model('DB::User')->find_or_create( { + email => 'p_user@example.com' +} ); + $mech->not_logged_in_ok; $mech->get_ok('/dashboard'); @@ -42,10 +47,8 @@ $mech->content_contains( 'Summary Statistics for City of Edinburgh' ); FixMyStreet::App->model('DB::Contact')->search( { area_id => $test_council } ) ->delete; -my $eight_weeks_ago = DateTime->now->subtract( weeks => 8 ); - FixMyStreet::App->model('DB::Problem')->search( { council => $test_council } ) - ->update( { confirmed => $eight_weeks_ago } ); + ->delete(); my @cats = qw( Grafitti Litter Potholes ); for my $contact ( @cats ) { @@ -70,7 +73,18 @@ my $categories = scraper { process "select[name=ward] > option", 'wards[]' => 'TEXT', process "table[id=overview] > tr", 'rows[]' => scraper { process 'td', 'cols[]' => 'TEXT' - } + }, + process "tr[id=total] > td", 'totals[]' => 'TEXT', + process "tr[id=fixed_council] > td", 'council[]' => 'TEXT', + process "tr[id=fixed_user] > td", 'user[]' => 'TEXT', + process "tr[id=total_fixed] > td", 'total_fixed[]' => 'TEXT', + process "tr[id=in_progress] > td", 'in_progress[]' => 'TEXT', + process "tr[id=planned] > td", 'planned[]' => 'TEXT', + process "tr[id=investigating] > td", 'investigating[]' => 'TEXT', + process "tr[id=marked] > td", 'marked[]' => 'TEXT', + process "tr[id=avg_marked] > td", 'avg_marked[]' => 'TEXT', + process "tr[id=avg_fixed] > td", 'avg_fixed[]' => 'TEXT', + process "tr[id=not_marked] > td", 'not_marked[]' => 'TEXT', }; my $expected_cats = [ 'All', '-- Pick a category --', @cats, 'Other' ]; @@ -83,4 +97,33 @@ foreach my $row ( @{ $res->{rows} }[1 .. 11] ) { } } +make_problem( { state => 'confirmed', conf_dt => DateTime->now } ); + +$mech->get_ok('/dashboard'); +$res = $categories->scrape( $mech->content ); + +is $res->{ totals }->[1], 1, 'Report in total'; +is $res->{ not_marked }->[1], 1, 'Report in not marked'; + +sub make_problem { + my $args = shift; + + my $p = FixMyStreet::App->model('DB::Problem')->create( { + title => 'a problem', + name => 'a user', + anonymous => 1, + detail => 'some detail', + state => $args->{state}, + confirmed => $args->{conf_dt}, + whensent => $args->{conf_dt}, + council => $test_council, + postcode => 'EH99 1SP', + latitude => '51', + longitude => '1', + areas => $test_ward, + used_map => 0, + user_id => $p_user->id, + } ); +} + done_testing; -- cgit v1.2.3 From 272bee8aee1c9b3584a5f345cd3c149d111fda60 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Tue, 15 May 2012 12:52:43 +0100 Subject: more detailed tests of problem counts --- t/app/controller/dashboard.t | 134 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 127 insertions(+), 7 deletions(-) (limited to 't/app/controller/dashboard.t') diff --git a/t/app/controller/dashboard.t b/t/app/controller/dashboard.t index 93aee9a72..4731397b7 100644 --- a/t/app/controller/dashboard.t +++ b/t/app/controller/dashboard.t @@ -47,8 +47,7 @@ $mech->content_contains( 'Summary Statistics for City of Edinburgh' ); FixMyStreet::App->model('DB::Contact')->search( { area_id => $test_council } ) ->delete; -FixMyStreet::App->model('DB::Problem')->search( { council => $test_council } ) - ->delete(); +delete_problems(); my @cats = qw( Grafitti Litter Potholes ); for my $contact ( @cats ) { @@ -97,13 +96,101 @@ foreach my $row ( @{ $res->{rows} }[1 .. 11] ) { } } -make_problem( { state => 'confirmed', conf_dt => DateTime->now } ); -$mech->get_ok('/dashboard'); -$res = $categories->scrape( $mech->content ); +foreach my $test ( + { + desc => 'confirmed today with no state', + dt => DateTime->now, + counts => [1,1,1,1], + }, + { + desc => 'confirmed last 7 days with no state', + dt => DateTime->now->subtract( days => 6, hours => 23 ), + counts => [1,2,2,2], + }, + { + desc => 'confirmed last 4 weeks with no state', + dt => DateTime->now->subtract( weeks => 2 ), + counts => [1,2,3,3], + }, + { + desc => 'confirmed this year with no state', + dt => DateTime->now->subtract( weeks => 7 ), + counts => [1,2,3,4], + }, +) { + subtest $test->{desc} => sub { + make_problem( { state => 'confirmed', conf_dt => $test->{dt} } ); + + $mech->get_ok('/dashboard'); + $res = $categories->scrape( $mech->content ); -is $res->{ totals }->[1], 1, 'Report in total'; -is $res->{ not_marked }->[1], 1, 'Report in not marked'; + check_row( $res, 'totals', $test->{counts} ); + check_row( $res, 'not_marked', $test->{counts} ); + }; +} + +delete_problems(); + +foreach my $test ( + { + desc => 'user fixed today', + confirm_dt => DateTime->now->subtract( days => 1 ), + mark_dt => DateTime->now, + state => 'fixed - user', + counts => { + totals => [1,1,1,1], + user => [1,1,1,1], + council => [0,0,0,0], + avg_fixed => [0,0,0,0], + total_fixed => [1,1,1,1], + } + }, + { + desc => 'council fixed today', + confirm_dt => DateTime->now->subtract( days => 1 ), + mark_dt => DateTime->now, + state => 'fixed - council', + counts => { + totals => [2,2,2,2], + user => [1,1,1,1], + council => [1,1,1,1], + avg_fixed => [1,1,1,1], + total_fixed => [2,2,2,2], + } + }, + { + desc => 'marked investigating today', + confirm_dt => DateTime->now->subtract( days => 1 ), + mark_dt => DateTime->now, + state => 'investigating', + counts => { + totals => [3,3,3,3], + user => [1,1,1,1], + council => [1,1,1,1], + total_fixed => [2,2,2,2], + avg_marked => [1,1,1,1], + investigating => [1,1,1,1], + } + }, +) { + subtest $test->{desc} => sub { + make_problem( + { + state => $test->{state}, + conf_dt => $test->{confirm_dt}, + mark_dt => $test->{mark_dt}, + } + ); + + $mech->get_ok('/dashboard'); + $res = $categories->scrape( $mech->content ); + + foreach my $row ( keys %{ $test->{counts} } ) { + check_row( $res, $row, $test->{counts}->{$row} ); + } + }; +} sub make_problem { my $args = shift; @@ -116,6 +203,7 @@ sub make_problem { state => $args->{state}, confirmed => $args->{conf_dt}, whensent => $args->{conf_dt}, + lastupdate => $args->{mark_dt} || $args->{conf_dt}, council => $test_council, postcode => 'EH99 1SP', latitude => '51', @@ -124,6 +212,38 @@ sub make_problem { used_map => 0, user_id => $p_user->id, } ); + + if ( $args->{state} ne 'confirmed' ) { + my $c = FixMyStreet::App->model('DB::Comment')->create( { + problem => $p, + user_id => $p_user->id, + state => 'confirmed', + problem_state => $args->{state}, + confirmed => $args->{mark_dt}, + text => 'an update', + mark_fixed => $args->{state} =~ /fixed/ ? 1 : 0, + anonymous => 1, + } ); + } +} + +sub check_row { + my $res = shift; + my $row = shift; + my $totals = shift; + + is $res->{ $row }->[0], $totals->[0], "Correct count in $row for WTD"; + is $res->{ $row }->[1], $totals->[1], "Correct count in $row for last 7 days"; + is $res->{ $row }->[2], $totals->[2], "Correct count in $row for last 4 weeks"; + is $res->{ $row }->[3], $totals->[3], "Correct count in $row for YTD"; +} + +sub delete_problems { + FixMyStreet::App->model('DB::Comment') + ->search( { 'problem.council' => $test_council }, { join => 'problem' } ) + ->delete; + FixMyStreet::App->model('DB::Problem') + ->search( { council => $test_council } )->delete(); } done_testing; -- cgit v1.2.3 From 67be3761781b6c5a2690474f65bc752e6d65cef1 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Tue, 15 May 2012 17:24:26 +0100 Subject: tests for date counting and limiting by category --- t/app/controller/dashboard.t | 226 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 226 insertions(+) (limited to 't/app/controller/dashboard.t') diff --git a/t/app/controller/dashboard.t b/t/app/controller/dashboard.t index 4731397b7..f814a2dd3 100644 --- a/t/app/controller/dashboard.t +++ b/t/app/controller/dashboard.t @@ -171,6 +171,111 @@ foreach my $test ( total_fixed => [2,2,2,2], avg_marked => [1,1,1,1], investigating => [1,1,1,1], + marked => [1,1,1,1] + } + }, + { + desc => 'marked in progress today', + confirm_dt => DateTime->now->subtract( days => 1 ), + mark_dt => DateTime->now, + state => 'in progress', + counts => { + totals => [4,4,4,4], + user => [1,1,1,1], + council => [1,1,1,1], + total_fixed => [2,2,2,2], + avg_marked => [1,1,1,1], + investigating => [1,1,1,1], + in_progress => [1,1,1,1], + marked => [2,2,2,2] + } + }, + { + desc => 'marked as planned today', + confirm_dt => DateTime->now->subtract( days => 1 ), + mark_dt => DateTime->now, + state => 'planned', + counts => { + totals => [5,5,5,5], + user => [1,1,1,1], + council => [1,1,1,1], + total_fixed => [2,2,2,2], + avg_marked => [1,1,1,1], + investigating => [1,1,1,1], + in_progress => [1,1,1,1], + planned => [1,1,1,1], + marked => [3,3,3,3] + } + }, + { + desc => 'marked as planned today, confirmed a week ago', + confirm_dt => DateTime->now->subtract( days => 8 ), + mark_dt => DateTime->now, + state => 'planned', + counts => { + totals => [5,5,6,6], + user => [1,1,1,1], + council => [1,1,1,1], + total_fixed => [2,2,2,2], + avg_marked => [3,3,3,3], + investigating => [1,1,1,1], + in_progress => [1,1,1,1], + planned => [2,2,2,2], + marked => [4,4,4,4] + } + }, + { + desc => 'marked as council fixed today, confirmed a week ago', + confirm_dt => DateTime->now->subtract( days => 8 ), + mark_dt => DateTime->now, + state => 'fixed - council', + counts => { + totals => [5,5,7,7], + user => [1,1,1,1], + council => [2,2,2,2], + total_fixed => [3,3,3,3], + avg_fixed => [5,5,5,5], + avg_marked => [3,3,3,3], + investigating => [1,1,1,1], + in_progress => [1,1,1,1], + planned => [2,2,2,2], + marked => [4,4,4,4] + } + }, + { + desc => 'marked as council fixed a week ago, confirmed 3 weeks ago', + confirm_dt => DateTime->now->subtract( days => 21), + mark_dt => DateTime->now->subtract( days => 8 ), + state => 'fixed - council', + counts => { + totals => [5,5,8,8], + user => [1,1,1,1], + council => [2,2,3,3], + total_fixed => [3,3,4,4], + avg_fixed => [5,5,7,7], + avg_marked => [3,3,3,3], + investigating => [1,1,1,1], + in_progress => [1,1,1,1], + planned => [2,2,2,2], + marked => [4,4,4,4] + } + }, + { + desc => 'marked as user fixed 6 weeks ago, confirmed 7 weeks ago', + confirm_dt => DateTime->now->subtract( weeks => 6 ), + mark_dt => DateTime->now->subtract( weeks => 7 ), + state => 'fixed - user', + counts => { + totals => [5,5,8,9], + user => [1,1,1,2], + council => [2,2,3,3], + total_fixed => [3,3,4,5], + avg_fixed => [5,5,7,7], + avg_marked => [3,3,3,3], + investigating => [1,1,1,1], + in_progress => [1,1,1,1], + planned => [2,2,2,2], + marked => [4,4,4,4] } }, ) { @@ -192,6 +297,126 @@ foreach my $test ( }; } +delete_problems(); + +for my $test ( + { + desc => 'Selecting no category does nothing', + p1 => { + state => 'confirmed', + conf_dt => DateTime->now(), + category => 'Potholes', + }, + p2 => { + state => 'confirmed', + conf_dt => DateTime->now(), + category => 'Litter', + }, + category => '', + counts => { + totals => [2,2,2,2], + }, + counts_after => { + totals => [2,2,2,2], + } + }, + { + desc => 'Limit display by category', + category => 'Potholes', + counts => { + totals => [2,2,2,2], + }, + counts_after => { + totals => [1,1,1,1], + } + }, + { + desc => 'Limit display for category with no entries', + category => 'Grafitti', + counts => { + totals => [2,2,2,2], + }, + counts_after => { + totals => [0,0,0,0], + } + }, + { + desc => 'Limit display by category for council fixed', + p1 => { + state => 'fixed - council', + conf_dt => DateTime->now()->subtract( weeks => 1 ), + mark_dt => DateTime->now()->subtract( weeks => 1 ), + category => 'Potholes', + }, + p2 => { + state => 'fixed - council', + conf_dt => DateTime->now()->subtract( weeks => 1 ), + mark_dt => DateTime->now()->subtract( weeks => 1 ), + category => 'Litter', + }, + category => 'Potholes', + counts => { + council => [0,0,2,2], + totals => [2,2,4,4], + }, + counts_after => { + council => [0,0,1,1], + totals => [1,1,2,2], + } + }, + { + desc => 'Limit display by category for user fixed', + p1 => { + state => 'fixed - user', + conf_dt => DateTime->now()->subtract( weeks => 1 ), + mark_dt => DateTime->now()->subtract( weeks => 1 ), + category => 'Potholes', + }, + p2 => { + state => 'fixed - user', + conf_dt => DateTime->now()->subtract( weeks => 1 ), + mark_dt => DateTime->now()->subtract( weeks => 1 ), + category => 'Litter', + }, + category => 'Potholes', + counts => { + user => [0,0,2,2], + council => [0,0,2,2], + totals => [2,2,6,6], + }, + counts_after => { + user => [0,0,1,1], + council => [0,0,1,1], + totals => [1,1,3,3], + } + }, +) { + subtest $test->{desc} => sub { + make_problem( $test->{p1} ) if $test->{p1}; + make_problem( $test->{p2} ) if $test->{p2}; + + $mech->get_ok('/dashboard'); + + $res = $categories->scrape( $mech->content ); + + foreach my $row ( keys %{ $test->{counts} } ) { + check_row( $res, $row, $test->{counts}->{$row} ); + } + + $mech->submit_form_ok( { + with_fields => { + category => $test->{category}, + } + } ); + + $res = $categories->scrape( $mech->content ); + + foreach my $row ( keys %{ $test->{counts_after} } ) { + check_row( $res, $row, $test->{counts_after}->{$row} ); + } + }; +} + sub make_problem { my $args = shift; @@ -211,6 +436,7 @@ sub make_problem { areas => $test_ward, used_map => 0, user_id => $p_user->id, + category => $args->{category} || 'Other', } ); if ( $args->{state} ne 'confirmed' ) { -- cgit v1.2.3 From e14373d9c9ece3497a12e712a823577f923fa25a Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Tue, 15 May 2012 22:51:29 +0100 Subject: tests for limiting by ward --- t/app/controller/dashboard.t | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 't/app/controller/dashboard.t') diff --git a/t/app/controller/dashboard.t b/t/app/controller/dashboard.t index f814a2dd3..a658eb68c 100644 --- a/t/app/controller/dashboard.t +++ b/t/app/controller/dashboard.t @@ -390,6 +390,35 @@ for my $test ( totals => [1,1,3,3], } }, + { + desc => 'Limit display by ward', + p1 => { + state => 'confirmed', + conf_dt => DateTime->now()->subtract( weeks => 1 ), + category => 'Potholes', + # in real life it has commas around it and the search + # uses them + areas => ',20720,', + }, + p2 => { + state => 'fixed - council', + conf_dt => DateTime->now()->subtract( weeks => 1 ), + mark_dt => DateTime->now()->subtract( weeks => 1 ), + category => 'Litter', + areas => ',20720,', + }, + ward => 20720, + counts => { + user => [0,0,2,2], + council => [0,0,3,3], + totals => [2,2,8,8], + }, + counts_after => { + user => [0,0,0,0], + council => [0,0,1,1], + totals => [0,0,2,2], + } + }, ) { subtest $test->{desc} => sub { make_problem( $test->{p1} ) if $test->{p1}; @@ -406,6 +435,7 @@ for my $test ( $mech->submit_form_ok( { with_fields => { category => $test->{category}, + ward => $test->{ward}, } } ); @@ -433,7 +463,7 @@ sub make_problem { postcode => 'EH99 1SP', latitude => '51', longitude => '1', - areas => $test_ward, + areas => $args->{areas} || $test_ward, used_map => 0, user_id => $p_user->id, category => $args->{category} || 'Other', -- cgit v1.2.3 From 3587d4288288438be7f717989da2a8e3945e66ec Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 16 May 2012 12:31:26 +0100 Subject: add in tests for report counts at bottom of dashboard --- t/app/controller/dashboard.t | 115 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 107 insertions(+), 8 deletions(-) (limited to 't/app/controller/dashboard.t') diff --git a/t/app/controller/dashboard.t b/t/app/controller/dashboard.t index a658eb68c..b12b886d9 100644 --- a/t/app/controller/dashboard.t +++ b/t/app/controller/dashboard.t @@ -84,6 +84,9 @@ my $categories = scraper { process "tr[id=avg_marked] > td", 'avg_marked[]' => 'TEXT', process "tr[id=avg_fixed] > td", 'avg_fixed[]' => 'TEXT', process "tr[id=not_marked] > td", 'not_marked[]' => 'TEXT', + process "table[id=reports] > tr > td", 'report_lists[]' => scraper { + process 'ul > li', 'reports[]' => 'TEXT' + }, }; my $expected_cats = [ 'All', '-- Pick a category --', @cats, 'Other' ]; @@ -96,27 +99,40 @@ foreach my $row ( @{ $res->{rows} }[1 .. 11] ) { } } +for my $reports ( @{ $res->{report_lists} } ) { + is_deeply $reports, {}, 'No reports'; +} foreach my $test ( { desc => 'confirmed today with no state', dt => DateTime->now, counts => [1,1,1,1], + report_counts => [1, 0, 0], }, { desc => 'confirmed last 7 days with no state', dt => DateTime->now->subtract( days => 6, hours => 23 ), counts => [1,2,2,2], + report_counts => [2, 0, 0], + }, + { + desc => 'confirmed last 8 days with no state', + dt => DateTime->now->subtract( days => 8 ), + counts => [1,2,3,3], + report_counts => [2, 1, 0], }, { desc => 'confirmed last 4 weeks with no state', dt => DateTime->now->subtract( weeks => 2 ), - counts => [1,2,3,3], + counts => [1,2,4,4], + report_counts => [2, 1, 1], }, { desc => 'confirmed this year with no state', dt => DateTime->now->subtract( weeks => 7 ), - counts => [1,2,3,4], + counts => [1,2,4,5], + report_counts => [2, 1, 1], }, ) { subtest $test->{desc} => sub { @@ -127,6 +143,8 @@ foreach my $test ( check_row( $res, 'totals', $test->{counts} ); check_row( $res, 'not_marked', $test->{counts} ); + + check_report_counts( $res, $test->{report_counts} ); }; } @@ -318,7 +336,9 @@ for my $test ( }, counts_after => { totals => [2,2,2,2], - } + }, + report_counts => [2,0,0], + report_counts_after => [2,0,0], }, { desc => 'Limit display by category', @@ -328,7 +348,9 @@ for my $test ( }, counts_after => { totals => [1,1,1,1], - } + }, + report_counts => [2,0,0], + report_counts_after => [1,0,0], }, { desc => 'Limit display for category with no entries', @@ -338,7 +360,9 @@ for my $test ( }, counts_after => { totals => [0,0,0,0], - } + }, + report_counts => [2,0,0], + report_counts_after => [0,0,0], }, { desc => 'Limit display by category for council fixed', @@ -362,7 +386,9 @@ for my $test ( counts_after => { council => [0,0,1,1], totals => [1,1,2,2], - } + }, + report_counts => [2,2,0], + report_counts_after => [1,1,0], }, { desc => 'Limit display by category for user fixed', @@ -388,7 +414,9 @@ for my $test ( user => [0,0,1,1], council => [0,0,1,1], totals => [1,1,3,3], - } + }, + report_counts => [2,4,0], + report_counts_after => [1,2,0], }, { desc => 'Limit display by ward', @@ -417,7 +445,9 @@ for my $test ( user => [0,0,0,0], council => [0,0,1,1], totals => [0,0,2,2], - } + }, + report_counts => [2,6,0], + report_counts_after => [0,2,0], }, ) { subtest $test->{desc} => sub { @@ -432,6 +462,8 @@ for my $test ( check_row( $res, $row, $test->{counts}->{$row} ); } + check_report_counts( $res, $test->{report_counts} ); + $mech->submit_form_ok( { with_fields => { category => $test->{category}, @@ -444,6 +476,56 @@ for my $test ( foreach my $row ( keys %{ $test->{counts_after} } ) { check_row( $res, $row, $test->{counts_after}->{$row} ); } + check_report_counts( $res, $test->{report_counts_after} ); + }; +} + +delete_problems(); + +for my $test ( + { + desc => 'Selecting no state does nothing', + p1 => { + state => 'fixed - user', + conf_dt => DateTime->now(), + category => 'Potholes', + }, + p2 => { + state => 'confirmed', + conf_dt => DateTime->now(), + category => 'Litter', + }, + state => '', + report_counts => [2,0,0], + report_counts_after => [2,0,0], + }, + { + desc => 'limit by state works', + state => 'fixed', + report_counts => [2,0,0], + report_counts_after => [1,0,0], + } + +) { + subtest $test->{desc} => sub { + make_problem( $test->{p1} ) if $test->{p1}; + make_problem( $test->{p2} ) if $test->{p2}; + + $mech->get_ok('/dashboard'); + + $res = $categories->scrape( $mech->content ); + + check_report_counts( $res, $test->{report_counts} ); + + $mech->submit_form_ok( { + with_fields => { + state => $test->{state}, + } + } ); + + $res = $categories->scrape( $mech->content ); + + check_report_counts( $res, $test->{report_counts_after} ); }; } @@ -494,6 +576,23 @@ sub check_row { is $res->{ $row }->[3], $totals->[3], "Correct count in $row for YTD"; } +sub check_report_counts { + my $res = shift; + my $counts = shift; + + for my $i ( 0 .. 2 ) { + if ( $counts->[$i] == 0 ) { + is_deeply $res->{report_lists}->[$i], {}, "No reports for column $i"; + } else { + if ( ref( $res->{report_lists}->[$i]->{reports} ) eq 'ARRAY' ) { + is scalar @{ $res->{report_lists}->[$i]->{reports} }, $counts->[$i], "Correct report count for column $i"; + } else { + fail "Correct report count for column $i ( no reports )"; + } + } + } +} + sub delete_problems { FixMyStreet::App->model('DB::Comment') ->search( { 'problem.council' => $test_council }, { join => 'problem' } ) -- cgit v1.2.3 From 3f2753b72d70a4b5144b3b380c821ba16b224939 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 16 May 2012 12:46:58 +0100 Subject: check that all fixed states covered --- t/app/controller/dashboard.t | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 't/app/controller/dashboard.t') diff --git a/t/app/controller/dashboard.t b/t/app/controller/dashboard.t index b12b886d9..356c06d93 100644 --- a/t/app/controller/dashboard.t +++ b/t/app/controller/dashboard.t @@ -504,8 +504,23 @@ for my $test ( state => 'fixed', report_counts => [2,0,0], report_counts_after => [1,0,0], - } - + }, + { + desc => 'All fixed states count as fixed', + p1 => { + state => 'fixed - council', + conf_dt => DateTime->now(), + category => 'Potholes', + }, + p2 => { + state => 'fixed', + conf_dt => DateTime->now(), + category => 'Potholes', + }, + state => 'fixed', + report_counts => [4,0,0], + report_counts_after => [3,0,0], + }, ) { subtest $test->{desc} => sub { make_problem( $test->{p1} ) if $test->{p1}; -- cgit v1.2.3 From 0b407b081762ffcb4ab3be666c7b12f67f9d4a4f Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 16 May 2012 13:33:09 +0100 Subject: add closed state to page --- t/app/controller/dashboard.t | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 't/app/controller/dashboard.t') diff --git a/t/app/controller/dashboard.t b/t/app/controller/dashboard.t index 356c06d93..b477c03bf 100644 --- a/t/app/controller/dashboard.t +++ b/t/app/controller/dashboard.t @@ -84,6 +84,7 @@ my $categories = scraper { process "tr[id=avg_marked] > td", 'avg_marked[]' => 'TEXT', process "tr[id=avg_fixed] > td", 'avg_fixed[]' => 'TEXT', process "tr[id=not_marked] > td", 'not_marked[]' => 'TEXT', + process "tr[id=closed] > td", 'closed[]' => 'TEXT', process "table[id=reports] > tr > td", 'report_lists[]' => scraper { process 'ul > li', 'reports[]' => 'TEXT' }, @@ -296,6 +297,25 @@ foreach my $test ( marked => [4,4,4,4] } }, + { + desc => 'marked as closed', + confirm_dt => DateTime->now->subtract( days => 1 ), + mark_dt => DateTime->now, + state => 'closed', + counts => { + totals => [6,6,9,10], + user => [1,1,1,2], + council => [2,2,3,3], + total_fixed => [3,3,4,5], + avg_fixed => [5,5,7,7], + avg_marked => [2,2,2,2], + investigating => [1,1,1,1], + in_progress => [1,1,1,1], + planned => [2,2,2,2], + closed => [1,1,1,1], + marked => [5,5,5,5] + } + }, ) { subtest $test->{desc} => sub { make_problem( -- cgit v1.2.3 From f4e2d66889a825d13ad4af6e8ad9168ceb7024b7 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 24 May 2012 15:32:01 +0100 Subject: problem_status is only set for council user updates so check for mark_fixed and null problem_status to identify user - fixed updates --- t/app/controller/dashboard.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't/app/controller/dashboard.t') diff --git a/t/app/controller/dashboard.t b/t/app/controller/dashboard.t index b477c03bf..7033fa02c 100644 --- a/t/app/controller/dashboard.t +++ b/t/app/controller/dashboard.t @@ -591,7 +591,7 @@ sub make_problem { problem => $p, user_id => $p_user->id, state => 'confirmed', - problem_state => $args->{state}, + problem_state => $args->{state} =~ /^fixed - user|fixed$/ ? undef : $args->{state}, confirmed => $args->{mark_dt}, text => 'an update', mark_fixed => $args->{state} =~ /fixed/ ? 1 : 0, -- cgit v1.2.3 From 8c181ccdcd8198d489c1530c477db679e3f7921d Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 18 Jun 2012 18:19:29 +0100 Subject: make tests pass if run on a Monday --- t/app/controller/dashboard.t | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 't/app/controller/dashboard.t') diff --git a/t/app/controller/dashboard.t b/t/app/controller/dashboard.t index 7033fa02c..472c6d9bd 100644 --- a/t/app/controller/dashboard.t +++ b/t/app/controller/dashboard.t @@ -151,6 +151,8 @@ foreach my $test ( delete_problems(); +my $is_monday = DateTime->now->day_of_week == 1 ? 1 : 0; + foreach my $test ( { desc => 'user fixed today', @@ -158,7 +160,7 @@ foreach my $test ( mark_dt => DateTime->now, state => 'fixed - user', counts => { - totals => [1,1,1,1], + totals => $is_monday ? [0,1,1,1] : [1,1,1,1], user => [1,1,1,1], council => [0,0,0,0], avg_fixed => [0,0,0,0], @@ -171,7 +173,7 @@ foreach my $test ( mark_dt => DateTime->now, state => 'fixed - council', counts => { - totals => [2,2,2,2], + totals => $is_monday ? [0,2,2,2] : [2,2,2,2], user => [1,1,1,1], council => [1,1,1,1], avg_fixed => [1,1,1,1], @@ -184,7 +186,7 @@ foreach my $test ( mark_dt => DateTime->now, state => 'investigating', counts => { - totals => [3,3,3,3], + totals => $is_monday ? [0,3,3,3] : [3,3,3,3], user => [1,1,1,1], council => [1,1,1,1], total_fixed => [2,2,2,2], @@ -199,7 +201,7 @@ foreach my $test ( mark_dt => DateTime->now, state => 'in progress', counts => { - totals => [4,4,4,4], + totals => $is_monday ? [0,4,4,4] : [4,4,4,4], user => [1,1,1,1], council => [1,1,1,1], total_fixed => [2,2,2,2], @@ -215,7 +217,7 @@ foreach my $test ( mark_dt => DateTime->now, state => 'planned', counts => { - totals => [5,5,5,5], + totals => $is_monday ? [ 0,5,5,5] : [5,5,5,5], user => [1,1,1,1], council => [1,1,1,1], total_fixed => [2,2,2,2], @@ -232,7 +234,7 @@ foreach my $test ( mark_dt => DateTime->now, state => 'planned', counts => { - totals => [5,5,6,6], + totals => $is_monday ? [0,5,6,6] : [5,5,6,6], user => [1,1,1,1], council => [1,1,1,1], total_fixed => [2,2,2,2], @@ -249,7 +251,7 @@ foreach my $test ( mark_dt => DateTime->now, state => 'fixed - council', counts => { - totals => [5,5,7,7], + totals => $is_monday ? [0,5,7,7] : [5,5,7,7], user => [1,1,1,1], council => [2,2,2,2], total_fixed => [3,3,3,3], @@ -267,7 +269,7 @@ foreach my $test ( mark_dt => DateTime->now->subtract( days => 8 ), state => 'fixed - council', counts => { - totals => [5,5,8,8], + totals => $is_monday ? [0,5,8,8] : [5,5,8,8], user => [1,1,1,1], council => [2,2,3,3], total_fixed => [3,3,4,4], @@ -285,7 +287,7 @@ foreach my $test ( mark_dt => DateTime->now->subtract( weeks => 7 ), state => 'fixed - user', counts => { - totals => [5,5,8,9], + totals => $is_monday ? [0,5,8,9] : [5,5,8,9], user => [1,1,1,2], council => [2,2,3,3], total_fixed => [3,3,4,5], @@ -303,7 +305,7 @@ foreach my $test ( mark_dt => DateTime->now, state => 'closed', counts => { - totals => [6,6,9,10], + totals => $is_monday ? [0,6,9,10] : [6,6,9,10], user => [1,1,1,2], council => [2,2,3,3], total_fixed => [3,3,4,5], -- cgit v1.2.3