Skip to content

Commit

Permalink
[Bexley] Add form for properties with no collections
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismytton committed Jun 12, 2024
1 parent 616c0e5 commit 036cc36
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 6 deletions.
14 changes: 10 additions & 4 deletions perllib/FixMyStreet/App/Controller/Waste.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,7 @@ sub enquiry : Chained('property') : Args(0) {

my $category = $c->get_param('category');
my $service = $c->get_param('service_id');
$c->detach('property_redirect') unless $category && $service && $c->stash->{services}{$service};
$c->detach('property_redirect') unless $category;

my ($contact) = grep { $_->category eq $category } @{$c->stash->{contacts}};
$c->detach('property_redirect') unless $contact;
Expand All @@ -1047,11 +1047,17 @@ sub enquiry : Chained('property') : Args(0) {
foreach (@{$contact->get_metadata_for_input}) {
$staff_form = 1 if $_->{code} eq 'staff_form';
next if ($_->{automated} || '') eq 'hidden_field';
my $type = 'Text';
$type = 'TextArea' if 'text' eq ($_->{datatype} || '');
my %config = (type => 'Text');
my $datatype = $_->{datatype} || '';
if ($datatype eq 'text') {
%config = (type => 'TextArea');
} elsif ($datatype eq 'multivaluelist') {
my @options = map { { label => $_->{name}, value => $_->{key} } } @{$_->{values}};
%config = (type => 'Multiple', widget => 'CheckboxGroup', options => \@options);
}
my $required = $_->{required} eq 'true' ? 1 : 0;
push @$field_list, "extra_$_->{code}" => {
type => $type, label => $_->{description}, required => $required
%config, label => $_->{description}, required => $required
};
}

Expand Down
20 changes: 20 additions & 0 deletions perllib/FixMyStreet/Cobrand/Bexley/Waste.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,26 @@ sub waste_munge_report_form_fields {
}
}

sub waste_munge_enquiry_data {
my ($self, $data) = @_;

my $address = $self->{c}->stash->{property}->{address};
$data->{title} = $data->{category};

my $detail;
foreach (sort grep { /^extra_/ } keys %$data) {
my $extra = $data->{$_};
if (ref $extra eq 'ARRAY') {
my $value = join(', ', @$extra);
$detail .= "$value\n\n";
} else {
$detail .= "$extra\n\n";

Check warning on line 1065 in perllib/FixMyStreet/Cobrand/Bexley/Waste.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/Bexley/Waste.pm#L1065

Added line #L1065 was not covered by tests
}
}
$detail .= $address;
$data->{detail} = $detail;
}

sub _bin_location_options {
return {
staff_or_assisted => [
Expand Down
55 changes: 55 additions & 0 deletions t/app/controller/waste_bexley.t
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ $whitespace_mock->mock(
}
);
my $comment_user = $mech->create_user_ok('comment');
my $user = $mech->create_user_ok('[email protected]', name => 'Test User', email_verified => 1);
my $body = $mech->create_body_ok(
2494,
'London Borough of Bexley',
Expand Down Expand Up @@ -185,6 +186,33 @@ $contact->set_extra_fields(

$contact->update;

my $contact2 = $mech->create_contact_ok(
body => $body,
category => 'Missed collection enquiry',
email => '[email protected]',
extra => { type => 'waste' },
group => ['Waste'],
);
$contact2->set_extra_fields(
{
code => "waste_types",
description => "Which collections would you like to report as missed?",
datatype => "multivaluelist",
required => "true",
values => [
map { { key => $_, name => $_ } } (
"Refuse",
"Paper/card recycling",
"Plastics/glass recycling",
"Food waste",
"Garden waste",
"Mixed recycling"
)
],
}
);
$contact2->update;

my ($existing_missed_collection_report1) = $mech->create_problems_for_body(1, $body->id, 'Report missed collection', {
external_id => "Whitespace-4",
});
Expand Down Expand Up @@ -1006,6 +1034,23 @@ FixMyStreet::override_config {
set_fixed_time('2024-03-31T02:00:00'); # March 31st, 02:00 BST
};

subtest 'Enquiry form for properties with no collections' => sub {
$mech->get_ok('/waste/10006');
$mech->content_contains('/waste/10006/enquiry?template=no-collections', 'link to no collections form present');
$mech->get_ok('/waste/10006/enquiry?template=no-collections');
$mech->submit_form_ok( { with_fields => { category => 'Missed collection enquiry' } } );
$mech->content_contains('Which collections would you like to report as missed?');
$mech->content_contains('Paper/card recycling');
$mech->submit_form_ok( { with_fields => { extra_waste_types => 'Refuse' } } );
$mech->content_contains('Full name');
$mech->submit_form_ok( { with_fields => { name => 'Test User', email => '[email protected]' } } );
$mech->content_contains('Refuse');
$mech->content_contains('Test User');
$mech->content_contains('[email protected]');
$mech->content_contains('Please review the information you’ve provided before you submit your enquiry.');
$mech->submit_form_ok( { with_fields => { submit => 'Submit' } } );
$mech->content_contains('Nearly done! Now check your email');
};
};

FixMyStreet::override_config {
Expand Down Expand Up @@ -1307,6 +1352,15 @@ sub _site_info {
SiteLongitude => 0.181108,
},
},
10006 => {
AccountSiteID => 6,
AccountSiteUPRN => 10006,
Site => {
SiteShortAddress => ', 6, THE AVENUE, DA1 3LD',
SiteLatitude => 51.466707,
SiteLongitude => 0.181108,
},
},
};
}

Expand Down Expand Up @@ -1466,6 +1520,7 @@ sub _site_collections {
RoundSchedule => 'N/A',
},
],
10006 => [],
};
}

