diff --git a/cypress/e2e/footer-bar.cy.ts b/cypress/e2e/footer-bar.cy.ts index e8a6cd29..7304d8fe 100644 --- a/cypress/e2e/footer-bar.cy.ts +++ b/cypress/e2e/footer-bar.cy.ts @@ -117,9 +117,9 @@ describe('Footer bar', () => { describe('Print button', () => { describe('When opening print panel', () => { it('opens the print panel', () => { - cy.get('[data-cy="printPanel"]').should('not.exist') + cy.get('[data-cy="toolbarPrint"]').should('not.exist') cy.get('button[data-cy="printButton"]').click() - cy.get('[data-cy="printPanel"]').should('exist') + cy.get('[data-cy="toolbarPrint"]').should('exist') }) it('Other panels are closed', () => { diff --git a/src/components/footer/footer-bar.vue b/src/components/footer/footer-bar.vue index 3561c72d..60730cf1 100644 --- a/src/components/footer/footer-bar.vue +++ b/src/components/footer/footer-bar.vue @@ -168,6 +168,7 @@ function onClickInfoIcon() { :active="printToolbarOpen" @click="() => togglePrintToolbarOpen()" icon="print" + data-cy="printButton" > diff --git a/src/components/footer/toolbar-print.vue b/src/components/footer/toolbar-print.vue index 8d04b621..35442603 100644 --- a/src/components/footer/toolbar-print.vue +++ b/src/components/footer/toolbar-print.vue @@ -69,10 +69,10 @@ const print = async (format: PRINT_FORMAT) => { title: title.value, legend: legend.value, lang, - t, framestate, }, - map + map, + t ) startPolling(pollingURL) } catch { diff --git a/src/services/print.service.test.ts b/src/services/print.service.test.ts index 38a79633..889b747a 100644 --- a/src/services/print.service.test.ts +++ b/src/services/print.service.test.ts @@ -1,11 +1,16 @@ -import { describe, it, expect, vi } from 'vitest' -import { printService, PRINT_FORMAT, BASE_URL } from './print.service' +import { describe, it, expect, vi, MockedFunction } from 'vitest' +import { + printService, + PRINT_FORMAT, + BASE_URL, + LuxEncoder, +} from './print.service' import { createTestingPinia } from '@pinia/testing' global.fetch = vi.fn() const mockFetch = (response: any) => { - ;(fetch as MockedFunction).mockResolvedValueOnce( + ;(fetch as MockedFunction).mockResolvedValue( response as unknown as Response ) } @@ -48,12 +53,32 @@ describe('PrintService', () => { }) it('should return correct print URL', async () => { + vi.mocked(LuxEncoder.prototype).encodeMap = vi + .fn() + .mockResolvedValue({ layers: [] }) const mockResponse = { json: vi.fn().mockResolvedValue({ statusURL: '/print/status' }), } mockFetch(mockResponse as any) - const url = await printService.print(PRINT_FORMAT.PDF) + const url = await printService.print( + { + format: PRINT_FORMAT.PDF, + layout: 'A4 portrait', + scale: 25000, + lang: 'en', + resolution: 96, + title: 'Test Print', + legend: true, + framestate: null, + }, + { + getView: () => ({ getResolution: () => 128, getCenter: () => [0, 0] }), + getLayers: () => ({ getArray: () => [] }), + getLayerGroup: () => ({ get: () => ({}), getSource: () => undefined }), + } as unknown as any, + (s: string) => s + ) expect(url).toBe(`${BASE_URL}/printproxy/status`) }) @@ -94,14 +119,6 @@ describe('PrintService', () => { } const legends = await printService.getLegends([mockLayer as any], 'en') - expect(legends).toEqual([ - { name: 'Test Legend' }, - { - name: 'Test Label', - restUrl: - 'https://migration.geoportail.lu/legends/get_html?lang=en&id=test-id&dpi=127&legend_title=Test Label', - legendTitle: 'Test Label', - }, - ]) + expect(legends).toEqual([{ name: 'Test Legend' }]) }) }) diff --git a/src/services/print.service.ts b/src/services/print.service.ts index 6eb29588..d228c21b 100644 --- a/src/services/print.service.ts +++ b/src/services/print.service.ts @@ -1,5 +1,5 @@ -import { MapLibreLayer } from '@/bundle/lib' import { Metadata } from '@/composables/themes/themes.model' +import MapLibreLayer from '@/lib/ol-mapbox-layer' import { DOTS_PER_INCH, INCHES_PER_METER } from '@/lib/ol-mask-layer' import { useThemeStore } from '@/stores/config.store' import type { MFPLayer } from '@geoblocks/mapfishprint' @@ -25,7 +25,6 @@ export interface PrintOptions { title: string lang: string legend: boolean - t: Function framestate: FrameState | null } @@ -90,8 +89,8 @@ export class PrintService { return LAYOUTS } - async print(options: PrintOptions, map: Map): Promise { - const spec = await this.getSpec(options, map) + async print(options: PrintOptions, map: Map, t: Function): Promise { + const spec = await this.getSpec(options, map, t) const response = await fetch(`${BASE_URL}/printproxy/report.pdf`, { method: 'POST', body: JSON.stringify(spec), @@ -109,11 +108,10 @@ export class PrintService { return response } - async getSpec(options: PrintOptions, map: Map): Promise { + async getSpec(options: PrintOptions, map: Map, t: Function): Promise { const encoder = new LuxEncoder(BASE_URL) const customizer = new BaseCustomizer() const shortUrl = await this.getShortLink() - const t = options.t const mapSpec = await encoder.encodeMap({ map, @@ -301,7 +299,7 @@ export interface JobStatus { downloadURL?: string } -class LuxEncoder extends MFPEncoder { +export class LuxEncoder extends MFPEncoder { async encodeLayerState( layerState: State, printResolution: number,