Skip to content

Commit 48a9c65

Browse files
Merge pull request #8027 from BacLuc/print-fix-empty-pages
print: fix empty pages at start and end
2 parents 59cef05 + 1aee6eb commit 48a9c65

File tree

9 files changed

+291
-14
lines changed

9 files changed

+291
-14
lines changed

e2e/cypress.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const { defineConfig } = require('cypress')
22
const { moveDownloads } = require('./tasks/moveDownloads')
33
const { deleteDownloads } = require('./tasks/deleteDownloads')
4+
const { getPdfProperties } = require('./tasks/getPdfProperties')
45

56
module.exports = defineConfig({
67
video: false,
@@ -15,6 +16,7 @@ module.exports = defineConfig({
1516
setupNodeEvents(on, config) {
1617
on('task', {
1718
deleteDownloads: () => deleteDownloads(config),
19+
getPdfProperties: async (path) => getPdfProperties(path),
1820
moveDownloads: (destSubDir) => moveDownloads(config, destSubDir),
1921
})
2022
const cypressTerminalReportOptions = {

e2e/package-lock.json

Lines changed: 210 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

e2e/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"eslint-plugin-cypress": "4.3.0",
2424
"eslint-plugin-prettier": "5.5.4",
2525
"globals": "16.3.0",
26+
"pdfjs-dist": "5.4.54",
2627
"prettier": "3.6.2"
2728
},
2829
"overrides": {

e2e/specs/clientPrint.cy.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ describe('Client print test', () => {
1414
cy.get('button:contains("PDF herunterladen (Layout #2)")').click()
1515

1616
const downloadsFolder = Cypress.config('downloadsFolder')
17-
cy.readFile(path.join(downloadsFolder, 'Pfila-2023.pdf'), {
17+
const filePath = path.join(downloadsFolder, 'Pfila-2023.pdf')
18+
cy.readFile(filePath, {
1819
timeout: 30000,
1920
})
21+
cy.getPdfProperties(filePath).its('numPages').should('eq', 18)
2022
cy.moveDownloads()
2123
})
2224
})

e2e/specs/nuxtPrint.cy.js

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,52 @@ describe('Nuxt print test', () => {
6666
})
6767
})
6868

69-
it('downloads PDF', () => {
70-
cy.task('deleteDownloads')
71-
cy.login('[email protected]')
69+
describe('downloads PDF', () => {
70+
beforeEach(() => {
71+
cy.task('deleteDownloads')
72+
cy.login('[email protected]')
73+
74+
cy.visit('/camps')
75+
cy.get('a:contains("GRGR")').click()
76+
})
77+
78+
afterEach(() => {
79+
cy.moveDownloads()
80+
})
81+
82+
it('for whole camp', () => {
83+
cy.get('a:contains("Admin")').click()
84+
cy.get('a:contains("Drucken")').click()
85+
cy.get('button:contains("PDF herunterladen (Layout #1)")').click()
7286

73-
cy.visit('/camps')
74-
cy.get('a:contains("GRGR")').click()
75-
cy.get('a:contains("Admin")').click()
76-
cy.get('a:contains("Drucken")').click()
77-
cy.get('button:contains("PDF herunterladen (Layout #1)")').click()
87+
const downloadsFolder = Cypress.config('downloadsFolder')
88+
const pdfPath = path.join(downloadsFolder, 'Pfila-2023.pdf')
89+
cy.readFile(pdfPath, {
90+
timeout: 30000,
91+
})
92+
cy.getPdfProperties(pdfPath).its('numPages').should('eq', 25)
93+
})
94+
95+
it('for picasso', () => {
96+
if (Cypress.browser.name === 'firefox') {
97+
console.log(
98+
"This test doesn't test browser specific behaviour. Firefox makes problems, thus we dont test this with firefox."
99+
)
100+
return
101+
}
102+
103+
cy.get('a:contains("Programm")').click()
104+
cy.get('[data-testid="campprogram-menu"]').click()
105+
cy.get('[role="menuitem"] :contains("PDF herunterladen (Layout #1)")')
106+
.should('be.visible')
107+
.click()
78108

79-
const downloadsFolder = Cypress.config('downloadsFolder')
80-
cy.readFile(path.join(downloadsFolder, 'Pfila-2023.pdf'), {
81-
timeout: 30000,
109+
const downloadsFolder = Cypress.config('downloadsFolder')
110+
const pdfPath = path.join(downloadsFolder, 'Pfila-2023-Hauptlager.pdf')
111+
cy.readFile(pdfPath, {
112+
timeout: 30000,
113+
})
114+
cy.getPdfProperties(pdfPath).its('numPages').should('eq', 1)
82115
})
83-
cy.moveDownloads()
84116
})
85117
})

e2e/support/commands.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ Cypress.Commands.add('moveDownloads', () => {
4040
cy.task('moveDownloads', `${Cypress.spec.name}/${Cypress.currentTest.title}`)
4141
})
4242

43+
Cypress.Commands.add('getPdfProperties', (path) => {
44+
return cy.task('getPdfProperties', path)
45+
})
46+
4347
Cypress.Commands.add('expectCacheHit', (uri) => {
4448
cy.request(Cypress.env('API_ROOT_URL_CACHED') + uri + '.jsonhal').then((response) => {
4549
const headers = response.headers

e2e/tasks/getPdfProperties.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const pdfjsLib = require('pdfjs-dist/legacy/build/pdf.mjs')
2+
const { readFileSync } = require('node:fs')
3+
4+
async function getPdfProperties(path) {
5+
const data = new Uint8Array(readFileSync(path))
6+
7+
const loadDocument = pdfjsLib.getDocument({ data: data })
8+
const pdfDocument = await loadDocument.promise
9+
return {
10+
numPages: pdfDocument.numPages,
11+
}
12+
}
13+
14+
module.exports = { getPdfProperties }

frontend/src/views/camp/CampProgram.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Show all activity schedule entries of a single period.
4444
/>
4545
<v-menu offset-y>
4646
<template #activator="{ on, attrs }">
47-
<v-btn icon v-bind="attrs" v-on="on">
47+
<v-btn icon v-bind="attrs" v-on="on" data-testid="campprogram-menu">
4848
<v-badge
4949
v-if="!$vuetify.breakpoint.smAndUp && filteredPropertiesCount > 0"
5050
overlap

print/layouts/default.vue

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,15 @@ useHead(header)
7676
padding: 0;
7777
}
7878
</style>
79+
80+
<!--
81+
Here we need to hack away 2 divs which nuxt generates,
82+
so these styles must be global.
83+
-->
84+
<!-- eslint-disable-next-line vue-scoped-css/enforce-style-type -->
85+
<style lang="scss">
86+
body > div > div.container > div:not(:has(*)),
87+
body > div#teleports {
88+
display: none;
89+
}
90+
</style>

0 commit comments

Comments
 (0)