aboutsummaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2017-08-31 16:15:46 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2017-08-31 16:15:46 +0100
commitcec5c77a4207b341947affed8e6e8e57ec29965d (patch)
tree246900550b394f956a8ac4bd76ffbe943cc8fb1e /t
parentc590981f0c198fa0491801a312a65eed054a0778 (diff)
parent51a5bcc74982aefea4f7b364e2f4bc49596bd9bf (diff)
Merge branch 'move-report-states-to-database'
Diffstat (limited to 't')
-rw-r--r--t/app/controller/admin_states.t24
-rw-r--r--t/app/controller/dashboard.t17
-rw-r--r--t/app/controller/report_display.t6
-rw-r--r--t/app/controller/report_inspect.t9
-rw-r--r--t/app/controller/report_updates.t124
-rw-r--r--t/app/model/state.t62
-rw-r--r--t/cobrand/bromley.t4
7 files changed, 155 insertions, 91 deletions
diff --git a/t/app/controller/admin_states.t b/t/app/controller/admin_states.t
new file mode 100644
index 000000000..60ffe5b88
--- /dev/null
+++ b/t/app/controller/admin_states.t
@@ -0,0 +1,24 @@
+use FixMyStreet::TestMech;
+
+my $mech = FixMyStreet::TestMech->new;
+
+my $user = $mech->create_user_ok('superuser@example.com', name => 'Super User', is_superuser => 1);
+
+$mech->log_in_ok( $user->email );
+
+subtest 'basic states admin' => sub {
+ $mech->get_ok('/admin/states');
+ $mech->submit_form_ok({ button => 'new', with_fields => { label => 'third party', type => 'closed', name => 'Third party referral' } });
+ $mech->content_contains('Third party referral');
+ $mech->content_contains('Fixed');
+ $mech->submit_form_ok({ button => 'delete:fixed' });
+ $mech->content_lacks('Fixed');
+ $mech->submit_form_ok({ form_number => 2, button => 'new_fixed' });
+ $mech->content_contains('Fixed');
+ $mech->submit_form_ok({ with_fields => { 'name:third party' => 'Third party incident' } });
+ $mech->content_contains('Third party incident');
+};
+
+# TODO Language tests
+
+done_testing;
diff --git a/t/app/controller/dashboard.t b/t/app/controller/dashboard.t
index 9d424c1ae..b87b58b38 100644
--- a/t/app/controller/dashboard.t
+++ b/t/app/controller/dashboard.t
@@ -545,22 +545,11 @@ FixMyStreet::override_config {
},
{
desc => 'limit by state works',
- state => 'fixed',
+ state => 'fixed - council',
report_counts => [2,0,0],
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',
@@ -573,7 +562,7 @@ FixMyStreet::override_config {
category => 'Potholes',
},
state => 'fixed',
- report_counts => [5,0,0],
+ report_counts => [4,0,0],
report_counts_after => [3,0,0],
},
) {
@@ -612,7 +601,7 @@ FixMyStreet::override_config {
while ( my $row = $csv->getline( $data_handle ) ) {
push @rows, $row;
}
- is scalar @rows, 7, '1 (header) + 6 (reports) = 7 lines';
+ is scalar @rows, 6, '1 (header) + 5 (reports) = 6 lines';
};
};
restore_time;
diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t
index 093ea9cf8..4d73a5204 100644
--- a/t/app/controller/report_display.t
+++ b/t/app/controller/report_display.t
@@ -313,7 +313,7 @@ for my $test (
date => DateTime->now,
state => 'investigating',
banner_id => 'progress',
- banner_text => 'progress',
+ banner_text => 'investigating',
fixed => 0
},
{
@@ -321,7 +321,7 @@ for my $test (
date => DateTime->now,
state => 'action scheduled',
banner_id => 'progress',
- banner_text => 'progress',
+ banner_text => 'action scheduled',
fixed => 0
},
{
@@ -329,7 +329,7 @@ for my $test (
date => DateTime->now,
state => 'planned',
banner_id => 'progress',
- banner_text => 'progress',
+ banner_text => 'planned',
fixed => 0
},
{
diff --git a/t/app/controller/report_inspect.t b/t/app/controller/report_inspect.t
index fcd7c724d..68f9063cf 100644
--- a/t/app/controller/report_inspect.t
+++ b/t/app/controller/report_inspect.t
@@ -57,7 +57,7 @@ FixMyStreet::override_config {
};
subtest "test basic inspect submission" => sub {
- $mech->submit_form_ok({ button => 'save', with_fields => { traffic_information => 'Yes', state => 'Action Scheduled', include_update => undef } });
+ $mech->submit_form_ok({ button => 'save', with_fields => { traffic_information => 'Yes', state => 'Action scheduled', include_update => undef } });
$report->discard_changes;
my $alert = FixMyStreet::App->model('DB::Alert')->find(
{ user => $user, alert_type => 'new_updates', confirmed => 1, }
@@ -90,9 +90,8 @@ FixMyStreet::override_config {
is $report->user->get_extra_metadata('reputation'), $reputation, "User reputation wasn't changed";
$mech->get_ok("/report/$report_id");
my $meta = $mech->extract_update_metas;
- like $meta->[0], qr/Updated by .*action scheduled/, 'First update mentions action scheduled';
- like $meta->[1], qr/Posted by .*defect raised/, 'Update mentions defect raised';
- unlike $meta->[2], qr/Posted by .*action scheduled/, 'Update does not mention action scheduled';
+ like $meta->[0], qr/State changed to: Action scheduled/, 'First update mentions action scheduled';
+ like $meta->[2], qr/Posted by .*defect raised/, 'Update mentions defect raised';
$user->unset_extra_metadata('categories');
$user->update;
@@ -300,7 +299,7 @@ FixMyStreet::override_config {
subtest "Oxfordshire-specific traffic management options are shown" => sub {
$report->update({ state => 'confirmed' });
$mech->get_ok("/report/$report_id");
- $mech->submit_form_ok({ button => 'save', with_fields => { traffic_information => 'Signs and Cones', state => 'Action Scheduled', include_update => undef } });
+ $mech->submit_form_ok({ button => 'save', with_fields => { traffic_information => 'Signs and Cones', state => 'Action scheduled', include_update => undef } });
$report->discard_changes;
is $report->state, 'action scheduled', 'report state changed';
is $report->get_extra_metadata('traffic_information'), 'Signs and Cones', 'report data changed';
diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t
index 4cb035bac..0526b2fd7 100644
--- a/t/app/controller/report_updates.t
+++ b/t/app/controller/report_updates.t
@@ -93,8 +93,7 @@ for my $test (
anonymous => 't',
mark_fixed => 'true',
mark_open => 'false',
- meta =>
-'Posted anonymously at 15:47, Sat 16 April 2011, marked as fixed',
+ meta => [ 'State changed to: Fixed', 'Posted anonymously at 15:47, Sat 16 April 2011' ]
},
{
description => 'named user, anon is true, reopened',
@@ -102,7 +101,7 @@ for my $test (
anonymous => 't',
mark_fixed => 'false',
mark_open => 'true',
- meta => 'Posted anonymously at 15:47, Sat 16 April 2011, reopened',
+ meta => [ 'State changed to: Open', 'Posted anonymously at 15:47, Sat 16 April 2011' ]
}
)
{
@@ -118,8 +117,9 @@ for my $test (
$mech->content_contains('This is some update text');
my $meta = $mech->extract_update_metas;
- is scalar @$meta, 1, 'number of updates';
- is $meta->[0], $test->{meta};
+ my $test_meta = ref $test->{meta} ? $test->{meta} : [ $test->{meta} ];
+ is scalar @$meta, scalar @$test_meta, 'number of updates';
+ is_deeply $meta, $test_meta;
};
}
@@ -131,7 +131,7 @@ subtest "updates displayed on report with empty bodies_str" => sub {
$mech->get_ok("/report/$report_id");
my $meta = $mech->extract_update_metas;
- is scalar @$meta, 1, 'update displayed';
+ is scalar @$meta, 2, 'update displayed';
$report->update({ bodies_str => $old_bodies_str });
};
@@ -185,10 +185,11 @@ subtest "several updates shown in correct order" => sub {
$mech->get_ok("/report/$report_id");
my $meta = $mech->extract_update_metas;
- is scalar @$meta, 3, 'number of updates';
+ is scalar @$meta, 4, 'number of updates';
is $meta->[0], 'Posted by Other User at 12:23, Thu 10 March 2011', 'first update';
is $meta->[1], 'Posted by Main User at 12:23, Thu 10 March 2011', 'second update';
- is $meta->[2], 'Posted anonymously at 08:12, Tue 15 March 2011, marked as fixed', 'third update';
+ is $meta->[2], 'State changed to: Fixed', 'third update, part 1';
+ is $meta->[3], 'Posted anonymously at 08:12, Tue 15 March 2011', 'third update, part 2';
};
for my $test (
@@ -613,7 +614,6 @@ for my $test (
state => 'internal referral',
},
state => 'internal referral',
- meta => "an internal referral",
},
{
desc => 'from authority user marks report as not responsible',
@@ -635,7 +635,6 @@ for my $test (
state => 'duplicate',
},
state => 'duplicate',
- meta => 'a duplicate report',
},
{
desc => 'from authority user marks report as internal referral',
@@ -646,7 +645,6 @@ for my $test (
state => 'internal referral',
},
state => 'internal referral',
- meta => 'an internal referral',
},
{
desc => 'from authority user marks report sent to two councils as fixed',
@@ -711,19 +709,13 @@ for my $test (
my $update_meta = $mech->extract_update_metas;
my $meta_state = $test->{meta} || $test->{fields}->{state};
- if ( $test->{reopened} ) {
- like $update_meta->[0], qr/reopened/, 'update meta says reopened';
- } elsif ( $test->{state} eq 'duplicate' ) {
- like $update_meta->[0], qr/closed as $meta_state/, 'update meta includes state change';
- } else {
- like $update_meta->[0], qr/marked as $meta_state/, 'update meta includes state change';
- }
+ like $update_meta->[0], qr/$meta_state/i, 'update meta includes state change';
if ($test->{view_username}) {
- like $update_meta->[0], qr{Westminster City Council \(Test User\)}, 'update meta includes council and user name';
+ like $update_meta->[1], qr{Westminster City Council \(Test User\)}, 'update meta includes council and user name';
$user->user_body_permissions->delete_all;
} else {
- like $update_meta->[0], qr{Westminster City Council}, 'update meta includes council name';
+ like $update_meta->[1], qr{Westminster City Council}, 'update meta includes council name';
$mech->content_contains( '<strong>Westminster City Council</strong>', 'council name in bold');
}
@@ -751,24 +743,22 @@ subtest 'check meta correct for comments marked confirmed but not marked open' =
$mech->get_ok( "/report/" . $report->id );
my $update_meta = $mech->extract_update_metas;
- unlike $update_meta->[0], qr/reopened/,
+ unlike $update_meta->[0], qr/Open/,
'update meta does not say reopened';
$comment->update( { mark_open => 1, problem_state => undef } );
$mech->get_ok( "/report/" . $report->id );
$update_meta = $mech->extract_update_metas;
- unlike $update_meta->[0], qr/marked as open/,
- 'update meta does not says marked as open';
- like $update_meta->[0], qr/reopened/, 'update meta does say reopened';
+ like $update_meta->[0], qr/Open/, 'update meta does say open';
$comment->update( { mark_open => 0, problem_state => undef } );
$mech->get_ok( "/report/" . $report->id );
$update_meta = $mech->extract_update_metas;
- unlike $update_meta->[0], qr/marked as open/,
+ unlike $update_meta->[0], qr/Open/,
'update meta does not says marked as open';
- unlike $update_meta->[0], qr/reopened/, 'update meta does not say reopened';
+ unlike $update_meta->[0], qr/Open/, 'update meta does not say reopened';
};
subtest "check first comment with no status change has no status in meta" => sub {
@@ -782,7 +772,7 @@ subtest "check first comment with no status change has no status in meta" => sub
$mech->get_ok("/report/$report_id");
my $update_meta = $mech->extract_update_metas;
- unlike $update_meta->[0], qr/marked as|reopened/, 'update meta does not include state change';
+ unlike $update_meta->[0], qr/State changed to/, 'update meta does not include state change';
};
subtest "check comment with no status change has not status in meta" => sub {
@@ -820,7 +810,7 @@ subtest "check comment with no status change has not status in meta" => sub {
is $report->state, 'fixed - council', 'correct report state';
is $update->problem_state, 'fixed - council', 'correct update state';
my $update_meta = $mech->extract_update_metas;
- unlike $update_meta->[1], qr/marked as/, 'update meta does not include state change';
+ unlike $update_meta->[1], qr/State changed to/, 'update meta does not include state change';
$user->from_body( $body->id );
$user->update;
@@ -854,9 +844,9 @@ subtest "check comment with no status change has not status in meta" => sub {
is $report->state, 'investigating', 'correct report state';
is $update->problem_state, 'investigating', 'correct 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';
+ like $update_meta->[0], qr/fixed/i, 'first update meta says fixed';
+ unlike $update_meta->[2], qr/State changed to/, 'second update meta does not include state change';
+ like $update_meta->[3], qr/investigating/i, 'third update meta says investigating';
my $dt = DateTime->now( time_zone => "local" )->add( seconds => 1 );
$comment = FixMyStreet::App->model('DB::Comment')->find_or_create(
@@ -883,10 +873,10 @@ subtest "check comment with no status change has not status in meta" => sub {
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';
+ like $update_meta->[0], qr/fixed/i, 'first update meta says fixed';
+ unlike $update_meta->[2], qr/State changed to/, 'second update meta does not include state change';
+ like $update_meta->[3], qr/investigating/i, 'third update meta says investigating';
+ unlike $update_meta->[5], qr/State changed to/, 'fourth update meta has no state change';
};
subtest 'check meta correct for second comment marking as reopened' => sub {
@@ -907,7 +897,7 @@ subtest 'check meta correct for second comment marking as reopened' => sub {
$mech->get_ok( "/report/" . $report->id );
my $update_meta = $mech->extract_update_metas;
- like $update_meta->[0], qr/fixed/, 'update meta says fixed';
+ like $update_meta->[0], qr/fixed/i, 'update meta says fixed';
$comment = FixMyStreet::App->model('DB::Comment')->create(
{
@@ -925,7 +915,7 @@ subtest 'check meta correct for second comment marking as reopened' => sub {
$mech->get_ok( "/report/" . $report->id );
$update_meta = $mech->extract_update_metas;
- like $update_meta->[1], qr/reopened/, 'update meta says reopened';
+ like $update_meta->[2], qr/Open/, 'update meta says reopened';
};
subtest "check first comment with status change but no text is displayed" => sub {
@@ -953,9 +943,9 @@ subtest "check first comment with status change but no text is displayed" => sub
$mech->get_ok("/report/$report_id");
my $update_meta = $mech->extract_update_metas;
- like $update_meta->[0], qr/Updated by/, 'updated by meta if no text';
- unlike $update_meta->[0], qr/Test User/, 'commenter name not included';
- like $update_meta->[0], qr/investigating/, 'update meta includes state change';
+ like $update_meta->[1], qr/Updated by/, 'updated by meta if no text';
+ unlike $update_meta->[1], qr/Test User/, 'commenter name not included';
+ like $update_meta->[0], qr/investigating/i, 'update meta includes state change';
ok $user->user_body_permissions->create({
body => $body,
@@ -964,9 +954,9 @@ subtest "check first comment with status change but no text is displayed" => sub
$mech->get_ok("/report/$report_id");
$update_meta = $mech->extract_update_metas;
- like $update_meta->[0], qr/Updated by/, 'updated by meta if no text';
- like $update_meta->[0], qr/Test User/, 'commenter name included if user has view contribute permission';
- like $update_meta->[0], qr/investigating/, 'update meta includes state change';
+ like $update_meta->[1], qr/Updated by/, 'updated by meta if no text';
+ like $update_meta->[1], qr/Test User/, 'commenter name included if user has view contribute permission';
+ like $update_meta->[0], qr/investigating/i, 'update meta includes state change';
};
@@ -1712,10 +1702,10 @@ for my $test (
desc => 'update unable to fix without marking as fixed leaves state unchanged',
initial_state => 'unable to fix',
expected_form_fields => {
- fixed => undef,
+ reopen => undef,
},
submitted_form_fields => {
- fixed => 0,
+ reopen => 0,
},
end_state => 'unable to fix',
},
@@ -1723,10 +1713,10 @@ for my $test (
desc => 'update internal referral without marking as fixed leaves state unchanged',
initial_state => 'internal referral',
expected_form_fields => {
- fixed => undef,
+ reopen => undef,
},
submitted_form_fields => {
- fixed => 0,
+ reopen => 0,
},
end_state => 'internal referral',
},
@@ -1734,10 +1724,10 @@ for my $test (
desc => 'update not responsible without marking as fixed leaves state unchanged',
initial_state => 'not responsible',
expected_form_fields => {
- fixed => undef,
+ reopen => undef,
},
submitted_form_fields => {
- fixed => 0,
+ reopen => 0,
},
end_state => 'not responsible',
},
@@ -1745,10 +1735,10 @@ for my $test (
desc => 'update duplicate without marking as fixed leaves state unchanged',
initial_state => 'duplicate',
expected_form_fields => {
- fixed => undef,
+ reopen => undef,
},
submitted_form_fields => {
- fixed => 0,
+ reopen => 0,
},
end_state => 'duplicate',
},
@@ -1808,48 +1798,48 @@ for my $test (
end_state => 'confirmed',
},
{
- desc => 'can mark unable to fix as fixed, cannot mark not closed',
+ desc => 'cannot mark unable to fix as fixed, can reopen',
initial_state => 'unable to fix',
expected_form_fields => {
- fixed => undef,
+ reopen => undef,
},
submitted_form_fields => {
- fixed => 1,
+ reopen => 1,
},
- end_state => 'fixed - user',
+ end_state => 'confirmed',
},
{
- desc => 'can mark internal referral as fixed, cannot mark not closed',
+ desc => 'cannot mark internal referral as fixed, can reopen',
initial_state => 'internal referral',
expected_form_fields => {
- fixed => undef,
+ reopen => undef,
},
submitted_form_fields => {
- fixed => 1,
+ reopen => 1,
},
- end_state => 'fixed - user',
+ end_state => 'confirmed',
},
{
- desc => 'can mark not responsible as fixed, cannot mark not closed',
+ desc => 'cannot mark not responsible as fixed, can reopen',
initial_state => 'not responsible',
expected_form_fields => {
- fixed => undef,
+ reopen => undef,
},
submitted_form_fields => {
- fixed => 1,
+ reopen => 1,
},
- end_state => 'fixed - user',
+ end_state => 'confirmed',
},
{
- desc => 'can mark duplicate as fixed, cannot mark not closed',
+ desc => 'cannot mark duplicate as fixed, can reopen',
initial_state => 'duplicate',
expected_form_fields => {
- fixed => undef,
+ reopen => undef,
},
submitted_form_fields => {
- fixed => 1,
+ reopen => 1,
},
- end_state => 'fixed - user',
+ end_state => 'confirmed',
},
) {
subtest $test->{desc} => sub {
diff --git a/t/app/model/state.t b/t/app/model/state.t
new file mode 100644
index 000000000..1653e36e2
--- /dev/null
+++ b/t/app/model/state.t
@@ -0,0 +1,62 @@
+use FixMyStreet::Test;
+use Test::More;
+
+my $rs = FixMyStreet::DB->resultset('State');
+my $trans_rs = FixMyStreet::DB->resultset('Translation');
+
+for (
+ { label => 'in progress', lang => 'de' },
+ { label => 'investigating', lang => 'fr' },
+ { label => 'duplicate', lang => 'de' },
+) {
+ my $lang = $_->{lang};
+ my $obj = $rs->find({ label => $_->{label} });
+ $trans_rs->create({ tbl => 'state', col => 'name', object_id => $obj->id,
+ lang => $lang, msgstr => "$lang $_->{label}" });
+}
+
+my $states = $rs->states;
+my %states = map { $_->label => $_ } @$states;
+
+subtest 'Open/closed database data is as expected' => sub {
+ my $open = $rs->open;
+ is @$open, 5;
+ my $closed = $rs->closed;
+ is @$closed, 5;
+};
+
+is $rs->display('investigating'), 'Investigating';
+is $rs->display('bad'), 'bad';
+is $rs->display('confirmed'), 'Open';
+is $rs->display('closed'), 'Closed';
+is $rs->display('fixed - council'), 'Fixed - Council';
+is $rs->display('fixed - user'), 'Fixed - User';
+is $rs->display('fixed'), 'Fixed';
+
+subtest 'default name is untranslated' => sub {
+ is $states{'in progress'}->name, 'In progress';
+ is $states{'in progress'}->msgstr, 'In progress';
+ is $states{'action scheduled'}->name, 'Action scheduled';
+ is $states{'action scheduled'}->msgstr, 'Action scheduled';
+};
+
+subtest 'msgstr gets translated if available when the language changes' => sub {
+ FixMyStreet::DB->schema->lang('de');
+ is $states{'in progress'}->name, 'In progress';
+ is $states{'in progress'}->msgstr, 'de in progress';
+ is $states{'investigating'}->name, 'Investigating';
+ is $states{'investigating'}->msgstr, 'Investigating';
+ is $states{'unable to fix'}->name, 'No further action';
+ is $states{'unable to fix'}->msgstr, 'No further action';
+};
+
+$rs->clear;
+
+is_deeply [ sort FixMyStreet::DB::Result::Problem->open_states ],
+ ['action scheduled', 'confirmed', 'in progress', 'investigating', 'planned'], 'open states okay';
+is_deeply [ sort FixMyStreet::DB::Result::Problem->closed_states ],
+ ['closed', 'duplicate', 'internal referral', 'not responsible', 'unable to fix'], 'closed states okay';
+is_deeply [ sort FixMyStreet::DB::Result::Problem->fixed_states ],
+ ['fixed', 'fixed - council', 'fixed - user'], 'fixed states okay';
+
+done_testing();
diff --git a/t/cobrand/bromley.t b/t/cobrand/bromley.t
index 46c2472cd..f3053c29a 100644
--- a/t/cobrand/bromley.t
+++ b/t/cobrand/bromley.t
@@ -41,9 +41,9 @@ for my $update ('in progress', 'unable to fix') {
# Test Bromley special casing of 'unable to fix'
$mech->get_ok( '/report/' . $report->id );
$mech->content_contains( 'marks it as in progress' );
-$mech->content_contains( 'marked as in progress' );
+$mech->content_contains( 'State changed to: In progress' );
$mech->content_contains( 'marks it as unable to fix' );
-$mech->content_contains( 'marked as no further action' );
+$mech->content_contains( 'State changed to: No further action' );
subtest 'testing special Open311 behaviour', sub {
$report->set_extra_fields();