Skip to content

Commit

Permalink
PB-818: adapt unit tests
Browse files Browse the repository at this point in the history
Issue : e2e tests were testing the values of the parameters sent, which could make the test fails whenever the code changed.

Fix : We only test the structure of the payload sent to the service, as checking the values are correctly computed should be done in the unit tests.
  • Loading branch information
ltkum authored and pakb committed Sep 11, 2024
1 parent bad40b0 commit f4e125c
Showing 1 changed file with 48 additions and 56 deletions.
104 changes: 48 additions & 56 deletions tests/cypress/tests-e2e/print.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,45 +426,46 @@ describe('Testing print', () => {
).to.lessThan(1.5) // thinner than the drawn in the OL map.
})
})
/**
* Currently, we are working on the print, which might alter the way data is sent, or the
* way data is interpreted. When the work on the print API (and backend) is over, we will
* need to modify those tests by providing new pdf reports as fixtures.
*/
it.skip('should send a print request correctly to mapfishprint (icon and label)', () => {
/** We need to ensure the structure of the query sent is correct */
it('should send a print request correctly to mapfishprint (icon and label)', () => {
startPrintWithKml('print/label.kml')

cy.wait('@printRequest').then((interception) => {
expect(interception.request.body).to.haveOwnProperty('layout')
expect(interception.request.body['layout']).to.equal('1. A4 landscape')
expect(interception.request.body).to.haveOwnProperty('format')
expect(interception.request.body['format']).to.equal('pdf')

const attributes = interception.request.body.attributes
expect(attributes).to.haveOwnProperty('printLegend')
expect(attributes['printLegend']).to.equals(0)
expect(attributes).to.haveOwnProperty('qrimage')
expect(attributes['qrimage']).to.contains(
encodeURIComponent('https://s.geo.admin.ch/0000000')
)

expect(attributes).to.haveOwnProperty('map')
const mapAttributes = attributes.map
expect(mapAttributes['scale']).to.equals(5000)
expect(mapAttributes['dpi']).to.equals(254)
expect(mapAttributes['projection']).to.equals('EPSG:2056')

expect(mapAttributes).to.haveOwnProperty('scale')
expect(mapAttributes).to.haveOwnProperty('dpi')
expect(mapAttributes).to.haveOwnProperty('projection')

expect(mapAttributes).to.haveOwnProperty('layers')

const layers = mapAttributes.layers

expect(layers).to.be.an('array')
expect(layers).to.have.length(2)
expect(layers[0]['type']).to.equals('geojson')
expect(layers[0]['geoJson']['features']).to.have.length(1)
expect(layers[0]['geoJson']['features'][0]['properties']).to.haveOwnProperty(

const geoJsonLayer = layers[0]

expect(geoJsonLayer).to.haveOwnProperty('type')
expect(geoJsonLayer).to.haveOwnProperty('geoJson')
expect(geoJsonLayer).to.haveOwnProperty('style')
expect(geoJsonLayer['geoJson']).to.haveOwnProperty('features')
expect(geoJsonLayer['geoJson']['features'][0]).to.haveOwnProperty('properties')
expect(geoJsonLayer['geoJson']['features'][0]['properties']).to.haveOwnProperty(
'_mfp_style'
)
expect(layers[0]['geoJson']['features'][0]['properties']['_mfp_style']).to.equal(
'1'
expect(geoJsonLayer['style']).to.haveOwnProperty("[_mfp_style = '1']")
expect(geoJsonLayer['style']["[_mfp_style = '1']"]).to.haveOwnProperty(
'symbolizers'
)
expect(layers[0]['style']).to.haveOwnProperty("[_mfp_style = '1']")

const symbolizers = layers[0]['style']["[_mfp_style = '1']"]['symbolizers']
const pointSymbol = symbolizers[0]
Expand All @@ -473,19 +474,13 @@ describe('Testing print', () => {
type: 'point',
externalGraphic: '001-marker@1x-255,0,0.png', // suffix only
graphicWidth: 19.133858267716537,
graphicXOffset: -8.503937007874017,
graphicYOffset: -8.503937007874017,
}

for (const attribute in pointSymbolAttributes) {
expect(pointSymbol).to.haveOwnProperty(attribute)
}
expect(
pointSymbol['externalGraphic'].endsWith(
pointSymbolAttributes['externalGraphic']
)
).to.be.true
expect(
pointSymbol['graphicWidth'] - pointSymbolAttributes['graphicWidth']
).to.lessThan(0.1)

const textSymbol = symbolizers[1]
const textSymbolAttributes = {
Expand All @@ -498,78 +493,75 @@ describe('Testing print', () => {
}
for (const attribute in textSymbolAttributes) {
expect(textSymbol).to.haveOwnProperty(attribute)
expect(textSymbol[attribute]).to.equal(textSymbolAttributes[attribute])
}
})
})
it.skip('should send a print request correctly to mapfishprint (KML from old geoadmin)', () => {
it('should send a print request correctly to mapfishprint (KML from old geoadmin)', () => {
startPrintWithKml('print/old-geoadmin-label.kml')

cy.wait('@printRequest').then((interception) => {
expect(interception.request.body).to.haveOwnProperty('layout')
expect(interception.request.body['layout']).to.equal('1. A4 landscape')
expect(interception.request.body).to.haveOwnProperty('format')
expect(interception.request.body['format']).to.equal('pdf')

const attributes = interception.request.body.attributes
expect(attributes).to.haveOwnProperty('printLegend')
expect(attributes['printLegend']).to.equals(0)
expect(attributes).to.haveOwnProperty('qrimage')
expect(attributes['qrimage']).to.contains(
encodeURIComponent('https://s.geo.admin.ch/0000000')
)

expect(attributes).to.haveOwnProperty('map')
const mapAttributes = attributes.map
expect(mapAttributes['scale']).to.equals(5000)
expect(mapAttributes['dpi']).to.equals(254)
expect(mapAttributes['projection']).to.equals('EPSG:2056')

expect(mapAttributes).to.haveOwnProperty('scale')
expect(mapAttributes).to.haveOwnProperty('dpi')
expect(mapAttributes).to.haveOwnProperty('projection')

expect(mapAttributes).to.haveOwnProperty('layers')

const layers = mapAttributes.layers

expect(layers).to.be.an('array')
expect(layers).to.have.length(2)
expect(layers[0]['type']).to.equals('geojson')
expect(layers[0]['geoJson']['features']).to.have.length(1)
expect(layers[0]['geoJson']['features'][0]['properties']).to.haveOwnProperty(

const geoJsonLayer = layers[0]

expect(geoJsonLayer).to.haveOwnProperty('type')
expect(geoJsonLayer).to.haveOwnProperty('geoJson')
expect(geoJsonLayer).to.haveOwnProperty('style')
expect(geoJsonLayer['geoJson']).to.haveOwnProperty('features')
expect(geoJsonLayer['geoJson']['features'][0]).to.haveOwnProperty('properties')
expect(geoJsonLayer['geoJson']['features'][0]['properties']).to.haveOwnProperty(
'_mfp_style'
)
expect(layers[0]['geoJson']['features'][0]['properties']['_mfp_style']).to.equal(
'1'
expect(geoJsonLayer['style']).to.haveOwnProperty("[_mfp_style = '1']")
expect(geoJsonLayer['style']["[_mfp_style = '1']"]).to.haveOwnProperty(
'symbolizers'
)
expect(layers[0]['style']).to.haveOwnProperty("[_mfp_style = '1']")

const symbolizers = layers[0]['style']["[_mfp_style = '1']"]['symbolizers']
const pointSymbol = symbolizers[0]
expect(pointSymbol).to.haveOwnProperty('type')
const pointSymbolAttributes = {
type: 'point',
externalGraphic: '001-marker@1x-255,0,0.png', // suffix only
graphicWidth: 17.007874015748033,
graphicWidth: 19.133858267716537,
graphicXOffset: -8.503937007874017,
graphicYOffset: -8.503937007874017,
}

for (const attribute in pointSymbolAttributes) {
expect(pointSymbol).to.haveOwnProperty(attribute)
if (attribute === 'externalGraphic') {
expect(pointSymbol[attribute].endsWith(pointSymbolAttributes[attribute])).to
.be.true
} else {
expect(pointSymbol[attribute]).to.equal(pointSymbolAttributes[attribute])
}
}

const textSymbol = symbolizers[1]
const textSymbolAttributes = {
type: 'text',
label: 'Old Label',
label: 'Sample Label',
fontFamily: 'Helvetica',
fontSize: '12px',
fontWeight: 'normal',
labelYOffset: 0,
labelYOffset: 44.75,
}
for (const attribute in textSymbolAttributes) {
expect(textSymbol).to.haveOwnProperty(attribute)
expect(textSymbol[attribute]).to.equal(textSymbolAttributes[attribute])
}
})
})
Expand Down

0 comments on commit f4e125c

Please sign in to comment.