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.t226
1 files changed, 193 insertions, 33 deletions
diff --git a/t/app/controller/around.t b/t/app/controller/around.t
index 8eaba6450..b123692fa 100644
--- a/t/app/controller/around.t
+++ b/t/app/controller/around.t
@@ -1,3 +1,13 @@
+package FixMyStreet::Map::Tester;
+use base 'FixMyStreet::Map::FMS';
+
+use constant ZOOM_LEVELS => 99;
+use constant MIN_ZOOM_LEVEL => 88;
+
+1;
+
+package main;
+
use Test::MockModule;
use FixMyStreet::TestMech;
@@ -8,28 +18,6 @@ subtest "check that if no query we get sent back to the homepage" => sub {
is $mech->uri->path, '/', "redirected to '/'";
};
-# x,y requests were generated by the old map code. We keep the behavior for
-# historic links
-subtest "redirect x,y requests to lat/lon (301 - permanent)" => sub {
-
- FixMyStreet::override_config {
- MAPIT_URL => 'http://mapit.uk/',
- }, sub {
- $mech->get_ok('/around?x=3281&y=1113');
- };
-
- # did we redirect to lat,lon?
- is $mech->uri->path, '/around', "still on /around";
- is_deeply { $mech->uri->query_form },
- { lat => 51.499825, lon => -0.140137, zoom => 3 },
- "lat,lon correctly set";
-
- # was it a 301?
- is $mech->res->code, 200, "got 200 for final destination";
- is $mech->res->previous->code, 301, "got 301 for redirect";
-
-};
-
# test various locations on inital search box
foreach my $test (
{
@@ -94,7 +82,10 @@ foreach my $test (
};
}
-my @edinburgh_problems = $mech->create_problems_for_body( 5, 2651, 'Around page', {
+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;
+
+my @edinburgh_problems = $mech->create_problems_for_body( 5, $body_edin_id, 'Around page', {
postcode => 'EH1 1BB',
latitude => 55.9519637512,
longitude => -3.17492254484,
@@ -118,7 +109,7 @@ subtest 'check non public reports are not displayed on around page' => sub {
$mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB' } },
"good location" );
};
- $mech->content_contains( 'Around page Test 3 for 2651',
+ $mech->content_contains( "Around page Test 3 for $body_edin_id",
'problem to be marked non public visible' );
my $private = $edinburgh_problems[2];
@@ -132,14 +123,82 @@ subtest 'check non public reports are not displayed on around page' => sub {
$mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB' } },
"good location" );
};
- $mech->content_lacks( 'Around page Test 3 for 2651',
+ $mech->content_lacks( "Around page Test 3 for $body_edin_id",
'problem marked non public is not visible' );
};
+for my $permission ( qw/ report_inspect report_mark_private/ ) {
+ 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' );
+ $user->user_body_permissions->delete();
+ $user->update({ from_body => $body });
+ $user->user_body_permissions->find_or_create({
+ body => $body,
+ permission_type => $permission,
+ });
-subtest 'check category, status and extra filtering works on /around' => sub {
- my $body = $mech->create_body_ok(2237, "Oxfordshire");
+ $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->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->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",
+ 'problem marked public is not visible' );
+
+ $user->user_body_permissions->delete();
+ $user->update({ from_body => $body2 });
+ $user->user_body_permissions->find_or_create({
+ body => $body2,
+ permission_type => $permission,
+ });
+
+ $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->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->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",
+ 'problem marked public is visible' );
+ };
+}
+
+my $body = $mech->create_body_ok(2237, "Oxfordshire");
+
+subtest 'check category, status and extra filtering works on /around' => sub {
my $categories = [ 'Pothole', 'Vegetation', 'Flytipping' ];
my $params = {
postcode => 'OX20 1SZ',
@@ -152,7 +211,7 @@ 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 ) {
$mech->create_contact_ok( category => $category, body_id => $body->id, email => "$category\@example.org" );
- foreach my $state ( 'confirmed', 'fixed' ) {
+ foreach my $state ( 'confirmed', 'fixed - user', 'fixed - council' ) {
my %report_params = (
%$params,
category => $category,
@@ -165,10 +224,11 @@ subtest 'check category, status and extra filtering works on /around' => sub {
my $json = $mech->get_ok_json( '/around?ajax=1&bbox=' . $bbox );
my $pins = $json->{pins};
- is scalar @$pins, 6, 'correct number of reports when no filters';
+ is scalar @$pins, 9, 'correct number of reports when no filters';
# Regression test for filter_category in /around URL
FixMyStreet::override_config {
+ ALLOWED_COBRANDS => 'fixmystreet',
MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->get_ok( '/around?filter_category=Pothole&bbox=' . $bbox );
@@ -177,7 +237,7 @@ subtest 'check category, status and extra filtering works on /around' => sub {
$json = $mech->get_ok_json( '/around?ajax=1&filter_category=Pothole&bbox=' . $bbox );
$pins = $json->{pins};
- is scalar @$pins, 2, 'correct number of Pothole reports';
+ is scalar @$pins, 3, 'correct number of Pothole reports';
$json = $mech->get_ok_json( '/around?ajax=1&status=open&bbox=' . $bbox );
$pins = $json->{pins};
@@ -185,16 +245,86 @@ subtest 'check category, status and extra filtering works on /around' => sub {
$json = $mech->get_ok_json( '/around?ajax=1&status=fixed&filter_category=Vegetation&bbox=' . $bbox );
$pins = $json->{pins};
- is scalar @$pins, 1, 'correct number of fixed Vegetation reports';
+ is scalar @$pins, 2, 'correct number of fixed Vegetation reports';
my $cobrand = Test::MockModule->new('FixMyStreet::Cobrand::Default');
- $cobrand->mock('display_location_extra_params', sub { { external_body => "Pothole-fixed" } });
+ $cobrand->mock('display_location_extra_params', sub { { external_body => "Pothole-confirmed" } });
$json = $mech->get_ok_json( '/around?ajax=1&bbox=' . $bbox );
$pins = $json->{pins};
is scalar @$pins, 1, 'correct number of external_body reports';
};
+subtest 'check old problems not shown by default on around page' => 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 $json = $mech->get_ok_json( '/around?ajax=1&bbox=' . $bbox );
+ my $pins = $json->{pins};
+ is scalar @$pins, 9, 'correct number of reports when no age';
+
+ my $problems = FixMyStreet::App->model('DB::Problem')->to_body( $body->id );
+ $problems->first->update( { confirmed => \"current_timestamp-'7 months'::interval" } );
+
+ $json = $mech->get_ok_json( '/around?ajax=1&bbox=' . $bbox );
+ $pins = $json->{pins};
+ is scalar @$pins, 8, 'correct number of reports with old report';
+
+ $json = $mech->get_ok_json( '/around?show_old_reports=1&ajax=1&bbox=' . $bbox );
+ $pins = $json->{pins};
+ is scalar @$pins, 9, 'correct number of reports with show_old_reports';
+
+ $problems->update( { confirmed => \"current_timestamp" } );
+};
+
+subtest 'check sorting by update uses lastupdate to determine age' => 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 $problems = FixMyStreet::App->model('DB::Problem')->to_body( $body->id );
+ $problems->first->update( { confirmed => \"current_timestamp-'7 months'::interval" } );
+
+ my $json = $mech->get_ok_json( '/around?ajax=1&bbox=' . $bbox );
+ my $pins = $json->{pins};
+ is scalar @$pins, 8, 'correct number of reports with default sorting';
+
+
+ $json = $mech->get_ok_json( '/around?ajax=1&sort=updated-desc&bbox=' . $bbox );
+ $pins = $json->{pins};
+ is scalar @$pins, 9, 'correct number of reports with updated sort';
+
+ $problems->update( { confirmed => \"current_timestamp" } );
+};
+
+subtest 'check show old reports checkbox shown on around page' => sub {
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ $mech->get_ok( '/around?pc=OX20+1SZ' );
+ $mech->content_contains('id="show_old_reports_wrapper" class="report-list-filters hidden"');
+
+ my $problems = FixMyStreet::App->model('DB::Problem')->to_body( $body->id );
+ $problems->first->update( { confirmed => \"current_timestamp-'7 months'::interval" } );
+
+ $mech->get_ok( '/around?pc=OX20+1SZ&status=all' );
+ $mech->content_lacks('id="show_old_reports_wrapper" class="report-list-filters hidden"');
+ $mech->content_contains('id="show_old_reports_wrapper" class="report-list-filters"');
+
+ $problems->update( { confirmed => \"current_timestamp" } );
+ };
+};
+
subtest 'check skip_around skips around page' => sub {
my $cobrand = Test::MockModule->new('FixMyStreet::Cobrand::Default');
$cobrand->mock('skip_around_page', sub { 1 });
@@ -202,11 +332,41 @@ subtest 'check skip_around skips around page' => sub {
FixMyStreet::override_config {
MAPIT_URL => 'http://mapit.uk/',
+ MAPIT_TYPES => ['CTY', 'DIS'],
}, sub {
$mech->get('/around?latitude=51.754926&longitude=-1.256179');
- is $mech->res->code, 302, "around page is a redirect";
+ is $mech->res->previous->code, 302, "around page is a redirect";
is $mech->uri->path, '/report/new', "and redirects to /report/new";
};
};
+subtest 'check map zoom level customisation' => sub {
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => 'fixmystreet',
+ MAPIT_URL => 'http://mapit.uk/',
+ MAP_TYPE => 'OSM',
+ }, sub {
+ $mech->get('/around?latitude=51.754926&longitude=-1.256179');
+ $mech->content_contains('data-numZoomLevels=6');
+ $mech->content_contains('data-zoomOffset=13');
+ };
+
+
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => 'fixmystreet',
+ MAPIT_URL => 'http://mapit.uk/',
+ MAP_TYPE => 'Tester',
+ }, sub {
+ $mech->get('/around?latitude=51.754926&longitude=-1.256179');
+ $mech->content_contains('data-numZoomLevels=99');
+ $mech->content_contains('data-zoomOffset=88');
+ };
+};
+
+subtest 'check nearby lookup' => sub {
+ my $p = FixMyStreet::DB->resultset("Problem")->search({ external_body => "Pothole-confirmed" })->first;
+ $mech->get_ok('/around/nearby?latitude=51.754926&longitude=-1.256179&filter_category=Pothole');
+ $mech->content_contains('["51.754926","-1.256179","yellow",' . $p->id . ',"Around page Test 1 for ' . $body->id . '","small",false]');
+};
+
done_testing();