diff options
-rw-r--r-- | .cypress/cypress/fixtures/highways-ajax.json | 37 | ||||
-rw-r--r-- | .cypress/cypress/integration/highways.js | 5 | ||||
-rw-r--r-- | web/cobrands/highways/assets.js | 63 |
3 files changed, 86 insertions, 19 deletions
diff --git a/.cypress/cypress/fixtures/highways-ajax.json b/.cypress/cypress/fixtures/highways-ajax.json new file mode 100644 index 000000000..d2234bf4c --- /dev/null +++ b/.cypress/cypress/fixtures/highways-ajax.json @@ -0,0 +1,37 @@ +{ + "councils_text_private":"These details will be sent to the council, but will never be shown online without your permission. (<a href=\"/privacy\">See our privacy policy</a>.)", + "by_category":{ + "Traffic lights":{"bodies":["Borsetshire", "Highways England"]}, + "Parks/landscapes":{"bodies":["Borsetshire"]}, + "Flyposting":{"bodies":["Borsetshire"]}, + "Footpath/bridleway away from road":{"bodies":["Borsetshire"]}, + "Street lighting":{"bodies":["Borsetshire"]}, + "Dog fouling":{"bodies":["Borsetshire"]}, + "Trees":{"bodies":["Borsetshire"]}, + "Graffiti":{"bodies":["Borsetshire"]}, + "Flytipping":{"bodies":["Borsetshire"]}, + "Other":{"bodies":["Borsetshire"]}, + "Public toilets":{"bodies":["Borsetshire"]}, + "Broken":{"bodies":["Borsetshire"]}, + "Rubbish (refuse and recycling)":{"bodies":["Borsetshire"]}, + "Street nameplates":{"bodies":["Borsetshire"]}, + "Roads/highways":{"bodies":["Borsetshire"]}, + "Missing":{"bodies":["Borsetshire"]}, + "Road traffic signs":{"bodies":["Borsetshire"]}, + "Overflowing":{"bodies":["Borsetshire"]}, + "Bus stops":{"bodies":["Borsetshire"]}, + "Pavements":{"bodies":["Borsetshire"]}, + "Street cleaning":{"bodies":["Borsetshire"]}, + "Abandoned vehicles":{"bodies":["Borsetshire"]}, + "Potholes":{"bodies":["Borsetshire"]}, + "Sign issue":{"bodies":["Highways England"]}, + "Road markings":{"bodies":["Highways England"]} + }, + "bodies":["Borsetshire", "Highways England"], + "display_names":{"Borsetshire":"Borsetshire County Council"}, + "unresponsive":"", + "extra_name_info":"", + "titles_list":null, + "councils_text":"<p> These will be sent to <strong>Borsetshire County Council</strong> and also published online for others to see, in accordance with our <a href=\"/privacy\">privacy policy</a>. </p>", + "category":"<label for='form_category' id=\"form_category_label\">Category</label> <select required class=\"validCategory form-control js-grouped-select\" name=\"category\" id=\"form_category\"> <option value='-- Pick a category --'>-- Pick a category --</option> <option value='Abandoned vehicles'>Abandoned vehicles</option> <option value='Bus stops'>Bus stops</option> <option value='Dog fouling'>Dog fouling</option> <option value='Flyposting'>Flyposting</option> <option value='Flytipping'>Flytipping</option> <option value='Footpath/bridleway away from road'>Footpath/bridleway away from road</option> <option value='Graffiti'>Graffiti</option> <option value='Parks/landscapes'>Parks/landscapes</option> <option value='Pavements'>Pavements</option> <option value='Potholes'>Potholes</option> <option value='Public toilets'>Public toilets</option> <option value='Roads/highways'>Roads/highways</option> <option value='Road traffic signs'>Road traffic signs</option> <option value='Rubbish (refuse and recycling)'>Rubbish (refuse and recycling)</option> <option value='Street cleaning'>Street cleaning</option> <option value='Street lighting'>Street lighting</option> <option value='Street nameplates'>Street nameplates</option> <option value='Traffic lights'>Traffic lights</option> <option value='Trees'>Trees</option> <option value='Other'>Other</option><optgroup label=\"** Highways England **\"><option>Road markings</option><option>Sign issue</option><option>Traffic lights</option></optgroup> <optgroup label=\"Bins\"> <option value='Broken'>Broken</option> <option value='Missing'>Missing</option> <option value='Overflowing'>Overflowing</option></optgroup></select><label id=\"form_subcategory_label\" class=\"hidden\">Subcategory</label>" +} diff --git a/.cypress/cypress/integration/highways.js b/.cypress/cypress/integration/highways.js index 72438b820..7f7214ae8 100644 --- a/.cypress/cypress/integration/highways.js +++ b/.cypress/cypress/integration/highways.js @@ -3,7 +3,7 @@ describe('Highways England tests', function() { cy.server(); cy.fixture('highways.xml'); cy.route('**/mapserver/highways*', 'fixture:highways.xml').as('highways-tilma'); - cy.route('/report/new/ajax*').as('report-ajax'); + cy.route('**/report/new/ajax*', 'fixture:highways-ajax.json').as('report-ajax'); cy.visit('/'); cy.contains('Go'); cy.get('[name=pc]').type(Cypress.env('postcode')); @@ -15,11 +15,14 @@ describe('Highways England tests', function() { cy.get('#highways').should('contain', 'M6'); cy.get('#js-councils_text').should('contain', 'Highways England'); cy.get('#single_body_only').should('have.value', 'Highways England'); + cy.get('#form_category').should('contain', 'Sign issue'); cy.get('#js-not-highways').click(); cy.get('#js-councils_text').should('contain', 'Borsetshire'); cy.get('#single_body_only').should('have.value', ''); + cy.get('#form_category').should('contain', 'Abandoned vehicles'); cy.get('#js-highways').click({ force: true }); cy.get('#js-councils_text').should('contain', 'Highways England'); cy.get('#single_body_only').should('have.value', 'Highways England'); + cy.get('#form_category').should('contain', 'Sign issue'); }); }); diff --git a/web/cobrands/highways/assets.js b/web/cobrands/highways/assets.js index c8cd274ab..2f00834d2 100644 --- a/web/cobrands/highways/assets.js +++ b/web/cobrands/highways/assets.js @@ -65,7 +65,6 @@ fixmystreet.assets.add(defaults, { } $('#highways').remove(); if ( !fixmystreet.assets.selectedFeature() ) { - fixmystreet.body_overrides.only_send('Highways England'); add_highways_warning(feature.attributes.ROA_NUMBER); $('#category_meta').empty(); } @@ -74,12 +73,54 @@ fixmystreet.assets.add(defaults, { fixmystreet.body_overrides.location = null; if (fixmystreet.body_overrides.get_only_send() === 'Highways England') { fixmystreet.body_overrides.remove_only_send(); + fixmystreet.body_overrides.do_not_send('Highways England'); } $('#highways').remove(); } } }); +function regenerate_category(he_flag) { + if (!fixmystreet.reporting_data) return; + + // Restart the category dropdown from the original data (not all of it as + // we keep subcategories the same) + var select = $(fixmystreet.reporting_data.category).filter('select'); + if (he_flag) { + var select1 = select.find('> option:first-child')[0].outerHTML; + var select2 = select.find('optgroup[label*="Highways England"]').html(); + $('#form_category').html(select1 + select2); + } else { + select.find('optgroup[label*="Highways England"]').remove(); + select = select.html(); + $('#form_category').html(select); + } + + // Recalculate the category groups + var old_category_group = $('#category_group').val() || $('#filter_group').val(); + $('#category_group').remove(); + fixmystreet.set_up.category_groups(old_category_group, true); +} + +function he_selected() { + fixmystreet.body_overrides.location = null; + fixmystreet.body_overrides.only_send('Highways England'); + fixmystreet.body_overrides.allow_send('Highways England'); + regenerate_category(true); + $(fixmystreet).trigger('report_new:highways_change'); +} + +function non_he_selected() { + fixmystreet.body_overrides.location = { + latitude: $('#fixmystreet\\.latitude').val(), + longitude: $('#fixmystreet\\.longitude').val() + }; + fixmystreet.body_overrides.remove_only_send(); + fixmystreet.body_overrides.do_not_send('Highways England'); + $(fixmystreet).trigger('report_new:highways_change'); + regenerate_category(false); +} + function add_highways_warning(road_name) { var $warning = $('<div class="box-warning" id="highways"><p>It looks like you clicked on the <strong>' + road_name + '</strong> which is managed by <strong>Highways England</strong>. ' + 'Does your report concern something on this road, or somewhere else (e.g a road crossing it)?<p></div>'); @@ -90,12 +131,7 @@ function add_highways_warning(road_name) { .attr('name', 'highways-choice') .attr('id', 'js-highways') .prop('checked', true) - .on('click', function() { - fixmystreet.body_overrides.location = null; - fixmystreet.body_overrides.only_send('Highways England'); - $(fixmystreet).trigger('report_new:highways_change'); - $('#category_meta').empty(); - }) + .on('click', he_selected) .appendTo($radios); $('<label>') .attr('for', 'js-highways') @@ -106,14 +142,7 @@ function add_highways_warning(road_name) { .attr('type', 'radio') .attr('name', 'highways-choice') .attr('id', 'js-not-highways') - .on('click', function() { - fixmystreet.body_overrides.location = { - latitude: $('#fixmystreet\\.latitude').val(), - longitude: $('#fixmystreet\\.longitude').val() - }; - fixmystreet.body_overrides.remove_only_send(); - $(fixmystreet).trigger('report_new:highways_change'); - }) + .on('click', non_he_selected) .appendTo($radios); $('<label>') .attr('for', 'js-not-highways') @@ -122,9 +151,7 @@ function add_highways_warning(road_name) { .appendTo($radios); $radios.appendTo($warning); $('.change_location').after($warning); - fixmystreet.body_overrides.location = null; - fixmystreet.body_overrides.only_send('Highways England'); - $(fixmystreet).trigger('report_new:highways_change'); + he_selected(); } })(); |