diff options
Diffstat (limited to 't/app')
-rw-r--r-- | t/app/controller/dashboard.t | 54 | ||||
-rw-r--r-- | t/app/controller/questionnaire.t | 16 | ||||
-rw-r--r-- | t/app/controller/report_display.t | 34 | ||||
-rw-r--r-- | t/app/controller/report_updates.t | 400 | ||||
-rw-r--r-- | t/app/model/problem.t | 28 | ||||
-rw-r--r-- | t/app/model/questionnaire.t | 16 |
6 files changed, 511 insertions, 37 deletions
diff --git a/t/app/controller/dashboard.t b/t/app/controller/dashboard.t index 47d10ff5c..25e144464 100644 --- a/t/app/controller/dashboard.t +++ b/t/app/controller/dashboard.t @@ -78,7 +78,7 @@ my $categories = scraper { 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=action_scheduled] > td", 'action_scheduled[]' => 'TEXT', process "tr[id=investigating] > td", 'investigating[]' => 'TEXT', process "tr[id=marked] > td", 'marked[]' => 'TEXT', process "tr[id=avg_marked] > td", 'avg_marked[]' => 'TEXT', @@ -212,10 +212,10 @@ foreach my $test ( } }, { - desc => 'marked as planned today', + desc => 'marked as action scheduled today', confirm_dt => DateTime->now->subtract( days => 1 ), mark_dt => DateTime->now, - state => 'planned', + state => 'action scheduled', counts => { totals => $is_monday ? [ 0,5,5,5] : [5,5,5,5], user => [1,1,1,1], @@ -224,15 +224,15 @@ foreach my $test ( avg_marked => [1,1,1,1], investigating => [1,1,1,1], in_progress => [1,1,1,1], - planned => [1,1,1,1], + action_scheduled => [1,1,1,1], marked => [3,3,3,3] } }, { - desc => 'marked as planned today, confirmed a week ago', + desc => 'marked as action scheduled today, confirmed a week ago', confirm_dt => DateTime->now->subtract( days => 8 ), mark_dt => DateTime->now, - state => 'planned', + state => 'action scheduled', counts => { totals => $is_monday ? [0,5,6,6] : [5,5,6,6], user => [1,1,1,1], @@ -241,7 +241,7 @@ foreach my $test ( avg_marked => [3,3,3,3], investigating => [1,1,1,1], in_progress => [1,1,1,1], - planned => [2,2,2,2], + action_scheduled => [2,2,2,2], marked => [4,4,4,4] } }, @@ -259,7 +259,7 @@ foreach my $test ( avg_marked => [3,3,3,3], investigating => [1,1,1,1], in_progress => [1,1,1,1], - planned => [2,2,2,2], + action_scheduled => [2,2,2,2], marked => [4,4,4,4] } }, @@ -277,7 +277,7 @@ foreach my $test ( avg_marked => [3,3,3,3], investigating => [1,1,1,1], in_progress => [1,1,1,1], - planned => [2,2,2,2], + action_scheduled => [2,2,2,2], marked => [4,4,4,4] } }, @@ -295,7 +295,7 @@ foreach my $test ( avg_marked => [3,3,3,3], investigating => [1,1,1,1], in_progress => [1,1,1,1], - planned => [2,2,2,2], + action_scheduled => [2,2,2,2], marked => [4,4,4,4] } }, @@ -313,11 +313,30 @@ foreach my $test ( avg_marked => [2,2,2,2], investigating => [1,1,1,1], in_progress => [1,1,1,1], - planned => [2,2,2,2], + action_scheduled => [2,2,2,2], closed => [1,1,1,1], marked => [5,5,5,5] } }, + { + desc => 'marked as planned', + confirm_dt => DateTime->now->subtract( days => 1 ), + mark_dt => DateTime->now, + state => 'planned', + counts => { + totals => $is_monday ? [0,7,10,11] : [7,7,10,11], + 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], + action_scheduled => [3,3,3,3], + closed => [1,1,1,1], + marked => [6,6,6,6] + } + }, ) { subtest $test->{desc} => sub { make_problem( @@ -528,6 +547,17 @@ for my $test ( report_counts_after => [1,0,0], }, { + desc => 'planned counted as action scheduled', + p1 => { + state => 'planned', + conf_dt => DateTime->now(), + category => 'Potholes', + }, + state => 'action scheduled', + report_counts => [3,0,0], + report_counts_after => [1,0,0], + }, + { desc => 'All fixed states count as fixed', p1 => { state => 'fixed - council', @@ -540,7 +570,7 @@ for my $test ( category => 'Potholes', }, state => 'fixed', - report_counts => [4,0,0], + report_counts => [5,0,0], report_counts_after => [3,0,0], }, ) { diff --git a/t/app/controller/questionnaire.t b/t/app/controller/questionnaire.t index 3a6a3d6ad..d8d1eb4f3 100644 --- a/t/app/controller/questionnaire.t +++ b/t/app/controller/questionnaire.t @@ -329,6 +329,10 @@ for my $test ( fixed => 0 }, { + state => 'action scheduled', + fixed => 0 + }, + { state => 'in progress', fixed => 0 }, @@ -337,6 +341,18 @@ for my $test ( fixed => 0 }, { + state => 'duplicate', + fixed => 0 + }, + { + state => 'not responsible', + fixed => 0 + }, + { + state => 'unable to fix', + fixed => 0 + }, + { state => 'closed', fixed => 0 }, diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t index 3bb0913f1..82c98dc5c 100644 --- a/t/app/controller/report_display.t +++ b/t/app/controller/report_display.t @@ -283,6 +283,30 @@ for my $test ( fixed => 1 }, { + description => 'duplicate report', + date => DateTime->now, + state => 'duplicate', + banner_id => 'closed', + banner_text => 'closed', + fixed => 0 + }, + { + description => 'not responsible report', + date => DateTime->now, + state => 'not responsible', + banner_id => 'closed', + banner_text => 'closed', + fixed => 0 + }, + { + description => 'unable to fix report', + date => DateTime->now, + state => 'unable to fix', + banner_id => 'closed', + banner_text => 'closed', + fixed => 0 + }, + { description => 'closed report', date => DateTime->now, state => 'closed', @@ -299,6 +323,14 @@ for my $test ( fixed => 0 }, { + description => 'action scheduled report', + date => DateTime->now, + state => 'action scheduled', + banner_id => 'progress', + banner_text => 'progress', + fixed => 0 + }, + { description => 'planned report', date => DateTime->now, state => 'planned', @@ -307,7 +339,7 @@ for my $test ( fixed => 0 }, { - description => 'in progressreport', + description => 'in progress report', date => DateTime->now, state => 'in progress', banner_id => 'progress', diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 82670d6cc..2204a9d99 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -477,64 +477,91 @@ for my $test ( state => 'investigating', }, { - desc => 'from authority user marks report as planned', + desc => 'from authority user marks report as in progress', fields => { name => $user->name, may_show_name => 1, add_alert => undef, photo => '', - update => 'Set state to planned', - state => 'planned', + update => 'Set state to in progress', + state => 'in progress', }, - state => 'planned', + state => 'in progress', }, { - desc => 'from authority user marks report as in progress', + desc => 'from authority user marks report as fixed', fields => { name => $user->name, may_show_name => 1, add_alert => undef, photo => '', - update => 'Set state to in progress', - state => 'in progress', + update => 'Set state to fixed', + state => 'fixed', }, - state => 'in progress', + state => 'fixed - council', }, { - desc => 'from authority user marks report as closed', + desc => 'from authority user marks report as confirmed', fields => { name => $user->name, may_show_name => 1, add_alert => undef, photo => '', - update => 'Set state to closed', - state => 'closed', + update => 'Set state to confirmed', + state => 'confirmed', }, - state => 'closed', + state => 'confirmed', + reopened => 1, }, { - desc => 'from authority user marks report as fixed', + desc => 'from authority user marks report as action scheduled', fields => { name => $user->name, may_show_name => 1, add_alert => undef, photo => '', - update => 'Set state to fixed', - state => 'fixed', + update => 'Set state to action scheduled', + state => 'action scheduled', }, - state => 'fixed - council', + state => 'action scheduled', }, { - desc => 'from authority user marks report as confirmed', + desc => 'from authority user marks report as unable to fix', fields => { name => $user->name, may_show_name => 1, add_alert => undef, photo => '', - update => 'Set state to confirmed', - state => 'confirmed', + update => 'Set state to unable to fix', + state => 'unable to fix', }, - state => 'confirmed', + state => 'unable to fix', + }, + { + desc => 'from authority user marks report as not responsible', + fields => { + name => $user->name, + may_show_name => 1, + add_alert => undef, + photo => '', + update => 'Set state to not responsible', + state => 'not responsible', + }, + state => 'not responsible', + meta => "not the council's responsibility" + }, + { + desc => 'from authority user marks report as duplicate', + fields => { + name => $user->name, + may_show_name => 1, + add_alert => undef, + photo => '', + update => 'Set state to duplicate', + state => 'duplicate', + }, + state => 'duplicate', + meta => 'duplicate report', }, { desc => 'from authority user marks report sent to two councils as fixed', @@ -577,11 +604,11 @@ for my $test ( is $update->problem_state, $test->{state}, 'problem state set'; my $update_meta = $mech->extract_update_metas; - # setting it to confirmed shouldn't say anything - if ( $test->{fields}->{state} ne 'confirmed' ) { - like $update_meta->[0], qr/marked as $test->{fields}->{state}$/, 'update meta includes state change'; + my $meta_state = $test->{meta} || $test->{fields}->{state}; + if ( $test->{reopened} ) { + like $update_meta->[0], qr/reopened$/, 'update meta says reopened'; } else { - like $update_meta->[0], qr/reopened$/, 'update meta includes state change'; + like $update_meta->[0], qr/marked as $meta_state$/, 'update meta includes state change'; } like $update_meta->[0], qr{Test User \(Westminster City Council\)}, 'update meta includes council name'; $mech->content_contains( 'Test User (<strong>Westminster City Council</strong>)', 'council name in bold'); @@ -629,6 +656,105 @@ subtest 'check meta correct for comments marked confirmed but not marked open' = unlike $update_meta->[0], qr/reopened$/, 'update meta does not say reopened'; }; +subtest "check comment with no status change has not status in meta" => sub { + $mech->log_in_ok( $user->email ); + $user->from_council( 0 ); + $user->update; + + my $comment = $report->comments->first; + $comment->update( { mark_fixed => 1, problem_state => 'fixed - council' } ); + + $mech->get_ok("/report/$report_id"); + + $mech->submit_form_ok( + { + with_fields => { + name => $user->name, + may_show_name => 1, + add_alert => undef, + photo => '', + update => 'Comment that does not change state', + }, + }, + 'submit update' + ); + + $report->discard_changes; + my @updates = $report->comments->all; + is scalar @updates, 2, 'correct number of updates'; + + warn $updates[0]->problem_state; + warn $updates[1]->problem_state; + my $update = pop @updates; + + is $report->state, 'fixed - council', 'correct report state'; + is $update->problem_state, 'fixed - council', 'corect update state'; + my $update_meta = $mech->extract_update_metas; + unlike $update_meta->[1], qr/marked as/, 'update meta does not include state change'; + + $user->from_council( 2504 ); + $user->update; + + $mech->get_ok("/report/$report_id"); + + $mech->submit_form_ok( + { + with_fields => { + name => $user->name, + may_show_name => 1, + add_alert => undef, + photo => '', + update => 'Comment that sets state to investigating', + state => 'investigating', + }, + }, + 'submit update' + ); + + $report->discard_changes; + @updates = $report->comments->all; + is scalar @updates, 3, 'correct number of updates'; + + $update = pop @updates; + + is $report->state, 'investigating', 'correct report state'; + is $update->problem_state, 'investigating', 'corect update state'; + $update_meta = $mech->extract_update_metas; + like $update_meta->[0], qr/marked as fixed/, 'first update meta says fixed'; + unlike $update_meta->[1], qr/marked as/, 'second update meta does not include state change'; + like $update_meta->[2], qr/marked as investigating/, 'third update meta says investigating'; + + my $dt = DateTime->now; + my $comment = FixMyStreet::App->model('DB::Comment')->find_or_create( + { + problem_id => $report_id, + user_id => $user->id, + name => 'Other User', + mark_fixed => 'false', + text => 'This is some update text', + state => 'confirmed', + confirmed => $dt->ymd . ' ' . $dt->hms, + anonymous => 'f', + } + ); + + $mech->get_ok("/report/$report_id"); + + $report->discard_changes; + @updates = $report->comments->all; + is scalar @updates, 4, 'correct number of updates'; + + $update = pop @updates; + + is $report->state, 'investigating', 'correct report state'; + is $update->problem_state, undef, 'no update state'; + $update_meta = $mech->extract_update_metas; + like $update_meta->[0], qr/marked as fixed/, 'first update meta says fixed'; + unlike $update_meta->[1], qr/marked as/, 'second update meta does not include state change'; + like $update_meta->[2], qr/marked as investigating/, 'third update meta says investigating'; + unlike $update_meta->[3], qr/marked as/, 'fourth update meta has no state change'; +}; + $user->from_council(0); $user->update; @@ -1286,6 +1412,232 @@ for my $test ( }; } +for my $test ( + { + desc => 'update confirmed without marking as fixed leaves state unchanged', + initial_state => 'confirmed', + expected_form_fields => { + fixed => undef, + }, + submitted_form_fields => { + fixed => 0, + }, + end_state => 'confirmed', + }, + { + desc => 'update investigating without marking as fixed leaves state unchanged', + initial_state => 'investigating', + expected_form_fields => { + fixed => undef, + }, + submitted_form_fields => { + fixed => 0, + }, + end_state => 'investigating', + }, + { + desc => 'update in progress without marking as fixed leaves state unchanged', + initial_state => 'in progress', + expected_form_fields => { + fixed => undef, + }, + submitted_form_fields => { + fixed => 0, + }, + end_state => 'in progress', + }, + { + desc => 'update action scheduled without marking as fixed leaves state unchanged', + initial_state => 'action scheduled', + expected_form_fields => { + fixed => undef, + }, + submitted_form_fields => { + fixed => 0, + }, + end_state => 'action scheduled', + }, + { + desc => 'update fixed without marking as open leaves state unchanged', + initial_state => 'fixed', + expected_form_fields => { + reopen => undef, + }, + submitted_form_fields => { + reopen => 0, + }, + end_state => 'fixed', + }, + { + desc => 'update unable to fix without marking as fixed leaves state unchanged', + initial_state => 'unable to fix', + expected_form_fields => { + fixed => undef, + }, + submitted_form_fields => { + fixed => 0, + }, + end_state => 'unable to fix', + }, + { + desc => 'update not responsible without marking as fixed leaves state unchanged', + initial_state => 'not responsible', + expected_form_fields => { + fixed => undef, + }, + submitted_form_fields => { + fixed => 0, + }, + end_state => 'not responsible', + }, + { + desc => 'update duplicate without marking as fixed leaves state unchanged', + initial_state => 'duplicate', + expected_form_fields => { + fixed => undef, + }, + submitted_form_fields => { + fixed => 0, + }, + end_state => 'duplicate', + }, + { + desc => 'can mark confirmed as fixed', + initial_state => 'confirmed', + expected_form_fields => { + fixed => undef, + }, + submitted_form_fields => { + fixed => 1, + }, + end_state => 'fixed - user', + }, + { + desc => 'can mark investigating as fixed', + initial_state => 'investigating', + expected_form_fields => { + fixed => undef, + }, + submitted_form_fields => { + fixed => 1, + }, + end_state => 'fixed - user', + }, + { + desc => 'can mark in progress as fixed', + initial_state => 'in progress', + expected_form_fields => { + fixed => undef, + }, + submitted_form_fields => { + fixed => 1, + }, + end_state => 'fixed - user', + }, + { + desc => 'can mark action scheduled as fixed', + initial_state => 'action scheduled', + expected_form_fields => { + fixed => undef, + }, + submitted_form_fields => { + fixed => 1, + }, + end_state => 'fixed - user', + }, + { + desc => 'cannot mark fixed as fixed, can mark as not fixed', + initial_state => 'fixed', + expected_form_fields => { + reopen => undef, + }, + submitted_form_fields => { + reopen => 1, + }, + end_state => 'confirmed', + }, + { + desc => 'can mark unable to fix as fixed, cannot mark not closed', + initial_state => 'unable to fix', + expected_form_fields => { + fixed => undef, + }, + submitted_form_fields => { + fixed => 1, + }, + end_state => 'fixed - user', + }, + { + desc => 'can mark not responsible as fixed, cannot mark not closed', + initial_state => 'not responsible', + expected_form_fields => { + fixed => undef, + }, + submitted_form_fields => { + fixed => 1, + }, + end_state => 'fixed - user', + }, + { + desc => 'can mark duplicate as fixed, cannot mark not closed', + initial_state => 'duplicate', + expected_form_fields => { + fixed => undef, + }, + submitted_form_fields => { + fixed => 1, + }, + end_state => 'fixed - user', + }, +) { + subtest $test->{desc} => sub { + $mech->log_in_ok( $report->user->email ); + + my %standard_fields = ( + name => $report->user->name, + update => 'update text', + photo => '', + may_show_name => 1, + add_alert => 1, + ); + + my %expected_fields = ( + %standard_fields, + %{ $test->{expected_form_fields} }, + update => '', + ); + + my %submitted_fields = ( + %standard_fields, + %{ $test->{submitted_form_fields} }, + ); + + # clear out comments for this problem to make + # checking details easier later + ok( $_->delete, 'deleted comment ' . $_->id ) for $report->comments; + + $report->discard_changes; + $report->state($test->{initial_state}); + $report->update; + + $mech->get_ok("/report/$report_id"); + + my $values = $mech->visible_form_values('updateForm'); + is_deeply $values, \%expected_fields, 'correct form fields present'; + + if ( $test->{submitted_form_fields} ) { + $mech->submit_form_ok( { + with_fields => \%submitted_fields + }, + 'submit update' + ); + + $report->discard_changes; + is $report->state, $test->{end_state}, 'update sets correct report state'; + } + }; +} + subtest 'check have to be logged in for creator fixed questionnaire' => sub { $mech->log_out_ok(); diff --git a/t/app/model/problem.t b/t/app/model/problem.t index 63204e05c..040790184 100644 --- a/t/app/model/problem.t +++ b/t/app/model/problem.t @@ -302,6 +302,13 @@ for my $test ( is_closed => 0, }, { + state => 'action scheduled', + is_visible => 1, + is_fixed => 0, + is_open => 1, + is_closed => 0, + }, + { state => 'in progress', is_visible => 1, is_fixed => 0, @@ -309,6 +316,27 @@ for my $test ( is_closed => 0, }, { + state => 'duplicate', + is_visible => 1, + is_fixed => 0, + is_open => 0, + is_closed => 1, + }, + { + state => 'not responsible', + is_visible => 1, + is_fixed => 0, + is_open => 0, + is_closed => 1, + }, + { + state => 'unable to fix', + is_visible => 1, + is_fixed => 0, + is_open => 0, + is_closed => 1, + }, + { state => 'fixed', is_visible => 1, is_fixed => 1, diff --git a/t/app/model/questionnaire.t b/t/app/model/questionnaire.t index 60b52043a..86af51c42 100644 --- a/t/app/model/questionnaire.t +++ b/t/app/model/questionnaire.t @@ -62,6 +62,10 @@ for my $test ( send_email => 1, }, { + state => 'action scheduled', + send_email => 1, + }, + { state => 'in progress', send_email => 1, }, @@ -78,6 +82,18 @@ for my $test ( send_email => 1, }, { + state => 'duplicate', + send_email => 1, + }, + { + state => 'unable to fix', + send_email => 1, + }, + { + state => 'not responsible', + send_email => 1, + }, + { state => 'closed', send_email => 1, }, |