Expand Down
4 changes: 3 additions & 1 deletion templates/web/base/waste/enquiry.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@

[% INCLUDE 'waste/_address_display.html' %]

[% IF services.$service_id %]
<dl class="waste__address">
<dt class="waste__address__title">Service</dt>
<dd class="waste__address__property">[% services.$service_id.service_name %]</dd>
</dl>
[% END %]

<form class="waste" method="get" action="[% c.uri_for_action('waste/enquiry', [ property.id ]) %]">
<div class="govuk-form-group">
[% PROCESS radio field = {
id = 'category',
html_name = 'category',
label = 'Category',
label = field_label || 'Category',
options = field_options
}
%]
Expand Down
6 changes: 5 additions & 1 deletion templates/web/base/waste/summary_enquiry.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@
[% BLOCK answers %]
[% FOR extra IN data.keys.grep('^extra_') %]
[% NEXT UNLESS data.$extra %]
[% SET extra_name = extra.replace('extra_', '') %]
[% SET extra_name = extra.replace('extra_', '').replace('_', ' ') %]
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key govuk-summary-list__key--sub">[% extra_name | title %]</dt>
[% IF data.$extra.size %]
<dd class="govuk-summary-list__value">[% data.$extra.join(', ') %]</dd>
[% ELSE %]
<dd class="govuk-summary-list__value">[% data.$extra %]</dd>
[% END %]
</div>
[% END %]
[% END %]
Expand Down
1 change: 1 addition & 0 deletions templates/web/bexley/waste/_bin_days_no_collections.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>There are currently no collections at this property. Please <a href="[% c.uri_for_action('waste/enquiry', [ property.id ]) %]?template=no-collections">use this form to report a missed collection</a>.</p>
8 changes: 8 additions & 0 deletions templates/web/bexley/waste/enquiry-no-collections.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[% PROCESS waste/enquiry.html
title = 'No collections'
field_label = 'Are you trying to report a missed collection from a business, school, community group or place of worship?',
field_options = [
{ label = 'Yes', value = 'Business or organisation missed collection enquiry' },
{ label = 'No', value = 'Missed collection enquiry'},
];
%]

0 comments on commit 036cc36

Please sign in to comment.