diff options
Diffstat (limited to 't/app')
-rw-r--r-- | t/app/controller/report_new.t | 116 |
1 files changed, 112 insertions, 4 deletions
diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index 625c7531f..1e751997b 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -48,6 +48,12 @@ my $contact3 = FixMyStreet::App->model('DB::Contact')->find_or_create( { category => 'Trees', email => 'trees@example.com', } ); +my $contact4 = FixMyStreet::App->model('DB::Contact')->find_or_create( { + %contact_params, + area_id => 2482, # Bromley + category => 'Trees', + email => 'trees@example.com', +} ); ok $contact1, "created test contact 1"; ok $contact2, "created test contact 2"; ok $contact3, "created test contact 3"; @@ -293,7 +299,7 @@ foreach my $test ( 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', }, + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); # submit the main form @@ -473,7 +479,7 @@ subtest "test password errors for a user who is signing in as they report" => su "submit location" ); # click through to the report page - $mech->follow_link_ok( { text => 'Skip this step', }, + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); $mech->submit_form_ok( @@ -520,7 +526,7 @@ subtest "test report creation for a user who is signing in as they report" => su "submit location" ); # click through to the report page - $mech->follow_link_ok( { text => 'Skip this step', }, + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); $mech->submit_form_ok( @@ -614,7 +620,7 @@ foreach my $test ( "submit location" ); # click through to the report page - $mech->follow_link_ok( { text => 'Skip this step', }, + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); # check that the fields are correctly prefilled @@ -725,6 +731,108 @@ subtest "check that a lat/lon off coast leads to /around" => sub { }; +for my $test ( + { + desc => 'title shown for bromley problem on main site', + host => 'http://www.fixmystreet.com', + extra => [ + { + name => 'fms_extra_title', + value => 'Mr', + description => 'FMS_EXTRA_TITLE', + }, + ], + }, + { + desc => + 'title, first and last name shown for bromley problem on cobrand', + host => 'http://bromley.fixmystreet.com', + first_name => 'Test', + last_name => 'User', + extra => [ + { + name => 'fms_extra_title', + value => 'Mr', + description => 'FMS_EXTRA_TITLE', + }, + { + name => 'first_name', + value => 'Test', + description => 'FIRST_NAME', + }, + { + name => 'last_name', + value => 'User', + description => 'LAST_NAME', + }, + ], + }, + ) +{ + subtest $test->{desc} => sub { + $mech->host( $test->{host} ); + + $mech->log_out_ok; + + $mech->get_ok('/around'); + $mech->submit_form_ok( { with_fields => { pc => 'BR1 3UH', } }, + "submit location" ); + $mech->follow_link_ok( + { text_regex => qr/skip this step/i, }, + "follow 'skip this step' link" + ); + + my $fields = $mech->visible_form_values('mapSkippedForm'); + ok exists( $fields->{fms_extra_title} ), 'user title field displayed'; + if ( $test->{first_name} ) { + ok exists( $fields->{first_name} ), 'first name field displayed'; + ok exists( $fields->{last_name} ), 'last name field displayed'; + ok !exists( $fields->{name} ), 'no name field displayed'; + } + else { + ok !exists( $fields->{first_name} ), + 'first name field not displayed'; + ok !exists( $fields->{last_name} ), 'last name field not displayed'; + ok exists( $fields->{name} ), 'name field displayed'; + } + + my $submission_fields = { + title => "Test Report", + detail => 'Test report details.', + photo => '', + email => 'firstlast@example.com', + fms_extra_title => 'Mr', + may_show_name => '1', + phone => '07903 123 456', + category => 'Trees', + password_register => '', + }; + + if ( $test->{first_name} ) { + $submission_fields->{first_name} = $test->{first_name}; + $submission_fields->{last_name} = $test->{last_name}; + } + else { + $submission_fields->{name} = 'Test User'; + } + + $mech->submit_form_ok( { with_fields => $submission_fields }, + "submit good details" ); + + my $user = + FixMyStreet::App->model('DB::User') + ->find( { email => 'firstlast@example.com' } ); + + my $report = $user->problems->first; + ok $report, "Found the report"; + my $extras = $report->extra; + is_deeply $extras, $test->{extra}, 'extra contains correct values'; + + $user->problems->delete; + $user->delete; + }; +} + $contact1->delete; $contact2->delete; $contact3->delete; |