diff --git a/public/serv-nero.png b/public/serv-nero.png
new file mode 100644
index 0000000..041c65b
Binary files /dev/null and b/public/serv-nero.png differ
diff --git a/src/referto.js b/src/referto.js
index c2a59cf..5524804 100644
--- a/src/referto.js
+++ b/src/referto.js
@@ -34,11 +34,11 @@ export function buildRefertoHtml(state, now = new Date()) {
return `
- A
+ Casa
${nomi.home}
vs
${nomi.guest}
- B
+ Ospiti
@@ -195,7 +204,7 @@ export function buildRefertoHtml(state, now = new Date()) {
- | Set | A | B |
+ | Set | ${nomi.home} | ${nomi.guest} |
${risultatoSetHtml}
Vince ${setVinti.home >= setVinti.guest ? nomi.home : nomi.guest} ${setVinti.home} – ${setVinti.guest}
@@ -219,5 +228,7 @@ export function generaReferto(state) {
const w = window.open('', '_blank')
w.document.write(html)
w.document.close()
- w.print()
+ // Aspetta il caricamento delle immagini (icona servizio) prima di stampare,
+ // altrimenti la stampa parte con risorse ancora in caricamento e appaiono vuote.
+ w.addEventListener('load', () => w.print())
}
diff --git a/tests/component/referto-generaReferto.test.js b/tests/component/referto-generaReferto.test.js
index 189cd11..be9a6a9 100644
--- a/tests/component/referto-generaReferto.test.js
+++ b/tests/component/referto-generaReferto.test.js
@@ -11,10 +11,12 @@ describe('generaReferto (referto.js)', () => {
vi.restoreAllMocks()
})
- it('apre una nuova scheda, scrive il referto e avvia la stampa', () => {
+ it('apre una nuova scheda, scrive il referto e avvia la stampa dopo il caricamento', () => {
+ const listeners = {}
const popup = {
document: { write: vi.fn(), close: vi.fn() },
print: vi.fn(),
+ addEventListener: vi.fn((evt, cb) => { listeners[evt] = cb }),
}
const openSpy = vi.spyOn(window, 'open').mockReturnValue(popup)
@@ -26,6 +28,9 @@ describe('generaReferto (referto.js)', () => {
expect(popup.document.write).toHaveBeenCalledTimes(1)
expect(popup.document.write.mock.calls[0][0]).toContain('Antoniana')
expect(popup.document.close).toHaveBeenCalledTimes(1)
+ expect(popup.print).not.toHaveBeenCalled()
+
+ listeners.load()
expect(popup.print).toHaveBeenCalledTimes(1)
})
})