diff options
author | Struan Donald <struan@exo.org.uk> | 2012-11-23 12:54:52 +0000 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2012-11-23 12:54:52 +0000 |
commit | 7d2e33d85542d641949a2b3058edaab4c20b79e1 (patch) | |
tree | c0cd601591156af6e8e3a8adf15a7da732c441bc | |
parent | bacba6c39090cbd6dfbca7f89303480e1dcc742a (diff) |
Correctly implement the display of update statuses on report pages
-rw-r--r-- | t/app/controller/report_updates.t | 101 | ||||
-rw-r--r-- | templates/web/default/report/updates.html | 30 |
2 files changed, 116 insertions, 15 deletions
diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index a486ee150..3d5ddebe0 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -511,6 +511,7 @@ for my $test ( state => 'confirmed', }, state => 'confirmed', + reopened => 1, }, { desc => 'from authority user marks report as action scheduled', @@ -604,7 +605,11 @@ for my $test ( my $update_meta = $mech->extract_update_metas; my $meta_state = $test->{meta} || $test->{fields}->{state}; - like $update_meta->[0], qr/marked as $meta_state$/, 'update meta includes state change'; + if ( $test->{reopened} ) { + like $update_meta->[0], qr/reopened$/, 'update meta says reopened'; + } else { + 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'); @@ -613,6 +618,100 @@ for my $test ( }; } +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; + + $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'; + + 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'; + my $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'; + my $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; diff --git a/templates/web/default/report/updates.html b/templates/web/default/report/updates.html index 4d2e94961..736d36528 100644 --- a/templates/web/default/report/updates.html +++ b/templates/web/default/report/updates.html @@ -1,3 +1,4 @@ +[% global.last_state = '' %] [% FOREACH update IN updates %] [% INCLUDE 'report/update.html' %] [% END %] @@ -22,19 +23,20 @@ [%- ELSE %] [% tprintf( loc( 'Posted by %s at %s' ), update.name, prettify_epoch( update.confirmed_local.epoch ) ) | html -%] [%- END -%] - [%- ", " _ loc( 'marked as fixed' ) IF update.mark_fixed %] - [%- ", " _ loc( 'reopened' ) IF update.mark_open %] - [%- IF c.cobrand.moniker == 'bromley' %] - [%- IF update.problem_state %] - [%- update_state = update_state.problem_state %] - [%- IF update.problem_state == 'unable to fix' %] - [%- update_state = loc('no further action') %] - [%- ELSIF update.problem_state == 'confirmed' %] - [%- update_state = loc('open') %] - [%- END %] - [%- ", " _ tprintf(loc( 'marked as %s' ), update_state ) %] + [%- update_state = '' %] + [%- IF update.mark_fixed %][% update_state = ", " _ loc( 'marked as fixed' ) %][% END %] + [%- IF update.mark_open %][% update_state = ", " _ loc( 'reopened' ) %][% END %] + [%- IF !update_state && update.problem_state %] + [%- state = update.meta_problem_state %] + [%- IF c.cobrand.moniker == 'bromley' AND update.problem_state == 'unable to fix' %] + [%- state = loc('no further action') %] + [% END %] + [%- IF update.problem_state == 'confirmed' %] + [%- update_state = ", " _ loc('reopened') %] + [%- ELSE %] + [%- update_state = ", " _ tprintf(loc( 'marked as %s' ), state ) %] + [% END %] [%- END %] - [%- ELSE %] - [%- ", " _ tprintf(loc( 'marked as %s' ), update.meta_problem_state ) IF update.problem_state %] - [% END %] + [%- update_state IF update_state != global.last_state %] + [%- global.last_state = update_state %] [% END %] |