aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2017-05-19 12:15:24 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2017-05-26 13:34:38 +0100
commit9e7c44777e9fbcbef6be463b4a7a1dc9b20d90f1 (patch)
treeab709d5975a9b61c2778559be59e76f8beb015ec
parent36baff2d6ea23dc6648160ce82e40e0e9f6d7bda (diff)
Make sure existing state is included in drop-down.
It is possible the report's state isn't one that the user can access, but in that case we should still show it to avoid confusion.
-rw-r--r--t/app/controller/report_inspect.t12
-rw-r--r--templates/web/base/report/_state_select_field.html11
2 files changed, 21 insertions, 2 deletions
diff --git a/t/app/controller/report_inspect.t b/t/app/controller/report_inspect.t
index 9d2ae0b0f..e1723b0cd 100644
--- a/t/app/controller/report_inspect.t
+++ b/t/app/controller/report_inspect.t
@@ -227,13 +227,23 @@ FixMyStreet::override_config {
is $report->get_extra_metadata('traffic_information'), 'Signs and Cones', 'report data changed';
};
- subtest "No action scheduled without the right permission" => sub {
+ subtest "Action scheduled only shown appropriately" => sub {
$report->update({ state => 'confirmed' });
$mech->get_ok("/report/$report_id");
$mech->content_lacks('action scheduled');
+ # If the report is already in that state, though, we should show it
+ $report->update({ state => 'action scheduled' });
+ $mech->get_ok("/report/$report_id");
+ $mech->content_unlike(qr/<optgroup label="Scheduled">\s*<option value="action scheduled">Action Scheduled<\/option>/);
+ $mech->content_contains('<option selected value="action scheduled">Action Scheduled</option>');
+
$user->user_body_permissions->create({ body => $oxon, permission_type => 'report_instruct' });
$mech->get_ok("/report/$report_id");
+ $mech->content_like(qr/<optgroup label="Scheduled">\s*<option selected value="action scheduled">Action Scheduled<\/option>/);
+
+ $report->update({ state => 'confirmed' });
+ $mech->get_ok("/report/$report_id");
$mech->content_like(qr/<optgroup label="Scheduled">\s*<option value="action scheduled">Action Scheduled<\/option>/);
};
diff --git a/templates/web/base/report/_state_select_field.html b/templates/web/base/report/_state_select_field.html
index 9b3ed18df..adec1ff06 100644
--- a/templates/web/base/report/_state_select_field.html
+++ b/templates/web/base/report/_state_select_field.html
@@ -2,10 +2,19 @@
[% IF include_empty %]
<option value="">---</option>
[% END %]
+[% SET found = 0 ~%]
+[% FOREACH group IN state_groups ~%]
+ [% FOREACH state IN group.1 ~%]
+ [% SET found = 1 IF state == current_state ~%]
+ [% END ~%]
+[% END ~%]
+[% IF NOT found ~%]
+ <option selected value="[% current_state %]">[% state_pretty.$current_state %]</option>
+[% END ~%]
[% FOREACH group IN state_groups %]
<optgroup label="[% group.0 %]">
[% FOREACH state IN group.1 %]
- <option [% 'selected ' IF state == current_state %] value="[% state %]">[% state_pretty.$state %]</option>
+ <option [% 'selected ' IF state == current_state %]value="[% state %]">[% state_pretty.$state %]</option>
[% END %]
</optgroup>
[% END %]