Skip to content

Commit

Permalink
BGDIINF_SB-3187: Reduce the number of tests for the search bar
Browse files Browse the repository at this point in the history
All possible coordinates formats are already tested in unittest so no need to
test everything here again.

This will speed up e2e tests but also reduce the number of tests result which
are not cheap if we want to run the tests on cypress cloud.
  • Loading branch information
ltshb committed Nov 8, 2023
1 parent 6ae1020 commit fc3f562
Showing 1 changed file with 35 additions and 176 deletions.
211 changes: 35 additions & 176 deletions tests/e2e-cypress/integration/search/coordinates-search.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,13 @@ import { LV03, LV95, WEBMERCATOR, WGS84 } from '@/utils/coordinates/coordinateSy
import CustomCoordinateSystem from '@/utils/coordinates/CustomCoordinateSystem.class'
import { STANDARD_ZOOM_LEVEL_1_25000_MAP } from '@/utils/coordinates/SwissCoordinateSystem.class'
import { latLonToMGRS } from '@/utils/militaryGridProjection'
import { toStringHDMS } from 'ol/coordinate'
import proj4 from 'proj4'

const searchbarSelector = '[data-cy="searchbar"]'

describe('Testing coordinates typing in search bar', { testIsolation: false }, () => {
// in order to ease test run, we only load the page once at the beginning of this context
// so that it doesn't load the page for each copy/paste in the search bar
before(() => {
cy.goToMapView()
})
describe('Testing coordinates typing in search bar', () => {
beforeEach(() => {
// emptying any potential search query
cy.readStoreValue('state.search.query').then((searchQuery) => {
if (searchQuery && searchQuery.length > 0) {
cy.get('[data-cy="searchbar-clear"]').click()
// replacing the view somewhere else in order to check that
// subsequent coordinate search will place the view at the correct location
cy.writeStoreValue('setZoom', DEFAULT_PROJECTION.getDefaultZoom())
cy.writeStoreValue('setCenter', DEFAULT_PROJECTION.bounds.center)
}
})
cy.goToMapView()
})
const expectedCenter = DEFAULT_PROJECTION.bounds.center.map((value) => value - 1000)
const expectedCenterLV95 = proj4(DEFAULT_PROJECTION.epsg, LV95.epsg, expectedCenter).map(
Expand Down Expand Up @@ -69,172 +54,48 @@ describe('Testing coordinates typing in search bar', { testIsolation: false }, (
expect(feature[1]).to.be.approximately(expectedCenter[1], acceptableDelta)
})
}
const numberWithThousandSeparator = (x, separator = "'") => {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, separator)
}
const standardCheck = (x, y, title, acceptableDelta = 0.0) => {
it(title, () => {
cy.get(searchbarSelector).paste(`${x} ${y}`)
checkCenterInStore(acceptableDelta)
checkZoomLevelInStore()
checkThatCoordinateAreHighlighted(acceptableDelta)
})
it(`${title} with comma as a separator`, () => {
cy.get(searchbarSelector).paste(`${x}, ${y}`)
checkCenterInStore(acceptableDelta)
checkZoomLevelInStore()
checkThatCoordinateAreHighlighted(acceptableDelta)
})
it(`${title} with slash as a separator`, () => {
cy.get(searchbarSelector).paste(`${x}/${y}`)
checkCenterInStore(acceptableDelta)
checkZoomLevelInStore()
checkThatCoordinateAreHighlighted(acceptableDelta)
})
}
const tryAllInputPossibilities = (
x,
y,
coordType,
acceptableDelta = 0.0,
withBackwardInputCheck = false,
withThousandSeparatorCheck = false
) => {
const mainTitle = `sets center accordingly when ${coordType} coordinates are entered in the search bar`
standardCheck(x, y, mainTitle, acceptableDelta)
if (withBackwardInputCheck) {
standardCheck(y, x, `${mainTitle} with coordinates entered backward`, acceptableDelta)
}
if (withThousandSeparatorCheck) {
standardCheck(
numberWithThousandSeparator(x, "'"),
numberWithThousandSeparator(y, "'"),
`${mainTitle} with ' as thousand separator`,
acceptableDelta
)
standardCheck(
numberWithThousandSeparator(x, ' '),
numberWithThousandSeparator(y, ' '),
`${mainTitle} with space as thousand separator`,
acceptableDelta
)
}
if (withThousandSeparatorCheck && withBackwardInputCheck) {
standardCheck(
numberWithThousandSeparator(y, "'"),
numberWithThousandSeparator(x, "'"),
`${mainTitle} with ' as thousand separator`,
acceptableDelta
)
standardCheck(
numberWithThousandSeparator(y, ' '),
numberWithThousandSeparator(x, ' '),
`${mainTitle} with space as thousand separator`,
acceptableDelta
)
}
const standardCheck = (x, y, acceptableDelta = 0.0) => {
const searchBar = cy.get(searchbarSelector)
searchBar.should('be.visible')
searchBar.paste(`${x} ${y}`)
checkCenterInStore(acceptableDelta)
checkZoomLevelInStore()
checkThatCoordinateAreHighlighted(acceptableDelta)
}

it('find the searchbar in the UI', () => {
cy.get(searchbarSelector).should('be.visible')
})
it('Remove the dropped pin when the search bar is cleared', () => {
cy.get(searchbarSelector).paste(`${expectedCenterLV95[0]} ${expectedCenterLV95[1]}`)
checkCenterInStore()
checkZoomLevelInStore()
checkThatCoordinateAreHighlighted()
it('Paste and clear LV95 coordinates in search bar', () => {
standardCheck(expectedCenterLV95[0], expectedCenterLV95[1])
cy.get('[data-cy="searchbar-clear"]').click()
// checking that search bar has been emptied
cy.readStoreValue('state.search.query').should('be.empty')
// checking that the dropped pin has been removed
cy.readStoreValue('state.map.pinnedLocation').should('be.null')
})

context('EPSG:4326 (Web-Mercator) inputs', () => {
it('Paste EPSG:4326 (WGS84) coordinate', () => {
const expectedCenterWGS84_DD = expectedCenterWGS84.map((val) => {
const [degree, minutesFraction] = `${val}`.split('.')
const minutes = parseFloat(`0.${minutesFraction}`)
return `${degree}° ${(minutes * 60.0).toFixed(4)}'`
})
const expectedCenterWGS84_DD_NoSymbol = expectedCenterWGS84_DD.map((val) =>
val.replace(/[°']/g, '')
)

const dmsString = toStringHDMS(expectedCenterWGS84, 2).replace(//g, "'").replace(//g, '"')
const expectedCenterWGS84_DMS = [
dmsString.slice(dmsString.indexOf('N') + 1, dmsString.length).trim(),
dmsString.slice(0, dmsString.indexOf('N') + 1).trim(),
]
const expectedCenterWGS84_DMS_No_NE = expectedCenterWGS84_DMS.map((val) =>
val.replace(/[NE]/g, '').trim()
)
const expectedCenterWGS84_DMS_NoSymbol = expectedCenterWGS84_DMS_No_NE.map((val) =>
val.replace(/[°'"]/g, '')
)
const acceptableDetla = 0.25
tryAllInputPossibilities(
expectedCenterWGS84[1],
expectedCenterWGS84[0],
'DD format',
acceptableDetla
)
tryAllInputPossibilities(
expectedCenterWGS84_DD[0],
expectedCenterWGS84_DD[1],
'DD format',
acceptableDetla
)
tryAllInputPossibilities(
expectedCenterWGS84_DD_NoSymbol[0],
expectedCenterWGS84_DD_NoSymbol[1],
'DD format (Google style)',
acceptableDetla
)
tryAllInputPossibilities(
expectedCenterWGS84_DMS[0],
expectedCenterWGS84_DMS[1],
'DMS format with cardinal point',
acceptableDetla
)
tryAllInputPossibilities(
expectedCenterWGS84_DMS[1],
expectedCenterWGS84_DMS[0],
'inverted DMS format with cardinal point',
acceptableDetla
)
tryAllInputPossibilities(
expectedCenterWGS84_DMS_No_NE[0],
expectedCenterWGS84_DMS_No_NE[1],
'DMS format without cardinal point',
acceptableDetla
)
tryAllInputPossibilities(
expectedCenterWGS84_DMS_NoSymbol[0],
expectedCenterWGS84_DMS_NoSymbol[1],
'DMS format without symbols',
acceptableDetla
)
const acceptableDelta = 0.25
standardCheck(expectedCenterWGS84[0], expectedCenterWGS84[1], acceptableDelta)
// clear the bar
cy.get('[data-cy="searchbar-clear"]').click()
// checking that search bar has been emptied
cy.readStoreValue('state.search.query').should('be.empty')
standardCheck(expectedCenterWGS84_DD[0], expectedCenterWGS84_DD[1], acceptableDelta)
})
context('EPSG:2056 (LV95) inputs', () => {
tryAllInputPossibilities(
expectedCenterLV95[0],
expectedCenterLV95[1],
'LV95',
0.0,
true,
true
)

it('Paste EPSG:3857 (Web-Mercator) coordinate', () => {
const acceptableDelta = 0
standardCheck(expectedCenterWebMercator[0], expectedCenterWebMercator[1], acceptableDelta)
})
context('EPSG:21781 (LV03) inputs', () => {
tryAllInputPossibilities(
expectedCenterLV03[0],
expectedCenterLV03[1],
'LV03',
0.1,
true,
true
)

it('Paste EPSG:21781 (LV03) coordinates', () => {
standardCheck(expectedCenterLV03[0], expectedCenterLV03[1], 0.1)
})

context('What3Words input', () => {
const what3words = 'bisher.meiste.einerseits'
// creating a what3words response stub
Expand All @@ -259,17 +120,15 @@ describe('Testing coordinates typing in search bar', { testIsolation: false }, (
checkThatCoordinateAreHighlighted(1.0)
})
})
context('MGRS input', () => {

it('Paste MGRS input', () => {
// as MGRS is a 1m based grid, the point could be anywhere in the square of 1m x 1m, we then accept a 1m delta
const acceptableDeltaForMGRS = 1

it('sets center accordingly when a MGRS input is given', () => {
cy.get(searchbarSelector).paste(
latLonToMGRS(expectedCenterWGS84[1], expectedCenterWGS84[0])
)
checkCenterInStore(acceptableDeltaForMGRS)
checkZoomLevelInStore()
checkThatCoordinateAreHighlighted(acceptableDeltaForMGRS)
})
cy.get(searchbarSelector).paste(
latLonToMGRS(expectedCenterWGS84[1], expectedCenterWGS84[0])
)
checkCenterInStore(acceptableDeltaForMGRS)
checkZoomLevelInStore()
checkThatCoordinateAreHighlighted(acceptableDeltaForMGRS)
})
})

0 comments on commit fc3f562

Please sign in to comment.