aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm4
-rw-r--r--t/app/controller/report_new_open311.t46
-rw-r--r--templates/web/base/report/new/category_extras.html24
3 files changed, 64 insertions, 10 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index a41aeb6ea..82787e9da 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -632,6 +632,8 @@ sub setup_categories_and_bodies : Private {
my %bodies_to_list = (); # Bodies with categories assigned
my @category_options = (); # categories to show
my %category_extras = (); # extra fields to fill in for open311
+ my %category_extras_hidden =
+ (); # whether all of a category's fields are hidden
my %non_public_categories =
(); # categories for which the reports are not public
$c->stash->{unresponsive} = {};
@@ -668,6 +670,7 @@ sub setup_categories_and_bodies : Private {
my $metas = $contact->get_metadata_for_input;
$category_extras{$contact->category} = $metas if @$metas;
+ $category_extras_hidden{$contact->category} = (grep { !$c->cobrand->category_extra_hidden($_) } @$metas) ? 0 : 1;
my $body_send_method = $bodies{$contact->body_id}->send_method || '';
$c->stash->{unresponsive}{$contact->category} = $contact->body_id
@@ -697,6 +700,7 @@ sub setup_categories_and_bodies : Private {
$c->stash->{bodies_to_list_urls} = [ map { $_->external_url } values %bodies_to_list ];
$c->stash->{category_options} = \@category_options;
$c->stash->{category_extras} = \%category_extras;
+ $c->stash->{category_extras_hidden} = \%category_extras_hidden;
$c->stash->{non_public_categories} = \%non_public_categories;
$c->stash->{extra_name_info} = $first_area->{id} == COUNCIL_ID_BROMLEY ? 1 : 0;
diff --git a/t/app/controller/report_new_open311.t b/t/app/controller/report_new_open311.t
index 58644eabb..17b489447 100644
--- a/t/app/controller/report_new_open311.t
+++ b/t/app/controller/report_new_open311.t
@@ -1,5 +1,6 @@
use FixMyStreet::TestMech;
use FixMyStreet::App;
+use Test::LongString;
use Web::Scraper;
# disable info logs for this test run
@@ -50,6 +51,17 @@ $mech->create_contact_ok(
] },
);
+my $body2 = $mech->create_body_ok(2651, 'Edinburgh Council');
+my $contact4 = $mech->create_contact_ok(
+ body_id => $body2->id, # Edinburgh
+ category => 'Pothole',
+ email => '103',
+ extra => { _fields => [
+ { description => 'USRN', code => 'usrn', required => 'true', automated => 'hidden_field', variable => 'true', order => '1' },
+ { description => 'Asset ID', code => 'central_asset_id', required => 'true', automated => 'hidden_field', variable => 'true', order => '2' },
+ ] },
+);
+
# test that the various bit of form get filled in and errors correctly
# generated.
my $empty_form = {
@@ -232,4 +244,38 @@ foreach my $test (
};
}
+subtest "Category extras omits description label when all fields are hidden" => sub {
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ my $json = $mech->get_ok_json('/report/new/category_extras?category=Pothole&latitude=55.952055&longitude=-3.189579');
+ my $category_extra = $json->{category_extra};
+ contains_string($category_extra, "usrn");
+ contains_string($category_extra, "central_asset_id");
+ lacks_string($category_extra, "USRN", "Lacks 'USRN' label");
+ lacks_string($category_extra, "Asset ID", "Lacks 'Asset ID' label");
+ lacks_string($category_extra, "resolve your problem quicker, by providing some extra detail", "Lacks description text");
+ };
+};
+
+subtest "Category extras includes description label for user" => sub {
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ $contact4->push_extra_fields({ description => 'Size?', code => 'size', required => 'true', automated => '', variable => 'true', order => '3' });
+ $contact4->update;
+
+ my $json = $mech->get_ok_json('/report/new/category_extras?category=Pothole&latitude=55.952055&longitude=-3.189579');
+ my $category_extra = $json->{category_extra};
+ contains_string($category_extra, "usrn");
+ contains_string($category_extra, "central_asset_id");
+ lacks_string($category_extra, "USRN", "Lacks 'USRN' label");
+ lacks_string($category_extra, "Asset ID", "Lacks 'Asset ID' label");
+ contains_string($category_extra, "Size?");
+ contains_string($category_extra, "resolve your problem quicker, by providing some extra detail", "Contains description text");
+ };
+};
+
done_testing();
diff --git a/templates/web/base/report/new/category_extras.html b/templates/web/base/report/new/category_extras.html
index fd2752388..e2926901c 100644
--- a/templates/web/base/report/new/category_extras.html
+++ b/templates/web/base/report/new/category_extras.html
@@ -7,16 +7,20 @@
[%- END %]
[%- IF category_extras.$category.size %]
- <div class="extra-category-questions full-width">
- <h2 class="form-section-heading">[% category %]</h2>
- <p class="form-section-description">
- [% tprintf(
- loc('Help <strong>%s</strong> resolve your problem quicker, by providing some extra detail. This extra information will not be published online.'),
- list_of_names.join( '</strong>' _ loc(' or ') _ '<strong>' )
- ); %]
- </p>
- [% INCLUDE 'report/new/category_extras_fields.html' metas=category_extras.$category %]
- </div>
+ [% UNLESS category_extras_hidden.$category %]
+ <div class="extra-category-questions full-width">
+ <h2 class="form-section-heading">[% category %]</h2>
+ <p class="form-section-description">
+ [% tprintf(
+ loc('Help <strong>%s</strong> resolve your problem quicker, by providing some extra detail. This extra information will not be published online.'),
+ list_of_names.join( '</strong>' _ loc(' or ') _ '<strong>' )
+ ); %]
+ </p>
+ [% INCLUDE 'report/new/category_extras_fields.html' metas=category_extras.$category %]
+ </div>
+ [% ELSE %]
+ [% INCLUDE 'report/new/category_extras_fields.html' metas=category_extras.$category %]
+ [% END %]
[%- END %]
[%- IF report_extra_fields %]