From 1e5e38f7938317e9170871d25ebaf2a51efab45e Mon Sep 17 00:00:00 2001 From: Ismail Sunni Date: Wed, 8 Jan 2025 12:32:54 +0700 Subject: [PATCH 1/7] PB-1187: Add test for geolocation outside switzerland. --- src/modules/i18n/index.js | 2 +- tests/cypress/tests-e2e/geolocation.cy.js | 54 ++++++++++++++++++----- 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/src/modules/i18n/index.js b/src/modules/i18n/index.js index 4834d6143..71c6339ec 100644 --- a/src/modules/i18n/index.js +++ b/src/modules/i18n/index.js @@ -30,7 +30,7 @@ const defaultLocal = ?.find((navigatorLang) => SUPPORTED_LANG.find((lang) => navigatorLang.startsWith(lang))) ?.split('-')[0] ?? SUPPORTED_LANG[0] log.info( - `Default local set to ${defaultLocal}, navigator langagues`, + `Default local set to ${defaultLocal}, navigator languages`, navigator.languages, `supported language`, SUPPORTED_LANG diff --git a/tests/cypress/tests-e2e/geolocation.cy.js b/tests/cypress/tests-e2e/geolocation.cy.js index 95106b157..fc7a38691 100644 --- a/tests/cypress/tests-e2e/geolocation.cy.js +++ b/tests/cypress/tests-e2e/geolocation.cy.js @@ -49,18 +49,9 @@ describe('Geolocation cypress', () => { }, }, () => { - // lon/lat to mock up the Geolocation API (see beforeEach) - const latitude = 47.5 - const longitude = 6.8 - // same position but in EPSG:2056 (default projection of the app) - const [x, y] = proj4(WGS84.epsg, DEFAULT_PROJECTION.epsg, [longitude, latitude]) - - beforeEach(() => { - cy.goToMapView({}, true, { latitude, longitude }) - getGeolocationButtonAndClickIt() - }) - it("Doesn't prompt the user if geolocation has previously been authorized", () => { + cy.goToMapView({}, true) + getGeolocationButtonAndClickIt() cy.on('window:alert', () => { throw new Error('Should not prompt for geolocation API permission again') }) @@ -68,6 +59,13 @@ describe('Geolocation cypress', () => { }) it('Uses the values given by the Geolocation API to feed the store', () => { + const latitude = 47.5 + const longitude = 6.8 + // same position but in EPSG:2056 (default projection of the app) + const [x, y] = proj4(WGS84.epsg, DEFAULT_PROJECTION.epsg, [longitude, latitude]) + cy.goToMapView({}, true, { latitude, longitude }) + + getGeolocationButtonAndClickIt() cy.readStoreValue('state.geolocation.position').then((position) => { expect(position).to.be.an('Array') expect(position.length).to.eq(2) @@ -75,6 +73,40 @@ describe('Geolocation cypress', () => { expect(position[1]).to.approximately(y, 0.1) }) }) + it('access from outside Switzerland shows an error message', () => { + // null island + cy.goToMapView({}, true, { latitude: 0, longitude: 0 }) + + getGeolocationButtonAndClickIt() + + // Check error in store + cy.readStoreValue('state.ui.errors').then((errors) => { + expect(errors).to.be.an('Set') + expect(errors.size).to.eq(1) + + const error = errors.values().next().value + expect(error.msg).to.eq('geoloc_out_of_bounds') + }) + // Check error in UI + cy.get('[data-cy="error-window"]').should('be.visible') + cy.get('[data-cy="error-window-close"]').should('be.visible').click() + + // Java island + // cy.goToMapView({}, true, { latitude: -7.71, longitude: 110.37 }) + + // getGeolocationButtonAndClickIt() + + // // Check error in store + // cy.readStoreValue('state.ui.errors').then((errors) => { + // expect(errors).to.be.an('Set') + // expect(errors.size).to.eq(1) + + // const error = errors.values().next().value + // expect(error.msg).to.eq('geoloc_out_of_bounds') + // }) + // // Check error in UI + // cy.get('[data-cy="error-window"]').should('be.visible') + }) } ) From 0d7e3f42b26bda489c3f9330b1c1f633c342824b Mon Sep 17 00:00:00 2001 From: Ismail Sunni Date: Wed, 8 Jan 2025 13:32:11 +0700 Subject: [PATCH 2/7] PB-1187: Fix covered error message in dev mode on small size screen --- src/utils/components/FeedbackPopup.vue | 7 +++---- tests/cypress/tests-e2e/geolocation.cy.js | 25 ++++++++++++----------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/utils/components/FeedbackPopup.vue b/src/utils/components/FeedbackPopup.vue index e10240ce3..521b269c7 100644 --- a/src/utils/components/FeedbackPopup.vue +++ b/src/utils/components/FeedbackPopup.vue @@ -59,16 +59,15 @@ const warning = computed(() => { flex-direction: column; @include respond-below(phone) { $top-margin: $header-height; + &.dev-disclaimer-present { + $top-margin: calc($header-height + $dev-disclaimer-height + 1rem); + } top: $top-margin; left: 50%; right: unset; transform: translate(-50%, 0%); max-height: calc(100vh - $top-margin); max-width: 100vw; - - &.dev-disclaimer-present { - $top-margin: calc($header-height + $dev-disclaimer-height); - } } } diff --git a/tests/cypress/tests-e2e/geolocation.cy.js b/tests/cypress/tests-e2e/geolocation.cy.js index fc7a38691..6dd3c6e95 100644 --- a/tests/cypress/tests-e2e/geolocation.cy.js +++ b/tests/cypress/tests-e2e/geolocation.cy.js @@ -89,23 +89,24 @@ describe('Geolocation cypress', () => { }) // Check error in UI cy.get('[data-cy="error-window"]').should('be.visible') - cy.get('[data-cy="error-window-close"]').should('be.visible').click() + cy.get('[data-cy="error-window-close"]').should('be.visible').click() // close the error window // Java island - // cy.goToMapView({}, true, { latitude: -7.71, longitude: 110.37 }) + cy.goToMapView({}, true, { latitude: -7.71, longitude: 110.37 }) - // getGeolocationButtonAndClickIt() + getGeolocationButtonAndClickIt() - // // Check error in store - // cy.readStoreValue('state.ui.errors').then((errors) => { - // expect(errors).to.be.an('Set') - // expect(errors.size).to.eq(1) + // Check error in store + cy.readStoreValue('state.ui.errors').then((errors) => { + expect(errors).to.be.an('Set') + expect(errors.size).to.eq(1) - // const error = errors.values().next().value - // expect(error.msg).to.eq('geoloc_out_of_bounds') - // }) - // // Check error in UI - // cy.get('[data-cy="error-window"]').should('be.visible') + const error = errors.values().next().value + expect(error.msg).to.eq('geoloc_out_of_bounds') + }) + // Check error in UI + cy.get('[data-cy="error-window"]').should('be.visible') + cy.get('[data-cy="error-window-close"]').should('be.visible').click() // close the error window }) } ) From c145fe3e806542e9abc3eb2de915b6ad80c8e708 Mon Sep 17 00:00:00 2001 From: Ismail Sunni Date: Wed, 8 Jan 2025 14:37:44 +0700 Subject: [PATCH 3/7] Pb-1187: Check the new position and zoom level after doing geolocation. --- tests/cypress/tests-e2e/geolocation.cy.js | 59 ++++++++++++++++++++--- 1 file changed, 52 insertions(+), 7 deletions(-) diff --git a/tests/cypress/tests-e2e/geolocation.cy.js b/tests/cypress/tests-e2e/geolocation.cy.js index 6dd3c6e95..dfb06b442 100644 --- a/tests/cypress/tests-e2e/geolocation.cy.js +++ b/tests/cypress/tests-e2e/geolocation.cy.js @@ -3,6 +3,7 @@ import proj4 from 'proj4' import { DEFAULT_PROJECTION } from '@/config/map.config' +import { SWISS_ZOOM_LEVEL_1_25000_MAP } from '@/utils/coordinates/CoordinateSystem.class' import { WGS84 } from '@/utils/coordinates/coordinateSystems' const geolocationButtonSelector = '[data-cy="geolocation-button"]' @@ -58,19 +59,63 @@ describe('Geolocation cypress', () => { cy.readStoreValue('state.geolocation.active').should('be.true') }) - it('Uses the values given by the Geolocation API to feed the store', () => { - const latitude = 47.5 - const longitude = 6.8 + it('Uses the values given by the Geolocation API to feed the store and position the map to the new position and zoom level', () => { + const startingLatitude = 47 + const startingLongitude = 7.5 + const startingZoom = 12 // same position but in EPSG:2056 (default projection of the app) - const [x, y] = proj4(WGS84.epsg, DEFAULT_PROJECTION.epsg, [longitude, latitude]) - cy.goToMapView({}, true, { latitude, longitude }) + const [x0, y0] = proj4(WGS84.epsg, DEFAULT_PROJECTION.epsg, [ + startingLongitude, + startingLatitude, + ]) + + const geoLatitude = 47.5 + const geoLongitude = 6.8 + // same position but in EPSG:2056 (default projection of the app) + const [geoX, geoY] = proj4(WGS84.epsg, DEFAULT_PROJECTION.epsg, [ + geoLongitude, + geoLatitude, + ]) + + cy.goToMapView( + { + center: proj4(WGS84.epsg, DEFAULT_PROJECTION.epsg, [ + startingLongitude, + startingLatitude, + ]).join(','), + z: startingZoom, + }, + true, + { latitude: geoLatitude, longitude: geoLongitude } + ) + + // check initial center and zoom + cy.readStoreValue('state.position.center').then((center) => { + expect(center).to.be.an('Array') + expect(center.length).to.eq(2) + expect(center[0]).to.approximately(x0, 0.1) + expect(center[1]).to.approximately(y0, 0.1) + }) + cy.readStoreValue('state.position.zoom').then((zoom) => { + expect(zoom).to.eq(startingZoom) + }) getGeolocationButtonAndClickIt() cy.readStoreValue('state.geolocation.position').then((position) => { expect(position).to.be.an('Array') expect(position.length).to.eq(2) - expect(position[0]).to.approximately(x, 0.1) - expect(position[1]).to.approximately(y, 0.1) + expect(position[0]).to.approximately(geoX, 0.1) + expect(position[1]).to.approximately(geoY, 0.1) + }) + // check that the map has been centered on the geolocation and zoom is updated + cy.readStoreValue('state.position.center').then((center) => { + expect(center).to.be.an('Array') + expect(center.length).to.eq(2) + expect(center[0]).to.approximately(geoX, 0.1) + expect(center[1]).to.approximately(geoY, 0.1) + }) + cy.readStoreValue('state.position.zoom').then((zoom) => { + expect(zoom).to.eq(SWISS_ZOOM_LEVEL_1_25000_MAP) }) }) it('access from outside Switzerland shows an error message', () => { From 680a773ba40b92e63ac776f4c7ec40a274503e0a Mon Sep 17 00:00:00 2001 From: Ismail Sunni Date: Wed, 8 Jan 2025 17:14:41 +0700 Subject: [PATCH 4/7] PB-1187: Test for failed geolocation retrieval and update geolocation mock to return error. --- .../plugins/geolocation-management.plugin.js | 20 +++-- tests/cypress/support/commands.js | 34 ++++++-- tests/cypress/tests-e2e/geolocation.cy.js | 82 ++++++++----------- 3 files changed, 74 insertions(+), 62 deletions(-) diff --git a/src/store/plugins/geolocation-management.plugin.js b/src/store/plugins/geolocation-management.plugin.js index 1614cf166..62d3685e7 100644 --- a/src/store/plugins/geolocation-management.plugin.js +++ b/src/store/plugins/geolocation-management.plugin.js @@ -6,6 +6,7 @@ import { LV95, WGS84 } from '@/utils/coordinates/coordinateSystems' import ErrorMessage from '@/utils/ErrorMessage.class' import log from '@/utils/logging' import { round } from '@/utils/numberUtils' +const { GeolocationPositionError } = window const dispatcher = { dispatcher: 'geolocation-management.plugin' } @@ -91,7 +92,7 @@ const handlePositionError = (error, store, state, options = {}) => { const { reactivate = false } = options log.error('Geolocation activation failed', error) switch (error.code) { - case error.PERMISSION_DENIED: + case GeolocationPositionError.PERMISSION_DENIED: store.dispatch('setGeolocationDenied', { denied: true, ...dispatcher, @@ -101,7 +102,7 @@ const handlePositionError = (error, store, state, options = {}) => { ...dispatcher, }) break - case error.TIMEOUT: + case GeolocationPositionError.TIMEOUT: store.dispatch('setGeolocation', { active: false, ...dispatcher }) store.dispatch('addErrors', { errors: [new ErrorMessage('geoloc_time_out', null)], @@ -109,12 +110,15 @@ const handlePositionError = (error, store, state, options = {}) => { }) break default: - if (IS_TESTING_WITH_CYPRESS && error.code === error.POSITION_UNAVAILABLE) { - // edge case for e2e testing, if we are testing with Cypress and we receive a POSITION_UNAVAILABLE - // we don't raise an error as it's "normal" in Electron to have this error raised (this API doesn't work - // on Electron embedded in Cypress : no Geolocation hardware detected, etc...) - // the position will be returned by a mocked up function by Cypress we can ignore this error - // we do nothing... + if ( + IS_TESTING_WITH_CYPRESS && + error.code === GeolocationPositionError.POSITION_UNAVAILABLE + ) { + store.dispatch('setGeolocation', { active: false, ...dispatcher }) + store.dispatch('addErrors', { + errors: [new ErrorMessage('geoloc_unknown', null)], + ...dispatcher, + }) } else { // It can happen that the position is not yet available so we retry the api call silently for the first // 3 call diff --git a/tests/cypress/support/commands.js b/tests/cypress/support/commands.js index c9197b393..f23419769 100644 --- a/tests/cypress/support/commands.js +++ b/tests/cypress/support/commands.js @@ -300,14 +300,34 @@ export function getDefaultFixturesAndIntercepts() { /** * Geolocation mockup * - * @param {Cypress.AUTWindow} win A reference to the window object. - * @param {GeolocationCoordinates} coords The fake coordinates to pass along. + * @param {Cypress.AUTWindow} win - A reference to the window object. + * @param {Object} options - Configuration object for the mock geolocation. + * @param {number} [options.latitude=47] - The latitude to use for the mock position. Default is + * `47` + * @param {number} [options.longitude=7] - The longitude to use for the mock position. Default is + * `7` + * @param {number} [options.errorCode=null] - The error code to simulate, if any. Default is `null` * @see https://github.com/cypress-io/cypress/issues/2671 */ -const mockGeolocation = (win, coords) => { - const handler = (callback) => callback({ coords }) - cy.stub(win.navigator.geolocation, 'getCurrentPosition').callsFake(handler) - cy.stub(win.navigator.geolocation, 'watchPosition').callsFake(handler) +const mockGeolocation = (win, options) => { + const { latitude = 47, longitude = 7, errorCode = null } = options + + if (errorCode) { + const error = { code: errorCode, message: 'Error' } + + cy.stub(win.navigator.geolocation, 'getCurrentPosition').callsFake((_, errorCallback) => { + errorCallback(error) + }) + + cy.stub(win.navigator.geolocation, 'watchPosition').callsFake((_, errorCallback) => { + errorCallback(error) + }) + } else { + const coords = { latitude, longitude } + const handler = (callback) => callback({ coords }) + cy.stub(win.navigator.geolocation, 'getCurrentPosition').callsFake(handler) + cy.stub(win.navigator.geolocation, 'watchPosition').callsFake(handler) + } } /** @@ -325,7 +345,7 @@ Cypress.Commands.add( ( queryParams = {}, withHash = true, - geolocationMockupOptions = { latitude: 47, longitude: 7 }, + geolocationMockupOptions = { latitude: 47, longitude: 7, errorCode: null }, fixturesAndIntercepts = {} ) => { // Intercepts passed as parameters to "fixturesAndIntercepts" will overwrite the correspondent diff --git a/tests/cypress/tests-e2e/geolocation.cy.js b/tests/cypress/tests-e2e/geolocation.cy.js index dfb06b442..4e9759905 100644 --- a/tests/cypress/tests-e2e/geolocation.cy.js +++ b/tests/cypress/tests-e2e/geolocation.cy.js @@ -5,6 +5,7 @@ import proj4 from 'proj4' import { DEFAULT_PROJECTION } from '@/config/map.config' import { SWISS_ZOOM_LEVEL_1_25000_MAP } from '@/utils/coordinates/CoordinateSystem.class' import { WGS84 } from '@/utils/coordinates/coordinateSystems' +const { GeolocationPositionError } = window const geolocationButtonSelector = '[data-cy="geolocation-button"]' @@ -12,6 +13,20 @@ function getGeolocationButtonAndClickIt() { cy.get(geolocationButtonSelector).should('be.visible').click() } +function testErrorMessage(message) { + // Check error in store + cy.readStoreValue('state.ui.errors').then((errors) => { + expect(errors).to.be.an('Set') + expect(errors.size).to.eq(1) + + const error = errors.values().next().value + expect(error.msg).to.eq(message) + }) + // Check error in UI + cy.get('[data-cy="error-window"]').should('be.visible') + cy.get('[data-cy="error-window-close"]').should('be.visible').click() // close the error window +} + // PB-701: TODO Those tests below are not working as expected, as the cypress-browser-permissions is not // working and the geolocation is always allowed, this needs to be reworked and probably need to // use another plugin. @@ -121,60 +136,33 @@ describe('Geolocation cypress', () => { it('access from outside Switzerland shows an error message', () => { // null island cy.goToMapView({}, true, { latitude: 0, longitude: 0 }) - getGeolocationButtonAndClickIt() - - // Check error in store - cy.readStoreValue('state.ui.errors').then((errors) => { - expect(errors).to.be.an('Set') - expect(errors.size).to.eq(1) - - const error = errors.values().next().value - expect(error.msg).to.eq('geoloc_out_of_bounds') - }) - // Check error in UI - cy.get('[data-cy="error-window"]').should('be.visible') - cy.get('[data-cy="error-window-close"]').should('be.visible').click() // close the error window + testErrorMessage('geoloc_out_of_bounds') // Java island cy.goToMapView({}, true, { latitude: -7.71, longitude: 110.37 }) - getGeolocationButtonAndClickIt() - - // Check error in store - cy.readStoreValue('state.ui.errors').then((errors) => { - expect(errors).to.be.an('Set') - expect(errors.size).to.eq(1) - - const error = errors.values().next().value - expect(error.msg).to.eq('geoloc_out_of_bounds') - }) - // Check error in UI - cy.get('[data-cy="error-window"]').should('be.visible') - cy.get('[data-cy="error-window-close"]').should('be.visible').click() // close the error window + testErrorMessage('geoloc_out_of_bounds') }) } ) - context( - 'Test geolocation when geolocation is unauthorized', - { - env: { - browserPermissions: { - geolocation: 'block', - }, - }, - }, - () => { - it('shows an alert telling the user geolocation is unauthorized when the geolocation button is clicked', () => { - cy.goToMapView() - getGeolocationButtonAndClickIt() - cy.on('window:alert', (txt) => { - expect(txt).to.contains( - 'The acquisition of the position failed because your browser settings does not allow it. Allow your browser /this website to use your location. Deactivate the "private" mode of your browser' - ) - }) - }) - } - ) + context('Test geolocation when geolocation is failed to be retrieved', () => { + it('shows an error telling the user geolocation is denied', () => { + cy.goToMapView({}, true, { errorCode: GeolocationPositionError.PERMISSION_DENIED }) + getGeolocationButtonAndClickIt() + testErrorMessage('geoloc_time_out') + }) + + it('shows an alert telling the user geolocation is not able to be retrieved due to time out', () => { + cy.goToMapView({}, true, { errorCode: GeolocationPositionError.TIMEOUT }) + getGeolocationButtonAndClickIt() + testErrorMessage('geoloc_time_out') + }) + it('shows an alert telling the user geolocation is not available for other reason', () => { + cy.goToMapView({}, true, { errorCode: GeolocationPositionError.POSITION_UNAVAILABLE }) + getGeolocationButtonAndClickIt() + testErrorMessage('geoloc_unknown') + }) + }) }) From 92042548d8565b880baedeb6eba03f40b296b9ab Mon Sep 17 00:00:00 2001 From: Ismail Sunni Date: Thu, 9 Jan 2025 12:21:47 +0700 Subject: [PATCH 5/7] PB-1187: Merge tests to it blocks. --- tests/cypress/tests-e2e/geolocation.cy.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tests/cypress/tests-e2e/geolocation.cy.js b/tests/cypress/tests-e2e/geolocation.cy.js index 4e9759905..926b6b6d4 100644 --- a/tests/cypress/tests-e2e/geolocation.cy.js +++ b/tests/cypress/tests-e2e/geolocation.cy.js @@ -148,18 +148,22 @@ describe('Geolocation cypress', () => { ) context('Test geolocation when geolocation is failed to be retrieved', () => { - it('shows an error telling the user geolocation is denied', () => { - cy.goToMapView({}, true, { errorCode: GeolocationPositionError.PERMISSION_DENIED }) + it('shows an error telling the user geolocation is denied or time out', () => { + // Timeout + cy.goToMapView({}, true, { errorCode: GeolocationPositionError.TIMEOUT }) getGeolocationButtonAndClickIt() testErrorMessage('geoloc_time_out') - }) - it('shows an alert telling the user geolocation is not able to be retrieved due to time out', () => { - cy.goToMapView({}, true, { errorCode: GeolocationPositionError.TIMEOUT }) + cy.reload() // to reset the stub + + // Permission denied + cy.goToMapView({}, true, { errorCode: GeolocationPositionError.PERMISSION_DENIED }) getGeolocationButtonAndClickIt() - testErrorMessage('geoloc_time_out') + testErrorMessage('geoloc_permission_denied') }) - it('shows an alert telling the user geolocation is not available for other reason', () => { + it('shows an error when geolocation is not available / other error', () => { + // Unfortunately, I need to put this position unavailable in a separate it block + // cy.reload doesn't fix the issue, even restore the stub doesn't work cy.goToMapView({}, true, { errorCode: GeolocationPositionError.POSITION_UNAVAILABLE }) getGeolocationButtonAndClickIt() testErrorMessage('geoloc_unknown') From bb6173b64146f18dede37df91ff9e0dc9edbff8c Mon Sep 17 00:00:00 2001 From: Ismail Sunni Date: Thu, 9 Jan 2025 12:39:29 +0700 Subject: [PATCH 6/7] PB-1187: Address PR request. --- .../plugins/geolocation-management.plugin.js | 55 ++++++++----------- 1 file changed, 22 insertions(+), 33 deletions(-) diff --git a/src/store/plugins/geolocation-management.plugin.js b/src/store/plugins/geolocation-management.plugin.js index 62d3685e7..c0aba2441 100644 --- a/src/store/plugins/geolocation-management.plugin.js +++ b/src/store/plugins/geolocation-management.plugin.js @@ -98,52 +98,41 @@ const handlePositionError = (error, store, state, options = {}) => { ...dispatcher, }) store.dispatch('addErrors', { - errors: [new ErrorMessage('geoloc_permission_denied', null)], + errors: [new ErrorMessage('geoloc_permission_denied')], ...dispatcher, }) break case GeolocationPositionError.TIMEOUT: store.dispatch('setGeolocation', { active: false, ...dispatcher }) store.dispatch('addErrors', { - errors: [new ErrorMessage('geoloc_time_out', null)], + errors: [new ErrorMessage('geoloc_time_out')], ...dispatcher, }) break default: - if ( - IS_TESTING_WITH_CYPRESS && - error.code === GeolocationPositionError.POSITION_UNAVAILABLE - ) { - store.dispatch('setGeolocation', { active: false, ...dispatcher }) + // It can happen that the position is not yet available so we retry the api call silently for the first + // 3 call + errorCount += IS_TESTING_WITH_CYPRESS ? 3 : 1 + if (errorCount < 3) { + if (reactivate) { + activeGeolocation(store, state, { useInitial: false }) + } + } else { store.dispatch('addErrors', { - errors: [new ErrorMessage('geoloc_unknown', null)], + errors: [new ErrorMessage('geoloc_unknown')], ...dispatcher, }) - } else { - // It can happen that the position is not yet available so we retry the api call silently for the first - // 3 call - errorCount += 1 - if (errorCount < 3) { - if (reactivate) { - activeGeolocation(store, state, { useInitial: false }) - } - } else { - store.dispatch('addErrors', { - errors: [new ErrorMessage('geoloc_unknown', null)], - ...dispatcher, - }) - if (reactivate) { - // If after 3 retries we failed to re-activate, set the geolocation to false - // so that the user can manually retry the geolocation later on. This can - // mean that the device don't support geolocation so it doesn't make sense - // to retry for ever. - // In the case where we are in the watcher, this means that we had at least - // one successful location and that geolocation is supported by the device. - // So we let the watcher continue has he might recover itself later on, if - // not the error will kept showing and the user will have to manually stop - // geolocation. - store.dispatch('setGeolocation', { active: false, ...dispatcher }) - } + if (reactivate) { + // If after 3 retries we failed to re-activate, set the geolocation to false + // so that the user can manually retry the geolocation later on. This can + // mean that the device don't support geolocation so it doesn't make sense + // to retry for ever. + // In the case where we are in the watcher, this means that we had at least + // one successful location and that geolocation is supported by the device. + // So we let the watcher continue has he might recover itself later on, if + // not the error will kept showing and the user will have to manually stop + // geolocation. + store.dispatch('setGeolocation', { active: false, ...dispatcher }) } } } From b346eaa18484fa0bcc0cc90890ed20f6177ecade Mon Sep 17 00:00:00 2001 From: Ismail Sunni Date: Thu, 9 Jan 2025 14:09:29 +0700 Subject: [PATCH 7/7] PB-1187: keep the test for geolocation separated because it failed in CI. --- tests/cypress/tests-e2e/geolocation.cy.js | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/tests/cypress/tests-e2e/geolocation.cy.js b/tests/cypress/tests-e2e/geolocation.cy.js index 926b6b6d4..c1be0c094 100644 --- a/tests/cypress/tests-e2e/geolocation.cy.js +++ b/tests/cypress/tests-e2e/geolocation.cy.js @@ -148,22 +148,18 @@ describe('Geolocation cypress', () => { ) context('Test geolocation when geolocation is failed to be retrieved', () => { - it('shows an error telling the user geolocation is denied or time out', () => { - // Timeout - cy.goToMapView({}, true, { errorCode: GeolocationPositionError.TIMEOUT }) - getGeolocationButtonAndClickIt() - testErrorMessage('geoloc_time_out') - - cy.reload() // to reset the stub - - // Permission denied + it('shows an error telling the user geolocation is denied', () => { cy.goToMapView({}, true, { errorCode: GeolocationPositionError.PERMISSION_DENIED }) getGeolocationButtonAndClickIt() testErrorMessage('geoloc_permission_denied') }) - it('shows an error when geolocation is not available / other error', () => { - // Unfortunately, I need to put this position unavailable in a separate it block - // cy.reload doesn't fix the issue, even restore the stub doesn't work + + it('shows an alert telling the user geolocation is not able to be retrieved due to time out', () => { + cy.goToMapView({}, true, { errorCode: GeolocationPositionError.TIMEOUT }) + getGeolocationButtonAndClickIt() + testErrorMessage('geoloc_time_out') + }) + it('shows an alert telling the user geolocation is not available for other reason', () => { cy.goToMapView({}, true, { errorCode: GeolocationPositionError.POSITION_UNAVAILABLE }) getGeolocationButtonAndClickIt() testErrorMessage('geoloc_unknown')