diff options
Diffstat (limited to 't/app')
-rw-r--r-- | t/app/controller/contact.t | 111 | ||||
-rw-r--r-- | t/app/controller/dashboard.t | 16 | ||||
-rw-r--r-- | t/app/controller/report_new.t | 117 |
3 files changed, 239 insertions, 5 deletions
diff --git a/t/app/controller/contact.t b/t/app/controller/contact.t index 11e0d30cf..89a1db5b2 100644 --- a/t/app/controller/contact.t +++ b/t/app/controller/contact.t @@ -8,7 +8,7 @@ my $mech = FixMyStreet::TestMech->new; $mech->get_ok('/contact'); $mech->title_like(qr/Contact Us/); -$mech->content_contains("We'd love to hear what you think about this site"); +$mech->content_contains("It's often quickest to "); my $problem_main; @@ -282,6 +282,115 @@ for my $test ( }; } +for my $test ( + { + fields => { + em => 'test@example.com', + name => 'A name', + subject => 'A subject', + message => 'A message', + dest => undef, + }, + page_errors => + [ 'There were problems with your report. Please see below.', + 'Please enter who your message is for', + ] + }, + { + fields => { + em => 'test@example.com', + name => 'A name', + subject => 'A subject', + message => 'A message', + dest => 'council', + }, + page_errors => + [ 'There were problems with your report. Please see below.', + 'You can only contact the team behind FixMyStreet using our contact form', + ] + }, + { + fields => { + em => 'test@example.com', + name => 'A name', + subject => 'A subject', + message => 'A message', + dest => 'update', + }, + page_errors => + [ 'There were problems with your report. Please see below.', + 'You can only contact the team behind FixMyStreet using our contact form', + ] + }, + ) +{ + subtest 'check submit page incorrect destination handling' => sub { + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'fixmystreet' ], + }, sub { + $mech->host('www.fixmystreet.com'); + $mech->get_ok( $test->{url} ? $test->{url} : '/contact' ); + $mech->submit_form_ok( { with_fields => $test->{fields} } ); + is_deeply $mech->page_errors, $test->{page_errors}, 'page errors'; + + # we santise this when we submit so need to remove it + delete $test->{fields}->{id} + if $test->{fields}->{id} and $test->{fields}->{id} eq 'invalid'; + is_deeply $mech->visible_form_values, $test->{fields}, 'form values'; + + if ( $test->{fields}->{dest} and $test->{fields}->{dest} eq 'update' ) { + $mech->content_contains( 'www.writetothem.com', 'includes link to WTT if trying to update report' ); + } elsif ( $test->{fields}->{dest} and $test->{fields}->{dest} eq 'council' ) { + $mech->content_lacks( 'www.writetothem.com', 'does not include link to WTT if trying to contact council' ); + $mech->content_contains( 'should find contact details', 'mentions checking council website for contact details' ); + } + } + }; +} + +for my $test ( + { + fields => { + em => 'test@example.com', + name => 'A name', + subject => 'A subject', + message => 'A message', + dest => 'help', + }, + }, + { + fields => { + em => 'test@example.com', + name => 'A name', + subject => 'A subject', + message => 'A message', + dest => 'feedback', + }, + }, + { + fields => { + em => 'test@example.com', + name => 'A name', + subject => 'A subject', + message => 'A message', + dest => 'from_council', + }, + }, + ) +{ + subtest 'check email sent correctly with dest field set to us' => sub { + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'fixmystreet' ], + }, sub { + $mech->clear_emails_ok; + $mech->get_ok('/contact'); + $mech->submit_form_ok( { with_fields => $test->{fields} } ); + $mech->content_contains('Thanks for your feedback'); + $mech->email_count_is(1); + } + }; +} + $problem_main->delete; done_testing(); diff --git a/t/app/controller/dashboard.t b/t/app/controller/dashboard.t index a87232e9b..4e62028b5 100644 --- a/t/app/controller/dashboard.t +++ b/t/app/controller/dashboard.t @@ -609,9 +609,19 @@ FixMyStreet::override_config { } subtest 'export as csv' => sub { + make_problem( { + detail => "this report\nis split across\nseveral lines", + state => "confirmed", + conf_dt => DateTime->now(), + } ); $mech->get_ok('/dashboard?export=1'); - my @lines = split /\n/, $mech->content; - is scalar @lines, 6, '1 (header) + 5 (reports) = 6 lines'; + open my $data_handle, '<', \$mech->content; + my $csv = Text::CSV->new( { binary => 1 } ); + my @rows; + while ( my $row = $csv->getline( $data_handle ) ) { + push @rows, $row; + } + is scalar @rows, 7, '1 (header) + 6 (reports) = 7 lines'; }; }; restore_time; @@ -623,7 +633,7 @@ sub make_problem { title => 'a problem', name => 'a user', anonymous => 1, - detail => 'some detail', + detail => $args->{detail} || 'some detail', state => $args->{state}, confirmed => $args->{conf_dt}, whensent => $args->{conf_dt}, diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index 84258f338..98b0175f8 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -46,6 +46,7 @@ for my $body ( { id => 2482, name => 'Bromley Council' }, { id => 2240, name => 'Staffordshire County Council' }, { id => 2434, name => 'Lichfield District Council' }, + { id => 2504, name => 'Westminster City Council' }, ) { $mech->create_body_ok($body->{id}, $body->{name}); } @@ -825,7 +826,7 @@ foreach my $test ( $mech->submit_form_ok( { with_fields => { - title => "Test Report at café", + title => "Test Report at café", detail => 'Test report details.', photo => '', name => 'Joe Bloggs', @@ -1481,6 +1482,120 @@ subtest "categories from deleted bodies shouldn't be visible for new reports" => }; }; +subtest "extra google analytics code displayed on logged in problem creation" => sub { + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], + BASE_URL => 'http://www.fixmystreet.com', + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + # check that the user does not exist + my $test_email = 'test-2@example.com'; + + $mech->clear_emails_ok; + my $user = $mech->log_in_ok($test_email); + + # setup the user. + ok $user->update( + { + name => 'Test User', + phone => '01234 567 890', + } + ), + "set users details"; + + # submit initial pc form + $mech->get_ok('/around'); + $mech->submit_form_ok( { with_fields => { pc => 'GL50 2PR', } }, + "submit location" ); + + # click through to the report page + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, + "follow 'skip this step' link" ); + + $mech->submit_form_ok( + { + with_fields => { + title => "Test Report at café", + detail => 'Test report details.', + photo => '', + name => 'Joe Bloggs', + may_show_name => '1', + phone => '07903 123 456', + category => 'Trees', + } + }, + "submit good details" + ); + + # find the report + my $report = $user->problems->first; + ok $report, "Found the report"; + + # check that we got redirected to /report/ + is $mech->uri->path, "/report/" . $report->id, "redirected to report page"; + + $mech->content_contains( "extra = '?created_report", 'extra google code present' ); + + # cleanup + $mech->delete_user($user); + }; +}; + +subtest "extra google analytics code displayed on email confirmation problem creation" => sub { + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], + BASE_URL => 'http://www.fixmystreet.com', + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + $mech->log_out_ok; + $mech->clear_emails_ok; + + $mech->get_ok('/'); + $mech->submit_form_ok( { with_fields => { pc => 'GL50 2PR' } }, + "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'); + my $submission_fields = { + title => "Test Report", + detail => 'Test report details.', + photo => '', + email => 'firstlast@example.com', + name => 'Test User', + may_show_name => '1', + phone => '07903 123 456', + category => 'Trees', + password_register => '', + }; + + $mech->submit_form_ok( { with_fields => $submission_fields }, + "submit good details" ); + + my $email = $mech->get_email; + ok $email, "got an email"; + like $email->body, qr/confirm the problem/i, "confirm the problem"; + + my ($url) = $email->body =~ m{(https?://\S+)}; + ok $url, "extracted confirm url '$url'"; + + # confirm token in order to update the user details + $mech->get_ok($url); + + $mech->content_contains( "extra = '?created_report", 'extra google code present' ); + + my $user = + FixMyStreet::App->model('DB::User') + ->find( { email => 'firstlast@example.com' } ); + + $user->problems->delete; + $user->alerts->delete; + $user->delete; + }; +}; + $contact1->delete; $contact2->delete; $contact3->delete; |