aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Arter <davea@mysociety.org>2020-01-07 20:20:45 +0000
committerDave Arter <davea@mysociety.org>2020-01-07 20:20:45 +0000
commit26edd4ed7a5c8fd90e3dba279d745c11d2ce0faf (patch)
tree76a21c8a79dead8b9166eba4c4cd9738df0dd566
parent27fe9940d3830b6a9d23c82aeca5a93975eee5c3 (diff)
Hide ‘provide extra information’ preamble when no visible fields are present
For categories that use the extra metadata fields to just show a notice message to the user, the ‘help the council fix the problem by providing extra information’ text was a bit out of place. This commit hides it unless there are actual UI elements also included in the markup. Fixes #2811.
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm13
-rw-r--r--t/app/controller/report_new_open311.t53
-rw-r--r--templates/web/base/report/new/category_extras.html18
3 files changed, 76 insertions, 8 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index db469f130..efcaf8ddc 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -697,6 +697,8 @@ sub setup_categories_and_bodies : Private {
my %category_extras = (); # extra fields to fill in for open311
my %category_extras_hidden =
(); # whether all of a category's fields are hidden
+ my %category_extras_notices =
+ (); # whether all of a category's fields are simple notices and not inputs
my %non_public_categories =
(); # categories for which the reports are not public
$c->stash->{unresponsive} = {};
@@ -729,6 +731,16 @@ sub setup_categories_and_bodies : Private {
} else {
$category_extras_hidden{$contact->category} = $all_hidden;
}
+
+ my $all_notices = (grep {
+ ( $_->{variable} || '' ) ne 'false'
+ && !$c->cobrand->category_extra_hidden($_)
+ } @$metas) ? 0 : 1;
+ if (exists($category_extras_notices{$contact->category})) {
+ $category_extras_notices{$contact->category} &&= $all_notices;
+ } else {
+ $category_extras_notices{$contact->category} = $all_notices;
+ }
}
$non_public_categories{ $contact->category } = 1 if $contact->non_public;
@@ -760,6 +772,7 @@ sub setup_categories_and_bodies : Private {
$c->stash->{category_options} = \@category_options;
$c->stash->{category_extras} = \%category_extras;
$c->stash->{category_extras_hidden} = \%category_extras_hidden;
+ $c->stash->{category_extras_notices} = \%category_extras_notices;
$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 264198052..3488b96ce 100644
--- a/t/app/controller/report_new_open311.t
+++ b/t/app/controller/report_new_open311.t
@@ -67,6 +67,23 @@ $mech->create_contact_ok(
category => 'Something Other',
email => '104',
);
+$mech->create_contact_ok(
+ body_id => $body2->id, # Edinburgh
+ category => 'Abandoned vehicle',
+ email => '105',
+ extra => { _fields => [
+ { description => 'This is a warning message.', code => 'notice', required => 'false', variable => 'false', order => '0' },
+ { description => 'USRN', code => 'usrn', required => 'false', automated => 'hidden_field' },
+ ] },
+);
+$mech->create_contact_ok(
+ body_id => $body2->id, # Edinburgh
+ category => 'Traffic signals',
+ email => '106',
+ extra => { _fields => [
+ { description => 'This is a warning message for traffic signals.', code => 'notice', required => 'false', variable => 'false', order => '0' },
+ ] },
+);
my $staff_user = $mech->create_user_ok('staff@example.org', name => 'staff', from_body => $body->id);
@@ -283,6 +300,42 @@ subtest "Category extras omits description label when all fields are hidden" =>
};
};
+subtest "Category extras omits preamble when all fields are notices" => sub {
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ for (
+ { url => '/report/new/ajax?' },
+ { url => '/report/new/category_extras?category=Traffic+signals' },
+ ) {
+ my $json = $mech->get_ok_json($_->{url} . '&latitude=55.952055&longitude=-3.189579');
+ my $category_extra = $json->{by_category} ? $json->{by_category}{'Traffic signals'}{category_extra} : $json->{category_extra};
+ contains_string($category_extra, "This is a warning message for traffic signals.");
+ lacks_string($category_extra, "resolve your problem quicker, by providing some extra detail", "Lacks description text");
+ }
+ };
+};
+
+subtest "Category extras omits preamble when fields are only notices and hidden" => sub {
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ for (
+ { url => '/report/new/ajax?' },
+ { url => '/report/new/category_extras?category=Abandoned+vehicle' },
+ ) {
+ my $json = $mech->get_ok_json($_->{url} . '&latitude=55.952055&longitude=-3.189579');
+ my $category_extra = $json->{by_category} ? $json->{by_category}{'Abandoned vehicle'}{category_extra} : $json->{category_extra};
+ contains_string($category_extra, "This is a warning message.");
+ contains_string($category_extra, "usrn");
+ lacks_string($category_extra, "USRN", "Lacks 'USRN' 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 => '.' } ],
diff --git a/templates/web/base/report/new/category_extras.html b/templates/web/base/report/new/category_extras.html
index f3293bbbb..5cef391ce 100644
--- a/templates/web/base/report/new/category_extras.html
+++ b/templates/web/base/report/new/category_extras.html
@@ -9,14 +9,16 @@
[%- IF category_extras.$category.size %]
[% UNLESS category_extras_hidden.$category %]
- <div class="extra-category-questions">
- <h2 class="visuallyhidden form-section-heading">[% loc('Extra details') %]</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.'),
- mark_safe(list_of_names.join( '</strong>' _ loc(' or ') _ '<strong>' ))
- ); %]
- </p>
+ <div class="extra-category-questions">
+ [% UNLESS category_extras_notices.$category %]
+ <h2 class="visuallyhidden form-section-heading">[% loc('Extra details') %]</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.'),
+ mark_safe(list_of_names.join( '</strong>' _ loc(' or ') _ '<strong>' ))
+ ); %]
+ </p>
+ [% END %]
[% INCLUDE 'report/new/category_extras_fields.html' metas=category_extras.$category %]
</div>
[% ELSE %]