|
1 | 1 | // @ts-check |
2 | 2 | import { test, expect } from '@playwright/test'; |
| 3 | +import {PrintPage} from "./pages/printpage"; |
3 | 4 | import { gotoMap, expectParametersToContain, getAuthStorageStatePath, expectToHaveLengthCompare } from './globals'; |
4 | 5 |
|
5 | 6 | test.describe('Print', () => { |
@@ -335,6 +336,153 @@ test.describe('Print', () => { |
335 | 336 | }); |
336 | 337 | }); |
337 | 338 |
|
| 339 | +test.describe( |
| 340 | + 'Print opacities', |
| 341 | + { |
| 342 | + tag: ['@readonly'], |
| 343 | + },() => |
| 344 | + { |
| 345 | + |
| 346 | + test('Group as layer', async ({ page }) => { |
| 347 | + |
| 348 | + const printPage = new PrintPage(page, 'group_as_layer_opacity'); |
| 349 | + await printPage.open(); |
| 350 | + await printPage.openPrintPanel(); |
| 351 | + await printPage.setPrintScale('50000'); |
| 352 | + |
| 353 | + // set opacity of `Group_opacity` (group as layer) layer to 60% |
| 354 | + await printPage.setLayerOpacity('Group_opacity','60'); |
| 355 | + |
| 356 | + // opacity notes: |
| 357 | + // the `raster` layer already has 80% opacity (inherited from QGIS project) |
| 358 | + // setting the opacity to 60% on the `Group_opacity` causes: |
| 359 | + // - `raster` layer to have a final total opacity of 48% (0.8*0.6) |
| 360 | + // -> OPACITIES PARAM = 255*0.48 ~= 122 |
| 361 | + // - `single_wms_polygons` layer to have a final total opacity of 60% (1*0.6) |
| 362 | + // -> OPACITIES PARAM = 255*0.6 = 153 |
| 363 | + // other layers have opacity 100% (255) |
| 364 | + |
| 365 | + const mapLayers = [ |
| 366 | + 'OpenStreetMap', |
| 367 | + 'raster', |
| 368 | + 'single_wms_polygons', |
| 369 | + 'single_wms_polygons_group_as_layer', |
| 370 | + 'single_wms_points_group', |
| 371 | + ] |
| 372 | + |
| 373 | + const expectedParameters = { |
| 374 | + 'SERVICE': 'WMS', |
| 375 | + 'REQUEST': 'GetPrint', |
| 376 | + 'VERSION': '1.3.0', |
| 377 | + 'FORMAT': 'pdf', |
| 378 | + 'TRANSPARENT': 'true', |
| 379 | + 'CRS': 'EPSG:3857', |
| 380 | + 'DPI': '100', |
| 381 | + 'TEMPLATE': 'test', |
| 382 | + 'map0:EXTENT': /425189.\d+,5401412.\d+,439539.\d+,5411262.\d+/, |
| 383 | + 'map0:SCALE': '50000', |
| 384 | + 'map0:LAYERS': mapLayers.join(','), |
| 385 | + 'map0:STYLES': 'default,default,default,default,default', |
| 386 | + 'map0:OPACITIES': '255,122,153,255,255', |
| 387 | + } |
| 388 | + // Test `test` template |
| 389 | + let getPrintPromise = page.waitForRequest( |
| 390 | + request => |
| 391 | + request.method() === 'POST' && |
| 392 | + request.postData()?.includes('GetPrint') === true |
| 393 | + ); |
| 394 | + |
| 395 | + // Launch print |
| 396 | + await printPage.launchPrint(); |
| 397 | + |
| 398 | + // check request |
| 399 | + let getPrintRequest = await getPrintPromise; |
| 400 | + |
| 401 | + // check response parameters |
| 402 | + let name = "Group as layer opacity requests"; |
| 403 | + let getPrintParams = await expectParametersToContain( |
| 404 | + name, getPrintRequest.postData() ?? '', expectedParameters); |
| 405 | + |
| 406 | + await expectToHaveLengthCompare( |
| 407 | + name, |
| 408 | + Array.from(getPrintParams.keys()), |
| 409 | + 13, |
| 410 | + Object.keys(expectedParameters) |
| 411 | + ); |
| 412 | + }) |
| 413 | + |
| 414 | + test('Layers in group with opacity', async ({ page }) => { |
| 415 | + const printPage = new PrintPage(page, 'group_as_layer_opacity'); |
| 416 | + await printPage.open(); |
| 417 | + await printPage.openPrintPanel(); |
| 418 | + await printPage.setPrintScale('50000'); |
| 419 | + |
| 420 | + // set opacity of `Group_a` group opacity to 60% |
| 421 | + await printPage.setLayerOpacity('Group_a','60'); |
| 422 | + // set opacity of `single_wms_points_group` (belonging to `Group_a`) layer to 40% |
| 423 | + await printPage.setLayerOpacity('single_wms_points_group','40'); |
| 424 | + // set opacity of `single_wms_polygons_group_as_layer` (belonging to `Group_a`) layer to 80% |
| 425 | + await printPage.setLayerOpacity('single_wms_polygons_group_as_layer','80'); |
| 426 | + |
| 427 | + // opacity notes: |
| 428 | + // setting the opacity to 60% on `Group_a` causes: |
| 429 | + // - `single_wms_points_group` layer to have a final total opacity of 24% (0.4*0.6) |
| 430 | + // -> OPACITIES PARAM = 255*0.24 ~= 61 |
| 431 | + // - `single_wms_polygons_group_as_layer` layer to have a final total opacity of 48% (0.8*0.6) |
| 432 | + // -> OPACITIES PARAM = 255*0.48 ~= 122 |
| 433 | + // other layers have opacity 100%, except for `raster` layer which has a 80% opacity by default, |
| 434 | + // resulting in a OPACITIES PARAM = 255*0.8 = 204 |
| 435 | + |
| 436 | + const mapLayers = [ |
| 437 | + 'OpenStreetMap', |
| 438 | + 'raster', |
| 439 | + 'single_wms_polygons', |
| 440 | + 'single_wms_polygons_group_as_layer', |
| 441 | + 'single_wms_points_group', |
| 442 | + ] |
| 443 | + |
| 444 | + const expectedParameters = { |
| 445 | + 'SERVICE': 'WMS', |
| 446 | + 'REQUEST': 'GetPrint', |
| 447 | + 'VERSION': '1.3.0', |
| 448 | + 'FORMAT': 'pdf', |
| 449 | + 'TRANSPARENT': 'true', |
| 450 | + 'CRS': 'EPSG:3857', |
| 451 | + 'DPI': '100', |
| 452 | + 'TEMPLATE': 'test', |
| 453 | + 'map0:EXTENT': /425189.\d+,5401412.\d+,439539.\d+,5411262.\d+/, |
| 454 | + 'map0:SCALE': '50000', |
| 455 | + 'map0:LAYERS': mapLayers.join(','), |
| 456 | + 'map0:STYLES': 'default,default,default,default,default', |
| 457 | + 'map0:OPACITIES': '255,204,255,122,61', |
| 458 | + } |
| 459 | + // Test `test` template |
| 460 | + let getPrintPromise = page.waitForRequest( |
| 461 | + request => |
| 462 | + request.method() === 'POST' && |
| 463 | + request.postData()?.includes('GetPrint') === true |
| 464 | + ); |
| 465 | + |
| 466 | + // Launch print |
| 467 | + await printPage.launchPrint(); |
| 468 | + |
| 469 | + // check request |
| 470 | + let getPrintRequest = await getPrintPromise; |
| 471 | + |
| 472 | + // check response parameters |
| 473 | + let name = "Layers in group with opacity request"; |
| 474 | + let getPrintParams = await expectParametersToContain( |
| 475 | + name, getPrintRequest.postData() ?? '', expectedParameters); |
| 476 | + await expectToHaveLengthCompare( |
| 477 | + name, |
| 478 | + Array.from(getPrintParams.keys()), |
| 479 | + 13, |
| 480 | + Object.keys(expectedParameters) |
| 481 | + ); |
| 482 | + }) |
| 483 | + } |
| 484 | +); |
| 485 | + |
338 | 486 | test.describe('Print in popup', () => { |
339 | 487 | test.beforeEach(async ({ page }) => { |
340 | 488 | const url = '/index.php/view/map/?repository=testsrepository&project=print'; |
|
0 commit comments