aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2018-03-23 18:09:04 +0000
committerMatthew Somerville <matthew-github@dracos.co.uk>2018-03-26 15:08:14 +0100
commit3b82cc190589cbc712ec35e28efa1dd0af2f0d82 (patch)
treec33bdff36feda1b049769aaf33d194d5fce38110
parent96d6d115c68d5e0a4b23612aa630c3e0de98daa5 (diff)
Fix race condition making a new report.
If you started a new report by clicking the map before the server had responded with the map list pins, when they did arrive they would replace the new report pin.
-rw-r--r--.cypress/cypress/integration/regressions.js14
-rw-r--r--CHANGELOG.md1
-rw-r--r--web/js/map-OpenLayers.js4
3 files changed, 19 insertions, 0 deletions
diff --git a/.cypress/cypress/integration/regressions.js b/.cypress/cypress/integration/regressions.js
index a0d5b3fc9..209013339 100644
--- a/.cypress/cypress/integration/regressions.js
+++ b/.cypress/cypress/integration/regressions.js
@@ -1,3 +1,10 @@
+// See https://github.com/cypress-io/cypress/issues/761 - Cypress dies if we
+// go straight to the next test with an XHR in progress. So visit a 404 page
+// to cancel anything in progress.
+Cypress.Commands.add('cleanUpXHR', function() {
+ cy.visit('/404', { failOnStatusCode: false });
+});
+
describe('Regression tests', function() {
it('Shows the sub-map links after clicking Try again', function() {
cy.viewport(480, 800);
@@ -5,5 +12,12 @@ describe('Regression tests', function() {
cy.get('#map_box').click(200, 200);
cy.get('#try_again').click();
cy.get('#sub_map_links').should('be.visible');
+ cy.cleanUpXHR();
+ });
+ it('Does not hide the new report pin even if you click really quick', function() {
+ cy.visit('/around?pc=BS10+5EE&js=1');
+ cy.get('#map_box').click(200, 200);
+ cy.get('#loading-indicator').should('be.hidden');
+ cy.get('#map_box image').should('be.visible');
});
});
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4ac766f73..90a77b7cf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -21,6 +21,7 @@
- Fix post-edit issues on admin report edit page.
- Truncate dates in Open311 output to the second. #2023
- Fix check for visible sub map links after 'Try again'.
+ - Stop race condition when making a new report quickly.
- Admin improvements:
- Inspectors can set non_public status of reports. #1992
- Default start date is shown on the dashboard.
diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js
index 0a1c947a0..ec4f8bc3d 100644
--- a/web/js/map-OpenLayers.js
+++ b/web/js/map-OpenLayers.js
@@ -96,6 +96,7 @@ $.extend(fixmystreet.utils, {
fixmystreet.markers.features[0].move(lonlat);
} else {
var markers = fixmystreet.maps.markers_list( [ [ lonlat.lat, lonlat.lon, fixmystreet.pin_new_report_colour ] ], false );
+ fixmystreet.bbox_strategy.layer.protocol.abort(fixmystreet.bbox_strategy.response);
fixmystreet.bbox_strategy.deactivate();
fixmystreet.markers.removeAllFeatures();
fixmystreet.markers.addFeatures( markers );
@@ -578,6 +579,9 @@ $.extend(fixmystreet.utils, {
});
fixmystreet.markers.events.register( 'loadstart', null, fixmystreet.maps.loading_spinner.show);
fixmystreet.markers.events.register( 'loadend', null, fixmystreet.maps.loading_spinner.hide);
+ OpenLayers.Request.XMLHttpRequest.onabort = function() {
+ fixmystreet.markers.events.triggerEvent("loadend", {response: null});
+ };
var markers = fixmystreet.maps.markers_list( fixmystreet.pins, true );
fixmystreet.markers.addFeatures( markers );