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

Capture group from hoisted categories. #5175

Merged
merged 1 commit into from
Sep 23, 2024
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
6 changes: 3 additions & 3 deletions .cypress/cypress/integration/category_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('Basic categories', function() {
'Footpath/bridleway away from road',
'Graffiti',
'Offensive graffiti',
'Licensing',
'G|Licensing',
'Parks/landscapes',
'Pavements',
'Potholes',
Expand Down Expand Up @@ -75,7 +75,7 @@ describe('Basic categories', function() {
cy.get('[value="Abandoned vehicles"]').should('not.be.visible');
cy.get('[value="Bus stops"]').should('not.be.visible');
cy.get('[value="Flyposting"]').should('not.be.visible');
cy.get('[value="Licensing"]').should('be.visible');
cy.get('[value="G|Licensing"]').should('be.visible');
cy.get('[value="Dropped Kerbs"]').should('be.visible');
cy.get('[value="Skips"]').should('be.visible');
cy.get('[value="Street lighting"]').should('be.visible');
Expand All @@ -84,7 +84,7 @@ describe('Basic categories', function() {
cy.get('[value="Abandoned vehicles"]').should('not.be.visible');
cy.get('[value="Bus stops"]').should('be.visible');
cy.get('[value="Flyposting"]').should('not.be.visible');
cy.get('[value="Licensing"]').should('be.visible');
cy.get('[value="G|Licensing"]').should('be.visible');
cy.get('[value="Dropped Kerbs"]').should('not.be.visible');
cy.get('[value="Skips"]').should('be.visible');
cy.get('[value="Road traffic signs"]').should('be.visible');
Expand Down
1 change: 1 addition & 0 deletions perllib/FixMyStreet/App/Controller/Report.pm
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,7 @@ sub stash_category_groups : Private {
(my $id = $_) =~ s/[^a-zA-Z]+//g;
if (@{$category_groups{$_}} == 1) {
my $contact = $category_groups{$_}[0];
$contact->set_extra_metadata(hoisted => $_);
push @list, [ $contact->category_display, $contact ];
} else {
my $cats = $category_groups{$_};
Expand Down
21 changes: 12 additions & 9 deletions perllib/FixMyStreet/App/Controller/Report/New.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1836,19 +1836,22 @@ sub generate_map : Private {
sub check_for_category : Private {
my ( $self, $c, $opts ) = @_;

my $category;
if (!$opts->{with_group}) {
$category = $c->get_param('category') || '';
} else {
# Group is either an actual group, or a category that wasn't in a group
my $group = $c->get_param('category') || $c->get_param('filter_group') || '';
if (any { $_->{name} && $group eq $_->{name} } @{$c->stash->{category_groups}}) {
my $category = $c->get_param('category') || '';
if ($opts->{with_group}) {
if (my ($group) = $category =~ /^G\|(.*)/) {
# A top-level group
$c->stash->{group} = $c->stash->{filter_group} = $group;
(my $group_id = $group) =~ s/[^a-zA-Z]+//g;
my $cat_param = "category.$group_id";
$category = $c->get_param($cat_param);
} else {
$category = $group;
} elsif ($category =~ /^H\|(.*?)\|(.*)/) {
# A hoisted to top-level category
($group, $category) = ($1, $2);
$c->stash->{group} = $c->stash->{filter_group} = $group;
} elsif (!$category && ($group = $c->get_param('filter_group'))) {
if (any { $_->{name} && $group eq $_->{name} } @{$c->stash->{category_groups}}) {
$c->stash->{group} = $c->stash->{filter_group} = $group;
}
}
}
$category ||= $c->stash->{report}->category || '';
Expand Down
6 changes: 3 additions & 3 deletions t/app/controller/auth_social.t
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ for my $state ( 'refused', 'no email', 'existing UID', 'okay' ) {
$mech->submit_form_ok( { with_fields => { pc => $test->{pc} || 'SW1A1AA' } }, "submit location" );
$mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" );
$mech->submit_form(with_fields => {
category => 'Bins',
category => 'G|Bins',
'category.Bins' => 'Damaged bin',
title => 'Test title',
detail => 'Test detail',
Expand Down Expand Up @@ -174,7 +174,7 @@ for my $state ( 'refused', 'no email', 'existing UID', 'okay' ) {
if ($page eq 'report') {
$mech->content_contains('/report/new');
$mech->content_contains('Salt bin');
$mech->content_contains('name="category" value="Bins" data-subcategory="Bins" checked');
$mech->content_like(qr{value="G|Bins"\s+data-subcategory="Bins" checked});
$mech->content_contains('name="category.Bins" data-category_display="Damaged bin" value=\'Damaged bin\' checked');
} elsif ($page eq 'update') {
$mech->content_contains('/report/update');
Expand Down Expand Up @@ -320,7 +320,7 @@ for my $tw_state ( 'refused', 'existing UID', 'no email' ) {
$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" );
$mech->submit_form(with_fields => {
category => 'Bins',
category => 'G|Bins',
'category.Bins' =>'Damaged bin',
title => 'Test title',
detail => 'Test detail',
Expand Down
20 changes: 15 additions & 5 deletions t/app/controller/report_new.t
Original file line number Diff line number Diff line change
Expand Up @@ -680,9 +680,9 @@ subtest "category groups" => sub {
my $div = '<div[^>]*>\s*';
my $div_end = '</div>\s*';
my $pavements_label = '<label[^>]* for="category_Pavements">Pavements</label>\s*' . $div_end;
my $pavements_input = '<input[^>]* value="Pavements" data-subcategory="Pavements">\s*';
my $pavements_input_checked = '<input[^>]* value="Pavements" data-subcategory="Pavements" checked>\s*';
my $roads = $div . '<input[^>]* value="Roads" data-subcategory="Roads">\s*<label[^>]* for="category_Roads">Roads</label>\s*' . $div_end;
my $pavements_input = '<input[^>]* value="G|Pavements"\s+data-subcategory="Pavements">\s*';
my $pavements_input_checked = '<input[^>]* value="G|Pavements"\s+data-subcategory="Pavements" checked>\s*';
my $roads = $div . '<input[^>]* value="G|Roads"\s+data-subcategory="Roads">\s*<label[^>]* for="category_Roads">Roads</label>\s*' . $div_end;
my $trees_label = '<label [^>]* for="category_\d+">Trees</label>\s*' . $div_end;
my $trees_input = $div . '<input[^>]* value=\'Trees\'>\s*';
my $trees_input_checked = $div . '<input[^>]* value=\'Trees\' checked>\s*';
Expand All @@ -708,18 +708,28 @@ subtest "category groups" => sub {
$mech->content_like(qr{$fieldset_pavements$options});
$mech->content_like(qr{$fieldset_roads$options});
# Server submission of pavement subcategory
$mech->get_ok("/report/new?lat=$saved_lat&lon=$saved_lon&category=Pavements&category.Pavements=Potholes");
$mech->get_ok("/report/new?lat=$saved_lat&lon=$saved_lon&category=G|Pavements&category.Pavements=Potholes");
$mech->content_like(qr{$pavements_input_checked$pavements_label$roads$trees_input$trees_label</fieldset>});
$mech->content_like(qr{$fieldset_pavements$optionsS});
$mech->content_like(qr{$fieldset_roads$options});

$contact9->update( { extra => { group => 'Lights' } } );
$mech->get_ok("/report/new?lat=$saved_lat&lon=$saved_lon");
$streetlighting = $div . '<input[^>]*value=\'Street lighting\'>\s*<label[^>]* for="category_\d+">Street lighting</label>\s*' . $div_end;
$streetlighting = $div . '<input[^>]*value=\'H|Lights\|Street lighting\'>\s*<label[^>]* for="category_\d+">Street lighting</label>\s*' . $div_end;
$potholes_input = $div . '<input[^>]* value=\'H|Pavements\|Potholes\'>\s*';
$potholes_label = '<label[^>]* for="category_\d+">Potholes</label>\s*' . $div_end;
$mech->content_like(qr{$potholes_input$potholes_label$roads$streetlighting$trees_input$trees_label</fieldset>});
$mech->content_unlike(qr{$fieldset_pavements});
$mech->content_like(qr{$fieldset_roads$options});

$mech->submit_form_ok({ with_fields => {
category => 'H|Lights|Street lighting',
title => 'Test Report',
detail => 'Test report details',
username_register => '[email protected]',
name => 'Jo Bloggs',
} });
$mech->content_contains('Now check your email');
};
};

Expand Down
8 changes: 4 additions & 4 deletions t/cobrand/brent.t
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ FixMyStreet::override_config {
with_fields => {
title => "Test Report",
detail => 'Test report details.',
category => 'Parks and open spaces',
category => 'G|Parks and open spaces',
'category.Parksandopenspaces' => 'Overgrown grass',
}
}, "submit details");
Expand All @@ -951,7 +951,7 @@ FixMyStreet::override_config {
with_fields => {
title => "Test Report",
detail => 'Test report details.',
category => 'Parks and open spaces',
category => 'G|Parks and open spaces',
'category.Parksandopenspaces' => 'Overgrown grass',
}
}, "submit details");
Expand All @@ -970,7 +970,7 @@ FixMyStreet::override_config {
with_fields => {
title => "Test Report",
detail => 'Test report details.',
category => 'Parks and open spaces',
category => 'G|Parks and open spaces',
'category.Parksandopenspaces' => 'Overgrown grass',
}
}, "submit details");
Expand All @@ -994,7 +994,7 @@ FixMyStreet::override_config {
with_fields => {
title => "Test Report",
detail => 'Test report details.',
category => 'Parks and open spaces',
category => 'G|Parks and open spaces',
'category.Parksandopenspaces' => 'Ponds',
}
}, "submit details");
Expand Down
6 changes: 3 additions & 3 deletions t/cobrand/northumberland.t
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ FixMyStreet::override_config {
$mech->content_contains('Main Carriageway');
$mech->content_contains('Potholes');
$mech->content_contains("Trees'>");
$mech->content_contains('value=\'Flytipping\' data-nh="1"');
$mech->content_contains('value=\'H|Staff Only - Out Of Hours|Flytipping\' data-nh="1"');

# A-road where NH responsible for litter, council categories will also be present
mock_road("A5103", 1);
Expand All @@ -97,7 +97,7 @@ FixMyStreet::override_config {
$mech->content_contains('Main Carriageway');
$mech->content_contains('Potholes');
$mech->content_contains('Trees\'>');
$mech->content_contains('value=\'Flytipping\' data-nh="1"');
$mech->content_contains('value=\'H|Staff Only - Out Of Hours|Flytipping\' data-nh="1"');

# A-road where NH not responsible for litter, no NH litter categories
mock_road("A34", 0);
Expand All @@ -107,7 +107,7 @@ FixMyStreet::override_config {
$mech->content_lacks('Main Carriageway');
$mech->content_contains('Potholes');
$mech->content_contains('Trees\'>');
$mech->content_contains('value=\'Flytipping\' data-nh="1"');
$mech->content_contains('value=\'H|Staff Only - Out Of Hours|Flytipping\' data-nh="1"');
};
};

Expand Down
19 changes: 15 additions & 4 deletions templates/web/base/report/new/category.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,28 @@
[%~ FOREACH group_or_cat IN category_groups ~%]
<div class="govuk-radios__item">
[% IF group_or_cat.name %]
<input class="govuk-radios__input" required id="category_[% group_or_cat.id %]" type="radio" name="category" value="[% group_or_cat.name %]" data-subcategory="[% group_or_cat.id %]"[% ' checked' IF filter_group == group_or_cat.name %]>
<input class="govuk-radios__input" required type="radio" name="category"
id="category_[% group_or_cat.id %]"
data-valuealone="[% group_or_cat.name %]"
value="G|[% group_or_cat.name %]"
data-subcategory="[% group_or_cat.id %]"
[%~ ' checked' IF filter_group == group_or_cat.name %]>
<label class="govuk-label govuk-radios__label" for="category_[% group_or_cat.id %]">[% group_or_cat.name %]</label>
[% group_hint = group_or_cat.categories.first.get_extra_metadata('group_hint') %]
[%~ IF group_hint %]
<div class="govuk-hint govuk-radios__hint">
[% group_hint | safe %]
</div>
[% END ~%]
[% ELSE # A category not in a group %]
[% cat_lc = group_or_cat.category | lower =%]
<input class="govuk-radios__input" required id="category_[% group_or_cat.id %]" type="radio" name="category" data-category_display="[% group_or_cat.category_display %]" value='[% group_or_cat.category %]'
[% ELSE # A category not in a group, or a hoisted category %]
[% cat_lc = group_or_cat.category | lower;
hoisted = group_or_cat.get_extra_metadata('hoisted');
=%]
<input class="govuk-radios__input" required type="radio" name="category"
id="category_[% group_or_cat.id %]"
data-category_display="[% group_or_cat.category_display %]"
data-valuealone="[% group_or_cat.category %]"
value='[% "H|" _ hoisted _ "|" IF hoisted %][% group_or_cat.category %]'
[%~ ' checked' IF ( report.category == group_or_cat.category || category_lc == cat_lc ) AND NOT filter_group ~%]
[%~ ' data-nh="1"' IF group_or_cat.get_extra_metadata('nh_council_cleaning') ~%]
>
Expand Down
6 changes: 3 additions & 3 deletions web/cobrands/fixmystreet/fixmystreet.js
Original file line number Diff line number Diff line change
Expand Up @@ -1848,11 +1848,11 @@ function re_select(group, category) {
var group_id = group.replace(/[^a-z]+/gi, '');
var cat_in_group = $("#subcategory_" + group_id + " input[value=\"" + category + "\"]");
if (cat_in_group.length) {
$('#form_category_fieldset input[value="' + group + '"]')[0].checked = true;
$('#form_category_fieldset input[data-valuealone="' + group + '"]')[0].checked = true;
cat_in_group[0].checked = true;
} else {
var top_level = group || category;
var top_level_match = $("#form_category_fieldset input[value=\"" + top_level + "\"]");
var top_level_match = $("#form_category_fieldset input[data-valuealone=\"" + top_level + "\"]");
if (top_level && top_level_match.length) {
top_level_match[0].checked = true;
}
Expand Down Expand Up @@ -1976,7 +1976,7 @@ fixmystreet.fetch_reporting_data = function() {
fixmystreet.reporting = {};
fixmystreet.reporting.selectedCategory = function() {
var $group_or_cat_input = $('#form_category_fieldset input:checked'),
group_or_cat = $group_or_cat_input.val() || '',
group_or_cat = $group_or_cat_input.data('valuealone') || '',
group_id = group_or_cat.replace(/[^a-z]+/gi, ''),
$subcategory = $("#subcategory_" + group_id),
$subcategory_input = $subcategory.find('input:checked'),
Expand Down
Loading