diff options
author | Edmund von der Burg <evdb@mysociety.org> | 2011-04-14 11:38:25 +0100 |
---|---|---|
committer | Edmund von der Burg <evdb@mysociety.org> | 2011-04-14 11:38:25 +0100 |
commit | 1031d78748f88c57d78fb79cb6771ab698b7d284 (patch) | |
tree | aa501b5ff025158f0a97ade0d87664a6792d2f79 | |
parent | 998a7b4aa08b9b4f5f857ad652d6f3f90eec076b (diff) |
Fim report creation tests
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Around.pm | 13 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 59 | ||||
-rw-r--r-- | t/app/controller/report_new.t | 53 | ||||
-rw-r--r-- | templates/web/default/around/around_index.html | 6 | ||||
-rwxr-xr-x | templates/web/default/around/display_location.html | 4 |
5 files changed, 102 insertions, 33 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm index 0c6db66be..ae0976de8 100644 --- a/perllib/FixMyStreet/App/Controller/Around.pm +++ b/perllib/FixMyStreet/App/Controller/Around.pm @@ -226,7 +226,7 @@ sub determine_location_from_pc : Private { } # pass errors back to the template - $c->stash->{pc_error} = $error; + $c->stash->{location_error} = $error; return; } @@ -258,13 +258,14 @@ sub check_location_is_acceptable : Private { ) if $@; } - # all good - return 1 if !$error_msg; - # show error - $c->stash->{pc_error} = $error_msg; - return; + if ($error_msg) { + $c->stash->{location_error} = $error_msg; + return; + } + # check that there are councils that can accept this location + return $c->forward('/report/new/load_and_check_councils'); } __PACKAGE__->meta->make_immutable; diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index 2dbec4235..7bb289bea 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -84,9 +84,8 @@ sub report_new : Path : Args(0) { $c->forward('initialize_report'); # work out the location for this report and do some checks - return - unless $c->forward('determine_location') - && $c->forward('load_councils'); + return $c->forward('redirect_to_around') + unless $c->forward('determine_location'); # create a problem from the submitted details $c->stash->{template} = "report/new/fill_in_details.html"; @@ -373,14 +372,15 @@ found. sub determine_location : Private { my ( $self, $c ) = @_; - return - unless $c->forward('determine_location_from_tile_click') - || $c->forward('/around/determine_location_from_coords') - || $c->forward('/around/determine_location_from_pc') - || $c->forward('determine_location_from_report'); - - - return $c->forward('/around/check_location_is_acceptable'); + return 1 + if # + ( # + $c->forward('determine_location_from_tile_click') + || $c->forward('/around/determine_location_from_coords') + || $c->forward('determine_location_from_report') + ) # + && $c->forward('/around/check_location_is_acceptable'); + return; } =head2 determine_location_from_tile_click @@ -455,14 +455,14 @@ sub determine_location_from_report : Private { return; } -=head2 load_councils +=head2 load_and_check_councils Try to load councils for this location and check that we have at least one. If there are no councils then return false. =cut -sub load_councils : Private { +sub load_and_check_councils : Private { my ( $self, $c ) = @_; my $latitude = $c->stash->{latitude}; my $longitude = $c->stash->{longitude}; @@ -484,6 +484,9 @@ sub load_councils : Private { return; } + # edit hash in-place + _remove_redundant_councils($all_councils); + # If we don't have any councils we can't accept the report if ( !scalar keys %$all_councils ) { $c->stash->{location_error} = @@ -493,9 +496,6 @@ sub load_councils : Private { return; } - # edit hash in-place - _remove_redundant_councils($all_councils); - # all good if we have some councils left $c->stash->{all_councils} = $all_councils; $c->stash->{all_council_names} = @@ -1089,6 +1089,33 @@ sub redirect_or_confirm_creation : Private { $c->stash->{email_type} = 'problem'; } +=head2 redirect_to_around + +Redirect the user to '/around' passing along all the relevant parameters. + +=cut + +sub redirect_to_around : Private { + my ( $self, $c ) = @_; + + my $params = { + pc => ( $c->stash->{pc} || $c->req->param('pc') || '' ), + lat => $c->stash->{latitude}, + lon => $c->stash->{longitude}, + }; + + # delete empty values + for ( keys %$params ) { + delete $params->{$_} if !$params->{$_}; + } + + # FIXME add partial here. + + my $around_uri = $c->uri_for( '/around', $params ); + + return $c->res->redirect($around_uri); +} + __PACKAGE__->meta->make_immutable; 1; diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index 1310a3e35..e9dae0da5 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -8,10 +8,19 @@ use Web::Scraper; my $mech = FixMyStreet::TestMech->new; $mech->get_ok('/report/new'); -fail "test that lat,lon not covered by council goes to '/around'"; - fail "test that partial code is transferred"; +subtest "test that bare requests to /report/new get redirected" => sub { + + $mech->get_ok('/report/new'); + is $mech->uri->path, '/around', "went to /around"; + is_deeply { $mech->uri->query_form }, {}, "query empty"; + + $mech->get_ok('/report/new?pc=SW1A%201AA'); + is $mech->uri->path, '/around', "went to /around"; + is_deeply { $mech->uri->query_form }, { pc => 'SW1A 1AA' }, + "pc correctly transferred"; +}; # test that the various bit of form get filled in and errors correctly # generated. @@ -203,13 +212,17 @@ foreach my $test ( ) { subtest "check form errors where $test->{msg}" => sub { - $mech->get_ok('/report/new'); + $mech->get_ok('/around'); # submit initial pc form $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } }, "submit location" ); is_deeply $mech->form_errors, [], "no errors for pc '$test->{pc}'"; + # click through to the report page + $mech->follow_link_ok( { text => 'skip this step', }, + "follow 'skip this step' link" ); + # submit the main form $mech->submit_form_ok( { with_fields => $test->{fields} }, "submit form" ); @@ -237,9 +250,14 @@ subtest "test report creation for a user who does not have an account" => sub { "test user does not exist"; # submit initial pc form - $mech->get_ok('/report/new'); + $mech->get_ok('/around'); $mech->submit_form_ok( { with_fields => { pc => 'SW1A 1AA', } }, "submit location" ); + + # click through to the report page + $mech->follow_link_ok( { text => 'skip this step', }, + "follow 'skip this step' link" ); + $mech->submit_form_ok( { with_fields => { @@ -323,10 +341,14 @@ subtest "test report creation for a user who is logged in" => sub { "set users details"; # submit initial pc form - $mech->get_ok('/report/new'); + $mech->get_ok('/around'); $mech->submit_form_ok( { with_fields => { pc => 'SW1A 1AA', } }, "submit location" ); + # click through to the report page + $mech->follow_link_ok( { text => 'skip this step', }, + "follow 'skip this step' link" ); + # check that the fields are correctly prefilled is_deeply( $mech->visible_form_values, @@ -395,4 +417,25 @@ subtest "test report creation for a user who is logged in" => sub { # create report by clicking on may with javascript off # create report with images off +subtest "check that a lat/lon off coast leads to /around" => sub { + my $off_coast_latitude = 50.78301; + my $off_coast_longitude = -0.646929; + + $mech->get_ok( # + "/report/new" + . "?latitude=$off_coast_latitude" + . "&longitude=$off_coast_longitude" + ); + + is $mech->uri->path, '/around', "redirected to '/around'"; + + is_deeply # + $mech->page_errors, + [ 'That spot does not appear to be covered by a council. If you have' + . ' tried to report an issue past the shoreline, for example, please' + . ' specify the closest point on land.' ], # + "Found location error"; + +}; + done_testing(); diff --git a/templates/web/default/around/around_index.html b/templates/web/default/around/around_index.html index 3f86761aa..554e4f1b7 100644 --- a/templates/web/default/around/around_index.html +++ b/templates/web/default/around/around_index.html @@ -18,8 +18,9 @@ [% END %] </form> + [% IF location_error %] - <div class="error">[% location_error %]</div> + <p class="error">[% location_error %]</p> [% END %] [% IF possible_location_matches %] @@ -38,9 +39,6 @@ </p> [% END %] -[% IF pc_error %] -<p class="error">[% pc_error %]</p> -[% END %] [% INCLUDE 'footer.html' %] diff --git a/templates/web/default/around/display_location.html b/templates/web/default/around/display_location.html index 89f2c79e4..ba1e6b73f 100755 --- a/templates/web/default/around/display_location.html +++ b/templates/web/default/around/display_location.html @@ -48,9 +48,9 @@ </a> </p> -[% IF pc_error %] +[% IF location_error %] <ul class="error"> - <li>[% pc_error | html %]</li> + <li>[% location_error | html %]</li> </ul> [% END %] |