aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/controller/around.t
diff options
context:
space:
mode:
Diffstat (limited to 't/app/controller/around.t')
-rw-r--r--t/app/controller/around.t174
1 files changed, 114 insertions, 60 deletions
diff --git a/t/app/controller/around.t b/t/app/controller/around.t
index 186b833fd..3f5d31c02 100644
--- a/t/app/controller/around.t
+++ b/t/app/controller/around.t
@@ -9,6 +9,7 @@ use constant MIN_ZOOM_LEVEL => 88;
package main;
use Test::MockModule;
+use t::Mock::Nominatim;
use FixMyStreet::TestMech;
my $mech = FixMyStreet::TestMech->new;
@@ -53,6 +54,11 @@ foreach my $test (
};
}
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => 'fixmystreet',
+ MAPIT_URL => 'http://mapit.uk/',
+}, sub {
+
# check that exact queries result in the correct lat,lng
foreach my $test (
{
@@ -69,19 +75,45 @@ foreach my $test (
{
subtest "check lat/lng for '$test->{pc}'" => sub {
$mech->get_ok('/');
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ],
- MAPIT_URL => 'http://mapit.uk/',
- }, sub {
- $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } },
- "good location" );
- };
+ $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } },
+ "good location" );
is_deeply $mech->page_errors, [], "no errors for pc '$test->{pc}'";
is_deeply $mech->extract_location, $test,
"got expected location for pc '$test->{pc}'";
+ $mech->get_ok('/');
+ my $pc = "$test->{latitude},$test->{longitude}";
+ $mech->submit_form_ok( { with_fields => { pc => $pc } },
+ "good location" );
+ is_deeply $mech->page_errors, [], "no errors for pc '$pc'";
+ is_deeply $mech->extract_location, { %$test, pc => $pc },
+ "got expected location for pc '$pc'";
};
}
+subtest "check lat/lng for full plus code" => sub {
+ $mech->get_ok('/');
+ $mech->submit_form_ok( { with_fields => { pc => "9C7RXR26+R5" } } );
+ is_deeply $mech->page_errors, [], "no errors for plus code";
+ is_deeply $mech->extract_location, {
+ pc => "9C7RXR26+R5",
+ latitude => 55.952063,
+ longitude => -3.189562,
+ },
+ "got expected location for full plus code";
+};
+
+subtest "check lat/lng for short plus code" => sub {
+ $mech->get_ok('/');
+ $mech->submit_form_ok( { with_fields => { pc => "XR26+R5 Edinburgh" } } );
+ is_deeply $mech->page_errors, [], "no errors for plus code";
+ is_deeply $mech->extract_location, {
+ pc => "XR26+R5 Edinburgh",
+ latitude => 55.952063,
+ longitude => -3.189562,
+ },
+ "got expected location for short plus code";
+};
+
my $body_edin_id = $mech->create_body_ok(2651, 'City of Edinburgh Council')->id;
my $body_west_id = $mech->create_body_ok(2504, 'Westminster City Council')->id;
@@ -93,10 +125,10 @@ my @edinburgh_problems = $mech->create_problems_for_body( 5, $body_edin_id, 'Aro
subtest 'check lookup by reference' => sub {
$mech->get_ok('/');
- $mech->submit_form_ok( { with_fields => { pc => 'ref:12345' } }, 'bad ref');
+ $mech->submit_form_ok( { with_fields => { pc => '12345' } }, 'bad ref');
$mech->content_contains('Searching found no reports');
my $id = $edinburgh_problems[0]->id;
- $mech->submit_form_ok( { with_fields => { pc => "ref:$id" } }, 'good ref');
+ $mech->submit_form_ok( { with_fields => { pc => $id } }, 'good ref');
is $mech->uri->path, "/report/$id", "redirected to report page";
};
@@ -106,19 +138,14 @@ subtest 'check lookup by reference does not show non_public reports' => sub {
});
my $id = $edinburgh_problems[0]->id;
$mech->get_ok('/');
- $mech->submit_form_ok( { with_fields => { pc => "ref:$id" } }, 'non_public ref');
+ $mech->submit_form_ok( { with_fields => { pc => $id } }, 'non_public ref');
$mech->content_contains('Searching found no reports');
};
subtest 'check non public reports are not displayed on around page' => sub {
$mech->get_ok('/');
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ],
- MAPIT_URL => 'http://mapit.uk/',
- }, sub {
- $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB' } },
- "good location" );
- };
+ $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB' } },
+ "good location" );
$mech->content_contains( "Around page Test 3 for $body_edin_id",
'problem to be marked non public visible' );
@@ -126,31 +153,21 @@ subtest 'check non public reports are not displayed on around page' => sub {
ok $private->update( { non_public => 1 } ), 'problem marked non public';
$mech->get_ok('/');
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ],
- MAPIT_URL => 'http://mapit.uk/',
- }, sub {
- $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB' } },
- "good location" );
- };
+ $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB' } },
+ "good location" );
$mech->content_lacks( "Around page Test 3 for $body_edin_id",
'problem marked non public is not visible' );
};
subtest 'check missing body message not shown when it does not need to be' => sub {
$mech->get_ok('/');
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => 'fixmystreet',
- MAPIT_URL => 'http://mapit.uk/',
- }, sub {
- $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB' } },
- "good location" );
- };
+ $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB' } },
+ "good location" );
$mech->content_lacks('yet have details for the other councils that cover this location');
};
for my $permission ( qw/ report_inspect report_mark_private/ ) {
- subtest 'check non public reports are displayed on around page with $permission permission' => sub {
+ subtest "check non public reports are displayed on around page with $permission permission" => sub {
my $body = FixMyStreet::DB->resultset('Body')->find( $body_edin_id );
my $body2 = FixMyStreet::DB->resultset('Body')->find( $body_west_id );
my $user = $mech->log_in_ok( 'test@example.com' );
@@ -162,24 +179,14 @@ for my $permission ( qw/ report_inspect report_mark_private/ ) {
});
$mech->get_ok('/');
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ],
- MAPIT_URL => 'http://mapit.uk/',
- }, sub {
- $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB' } },
- "good location" );
- };
+ $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB' } },
+ "good location" );
$mech->content_contains( "Around page Test 3 for $body_edin_id",
'problem marked non public is visible' );
$mech->content_contains( "Around page Test 2 for $body_edin_id",
'problem marked public is visible' );
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ],
- MAPIT_URL => 'http://mapit.uk/',
- }, sub {
- $mech->get_ok('/around?pc=EH1+1BB&status=non_public');
- };
+ $mech->get_ok('/around?pc=EH1+1BB&status=non_public');
$mech->content_contains( "Around page Test 3 for $body_edin_id",
'problem marked non public is visible' );
$mech->content_lacks( "Around page Test 2 for $body_edin_id",
@@ -193,24 +200,14 @@ for my $permission ( qw/ report_inspect report_mark_private/ ) {
});
$mech->get_ok('/');
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ],
- MAPIT_URL => 'http://mapit.uk/',
- }, sub {
- $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB' } },
- "good location" );
- };
+ $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB' } },
+ "good location" );
$mech->content_lacks( "Around page Test 3 for $body_edin_id",
'problem marked non public is not visible' );
$mech->content_contains( "Around page Test 2 for $body_edin_id",
'problem marked public is visible' );
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ],
- MAPIT_URL => 'http://mapit.uk/',
- }, sub {
- $mech->get_ok('/around?pc=EH1+1BB&status=non_public');
- };
+ $mech->get_ok('/around?pc=EH1+1BB&status=non_public');
$mech->content_lacks( "Around page Test 3 for $body_edin_id",
'problem marked non public is not visible' );
$mech->content_lacks( "Around page Test 2 for $body_edin_id",
@@ -218,6 +215,26 @@ for my $permission ( qw/ report_inspect report_mark_private/ ) {
};
}
+subtest 'check assigned-only list items do not display shortlist buttons' => sub {
+ my $body = FixMyStreet::DB->resultset('Body')->find( $body_edin_id );
+ my $contact = $mech->create_contact_ok( category => 'Horses & Ponies', body_id => $body->id, email => "horses\@example.org" );
+ $edinburgh_problems[4]->update({ category => 'Horses & Ponies' });
+
+ my $user = $mech->log_in_ok( 'test@example.com' );
+ $user->set_extra_metadata(assigned_categories_only => 1);
+ $user->user_body_permissions->delete();
+ $user->set_extra_metadata(categories => [ $contact->id ]);
+ $user->update({ from_body => $body });
+ $user->user_body_permissions->find_or_create({ body => $body, permission_type => 'planned_reports' });
+
+ $mech->get_ok('/around?pc=EH1+1BB');
+ $mech->content_contains('shortlist-add-' . $edinburgh_problems[4]->id);
+ $mech->content_lacks('shortlist-add-' . $edinburgh_problems[3]->id);
+ $mech->content_lacks('shortlist-add-' . $edinburgh_problems[1]->id);
+};
+
+}; # End big override_config
+
my $body = $mech->create_body_ok(2237, "Oxfordshire");
subtest 'check category, status and extra filtering works on /around' => sub {
@@ -233,7 +250,10 @@ subtest 'check category, status and extra filtering works on /around' => sub {
# Create one open and one fixed report in each category
foreach my $category ( @$categories ) {
my $contact = $mech->create_contact_ok( category => $category, body_id => $body->id, email => "$category\@example.org" );
- if ($category ne 'Pothole') {
+ if ($category eq 'Vegetation') {
+ $contact->set_extra_metadata(group => ['Environment', 'Green']);
+ $contact->update;
+ } elsif ($category eq 'Flytipping') {
$contact->set_extra_metadata(group => ['Environment']);
$contact->update;
}
@@ -264,6 +284,9 @@ subtest 'check category, status and extra filtering works on /around' => sub {
$mech->get_ok( '/around?filter_group=Environment&bbox=' . $bbox );
$mech->content_contains('<option value="Flytipping" selected>');
+
+ $mech->get_ok( '/around?filter_group=Environment&filter_category=Vegetation&bbox=' . $bbox );
+ $mech->content_like(qr/<optgroup label="Environment">.*?<option value="Vegetation" selected>.*?<optgroup label="Green">.*?<option value="Vegetation">/s);
};
$json = $mech->get_ok_json( '/around?ajax=1&filter_category=Pothole&bbox=' . $bbox );
@@ -286,6 +309,37 @@ subtest 'check category, status and extra filtering works on /around' => sub {
is scalar @$pins, 1, 'correct number of external_body reports';
};
+subtest 'check categories with same name are only shown once in filters' => sub {
+ my $params = {
+ postcode => 'OX20 1SZ',
+ latitude => 51.754926,
+ longitude => -1.256179,
+ };
+ my $bbox = ($params->{longitude} - 0.01) . ',' . ($params->{latitude} - 0.01)
+ . ',' . ($params->{longitude} + 0.01) . ',' . ($params->{latitude} + 0.01);
+
+ my $district = $mech->create_body_ok(2421, "Oxford City");
+ # Identically-named categories should be combined even if their extra metadata is different
+ my $contact2 = $mech->create_contact_ok( category => "Pothole", body_id => $district->id, email => 'pothole@district-example.org' );
+ $contact2->set_extra_metadata(some_extra_field => "dummy");
+ $contact2->update;
+ # And categories with the same display name should be combined too
+ my $contact3 = $mech->create_contact_ok( category => "Pothole (alternative)", body_id => $district->id, email => 'pothole-alternative@district-example.org' );
+ $contact3->set_extra_metadata(display_name => "Pothole");
+ $contact3->update;
+
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => 'fixmystreet',
+ MAPIT_URL => 'http://mapit.uk/',
+ COBRAND_FEATURES => { category_groups => { fixmystreet => 1 } },
+ }, sub {
+ $mech->get_ok( '/around?bbox=' . $bbox );
+ $mech->content_contains('<option value="Pothole">');
+ $mech->content_unlike(qr{Pothole</option>.*<option value="Pothole">\s*Pothole</option>}s, "Pothole category only appears once");
+ $mech->content_lacks('<option value="Pothole (alternative)">');
+ };
+};
+
subtest 'check old problems not shown by default on around page' => sub {
my $params = {
postcode => 'OX20 1SZ',
@@ -390,7 +444,7 @@ subtest 'check map zoom level customisation' => sub {
MAP_TYPE => 'OSM',
}, sub {
$mech->get('/around?latitude=51.754926&longitude=-1.256179');
- $mech->content_contains('data-numZoomLevels=6');
+ $mech->content_contains('data-numZoomLevels=7');
$mech->content_contains('data-zoomOffset=13');
};