Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix non-JS form when all extra questions answered. #3248

Merged
merged 1 commit into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## Releases

* Unreleased
- Bugfixes:
- Fix non-JS form when all extra questions answered. #3248

* v3.1 (16th November 2020)
- Security:
Expand Down
5 changes: 4 additions & 1 deletion perllib/FixMyStreet/App/Controller/Report/New.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1642,6 +1642,7 @@ sub check_for_category : Private {
if ($disable_form_messages->{all}) {
$c->stash->{disable_form_message} = $disable_form_messages->{all};
} elsif (my $questions = $disable_form_messages->{questions}) {
my $all_disable_qns_answered = 1;
foreach my $question (@$questions) {
my $answer = $c->get_param($question->{code});
my $message = $question->{message};
Expand All @@ -1651,10 +1652,12 @@ sub check_for_category : Private {
$c->stash->{disable_form_message} = $message;
}
}
} else {
$all_disable_qns_answered = 0;
}
}
if (!$c->stash->{disable_form_message}) {
$c->stash->{have_disable_qn_to_answer} = 1;
$c->stash->{have_disable_qn_to_answer} = !$all_disable_qns_answered;
}
}
}
Expand Down
19 changes: 16 additions & 3 deletions t/app/controller/report_new_open311.t
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ subtest "Category extras includes form disabling string" => sub {
# Test new non-JS form disabling flow
$mech->get_ok('/report/new?latitude=55.952055&longitude=-3.189579');
$mech->content_contains('name="submit_category_part_only"');
$mech->submit_form_ok({ with_fields => { category => 'Pothole' } });
$mech->submit_form_ok({ with_fields => { category => $contact4->category } });
$mech->content_contains('<div id="js-category-stopper" class="box-warning" role="alert" aria-live="assertive">');
$mech->content_contains('Please ring us!');
# Switch to another, okay, category
Expand All @@ -452,7 +452,7 @@ subtest "Category extras includes form disabling string" => sub {

# Test submission of whole form, switching back to a blocked category at the same time
$mech->submit_form_ok({ with_fields => {
category => 'Pothole', title => 'Title', detail => 'Detail',
category => $contact4->category, title => 'Title', detail => 'Detail',
username_register => '[email protected]', name => 'Testing Example',
} });
$mech->content_contains('<div id="js-category-stopper" class="box-warning" role="alert" aria-live="assertive">');
Expand All @@ -465,14 +465,27 @@ subtest "Category extras includes form disabling string" => sub {
$contact4->update;
$mech->get_ok('/report/new?latitude=55.952055&longitude=-3.189579');
$mech->content_contains('name="submit_category_part_only"');
$mech->submit_form_ok({ with_fields => { category => 'Pothole' } });
$mech->submit_form_ok({ with_fields => { category => $contact4->category } });
$mech->content_contains('name="submit_category_part_only"');
$mech->submit_form_ok({ with_fields => { dangerous => 'no' } });
$mech->content_lacks('<div id="js-category-stopper" class="box-warning" role="alert" aria-live="assertive">');
$mech->content_lacks('Please please ring');
$mech->submit_form_ok({ with_fields => { dangerous => 'yes' } });
$mech->content_contains('name="submit_category_part_only"'); # Did not answer type question
$mech->content_contains('<div id="js-category-stopper" class="box-warning" role="alert" aria-live="assertive">');
$mech->content_contains('Please please ring');

$mech->get_ok('/report/new?latitude=55.952055&longitude=-3.189579');
$mech->submit_form_ok({ with_fields => { category => $contact4->category } });
$mech->submit_form_ok({ with_fields => { dangerous => 'no', danger_type => 'no' } });
$mech->content_lacks('name="submit_category_part_only"');
$mech->content_lacks('<div id="js-category-stopper" class="box-warning" role="alert" aria-live="assertive">');
$mech->content_lacks('Please please ring');
$mech->content_lacks('Ring the very number');
$mech->submit_form_ok({ with_fields => { dangerous => 'no', danger_type => 'very' } });
$mech->content_contains('name="submit_category_part_only"');
$mech->content_contains('<div id="js-category-stopper" class="box-warning" role="alert" aria-live="assertive">');
$mech->content_contains('Ring the very number');
};
};

Expand Down