Skip to content

Commit

Permalink
fixup! [Island Roads] Default 'CONFIRM Subject' to be a blank selection
Browse files Browse the repository at this point in the history
  • Loading branch information
nephila-nacrea committed Sep 26, 2024
1 parent 0e5c67e commit 9a015c7
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 55 deletions.
36 changes: 36 additions & 0 deletions t/cobrand/isleofwight.t
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ $contact->set_extra_fields( ( {
order => 1,
datatype_description => 'datatype',
} ) );
$contact->set_extra_metadata( group => ['Roads'] );
$contact->update;

my $user = $mech->create_user_ok('[email protected]', name => 'Test User');
Expand All @@ -67,6 +68,10 @@ $admin_user->user_body_permissions->create({
body => $isleofwight,
permission_type => 'triage'
});
$admin_user->user_body_permissions->create({
body => $isleofwight,
permission_type => 'report_inspect',
});

my @reports = $mech->create_problems_for_body(1, $isleofwight->id, 'An Isle of wight report', {
confirmed => '2019-10-25 09:00',
Expand Down Expand Up @@ -590,6 +595,37 @@ subtest "reports are marked for triage upon submission" => sub {
my $email = $mech->get_email;
like $mech->get_text_body_from_email($email),
qr/submitted to Island Roads for review/, 'correct text for email sent for Triage';

$mech->log_in_ok( $admin_user->email );
$mech->get_ok( '/report/' . $report->id );
$mech->content_contains(
'<optgroup label="Roads">',
'there is a "Roads" optgroup',
);
$mech->content_contains(
'<option value="" selected>-- Please select --</option>',
'there is an empty-valued option selected by default',
);

$mech->submit_form( form_id => 'report_inspect_form' );
$mech->text_contains( 'Please choose a category',
'Form requires a category be chosen' );

$mech->submit_form(
form_id => 'report_inspect_form',
fields => { category => 1 }, # Pothole
);
$mech->get_ok( '/report/' . $report->id );
$mech->text_contains(
'Report triaged from Roads to Potholes',
'Update message describes triage',
);
$mech->content_contains(
'<option value="Potholes" selected>',
'Potholes selected as category',
);
$mech->content_lacks( '-- Please select --',
'No blank category available anymore' );
};
};

Expand Down
89 changes: 34 additions & 55 deletions templates/web/base/admin/triage/_inspect.html
Original file line number Diff line number Diff line change
@@ -1,61 +1,40 @@
[% BLOCK category_list %]
[%
# Isle of Wight selects a blank option by default,
# to force admin user to select a triage category
%]
[% IF c.cobrand.moniker == 'isleofwight' %]
<select class="form-control" name="[% field_name %]" id="[% field_name %]">
[% IF category_options.size %]
[%~ IF category_groups.size ~%]
[%~ FOREACH group IN category_groups ~%]
[% IF group.name %]<optgroup label="[% group.name %]">[% END %]
[% group_select = 0 %]
[% selected = 0 %]
<select class="form-control" name="[% field_name %]" id="[% field_name %]" required>
[% IF category_options.size %]
[%~ IF category_groups.size ~%]
[%~ FOREACH group IN category_groups ~%]
[% IF group.name %]<optgroup label="[% group.name %]">[% END %]
[% group_select = 0 %]
[% selected = 0 %]

[% IF group_select == 0 AND problem.category == group.name %]
[% selected = 1; group_select = 1 %]
[% END %]

<option value="" [% ' selected' IF selected %]>[% loc('-- Please select --') %]</option>

[%~ FOREACH cat_op IN group.categories ~%]
<option value="[% cat_op.id %]"[% ' selected' IF problem.contact.id == cat_op.id %]>[% cat_op.category_display %] ([% cat_op.email %])</option>
[% selected = 0 %]
[%~ END ~%]
[% IF group.name %]</optgroup>[% END %]
[%~ END =%]
[% ELSE %]
[% FOREACH cat IN category_options %]
<option value="[% cat.id %]"[% ' selected' IF problem.contact.id == cat.id %]>[% cat.category_display %]</option>
[% END %]
[% END %]
[% END %]
</select>
[% ELSE %]
<select class="form-control" name="[% field_name %]" id="[% field_name %]">
[% IF category_options.size %]
[%~ IF category_groups.size ~%]
[%~ FOREACH group IN category_groups ~%]
[% IF group.name %]<optgroup label="[% group.name %]">[% END %]
[% group_select = 0 %]
[% selected = 0 %]
[%~ FOREACH cat_op IN group.categories ~%]
[% IF group_select == 0 AND problem.category == group.name %]
[% selected = 1; group_select = 1 %]
[% END %]
<option value="[% cat_op.id %]"[% ' selected' IF selected OR problem.contact.id == cat_op.id %]>[% cat_op.category_display %] ([% cat_op.email %])</option>
[% selected = 0 %]
[%~ END ~%]
[% IF group.name %]</optgroup>[% END %]
[%~ END =%]
[% ELSE %]
[% FOREACH cat IN category_options %]
<option value="[% cat.id %]"[% ' selected' IF problem.contact.id == cat.id %]>[% cat.category_display %]</option>
[% SET categories = group.categories %]
[% IF c.cobrand.moniker == 'isleofwight' %]
[%
# Isle of Wight selects a blank option by default,
# to force admin user to select a triage category
%]
[% categories.unshift(
{ id => '', category_display => loc('-- Please select --') }
)
%]
[% END %]
[% END %]
[% END %]
</select>
[% END %]

[%~ FOREACH cat_op IN categories ~%]
[% IF group_select == 0 AND problem.category == group.name %]
[% selected = 1; group_select = 1 %]
[% END %]
<option value="[% cat_op.id %]"[% ' selected' IF selected OR problem.contact.id == cat_op.id %]>[% cat_op.category_display %][% IF cat_op.email %] ([% cat_op.email %])[% END %]</option>
[% selected = 0 %]
[%~ END ~%]
[% IF group.name %]</optgroup>[% END %]
[%~ END =%]
[% ELSE %]
[% FOREACH cat IN category_options %]
<option value="[% cat.id %]"[% ' selected' IF problem.contact.id == cat.id %]>[% cat.category_display %]</option>
[% END %]
[% END %]
[% END %]
</select>
[% END %]

[% second_column = BLOCK -%]
Expand Down

0 comments on commit 9a015c7

Please sign in to comment.