Skip to content

Commit

Permalink
PB-878: Tidy up code.
Browse files Browse the repository at this point in the history
  • Loading branch information
ismailsunni committed Oct 7, 2024
1 parent 25fcbc6 commit 4f8316e
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 101 deletions.
10 changes: 0 additions & 10 deletions tests/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -878,16 +878,6 @@ Cypress.Commands.add('checkOlLayer', (args = null) => {
errorMsg: `[${layer.id}] layer.rendered is not true`,
})
cy.log(`[${layer.id}] layer at index ${index} is rendered ${olLayer.rendered}`)
// expect(olLayer.rendered, `[${layer.id}] layer.rendered`).to.be.true
cy.log(`Class: ${olLayer.constructor.name}`)
if (olLayer.constructor.name === 'VectorLayer') {
cy.log(`[${layer.id}] extent: ${olLayer.getSource().getExtent()}`)
const features = olLayer.getSource().getFeatures()
cy.log(`Number of features: ${features.length}`)
features.forEach((feature, featureIndex) => {
cy.log(`Feature ${featureIndex}: ${JSON.stringify(feature.getProperties())}`)
})
}
})
})
invisibleLayers.forEach((layer) => {
Expand Down
182 changes: 91 additions & 91 deletions tests/cypress/tests-e2e/print.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ describe('Testing print', () => {

// Add a wait to make sure the print request is sent
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(2000) // Wait for 2 seconds
// cy.wait(2000) // Wait for 2 seconds

cy.wait('@printRequest').then((interception) => {
expect(interception.request.body).to.haveOwnProperty('layout')
Expand Down Expand Up @@ -349,96 +349,96 @@ describe('Testing print', () => {
expect(layers[0]['style']).to.haveOwnProperty("[_mfp_style = '1']")
})
})
it.skip('should send a print request correctly to mapfishprint (with KML layer) - with import layer', () => {
interceptPrintRequest()
interceptPrintStatus()
interceptDownloadReport()

cy.goToMapView({}, true)
cy.readStoreValue('state.layers.activeLayers').should('be.empty')
cy.openMenuIfMobile()
cy.get('[data-cy="menu-tray-tool-section"]:visible').click()
cy.get('[data-cy="menu-advanced-tools-import-file"]:visible').click()

cy.get('[data-cy="import-file-content"]').should('be.visible')
cy.get('[data-cy="import-file-online-content"]').should('be.visible')

const localKmlFileName = 'external-kml-file.kml'
const localKmlFile = `import-tool/${localKmlFileName}`

// Test local import
cy.log('Switch to local import')
cy.get('[data-cy="import-file-local-btn"]:visible').click()
cy.get('[data-cy="import-file-local-content"]').should('be.visible')

// Attach a local KML file
cy.log('Test add a local KML file')
cy.fixture(localKmlFile, null).as('kmlFixture')
cy.get('[data-cy="file-input"]').selectFile('@kmlFixture', {
force: true,
})
cy.get('[data-cy="import-file-load-button"]:visible').click()

// Assertions for successful import
cy.get('[data-cy="file-input-text"]')
.should('have.class', 'is-valid')
.should('not.have.class', 'is-invalid')
cy.get('[data-cy="file-input-valid-feedback"]')
.should('be.visible')
.contains('File successfully imported')
cy.get('[data-cy="import-file-load-button"]').should('be.visible').contains('Import')
cy.get('[data-cy="import-file-online-content"]').should('not.be.visible')
cy.readStoreValue('state.layers.activeLayers').should('have.length', 1)

// Close the import tool
cy.get('[data-cy="import-file-close-button"]:visible').click()
cy.get('[data-cy="import-file-content"]').should('not.exist')

// Print
cy.get('[data-cy="menu-print-section"]').should('be.visible').click()
cy.get('[data-cy="menu-print-form"]').should('be.visible')

cy.get('[data-cy="print-map-button"]').should('be.visible').click()
cy.get('[data-cy="abort-print-button"]').should('be.visible')

cy.checkOlLayer(['test.background.layer2', localKmlFileName])

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')
)

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

const layers = mapAttributes.layers
expect(layers).to.be.an('array')
cy.log('Layers:', layers)
cy.log('Layer 0:', layers[0]['type'])

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(
'_mfp_style'
)
expect(layers[0]['geoJson']['features'][0]['properties']['_mfp_style']).to.equal(
'1'
)
expect(layers[0]['style']).to.haveOwnProperty("[_mfp_style = '1']")
})
})
// it.skip('should send a print request correctly to mapfishprint (with KML layer) - with import layer', () => {
// interceptPrintRequest()
// interceptPrintStatus()
// interceptDownloadReport()

// cy.goToMapView({}, true)
// cy.readStoreValue('state.layers.activeLayers').should('be.empty')
// cy.openMenuIfMobile()
// cy.get('[data-cy="menu-tray-tool-section"]:visible').click()
// cy.get('[data-cy="menu-advanced-tools-import-file"]:visible').click()

// cy.get('[data-cy="import-file-content"]').should('be.visible')
// cy.get('[data-cy="import-file-online-content"]').should('be.visible')

// const localKmlFileName = 'external-kml-file.kml'
// const localKmlFile = `import-tool/${localKmlFileName}`

// // Test local import
// cy.log('Switch to local import')
// cy.get('[data-cy="import-file-local-btn"]:visible').click()
// cy.get('[data-cy="import-file-local-content"]').should('be.visible')

// // Attach a local KML file
// cy.log('Test add a local KML file')
// cy.fixture(localKmlFile, null).as('kmlFixture')
// cy.get('[data-cy="file-input"]').selectFile('@kmlFixture', {
// force: true,
// })
// cy.get('[data-cy="import-file-load-button"]:visible').click()

// // Assertions for successful import
// cy.get('[data-cy="file-input-text"]')
// .should('have.class', 'is-valid')
// .should('not.have.class', 'is-invalid')
// cy.get('[data-cy="file-input-valid-feedback"]')
// .should('be.visible')
// .contains('File successfully imported')
// cy.get('[data-cy="import-file-load-button"]').should('be.visible').contains('Import')
// cy.get('[data-cy="import-file-online-content"]').should('not.be.visible')
// cy.readStoreValue('state.layers.activeLayers').should('have.length', 1)

// // Close the import tool
// cy.get('[data-cy="import-file-close-button"]:visible').click()
// cy.get('[data-cy="import-file-content"]').should('not.exist')

// // Print
// cy.get('[data-cy="menu-print-section"]').should('be.visible').click()
// cy.get('[data-cy="menu-print-form"]').should('be.visible')

// cy.get('[data-cy="print-map-button"]').should('be.visible').click()
// cy.get('[data-cy="abort-print-button"]').should('be.visible')

// cy.checkOlLayer(['test.background.layer2', localKmlFileName])

// 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')
// )

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

// const layers = mapAttributes.layers
// expect(layers).to.be.an('array')
// cy.log('Layers:', layers)
// cy.log('Layer 0:', layers[0]['type'])

// 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(
// '_mfp_style'
// )
// expect(layers[0]['geoJson']['features'][0]['properties']['_mfp_style']).to.equal(
// '1'
// )
// expect(layers[0]['style']).to.haveOwnProperty("[_mfp_style = '1']")
// })
// })
it('should send a print request correctly to mapfishprint with GPX layer', () => {
interceptPrintRequest()
interceptPrintStatus()
Expand Down

0 comments on commit 4f8316e

Please sign in to comment.