From bc48303b3c854c28b9d19cd4f6215c7f1042f3d4 Mon Sep 17 00:00:00 2001 From: Ismail Sunni Date: Mon, 2 Sep 2024 16:44:15 +0200 Subject: [PATCH 01/23] PB-878: Use print extent to filter out features to be printed. --- src/api/print.api.js | 10 +++++++--- .../utils/usePrintAreaRenderer.composable.js | 15 +++++++++++++++ src/store/modules/print.store.js | 5 +++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/api/print.api.js b/src/api/print.api.js index c9475bdea..391b09d7f 100644 --- a/src/api/print.api.js +++ b/src/api/print.api.js @@ -15,6 +15,7 @@ import { getWmsBaseUrl, } from '@/config/baseUrl.config' import i18n from '@/modules/i18n' +import store from '@/store' import log from '@/utils/logging' import { adjustWidth } from '@/utils/styleUtils' @@ -26,11 +27,12 @@ const MAX_PRINT_SPEC_SIZE = 1 * 1024 * 1024 // 1MB in bytes (should be in sync w class GeoAdminCustomizer extends BaseCustomizer { /** @param {string[]} layerIDsToExclude List of layer names to exclude from the print */ - constructor(layerIDsToExclude, printResolution) { - super() + constructor(printExtent, layerIDsToExclude, printResolution) { + super(printExtent) this.layerIDsToExclude = layerIDsToExclude this.printResolution = printResolution this.layerFilter = this.layerFilter.bind(this) + this.geometryFilter = this.geometryFilter.bind(this) this.line = this.line.bind(this) this.text = this.text.bind(this) this.point = this.point.bind(this) @@ -350,7 +352,9 @@ async function transformOlMapToPrintParams(olMap, config) { if (!dpi) { throw new PrintError('Missing DPI for printing') } - const customizer = new GeoAdminCustomizer(excludedLayerIDs, dpi) + const printExtent = store.state.print.printExtent + const customizer = new GeoAdminCustomizer(printExtent, excludedLayerIDs, dpi) + const attributionsOneLine = attributions.length > 0 ? `© ${attributions.join(', ')}` : '' try { diff --git a/src/modules/map/components/openlayers/utils/usePrintAreaRenderer.composable.js b/src/modules/map/components/openlayers/utils/usePrintAreaRenderer.composable.js index 7f6bbd838..c340bfb81 100644 --- a/src/modules/map/components/openlayers/utils/usePrintAreaRenderer.composable.js +++ b/src/modules/map/components/openlayers/utils/usePrintAreaRenderer.composable.js @@ -118,6 +118,21 @@ export default function usePrintAreaRenderer(map) { const width = size[0] const printRectangle = calculatePageBoundsPixels(selectedScale.value, printLayoutSize.value) + const topLeftCoordinate = map.getCoordinateFromPixel([printRectangle[0], printRectangle[1]]) + const rightBottomCoordinate = map.getCoordinateFromPixel([ + printRectangle[2], + printRectangle[3], + ]) + + store.commit('setPrintExtent', { + printExtent: [ + topLeftCoordinate[0], + rightBottomCoordinate[1], + rightBottomCoordinate[0], + topLeftCoordinate[1], + ], + dispatcher, + }) const minx = printRectangle[0] const miny = printRectangle[1] diff --git a/src/store/modules/print.store.js b/src/store/modules/print.store.js index a959914a1..3ba6e181a 100644 --- a/src/store/modules/print.store.js +++ b/src/store/modules/print.store.js @@ -7,6 +7,7 @@ export default { selectedLayout: null, selectedScale: null, printSectionShown: false, + printExtent: [], }, getters: { printLayoutSize(state) { @@ -44,11 +45,15 @@ export default { setPrintSectionShown({ commit }, { show, dispatcher }) { commit('setPrintSectionShown', { show, dispatcher }) }, + setPrintExtent({ commit }, { printExtent, dispatcher }) { + commit('setPrintExtent', { printExtent, dispatcher }) + }, }, mutations: { setPrintLayouts: (state, { layouts }) => (state.layouts = layouts), setSelectedLayout: (state, { layout }) => (state.selectedLayout = layout), setSelectedScale: (state, { scale }) => (state.selectedScale = scale), setPrintSectionShown: (state, { show }) => (state.printSectionShown = show), + setPrintExtent: (state, { printExtent }) => (state.printExtent = printExtent), }, } From 997fa6a37edd391d507750ecda9e84c5fb09b724 Mon Sep 17 00:00:00 2001 From: Ismail Sunni Date: Wed, 4 Sep 2024 11:00:52 +0200 Subject: [PATCH 02/23] PB-878: Fix unit test by using higher zoom level so that layer can be seen (not filtered out). --- tests/cypress/tests-e2e/print.cy.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/cypress/tests-e2e/print.cy.js b/tests/cypress/tests-e2e/print.cy.js index 21c024e90..dc6b18a49 100644 --- a/tests/cypress/tests-e2e/print.cy.js +++ b/tests/cypress/tests-e2e/print.cy.js @@ -184,7 +184,7 @@ describe('Testing print', () => { cy.goToMapView( { layers: `KML|${getServiceKmlBaseUrl()}some-kml-file.kml`, - z: 9, + z: 15, }, true ) @@ -312,7 +312,7 @@ describe('Testing print', () => { ) const mapAttributes = attributes.map - expect(mapAttributes['scale']).to.equals(5000) + expect(mapAttributes['scale']).to.equals(2500000) expect(mapAttributes['dpi']).to.equals(254) expect(mapAttributes['projection']).to.equals('EPSG:2056') @@ -446,6 +446,9 @@ describe('Testing print', () => { expect(mapAttributes).to.haveOwnProperty('projection') expect(mapAttributes).to.haveOwnProperty('layers') + expect(mapAttributes['scale']).to.equals(2500000) + expect(mapAttributes['dpi']).to.equals(254) + expect(mapAttributes['projection']).to.equals('EPSG:2056') const layers = mapAttributes.layers @@ -515,6 +518,9 @@ describe('Testing print', () => { expect(mapAttributes).to.haveOwnProperty('projection') expect(mapAttributes).to.haveOwnProperty('layers') + expect(mapAttributes['scale']).to.equals(2500000) + expect(mapAttributes['dpi']).to.equals(254) + expect(mapAttributes['projection']).to.equals('EPSG:2056') const layers = mapAttributes.layers From 4df8b3e15fb7106c3603b5c6312f359ecfe7ab22 Mon Sep 17 00:00:00 2001 From: Ismail Sunni Date: Wed, 4 Sep 2024 13:32:15 +0200 Subject: [PATCH 03/23] PB-878: Fix unit test on importing router. --- src/api/__tests__/print.api.spec.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/api/__tests__/print.api.spec.js b/src/api/__tests__/print.api.spec.js index 7b39e9404..65ced6967 100644 --- a/src/api/__tests__/print.api.spec.js +++ b/src/api/__tests__/print.api.spec.js @@ -3,6 +3,10 @@ import { describe, it } from 'vitest' import { PrintLayout, PrintLayoutAttribute } from '@/api/print.api.js' import { PRINT_DPI_COMPENSATION } from '@/config/print.config' +// We need to import the router here to avoid error when initializing router plugins, this is +// needed since some store plugins might require access to router to get the query parameters +// (e.g. topic management plugin) +import router from '@/router' // eslint-disable-line no-unused-vars import { adjustWidth } from '@/utils/styleUtils' describe('Print API unit tests', () => { From f07d4c04a5683b2920358db21254358d6df452f7 Mon Sep 17 00:00:00 2001 From: Ismail Sunni Date: Wed, 4 Sep 2024 13:37:37 +0200 Subject: [PATCH 04/23] PB-878: Add JSDoc for GeoAdminCustomizer. --- src/api/print.api.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/api/print.api.js b/src/api/print.api.js index 391b09d7f..e0021a43f 100644 --- a/src/api/print.api.js +++ b/src/api/print.api.js @@ -25,12 +25,22 @@ const PRINTING_DEFAULT_POLL_TIMEOUT = 600000 // ms (10 minutes) const SERVICE_PRINT_URL = `${getViewerDedicatedServicesBaseUrl()}print3/print/mapviewer` const MAX_PRINT_SPEC_SIZE = 1 * 1024 * 1024 // 1MB in bytes (should be in sync with the backend) +/** + * Customizes the printing behavior for GeoAdmin. + * + * @extends BaseCustomizer + */ class GeoAdminCustomizer extends BaseCustomizer { - /** @param {string[]} layerIDsToExclude List of layer names to exclude from the print */ + /** + * @param {number[]} printExtent - The extent of the area to be printed. + * @param {string[]} layerIDsToExclude - An array of layer IDs to exclude from the print. + * @param {number} printResolution - The resolution for the print. + */ constructor(printExtent, layerIDsToExclude, printResolution) { super(printExtent) this.layerIDsToExclude = layerIDsToExclude this.printResolution = printResolution + this.layerFilter = this.layerFilter.bind(this) this.geometryFilter = this.geometryFilter.bind(this) this.line = this.line.bind(this) From dedf1a9bfbe4593a6b11810155b7a856c13e1b6c Mon Sep 17 00:00:00 2001 From: Ismail Sunni Date: Wed, 4 Sep 2024 13:46:51 +0200 Subject: [PATCH 05/23] PB-878: Add comment and try to fix failed CI build. --- src/api/__tests__/print.api.spec.js | 1 + .../openlayers/utils/usePrintAreaRenderer.composable.js | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/api/__tests__/print.api.spec.js b/src/api/__tests__/print.api.spec.js index 65ced6967..f5affe764 100644 --- a/src/api/__tests__/print.api.spec.js +++ b/src/api/__tests__/print.api.spec.js @@ -7,6 +7,7 @@ import { PRINT_DPI_COMPENSATION } from '@/config/print.config' // needed since some store plugins might require access to router to get the query parameters // (e.g. topic management plugin) import router from '@/router' // eslint-disable-line no-unused-vars +import store from '@/store' // eslint-disable-line no-unused-vars import { adjustWidth } from '@/utils/styleUtils' describe('Print API unit tests', () => { diff --git a/src/modules/map/components/openlayers/utils/usePrintAreaRenderer.composable.js b/src/modules/map/components/openlayers/utils/usePrintAreaRenderer.composable.js index c340bfb81..24eed4f1d 100644 --- a/src/modules/map/components/openlayers/utils/usePrintAreaRenderer.composable.js +++ b/src/modules/map/components/openlayers/utils/usePrintAreaRenderer.composable.js @@ -126,10 +126,10 @@ export default function usePrintAreaRenderer(map) { store.commit('setPrintExtent', { printExtent: [ - topLeftCoordinate[0], - rightBottomCoordinate[1], - rightBottomCoordinate[0], - topLeftCoordinate[1], + topLeftCoordinate[0], // minX + rightBottomCoordinate[1], // minY + rightBottomCoordinate[0], // maxX + topLeftCoordinate[1], // maxY ], dispatcher, }) From ec63949f74d82c529d12ad9229750c74b8fd49f5 Mon Sep 17 00:00:00 2001 From: Ismail Sunni Date: Wed, 4 Sep 2024 14:37:27 +0200 Subject: [PATCH 06/23] PB-878: Ignore simple-import-sort/imports to fix import issue. --- src/api/__tests__/print.api.spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/api/__tests__/print.api.spec.js b/src/api/__tests__/print.api.spec.js index f5affe764..d5778d077 100644 --- a/src/api/__tests__/print.api.spec.js +++ b/src/api/__tests__/print.api.spec.js @@ -1,3 +1,4 @@ +// eslint-disable-next-line simple-import-sort/imports import { expect } from 'chai' import { describe, it } from 'vitest' From d5de3e42b6750c45f50bd5f3dfe30d4ab978bf1d Mon Sep 17 00:00:00 2001 From: Ismail Sunni Date: Wed, 4 Sep 2024 14:57:12 +0200 Subject: [PATCH 07/23] PB-878: Use different zoom level for failed test in CI. --- tests/cypress/tests-e2e/print.cy.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/cypress/tests-e2e/print.cy.js b/tests/cypress/tests-e2e/print.cy.js index dc6b18a49..dbe8efbc3 100644 --- a/tests/cypress/tests-e2e/print.cy.js +++ b/tests/cypress/tests-e2e/print.cy.js @@ -175,7 +175,7 @@ describe('Testing print', () => { }) }) context('Send print request with layers', () => { - function startPrintWithKml(kmlFixture) { + function startPrintWithKml(kmlFixture, zoom) { interceptPrintRequest() interceptPrintStatus() interceptDownloadReport() @@ -184,7 +184,7 @@ describe('Testing print', () => { cy.goToMapView( { layers: `KML|${getServiceKmlBaseUrl()}some-kml-file.kml`, - z: 15, + z: zoom || 15, }, true ) @@ -500,7 +500,7 @@ describe('Testing print', () => { }) }) it('should send a print request correctly to mapfishprint (KML from old geoadmin)', () => { - startPrintWithKml('print/old-geoadmin-label.kml') + startPrintWithKml('print/old-geoadmin-label.kml', 16) cy.wait('@printRequest').then((interception) => { expect(interception.request.body).to.haveOwnProperty('layout') From b7a8d6668bfd424bc46fd0de556b9f625b11d794 Mon Sep 17 00:00:00 2001 From: Ismail Sunni Date: Wed, 4 Sep 2024 15:45:38 +0200 Subject: [PATCH 08/23] PB-878: Set center to fix failed test in CI. --- tests/cypress/tests-e2e/print.cy.js | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/cypress/tests-e2e/print.cy.js b/tests/cypress/tests-e2e/print.cy.js index dbe8efbc3..16a86f761 100644 --- a/tests/cypress/tests-e2e/print.cy.js +++ b/tests/cypress/tests-e2e/print.cy.js @@ -185,6 +185,7 @@ describe('Testing print', () => { { layers: `KML|${getServiceKmlBaseUrl()}some-kml-file.kml`, z: zoom || 15, + center: '2655000,1203250', }, true ) From 296c2b7e744b16a00d2671e8ae1e046738909af3 Mon Sep 17 00:00:00 2001 From: Ismail Sunni Date: Wed, 4 Sep 2024 16:39:12 +0200 Subject: [PATCH 09/23] PB-878: Check center and zoom level for failed test. --- tests/cypress/tests-e2e/print.cy.js | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/tests/cypress/tests-e2e/print.cy.js b/tests/cypress/tests-e2e/print.cy.js index 16a86f761..5301b14ec 100644 --- a/tests/cypress/tests-e2e/print.cy.js +++ b/tests/cypress/tests-e2e/print.cy.js @@ -175,7 +175,7 @@ describe('Testing print', () => { }) }) context('Send print request with layers', () => { - function startPrintWithKml(kmlFixture, zoom) { + function startPrintWithKml(kmlFixture, center, zoom) { interceptPrintRequest() interceptPrintStatus() interceptDownloadReport() @@ -184,8 +184,8 @@ describe('Testing print', () => { cy.goToMapView( { layers: `KML|${getServiceKmlBaseUrl()}some-kml-file.kml`, - z: zoom || 15, - center: '2655000,1203250', + z: zoom || 9, + center: center || '2655000,1203250', }, true ) @@ -296,7 +296,7 @@ describe('Testing print', () => { }) }) it('should send a print request correctly to mapfishprint (with KML layer)', () => { - startPrintWithKml('import-tool/external-kml-file.kml') + startPrintWithKml('import-tool/external-kml-file.kml', 13) cy.wait('@printRequest').then((interception) => { expect(interception.request.body).to.haveOwnProperty('layout') @@ -429,7 +429,7 @@ describe('Testing print', () => { }) /** 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') + startPrintWithKml('print/label.kml', 13) cy.wait('@printRequest').then((interception) => { expect(interception.request.body).to.haveOwnProperty('layout') @@ -501,7 +501,22 @@ describe('Testing print', () => { }) }) it('should send a print request correctly to mapfishprint (KML from old geoadmin)', () => { - startPrintWithKml('print/old-geoadmin-label.kml', 16) + const customZoom = 13 + startPrintWithKml('print/old-geoadmin-label.kml', customZoom) + + cy.readStoreValue('getters.centerEpsg4326').should((center) => { + expect(center[0]).to.eq(8.161492) + expect(center[1]).to.eq(46.978042) + }) + + cy.readStoreValue('state.position.center').should((center) => { + expect(center[0]).to.eq(2655000) + expect(center[1]).to.eq(1203250) + }) + + cy.readStoreValue('state.position.zoom').should((zoom) => { + expect(zoom).to.equal(customZoom) + }) cy.wait('@printRequest').then((interception) => { expect(interception.request.body).to.haveOwnProperty('layout') From fb56a9c8c73d2cc3882b1d659825b0c0f4bec88a Mon Sep 17 00:00:00 2001 From: Ismail Sunni Date: Wed, 4 Sep 2024 17:05:43 +0200 Subject: [PATCH 10/23] PB-878: Also test the zoom level --- tests/cypress/tests-e2e/print.cy.js | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/tests/cypress/tests-e2e/print.cy.js b/tests/cypress/tests-e2e/print.cy.js index 5301b14ec..17fa7df65 100644 --- a/tests/cypress/tests-e2e/print.cy.js +++ b/tests/cypress/tests-e2e/print.cy.js @@ -1,9 +1,17 @@ /// +import { zoom } from 'chartjs-plugin-zoom' + import { getServiceKmlBaseUrl } from '@/config/baseUrl.config' import { formatThousand } from '@/utils/numberUtils.js' const printID = 'print-123456789' +function checkZoom(customZoom) { + cy.readStoreValue('state.position.zoom').should((zoom) => { + expect(zoom).to.equal(customZoom) + }) +} + describe('Testing print', () => { beforeEach(() => { cy.viewport(1920, 1080) @@ -175,7 +183,7 @@ describe('Testing print', () => { }) }) context('Send print request with layers', () => { - function startPrintWithKml(kmlFixture, center, zoom) { + function startPrintWithKml(kmlFixture, zoom, center) { interceptPrintRequest() interceptPrintStatus() interceptDownloadReport() @@ -296,7 +304,9 @@ describe('Testing print', () => { }) }) it('should send a print request correctly to mapfishprint (with KML layer)', () => { - startPrintWithKml('import-tool/external-kml-file.kml', 13) + const zoom = 13 + startPrintWithKml('import-tool/external-kml-file.kml', zoom) + checkZoom(zoom) cy.wait('@printRequest').then((interception) => { expect(interception.request.body).to.haveOwnProperty('layout') @@ -429,7 +439,9 @@ describe('Testing print', () => { }) /** 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', 13) + const customZoom = 13 + startPrintWithKml('print/label.kml', customZoom) + checkZoom(customZoom) cy.wait('@printRequest').then((interception) => { expect(interception.request.body).to.haveOwnProperty('layout') @@ -504,6 +516,8 @@ describe('Testing print', () => { const customZoom = 13 startPrintWithKml('print/old-geoadmin-label.kml', customZoom) + checkZoom(customZoom) + cy.readStoreValue('getters.centerEpsg4326').should((center) => { expect(center[0]).to.eq(8.161492) expect(center[1]).to.eq(46.978042) @@ -514,10 +528,6 @@ describe('Testing print', () => { expect(center[1]).to.eq(1203250) }) - cy.readStoreValue('state.position.zoom').should((zoom) => { - expect(zoom).to.equal(customZoom) - }) - cy.wait('@printRequest').then((interception) => { expect(interception.request.body).to.haveOwnProperty('layout') expect(interception.request.body).to.haveOwnProperty('format') From 6851bb9c0dc8bd22add690e0cff98375feb0f079 Mon Sep 17 00:00:00 2001 From: Ismail Sunni Date: Thu, 19 Sep 2024 10:28:18 +0700 Subject: [PATCH 11/23] PB-878: Add check for layers loaded in OpenLayers. --- tests/cypress/tests-e2e/print.cy.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/tests/cypress/tests-e2e/print.cy.js b/tests/cypress/tests-e2e/print.cy.js index 17fa7df65..fc6027fc5 100644 --- a/tests/cypress/tests-e2e/print.cy.js +++ b/tests/cypress/tests-e2e/print.cy.js @@ -1,5 +1,4 @@ /// -import { zoom } from 'chartjs-plugin-zoom' import { getServiceKmlBaseUrl } from '@/config/baseUrl.config' import { formatThousand } from '@/utils/numberUtils.js' @@ -188,10 +187,10 @@ describe('Testing print', () => { interceptPrintStatus() interceptDownloadReport() interceptKml(kmlFixture) - + const kmlID = `${getServiceKmlBaseUrl()}some-kml-file.kml` cy.goToMapView( { - layers: `KML|${getServiceKmlBaseUrl()}some-kml-file.kml`, + layers: `KML|${kmlID}`, z: zoom || 9, center: center || '2655000,1203250', }, @@ -208,6 +207,7 @@ describe('Testing print', () => { cy.get('[data-cy="print-map-button"]').should('be.visible').click() cy.get('[data-cy="abort-print-button"]').should('be.visible') + return kmlID } it('should send a print request to mapfishprint (with layers added)', () => { @@ -304,9 +304,10 @@ describe('Testing print', () => { }) }) it('should send a print request correctly to mapfishprint (with KML layer)', () => { - const zoom = 13 - startPrintWithKml('import-tool/external-kml-file.kml', zoom) - checkZoom(zoom) + const customZoom = 13 + const kmlID = startPrintWithKml('import-tool/external-kml-file.kml', customZoom) + checkZoom(customZoom) + cy.checkOlLayer(['test.background.layer2', kmlID]) cy.wait('@printRequest').then((interception) => { expect(interception.request.body).to.haveOwnProperty('layout') @@ -440,8 +441,9 @@ describe('Testing print', () => { /** We need to ensure the structure of the query sent is correct */ it('should send a print request correctly to mapfishprint (icon and label)', () => { const customZoom = 13 - startPrintWithKml('print/label.kml', customZoom) + const kmlID = startPrintWithKml('print/label.kml', customZoom) checkZoom(customZoom) + cy.checkOlLayer(['test.background.layer2', kmlID]) cy.wait('@printRequest').then((interception) => { expect(interception.request.body).to.haveOwnProperty('layout') @@ -514,7 +516,7 @@ describe('Testing print', () => { }) it('should send a print request correctly to mapfishprint (KML from old geoadmin)', () => { const customZoom = 13 - startPrintWithKml('print/old-geoadmin-label.kml', customZoom) + const kmlID = startPrintWithKml('print/old-geoadmin-label.kml', customZoom) checkZoom(customZoom) @@ -528,6 +530,8 @@ describe('Testing print', () => { expect(center[1]).to.eq(1203250) }) + cy.checkOlLayer(['test.background.layer2', kmlID]) + cy.wait('@printRequest').then((interception) => { expect(interception.request.body).to.haveOwnProperty('layout') expect(interception.request.body).to.haveOwnProperty('format') From 6e44ca5a326aa167918d8250316e85527b932937 Mon Sep 17 00:00:00 2001 From: Ismail Sunni Date: Thu, 19 Sep 2024 10:45:01 +0700 Subject: [PATCH 12/23] PB-878: Add wait (test only, removed later). --- tests/cypress/tests-e2e/print.cy.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/cypress/tests-e2e/print.cy.js b/tests/cypress/tests-e2e/print.cy.js index fc6027fc5..3ad77bd17 100644 --- a/tests/cypress/tests-e2e/print.cy.js +++ b/tests/cypress/tests-e2e/print.cy.js @@ -309,6 +309,10 @@ describe('Testing print', () => { checkZoom(customZoom) cy.checkOlLayer(['test.background.layer2', kmlID]) + // 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('@printRequest').then((interception) => { expect(interception.request.body).to.haveOwnProperty('layout') expect(interception.request.body['layout']).to.equal('1. A4 landscape') From a75cdc22c5f445f2e7751be7fd6ec49a3c6bfedc Mon Sep 17 00:00:00 2001 From: Ismail Sunni Date: Thu, 19 Sep 2024 11:05:49 +0700 Subject: [PATCH 13/23] PB-878: Add render check on checkOlLayer. --- tests/cypress/support/commands.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/cypress/support/commands.js b/tests/cypress/support/commands.js index 70b299460..bab09c7f2 100644 --- a/tests/cypress/support/commands.js +++ b/tests/cypress/support/commands.js @@ -877,6 +877,8 @@ Cypress.Commands.add('checkOlLayer', (args = null) => { description: `[${layer.id}] waitUntil layer.rendered`, 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 }) }) invisibleLayers.forEach((layer) => { From b4c8e6094201df52ed255f1a38f8c662f3cb2543 Mon Sep 17 00:00:00 2001 From: Ismail Sunni Date: Thu, 19 Sep 2024 13:58:38 +0700 Subject: [PATCH 14/23] PB-878: Check if there are features and the extent is correct. --- tests/cypress/support/commands.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/cypress/support/commands.js b/tests/cypress/support/commands.js index bab09c7f2..1c9dbf373 100644 --- a/tests/cypress/support/commands.js +++ b/tests/cypress/support/commands.js @@ -879,6 +879,15 @@ Cypress.Commands.add('checkOlLayer', (args = null) => { }) 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) => { From aafb7ae0193f242d1a540a9ceb9cc6cba0a8b32b Mon Sep 17 00:00:00 2001 From: Ismail Sunni Date: Thu, 19 Sep 2024 14:31:38 +0700 Subject: [PATCH 15/23] PB-878: remove check on rendering. --- tests/cypress/support/commands.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cypress/support/commands.js b/tests/cypress/support/commands.js index 1c9dbf373..4ae218ec6 100644 --- a/tests/cypress/support/commands.js +++ b/tests/cypress/support/commands.js @@ -878,7 +878,7 @@ 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 + // 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()}`) From 252fe6adcaac21755d27dbca08c5c83b2088a306 Mon Sep 17 00:00:00 2001 From: Ismail Sunni Date: Wed, 2 Oct 2024 15:24:48 +0700 Subject: [PATCH 16/23] PB-878: Log the layer type. --- tests/cypress/tests-e2e/print.cy.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/cypress/tests-e2e/print.cy.js b/tests/cypress/tests-e2e/print.cy.js index 3ad77bd17..f529b961a 100644 --- a/tests/cypress/tests-e2e/print.cy.js +++ b/tests/cypress/tests-e2e/print.cy.js @@ -334,6 +334,8 @@ describe('Testing print', () => { const layers = mapAttributes.layers expect(layers).to.be.an('array') + cy.log('Layers:', layers) + cy.log('Layer 1:', 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) From d42330012c90ebbd42893ab5b0aa4f5e345e7f1a Mon Sep 17 00:00:00 2001 From: Ismail Sunni Date: Wed, 2 Oct 2024 16:12:58 +0700 Subject: [PATCH 17/23] PB-878: More cy.log to see the failed layer. --- tests/cypress/tests-e2e/print.cy.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/cypress/tests-e2e/print.cy.js b/tests/cypress/tests-e2e/print.cy.js index f529b961a..c1e9a52ef 100644 --- a/tests/cypress/tests-e2e/print.cy.js +++ b/tests/cypress/tests-e2e/print.cy.js @@ -335,7 +335,8 @@ describe('Testing print', () => { const layers = mapAttributes.layers expect(layers).to.be.an('array') cy.log('Layers:', layers) - cy.log('Layer 1:', layers[0]['type']) + 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) @@ -420,6 +421,8 @@ describe('Testing print', () => { 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) // In this GPX layer, htere are two features (a line and a point). @@ -474,6 +477,8 @@ describe('Testing print', () => { 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) const geoJsonLayer = layers[0] @@ -561,6 +566,8 @@ describe('Testing print', () => { 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) const geoJsonLayer = layers[0] From 487ff1edfeee81d91f9423cc2125d9ed02fbc2ab Mon Sep 17 00:00:00 2001 From: Ismail Sunni Date: Mon, 7 Oct 2024 11:55:58 +0700 Subject: [PATCH 18/23] PB-878: Try with import file to load KML. --- tests/cypress/tests-e2e/print.cy.js | 90 +++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/tests/cypress/tests-e2e/print.cy.js b/tests/cypress/tests-e2e/print.cy.js index c1e9a52ef..781223466 100644 --- a/tests/cypress/tests-e2e/print.cy.js +++ b/tests/cypress/tests-e2e/print.cy.js @@ -349,6 +349,96 @@ describe('Testing print', () => { expect(layers[0]['style']).to.haveOwnProperty("[_mfp_style = '1']") }) }) + it('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() From d508afabe910060e872315dc87439869fbe21ee1 Mon Sep 17 00:00:00 2001 From: Ismail Sunni Date: Mon, 7 Oct 2024 12:08:59 +0700 Subject: [PATCH 19/23] PB-878: Skip duplicated test. --- tests/cypress/tests-e2e/print.cy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cypress/tests-e2e/print.cy.js b/tests/cypress/tests-e2e/print.cy.js index 781223466..0c8dc6862 100644 --- a/tests/cypress/tests-e2e/print.cy.js +++ b/tests/cypress/tests-e2e/print.cy.js @@ -349,7 +349,7 @@ describe('Testing print', () => { expect(layers[0]['style']).to.haveOwnProperty("[_mfp_style = '1']") }) }) - it('should send a print request correctly to mapfishprint (with KML layer) - with import layer', () => { + it.skip('should send a print request correctly to mapfishprint (with KML layer) - with import layer', () => { interceptPrintRequest() interceptPrintStatus() interceptDownloadReport() From 25fcbc6f27782c6fff86e6be3dff6a8504a25da1 Mon Sep 17 00:00:00 2001 From: Ismail Sunni Date: Mon, 7 Oct 2024 12:40:06 +0700 Subject: [PATCH 20/23] PB-878: Fix import issue on runt unit test. --- src/api/__tests__/print.api.spec.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/api/__tests__/print.api.spec.js b/src/api/__tests__/print.api.spec.js index d5778d077..2f4f5ffac 100644 --- a/src/api/__tests__/print.api.spec.js +++ b/src/api/__tests__/print.api.spec.js @@ -2,13 +2,14 @@ import { expect } from 'chai' import { describe, it } from 'vitest' -import { PrintLayout, PrintLayoutAttribute } from '@/api/print.api.js' -import { PRINT_DPI_COMPENSATION } from '@/config/print.config' // We need to import the router here to avoid error when initializing router plugins, this is // needed since some store plugins might require access to router to get the query parameters // (e.g. topic management plugin) import router from '@/router' // eslint-disable-line no-unused-vars import store from '@/store' // eslint-disable-line no-unused-vars + +import { PrintLayout, PrintLayoutAttribute } from '@/api/print.api.js' +import { PRINT_DPI_COMPENSATION } from '@/config/print.config' import { adjustWidth } from '@/utils/styleUtils' describe('Print API unit tests', () => { From 4f8316eeae2e52dc0f05b6aad8e97d83166c16dd Mon Sep 17 00:00:00 2001 From: Ismail Sunni Date: Mon, 7 Oct 2024 12:54:56 +0700 Subject: [PATCH 21/23] PB-878: Tidy up code. --- tests/cypress/support/commands.js | 10 -- tests/cypress/tests-e2e/print.cy.js | 182 ++++++++++++++-------------- 2 files changed, 91 insertions(+), 101 deletions(-) diff --git a/tests/cypress/support/commands.js b/tests/cypress/support/commands.js index 4ae218ec6..24040db19 100644 --- a/tests/cypress/support/commands.js +++ b/tests/cypress/support/commands.js @@ -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) => { diff --git a/tests/cypress/tests-e2e/print.cy.js b/tests/cypress/tests-e2e/print.cy.js index 0c8dc6862..c9cf0bdf7 100644 --- a/tests/cypress/tests-e2e/print.cy.js +++ b/tests/cypress/tests-e2e/print.cy.js @@ -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') @@ -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() From 70eb9d9649916300c60ae307bb1ebb00eff38669 Mon Sep 17 00:00:00 2001 From: Ismail Sunni Date: Mon, 7 Oct 2024 13:41:14 +0700 Subject: [PATCH 22/23] PB-878: Re-enable test with import layer. --- tests/cypress/tests-e2e/print.cy.js | 182 ++++++++++++++-------------- 1 file changed, 91 insertions(+), 91 deletions(-) diff --git a/tests/cypress/tests-e2e/print.cy.js b/tests/cypress/tests-e2e/print.cy.js index c9cf0bdf7..f18a80c83 100644 --- a/tests/cypress/tests-e2e/print.cy.js +++ b/tests/cypress/tests-e2e/print.cy.js @@ -303,7 +303,7 @@ describe('Testing print', () => { expect(layers[0]['matrices'][0]['matrixSize']).to.deep.eq([1, 1]) }) }) - it('should send a print request correctly to mapfishprint (with KML layer)', () => { + it.skip('should send a print request correctly to mapfishprint (with KML layer)', () => { const customZoom = 13 const kmlID = startPrintWithKml('import-tool/external-kml-file.kml', customZoom) checkZoom(customZoom) @@ -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('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() From 2f20e4a07ed84ca08c90cb27c3e3b891e57b8a51 Mon Sep 17 00:00:00 2001 From: Ismail Sunni Date: Mon, 7 Oct 2024 15:57:09 +0700 Subject: [PATCH 23/23] PB-878: Remove unused comment. --- tests/cypress/tests-e2e/print.cy.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/cypress/tests-e2e/print.cy.js b/tests/cypress/tests-e2e/print.cy.js index f18a80c83..cf194c845 100644 --- a/tests/cypress/tests-e2e/print.cy.js +++ b/tests/cypress/tests-e2e/print.cy.js @@ -309,10 +309,6 @@ describe('Testing print', () => { checkZoom(customZoom) cy.checkOlLayer(['test.background.layer2', kmlID]) - // 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('@printRequest').then((interception) => { expect(interception.request.body).to.haveOwnProperty('layout') expect(interception.request.body['layout']).to.equal('1. A4 landscape')