aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm11
-rw-r--r--t/app/controller/auth_social.t31
-rw-r--r--templates/web/base/report/new/category.html4
3 files changed, 40 insertions, 6 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index 2246f6aea..120467905 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -104,6 +104,7 @@ sub report_new : Path : Args(0) {
$c->forward('setup_report_extra_fields');
$c->forward('generate_map');
$c->forward('check_for_category');
+ $c->forward('setup_report_extras');
# deal with the user and report and check both are happy
@@ -1073,6 +1074,14 @@ sub contacts_to_bodies : Private {
[ map { $_->body } @contacts ];
}
+sub setup_report_extras : Private {
+ my ($self, $c) = @_;
+
+ # report_meta is used by the templates to fill in the extra field values
+ my $extra = $c->stash->{report}->get_extra_fields;
+ $c->stash->{report_meta} = { map { 'x' . $_->{name} => $_ } @$extra };
+}
+
sub set_report_extras : Private {
my ($self, $c, $contacts, $param_prefix) = @_;
@@ -1458,7 +1467,7 @@ sub generate_map : Private {
sub check_for_category : Private {
my ( $self, $c ) = @_;
- $c->stash->{category} = $c->get_param('category');
+ $c->stash->{category} = $c->get_param('category') || $c->stash->{report}->category;
return 1;
}
diff --git a/t/app/controller/auth_social.t b/t/app/controller/auth_social.t
index ac3d98b15..75eabfc43 100644
--- a/t/app/controller/auth_social.t
+++ b/t/app/controller/auth_social.t
@@ -13,7 +13,22 @@ my $mech = FixMyStreet::TestMech->new;
FixMyStreet::App->log->disable('info');
END { FixMyStreet::App->log->enable('info'); }
-my ($report) = $mech->create_problems_for_body(1, '2345', 'Test');
+my $body = $mech->create_body_ok(2504, 'Westminster Council');
+
+my ($report) = $mech->create_problems_for_body(1, $body->id, 'Test');
+
+my $contact = $mech->create_contact_ok(
+ body_id => $body->id, category => 'Damaged bin', email => 'BIN',
+ extra => [
+ { code => 'bin_type', description => 'Type of bin', required => 'True' },
+ { code => 'bin_service', description => 'Service needed', required => 'False' },
+ ]
+);
+# Two options, incidentally, so that the template "Only one option, select it"
+# code doesn't kick in and make the tests pass
+my $contact2 = $mech->create_contact_ok(
+ body_id => $body->id, category => 'Whatever', email => 'WHATEVER',
+);
FixMyStreet::override_config {
FACEBOOK_APP_ID => 'facebook-app-id',
@@ -62,9 +77,13 @@ for my $fb_state ( 'refused', 'no email', 'existing UID', 'okay' ) {
$mech->get_ok('/');
$mech->submit_form_ok( { with_fields => { pc => 'SW1A1AA' } }, "submit location" );
$mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" );
- $fields = {
+ $mech->submit_form(with_fields => {
+ category => 'Damaged bin',
title => 'Test title',
detail => 'Test detail',
+ });
+ $fields = {
+ bin_type => 'Salt bin',
};
} else {
$mech->get_ok('/report/' . $report->id);
@@ -91,6 +110,7 @@ for my $fb_state ( 'refused', 'no email', 'existing UID', 'okay' ) {
# Check we're showing the right form, regardless of what came back
if ($page eq 'report') {
$mech->content_contains('/report/new');
+ $mech->content_contains('Salt bin');
} elsif ($page eq 'update') {
$mech->content_contains('/report/update');
}
@@ -170,9 +190,13 @@ for my $tw_state ( 'refused', 'existing UID', 'no email' ) {
$mech->get_ok('/');
$mech->submit_form_ok( { with_fields => { pc => 'SW1A1AA' } }, "submit location" );
$mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" );
- $fields = {
+ $mech->submit_form(with_fields => {
+ category => 'Damaged bin',
title => 'Test title',
detail => 'Test detail',
+ });
+ $fields = {
+ bin_type => 'Salt bin',
};
} else {
$mech->get_ok('/report/' . $report->id);
@@ -199,6 +223,7 @@ for my $tw_state ( 'refused', 'existing UID', 'no email' ) {
# Check we're showing the right form, regardless of what came back
if ($page eq 'report') {
$mech->content_contains('/report/new');
+ $mech->content_contains('Salt bin');
} elsif ($page eq 'update') {
$mech->content_contains('/report/update');
}
diff --git a/templates/web/base/report/new/category.html b/templates/web/base/report/new/category.html
index ec53263ca..264a08861 100644
--- a/templates/web/base/report/new/category.html
+++ b/templates/web/base/report/new/category.html
@@ -21,12 +21,12 @@ END
<label for='form_category' id="form_category_label">
[%~ loc('Category') ~%]
</label>[% =%]
- <select class="validCategory form-control[% IF category_groups.size %] js-grouped-select[% END %]" name="category" id="form_category"
+ <select required class="validCategory form-control[% IF category_groups.size %] js-grouped-select[% END %]" name="category" id="form_category"
[%~ IF c.user.from_body =%]
[%~ prefill_report = ( c.cobrand.prefill_report_fields_for_inspector && inspector ) || c.user.has_body_permission_to('report_prefill') %]
data-body="[% c.user.from_body.name %]" data-prefill="[% prefill_report %]"
[%~ END ~%]
- required>
+ >
[%~ IF category_groups.size ~%]
[%~ FOREACH group IN category_groups ~%]
[% IF group.name %]<optgroup label="[% group.name %]">[% END %]