diff options
-rw-r--r-- | .cypress/cypress/integration/peterborough.js | 34 | ||||
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rwxr-xr-x | bin/browser-tests | 4 | ||||
-rwxr-xr-x | bin/fixmystreet.com/fixture | 33 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 27 | ||||
-rw-r--r-- | t/app/controller/report_new_open311.t | 10 | ||||
-rw-r--r-- | web/cobrands/fixmystreet/fixmystreet.js | 28 |
7 files changed, 111 insertions, 26 deletions
diff --git a/.cypress/cypress/integration/peterborough.js b/.cypress/cypress/integration/peterborough.js new file mode 100644 index 000000000..67c468be8 --- /dev/null +++ b/.cypress/cypress/integration/peterborough.js @@ -0,0 +1,34 @@ +describe('new report form', function() { + + beforeEach(function() { + cy.server(); + cy.route('/report/new/ajax*').as('report-ajax'); + cy.visit('http://peterborough.localhost:3001/'); + cy.contains('Peterborough'); + cy.get('[name=pc]').type('PE1 1HF'); + cy.get('[name=pc]').parents('form').submit(); + cy.get('#map_box').click(); + cy.wait('@report-ajax'); + }); + + it('is hidden when emergency option is yes', function() { + cy.get('select:eq(4)').select('Fallen branch'); + cy.get('#form_emergency').select('yes'); + cy.get('#js-category-stopper').should('contain', 'Please phone customer services to report this problem.'); + cy.get('.js-hide-if-invalid-category').should('be.hidden'); + cy.get('#form_emergency').select('no'); + cy.get('#js-category-stopper').should('not.contain', 'Please phone customer services to report this problem.'); + cy.get('.js-hide-if-invalid-category').should('be.visible'); + }); + + it('is hidden when private land option is yes', function() { + cy.get('select:eq(4)').select('Fallen branch'); + cy.get('#form_private_land').select('yes'); + cy.get('#js-category-stopper').should('contain', 'The council do not have powers to address issues on private land.'); + cy.get('.js-hide-if-invalid-category').should('be.hidden'); + cy.get('#form_private_land').select('no'); + cy.get('#js-category-stopper').should('not.contain', 'The council do not have powers to address issues on private land.'); + cy.get('.js-hide-if-invalid-category').should('be.visible'); + }); + +}); diff --git a/CHANGELOG.md b/CHANGELOG.md index f135fb91f..057506c4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -60,6 +60,7 @@ - Checking of cached front page details against database. #2696 - Inconsistent display of mark private checkbox for staff users - Clear user categories when staff access is removed. #2815 + - Only trigger one change event on initial popstate. - Development improvements: - Upgrade the underlying framework and a number of other packages. #2473 - Add feature cobrand helper function. diff --git a/bin/browser-tests b/bin/browser-tests index 0180db0b5..04b019880 100755 --- a/bin/browser-tests +++ b/bin/browser-tests @@ -11,7 +11,7 @@ my ($cobrand, $coords, $area_id, $name, $mapit_url); BEGIN { $config_file = 'conf/general.yml-example'; - $cobrand = [ 'borsetshire', 'fixmystreet', 'northamptonshire', 'bathnes', 'buckinghamshire', 'hounslow', 'isleofwight' ]; + $cobrand = [ 'borsetshire', 'fixmystreet', 'northamptonshire', 'bathnes', 'buckinghamshire', 'hounslow', 'isleofwight', 'peterborough' ]; $coords = '51.532851,-2.284277'; $area_id = 2608; $name = 'Borsetshire'; @@ -150,7 +150,7 @@ browser-tests [running options] [fixture options] [cypress options] --help this help message Fixture option: - --cobrand Cobrand(s) to use, default is fixmystreet,northamptonshire,bathnes,buckinghamshire,isleofwight + --cobrand Cobrand(s) to use, default is fixmystreet,northamptonshire,bathnes,buckinghamshire,isleofwight,peterborough --coords Default co-ordinates for created reports --area_id Area ID to use for created body --name Name to use for created body diff --git a/bin/fixmystreet.com/fixture b/bin/fixmystreet.com/fixture index 1fa17dfad..98b086eb2 100755 --- a/bin/fixmystreet.com/fixture +++ b/bin/fixmystreet.com/fixture @@ -100,6 +100,7 @@ if ($opt->test_fixtures) { { area_id => 2397, categories => [ 'Graffiti' ], name => 'Northampton Borough Council' }, { area_id => 2483, categories => [ 'Potholes', 'Other' ], name => 'Hounslow Borough Council' }, { area_id => 2636, categories => [ 'Potholes', 'Private', 'Extra' ], name => 'Isle of Wight Council' }, + { area_id => 2566, categories => [ 'Fallen branch' ], name => 'Peterborough City Council' }, ) { $bodies->{$_->{area_id}} = FixMyStreet::DB::Factory::Body->find_or_create($_); my $cats = join(', ', @{$_->{categories}}); @@ -190,6 +191,38 @@ if ($opt->test_fixtures) { variable => 'true', }); $child_cat->update; + + $child_cat = FixMyStreet::DB->resultset("Contact")->find({ + body => $bodies->{2566}, + category => 'Fallen branch', + }); + $child_cat->set_extra_fields( + { + code => 'emergency', + datatype => 'singlevaluelist', + description => 'Is it blocking a footpath or a highway?', + order => 0, + variable => 'true', + required => 'true', + values => [ + { key => 'yes', name => 'Yes', disable => 1, disable_message => 'Please phone customer services to report this problem.' }, + { key => 'no', name => 'No' }, + ] + }, + { + code => 'private_land', + datatype => 'singlevaluelist', + description => 'Is this problem on private land?', + order => 0, + variable => 'true', + required => 'true', + values => [ + { key => 'yes', name => 'Yes', disable => 1, disable_message => 'The council do not have powers to address issues on private land.' }, + { key => 'no', name => 'No' }, + ] + } + ); + $child_cat->update; } FixMyStreet::DB::Factory::ResponseTemplate->create({ diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index ba37a25fa..6f6428089 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -328,13 +328,15 @@ sub disable_form_message : Private { $out{all} .= ' ' if $out{all}; $out{all} .= $_->{description}; } elsif (($_->{variable} || '') eq 'true' && @{$_->{values} || []}) { + my %category; foreach my $opt (@{$_->{values}}) { if ($opt->{disable}) { - $out{message} = $opt->{disable_message} || $_->{datatype_description}; - $out{code} = $_->{code}; - push @{$out{answers}}, $opt->{key}; + $category{message} = $opt->{disable_message} || $_->{datatype_description}; + $category{code} = $_->{code}; + push @{$category{answers}}, $opt->{key}; } } + push @{$out{questions}}, \%category if %category; } } @@ -1575,16 +1577,19 @@ sub check_for_category : Private { my $disable_form_messages = $c->forward('disable_form_message'); if ($disable_form_messages->{all}) { $c->stash->{disable_form_message} = $disable_form_messages->{all}; - } elsif (my $code = $disable_form_messages->{code}) { - my $answer = $c->get_param($code); - my $message = $disable_form_messages->{message}; - if ($answer) { - foreach (@{$disable_form_messages->{answers}}) { - if ($answer eq $_) { - $c->stash->{disable_form_message} = $message; + } elsif (my $questions = $disable_form_messages->{questions}) { + foreach my $question (@$questions) { + my $answer = $c->get_param($question->{code}); + my $message = $question->{message}; + if ($answer) { + foreach (@{$question->{answers}}) { + if ($answer eq $_) { + $c->stash->{disable_form_message} = $message; + } } } - } else { + } + if (!$c->stash->{disable_form_message}) { $c->stash->{have_disable_qn_to_answer} = 1; } } diff --git a/t/app/controller/report_new_open311.t b/t/app/controller/report_new_open311.t index 3488b96ce..dcad10899 100644 --- a/t/app/controller/report_new_open311.t +++ b/t/app/controller/report_new_open311.t @@ -378,9 +378,13 @@ subtest "Category extras includes form disabling string" => sub { my $output = $json->{by_category} ? $json->{by_category}{Pothole}{disable_form} : $json->{disable_form}; is_deeply $output, { all => 'Please ring us!', - message => 'Please please ring', - code => 'dangerous', - answers => [ 'yes' ], + questions => [ + { + message => 'Please please ring', + code => 'dangerous', + answers => [ 'yes' ], + }, + ], }; } diff --git a/web/cobrands/fixmystreet/fixmystreet.js b/web/cobrands/fixmystreet/fixmystreet.js index 1a513a1a5..68b12c323 100644 --- a/web/cobrands/fixmystreet/fixmystreet.js +++ b/web/cobrands/fixmystreet/fixmystreet.js @@ -459,9 +459,13 @@ $.extend(fixmystreet.set_up, { $(".js-hide-if-public-category").hide(); } - if (fixmystreet.message_controller && data && data.disable_form && data.disable_form.answers) { - $('#form_' + data.disable_form.code).on('change.category', function() { - $(fixmystreet).trigger('report_new:category_change'); + if (fixmystreet.message_controller && data && data.disable_form && data.disable_form.questions) { + $.each(data.disable_form.questions, function(_, question) { + if (question.message && question.code) { + $('#form_' + question.code).on('change.category', function() { + $(fixmystreet).trigger('report_new:category_change'); + }); + } }); } @@ -1334,10 +1338,14 @@ fixmystreet.fetch_reporting_data = function() { message: details.disable_form.all }); } - if (details.disable_form.answers) { - details.disable_form.category = category; - details.disable_form.keep_category_extras = true; - fixmystreet.message_controller.register_category(details.disable_form); + if (details.disable_form.questions) { + $.each(details.disable_form.questions, function(_, question) { + if (question.message && question.code) { + question.category = category; + question.keep_category_extras = true; + fixmystreet.message_controller.register_category(question); + } + }); } }); } @@ -1716,9 +1724,9 @@ $(function() { // location.href is something like foo.com/around?pc=abc-123, // which we pass into fixmystreet.display.reports_list() as a fallback // in case the list isn't already in the DOM. - $('#filter_categories').add('#statuses').add('#sort').find('option') - .prop('selected', function() { return this.defaultSelected; }) - .trigger('change.multiselect'); + var filters = $('#filter_categories').add('#statuses').add('#sort'); + filters.find('option').prop('selected', function() { return this.defaultSelected; }); + filters.trigger('change.multiselect'); if (fixmystreet.utils && fixmystreet.utils.parse_query_string) { var qs = fixmystreet.utils.parse_query_string(); var page = qs.p || 1; |