aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpezholio <pezholio@gmail.com>2017-05-05 15:47:43 +0100
committerpezholio <pezholio@gmail.com>2017-05-05 15:47:43 +0100
commit153225c079eae50cb8e2e2e024c468c9ba3146c1 (patch)
tree467699bce57ab9f1596e7c72564268b29bf76c87
parent252cacd2447fac8a5050e819475a87dc3c5e0509 (diff)
Add method to shortlist multiple reports
-rw-r--r--perllib/FixMyStreet/App/Controller/My.pm14
-rw-r--r--t/app/controller/my_planned.t31
2 files changed, 42 insertions, 3 deletions
diff --git a/perllib/FixMyStreet/App/Controller/My.pm b/perllib/FixMyStreet/App/Controller/My.pm
index 77711f807..0eb1ad3f1 100644
--- a/perllib/FixMyStreet/App/Controller/My.pm
+++ b/perllib/FixMyStreet/App/Controller/My.pm
@@ -205,6 +205,20 @@ sub planned_change : Path('planned/change') {
}
}
+sub shortlist_multiple : Path('planned/change_multiple') {
+ my ($self, $c) = @_;
+ $c->forward('/auth/check_csrf_token');
+
+ my @ids = $c->get_param_list('ids[]');
+
+ foreach my $id (@ids) {
+ $c->forward( '/report/load_problem_or_display_error', [ $id ] );
+ $c->user->add_to_planned_reports($c->stash->{problem});
+ }
+
+ $c->res->body(encode_json({ outcome => 'add' }));
+}
+
sub by_shortlisted {
my $a_order = $a->get_extra_metadata('order') || 0;
my $b_order = $b->get_extra_metadata('order') || 0;
diff --git a/t/app/controller/my_planned.t b/t/app/controller/my_planned.t
index fa463e61e..79ed0e72c 100644
--- a/t/app/controller/my_planned.t
+++ b/t/app/controller/my_planned.t
@@ -39,11 +39,11 @@ $mech->get_ok('/my/planned');
$mech->content_contains('Test Title');
$mech->get_ok($problem->url);
-$mech->content_contains('Shortlisted');
+$mech->text_contains('Shortlisted');
$mech->submit_form_ok({ with_fields => { 'shortlist-remove' => 1 } });
-$mech->content_contains('Shortlist');
+$mech->text_contains('Shortlist');
$mech->submit_form_ok({ with_fields => { 'shortlist-add' => 1 } });
-$mech->content_contains('Shortlisted');
+$mech->text_contains('Shortlisted');
$mech->get_ok('/my/planned?sort=shortlist&ajax=1');
$mech->content_contains('shortlist-up');
@@ -57,6 +57,31 @@ $mech->get_ok('/my/planned?ajax=1');
$mech->content_contains('shortlist-up');
$mech->content_contains('shortlist-down');
+subtest "POSTing multiple problems to my/planned/change adds all to shortlist" => sub {
+ my ($problem1, $problem2, $problem3) = $mech->create_problems_for_body(3, $body->id, 'New Problem');
+
+ # Grab CSRF token
+ $mech->get_ok($problem1->url);
+ my ($csrf) = $mech->content =~ /meta content="([^"]*)" name="csrf-token"/;
+
+ $mech->post_ok( '/my/planned/change_multiple', {
+ 'ids[]' => [
+ $problem1->id,
+ $problem2->id,
+ $problem3->id,
+ ],
+ token => $csrf,
+ }
+ );
+
+ $mech->get_ok($problem1->url);
+ $mech->text_contains('Shortlisted');
+ $mech->get_ok($problem2->url);
+ $mech->text_contains('Shortlisted');
+ $mech->get_ok($problem3->url);
+ $mech->text_contains('Shortlisted');
+};
+
done_testing();
END {