diff options
author | Struan Donald <struan@exo.org.uk> | 2014-04-17 10:06:28 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2014-04-17 10:06:28 +0100 |
commit | 2edcbe06b98e0f1daa11173477b7a90a57efcdbc (patch) | |
tree | 7b8ba67246b743ae568bf215810e59dfe19db170 /t/app | |
parent | 0625dbe113dc88fe707ca1fb036bf0a580781e15 (diff) | |
parent | 565c6498aefea0fd39ec7453019bbf86b52672dd (diff) |
Merge branch 'improve-contact-form'
Diffstat (limited to 't/app')
-rw-r--r-- | t/app/controller/contact.t | 111 |
1 files changed, 110 insertions, 1 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(); |