diff options
author | Struan Donald <struan@exo.org.uk> | 2018-06-12 17:46:47 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2018-07-03 15:55:52 +0100 |
commit | 1b7418e2aec2ce269fde49efcff8493e4e24ad7e (patch) | |
tree | 2761dc4196b1c5f306b4e498ee633a5e939f2d9b /t | |
parent | 04e49afc9a7c10405464c62b0cfd6f6c55b286ac (diff) |
Only display reports from last 6 months on around.
Add a checkbox to show older reports, plus if we get to the end of the new
reports then instead of a Next button show a "show older" button that will
reload the current page but with older reports also loaded. Wire it all up
into the pushState code as well.
Diffstat (limited to 't')
-rw-r--r-- | t/app/controller/around.t | 74 | ||||
-rw-r--r-- | t/map/tilma/original.t | 1 |
2 files changed, 73 insertions, 2 deletions
diff --git a/t/app/controller/around.t b/t/app/controller/around.t index 02abefe7e..dc755a67f 100644 --- a/t/app/controller/around.t +++ b/t/app/controller/around.t @@ -137,9 +137,9 @@ subtest 'check non public reports are not displayed on around page' => sub { }; -subtest 'check category, status and extra filtering works on /around' => sub { - my $body = $mech->create_body_ok(2237, "Oxfordshire"); +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', @@ -195,6 +195,76 @@ subtest 'check category, status and extra filtering works on /around' => sub { 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' ); + $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 }); diff --git a/t/map/tilma/original.t b/t/map/tilma/original.t index e89251285..42cbbd9f2 100644 --- a/t/map/tilma/original.t +++ b/t/map/tilma/original.t @@ -91,6 +91,7 @@ for my $test ( subtest "pin colour for state $test->{state}" => sub { $report->state($test->{state}); $report->update; + $c->stash->{report_age_field} = 'lastupdate'; my ( $on_map, $nearby, $dist ) = FixMyStreet::Map::map_features($c, bbox => "0,0,0,0"); |