Skip to content

Commit

Permalink
PB-1254: fix embed test
Browse files Browse the repository at this point in the history
Issue : the tests for the embed links checked strings as they are without any further processing. This meant that if the order of the parameters changed, it would make the test fail.

Fix : We update the tests with a deep comparison between two 'URLSearchParams' made from the variable parameter and the validation string
  • Loading branch information
ltkum committed Dec 5, 2024
1 parent f10e2ca commit bcf2432
Showing 1 changed file with 35 additions and 21 deletions.
56 changes: 35 additions & 21 deletions tests/cypress/tests-e2e/embed.cy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
/// <reference types="cypress" />

describe('Testing the embed view', () => {
function checkUrlParams(urlToCheck, validationUrl) {
const href = new URLSearchParams(urlToCheck.replace('#map', ''))
const validation = new URLSearchParams(validationUrl.replace('#map', ''))
for (const key of validation.keys()) {
expect(validation.get(key)).to.equal(href.get(key))
}
}
it('Open in embed mode and can jump to the non embed mode', () => {
cy.goToEmbedView()

Expand Down Expand Up @@ -29,13 +36,14 @@ describe('Testing the embed view', () => {
cy.log(`Check the link url`)
cy.get('[data-cy="open-full-app-link"]').should('be.visible').should('contain', 'View on ')
cy.get('[data-cy="open-full-app-link-anchor"]', { timeout: 20000 })
.should(
'have.attr',
'href',
`#/map?lang=en&center=2660000,1190000&z=1&bgLayer=test.background.layer2&topic=ech&layers=`
)
.should('have.attr', 'target', '_blank')

.invoke('attr', 'href')
.then((href) =>
checkUrlParams(
href,
`#/map?lang=en&center=2660000,1190000&z=1&bgLayer=test.background.layer2&topic=ech&layers=`
)
)
cy.log('Test mouse zoom scrolling')
cy.location('hash').should('contain', 'z=1')
cy.get('[data-cy="scaleline"]').should('contain', '50 km')
Expand Down Expand Up @@ -84,12 +92,14 @@ describe('Testing the embed view', () => {
cy.log(`Check the link url`)
cy.get('[data-cy="open-full-app-link"]').should('be.visible').should('contain', 'View on ')
cy.get('[data-cy="open-full-app-link-anchor"]')
.should(
'have.attr',
'href',
`#/map?layers=test-1.wms.layer;test.wmts.layer,,0.5;test-2.wms.layer,f;test.timeenabled.wmts.layer&lang=en&center=2660000,1190000&z=1.667&bgLayer=test.background.layer2&topic=ech`
)
.should('have.attr', 'target', '_blank')
.invoke('attr', 'href')
.then((href) =>
checkUrlParams(
href,
`#/map?layers=test-1.wms.layer;test.wmts.layer,,0.5;test-2.wms.layer,f;test.timeenabled.wmts.layer&lang=en&center=2660000,1190000&z=1.667&bgLayer=test.background.layer2&topic=ech`
)
)
})
it('Open in legacy embed mode and can jump to the non embed mode', () => {
cy.log(`Open in legacy mode without parameters`)
Expand Down Expand Up @@ -120,12 +130,14 @@ describe('Testing the embed view', () => {
cy.log(`Check the link url`)
cy.get('[data-cy="open-full-app-link"]').should('be.visible').should('contain', 'View on ')
cy.get('[data-cy="open-full-app-link-anchor"]')
.should(
'have.attr',
'href',
`#/map?lang=en&center=2660000,1190000&z=1&bgLayer=test.background.layer2&topic=ech&layers=`
)
.should('have.attr', 'target', '_blank')
.invoke('attr', 'href')
.then((href) =>
checkUrlParams(
href,
`#/map?lang=en&center=2660000,1190000&z=1&bgLayer=test.background.layer2&topic=ech&layers=`
)
)

cy.log('Test mouse zoom scrolling')
cy.location('hash').should('contain', 'z=1')
Expand Down Expand Up @@ -181,11 +193,13 @@ describe('Testing the embed view', () => {
cy.log(`Check the link url`)
cy.get('[data-cy="open-full-app-link"]').should('be.visible').should('contain', 'View on ')
cy.get('[data-cy="open-full-app-link-anchor"]')
.should(
'have.attr',
'href',
`#/map?lang=en&center=2660000,1190000&z=1&bgLayer=test.background.layer2&topic=ech&layers=test-1.wms.layer;test.wmts.layer,,0.5;test-2.wms.layer,f,1;test.timeenabled.wmts.layer@year=2016,,1`
)
.should('have.attr', 'target', '_blank')
.invoke('attr', 'href')
.then((href) =>
checkUrlParams(
href,
`#/map?lang=en&center=2660000,1190000&z=1&bgLayer=test.background.layer2&topic=ech&layers=test-1.wms.layer;test.wmts.layer,,0.5;test-2.wms.layer,f,1;test.timeenabled.wmts.layer@year=2016,,1`
)
)
})
})

0 comments on commit bcf2432

Please sign in to comment.