Skip to content

Commit

Permalink
[Tech] fix duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
claire2212 committed Oct 18, 2024
1 parent c4bc2a8 commit 2f0fd00
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 121 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { FAKE_MAPBOX_RESPONSE } from '../../constants'
import { getBaseLayerSnapShot } from '../utils'

context('LayerTree > Regulatory Layers', () => {
beforeEach(() => {
Expand All @@ -9,7 +10,7 @@ context('LayerTree > Regulatory Layers', () => {
cy.wait(300) // wait for rendering initial zoom

cy.log('load the regulation layer')
cy.wait('@getRegulation').then(({ response }) => expect(response && response.statusCode).equal(200))
cy.wait('@getRegulation').then(({ response }) => expect(response?.statusCode).equal(200))
cy.log('search for a regulation by zone')
cy.clickButton('Arbre des couches')
})
Expand All @@ -26,80 +27,24 @@ context('LayerTree > Regulatory Layers', () => {
cy.getDataCy('regulatory-result-zone').contains('Zone au sud de la cale').click()
cy.getDataCy('regulatory-metadata-header').contains('ZMEL Cale Querlen').click()
cy.wait(1000) // let OL do the rendering
cy.get('.baselayer').toMatchImageSnapshot({
imageConfig: {
threshold: 0.05,
thresholdType: 'percent'
},
screenshotConfig: {
clip: { height: 250, width: 250, x: 440, y: 450 }
}
})
getBaseLayerSnapShot()

cy.log('add the regulation to My Zones')
cy.clickButton('Sélectionner la zone')

cy.getDataCy('my-regulatory-layers').click() // zoom on the regulation's zone
cy.clickButton('Effacer les résultats de la recherche')
cy.get('.baselayer').toMatchImageSnapshot({
imageConfig: {
threshold: 0.05,
thresholdType: 'percent'
},
screenshotConfig: {
clip: { height: 250, width: 250, x: 440, y: 450 }
}
})
getBaseLayerSnapShot()
cy.clickButton('Cacher la/les zone(s)')
cy.get('.baselayer').toMatchImageSnapshot({
imageConfig: {
threshold: 0.05,
thresholdType: 'percent'
},
screenshotConfig: {
clip: { height: 250, width: 250, x: 440, y: 450 }
}
})
getBaseLayerSnapShot()
cy.clickButton('Afficher la/les zone(s)')
cy.get('.baselayer').toMatchImageSnapshot({
imageConfig: {
threshold: 0.05,
thresholdType: 'percent'
},
screenshotConfig: {
clip: { height: 250, width: 250, x: 440, y: 450 }
}
})
getBaseLayerSnapShot()
cy.clickButton('Cacher la zone')
cy.get('.baselayer').toMatchImageSnapshot({
imageConfig: {
threshold: 0.05,
thresholdType: 'percent'
},
screenshotConfig: {
clip: { height: 250, width: 250, x: 440, y: 450 }
}
})
getBaseLayerSnapShot()
cy.clickButton('Afficher la zone')
cy.get('.baselayer').toMatchImageSnapshot({
imageConfig: {
threshold: 0.05,
thresholdType: 'percent'
},
screenshotConfig: {
clip: { height: 250, width: 250, x: 440, y: 450 }
}
})
getBaseLayerSnapShot()
cy.clickButton('Supprimer la zone de ma sélection')
cy.get('.baselayer').toMatchImageSnapshot({
imageConfig: {
threshold: 0.05,
thresholdType: 'percent'
},
screenshotConfig: {
clip: { height: 250, width: 250, x: 440, y: 450 }
}
})
getBaseLayerSnapShot()
cy.getDataCy('my-regulatory-layers-list').contains('Aucune zone sélectionnée')
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { FAKE_MAPBOX_RESPONSE } from '../../constants'
import { getBaseLayerSnapShot } from '../utils'

context('LayerTree > Vigilance Area Layers', () => {
beforeEach(() => {
Expand All @@ -8,7 +9,7 @@ context('LayerTree > Vigilance Area Layers', () => {
cy.visit('/#@-444365.78,6153753.97,7.20')
cy.wait(300) // wait for rendering initial zoom

cy.wait('@getVigilanceAreas').then(({ response }) => expect(response && response.statusCode).equal(200))
cy.wait('@getVigilanceAreas').then(({ response }) => expect(response?.statusCode).equal(200))

cy.clickButton('Arbre des couches')
})
Expand All @@ -22,60 +23,20 @@ context('LayerTree > Vigilance Area Layers', () => {
cy.getDataCy('vigilance-area-result-zone').contains('Zone de vigilance 4').click()
cy.getDataCy('vigilance-area-title').contains('Zone de vigilance 4')
cy.wait(1000) // let OL do the rendering
cy.get('.baselayer').toMatchImageSnapshot({
imageConfig: {
threshold: 0.05,
thresholdType: 'percent'
},
screenshotConfig: {
clip: { height: 250, width: 250, x: 440, y: 450 }
}
})
getBaseLayerSnapShot()

// Save vigilance Area in "Mes zones de vigilance"
cy.clickButton('Sélectionner la zone')
cy.getDataCy('my-vigilance-areas-layers').click()
cy.clickButton('Effacer les résultats de la recherche')
cy.get('.baselayer').toMatchImageSnapshot({
imageConfig: {
threshold: 0.05,
thresholdType: 'percent'
},
screenshotConfig: {
clip: { height: 250, width: 250, x: 440, y: 450 }
}
})
getBaseLayerSnapShot()

cy.clickButton('Cacher la zone')
cy.get('.baselayer').toMatchImageSnapshot({
imageConfig: {
threshold: 0.05,
thresholdType: 'percent'
},
screenshotConfig: {
clip: { height: 250, width: 250, x: 440, y: 450 }
}
})
getBaseLayerSnapShot()
cy.clickButton('Afficher la zone')
cy.get('.baselayer').toMatchImageSnapshot({
imageConfig: {
threshold: 0.05,
thresholdType: 'percent'
},
screenshotConfig: {
clip: { height: 250, width: 250, x: 440, y: 450 }
}
})
getBaseLayerSnapShot()
cy.clickButton('Supprimer la zone de ma sélection')
cy.get('.baselayer').toMatchImageSnapshot({
imageConfig: {
threshold: 0.05,
thresholdType: 'percent'
},
screenshotConfig: {
clip: { height: 250, width: 250, x: 440, y: 450 }
}
})
getBaseLayerSnapShot()
cy.getDataCy('my-vigilance-area-zones-list').contains('Aucune zone sélectionnée')
})

Expand Down
11 changes: 2 additions & 9 deletions frontend/cypress/e2e/main_window/monitor-ext.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { FAKE_MAPBOX_RESPONSE } from '../constants'
import { getBaseLayerSnapShot } from './utils'

context('MonitorExt', () => {
beforeEach(() => {
Expand All @@ -11,15 +12,7 @@ context('MonitorExt', () => {
cy.wait(200)
cy.clickButton('Chercher un sémaphore')
cy.fill('Rechercher un sémaphore', 'Sémaphore de Fécamp', { delay: 400 })
cy.get('.baselayer').toMatchImageSnapshot({
imageConfig: {
threshold: 0.05,
thresholdType: 'percent'
},
screenshotConfig: {
clip: { height: 250, width: 250, x: 440, y: 450 }
}
})
getBaseLayerSnapShot()
})

it("A user can't see missions, reportings, bases and measurements tools button", () => {
Expand Down
12 changes: 12 additions & 0 deletions frontend/cypress/e2e/main_window/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,15 @@ export function goToMainWindow() {

cy.visit(`/`).wait(1000)
}

export function getBaseLayerSnapShot() {
cy.get('.baselayer').toMatchImageSnapshot({
imageConfig: {
threshold: 0.05,
thresholdType: 'percent'
},
screenshotConfig: {
clip: { height: 250, width: 250, x: 440, y: 450 }
}
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ context('Side Window > Mission Form > Mission zone', () => {
5,
0,
response => {
expect(response && response.statusCode).equal(200)
expect(response?.statusCode).equal(200)
expect(response.body.geom).to.deep.equal(response.body.envActions[0].geom)

cy.wait(200)
Expand Down Expand Up @@ -241,7 +241,7 @@ context('Side Window > Mission Form > Mission zone', () => {
5,
0,
response => {
expect(response && response.statusCode).equal(200)
expect(response?.statusCode).equal(200)
expect(response.body.geom.coordinates).to.deep.equal(computedMissionZone.coordinates)
expect(response.body.geom.type).to.deep.equal(computedMissionZone.type)

Expand Down

0 comments on commit 2f0fd00

Please sign in to comment.