diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2018-08-09 17:02:58 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2018-08-28 13:16:39 +0100 |
commit | 22c12ab78128788bb44b8567d8735671b73b02e6 (patch) | |
tree | 11fa75561358f257accc3f321aec352cf0c6f124 /t | |
parent | 60629c93d6f6ebb48ba00e16abffd8df4df79abe (diff) |
Remove need for category_extras ajax call.
Add by_category output to the /report/new/ajax call, containing all the data
that /report/new/category_extras returns for one category. Then alter the JS
to use that data immediately when needed.
Diffstat (limited to 't')
-rw-r--r-- | t/app/controller/report_new.t | 7 | ||||
-rw-r--r-- | t/app/controller/report_new_open311.t | 41 |
2 files changed, 28 insertions, 20 deletions
diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index 048f2644e..94c7b1231 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -1669,10 +1669,9 @@ subtest "unresponsive body handling works" => sub { # Test body-level send method my $old_send = $contact1->body->send_method; $contact1->body->update( { send_method => 'Refused' } ); - $mech->get_ok('/report/new/ajax?latitude=55.952055&longitude=-3.189579'); # Edinburgh my $body_id = $contact1->body->id; - ok $mech->content_like( qr{Edinburgh.*accept reports.*/unresponsive\?body=$body_id} ); my $extra_details = $mech->get_ok_json('/report/new/ajax?latitude=55.952055&longitude=-3.189579'); + like $extra_details->{top_message}, qr{Edinburgh.*accept reports.*/unresponsive\?body=$body_id}; is $extra_details->{unresponsive}, $body_id, "unresponsive json set"; $extra_details = $mech->get_ok_json('/report/new/category_extras?category=Street%20lighting&latitude=55.952055&longitude=-3.189579'); is $extra_details->{unresponsive}, $body_id, "unresponsive json set"; @@ -1749,8 +1748,8 @@ subtest "unresponsive body handling works" => sub { # And test per-category refusing my $old_email = $contact3->email; $contact3->update( { email => 'REFUSED' } ); - $mech->get_ok('/report/new/category_extras?category=Trees&latitude=51.896268&longitude=-2.093063'); - ok $mech->content_like( qr/Cheltenham.*Trees.*unresponsive.*category=Trees/ ); + $extra_details = $mech->get_ok_json('/report/new/ajax?latitude=51.896268&longitude=-2.093063'); + like $extra_details->{by_category}{$contact3->category}{category_extra}, qr/Cheltenham.*Trees.*unresponsive.*category=Trees/s; $extra_details = $mech->get_ok_json('/report/new/category_extras?category=Trees&latitude=51.896268&longitude=-2.093063'); is $extra_details->{unresponsive}, $contact3->body->id, "unresponsive json set"; diff --git a/t/app/controller/report_new_open311.t b/t/app/controller/report_new_open311.t index 17b489447..7d4f5429f 100644 --- a/t/app/controller/report_new_open311.t +++ b/t/app/controller/report_new_open311.t @@ -249,13 +249,18 @@ subtest "Category extras omits description label when all fields are hidden" => ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], MAPIT_URL => 'http://mapit.uk/', }, sub { - my $json = $mech->get_ok_json('/report/new/category_extras?category=Pothole&latitude=55.952055&longitude=-3.189579'); - my $category_extra = $json->{category_extra}; - contains_string($category_extra, "usrn"); - contains_string($category_extra, "central_asset_id"); - lacks_string($category_extra, "USRN", "Lacks 'USRN' label"); - lacks_string($category_extra, "Asset ID", "Lacks 'Asset ID' label"); - lacks_string($category_extra, "resolve your problem quicker, by providing some extra detail", "Lacks description text"); + for ( + { url => '/report/new/ajax?' }, + { url => '/report/new/category_extras?category=Pothole' }, + ) { + my $json = $mech->get_ok_json($_->{url} . '&latitude=55.952055&longitude=-3.189579'); + my $category_extra = $json->{by_category} ? $json->{by_category}{Pothole}{category_extra} : $json->{category_extra}; + contains_string($category_extra, "usrn"); + contains_string($category_extra, "central_asset_id"); + lacks_string($category_extra, "USRN", "Lacks 'USRN' label"); + lacks_string($category_extra, "Asset ID", "Lacks 'Asset ID' label"); + lacks_string($category_extra, "resolve your problem quicker, by providing some extra detail", "Lacks description text"); + } }; }; @@ -266,15 +271,19 @@ subtest "Category extras includes description label for user" => sub { }, sub { $contact4->push_extra_fields({ description => 'Size?', code => 'size', required => 'true', automated => '', variable => 'true', order => '3' }); $contact4->update; - - my $json = $mech->get_ok_json('/report/new/category_extras?category=Pothole&latitude=55.952055&longitude=-3.189579'); - my $category_extra = $json->{category_extra}; - contains_string($category_extra, "usrn"); - contains_string($category_extra, "central_asset_id"); - lacks_string($category_extra, "USRN", "Lacks 'USRN' label"); - lacks_string($category_extra, "Asset ID", "Lacks 'Asset ID' label"); - contains_string($category_extra, "Size?"); - contains_string($category_extra, "resolve your problem quicker, by providing some extra detail", "Contains description text"); + for ( + { url => '/report/new/ajax?' }, + { url => '/report/new/category_extras?category=Pothole' }, + ) { + my $json = $mech->get_ok_json($_->{url} . '&latitude=55.952055&longitude=-3.189579'); + my $category_extra = $json->{by_category} ? $json->{by_category}{Pothole}{category_extra} : $json->{category_extra}; + contains_string($category_extra, "usrn"); + contains_string($category_extra, "central_asset_id"); + lacks_string($category_extra, "USRN", "Lacks 'USRN' label"); + lacks_string($category_extra, "Asset ID", "Lacks 'Asset ID' label"); + contains_string($category_extra, "Size?"); + contains_string($category_extra, "resolve your problem quicker, by providing some extra detail", "Contains description text"); + } }; }; |