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 e2aeea3..722b546 100644 --- a/src/referto.js +++ b/src/referto.js @@ -81,6 +81,10 @@ export function buildRefertoHtml(state, now = new Date()) { const nomeVinc = vinc === 'h' ? nomi.home : vinc === 'g' ? nomi.guest : '' const etichettaVinc = nomeVinc ? `  ·  vinto da ${nomeVinc}` : '' + const servIcon = 'Servizio' + const servHomeIcon = s.serv === 'h' ? servIcon : '' + const servGuestIcon = s.serv === 'g' ? servIcon : '' + const puntiHtml = punti.map(p => `${p.h}-${p.g}` ).join('') @@ -90,7 +94,7 @@ export function buildRefertoHtml(state, now = new Date()) {
SET${i + 1}
- ${nomi.home} ${h} · ${g} ${nomi.guest}${etichettaVinc} + ${servHomeIcon}${nomi.home} ${h} · ${g} ${nomi.guest}${servGuestIcon}${etichettaVinc}
Formazione di partenza
@@ -144,6 +148,7 @@ export function buildRefertoHtml(state, now = new Date()) { .set-numero { font-weight: bold; font-size: 15px; } .set-corpo { flex: 1; min-width: 0; } .set-header { background: #eaf7fb; padding: 6px 12px; font-size: 13px; border-bottom: 1px solid #111; } + .serv-icon { width: 12px; height: 12px; vertical-align: middle; margin: 0 3px; } .punti-grid { display: flex; flex-wrap: wrap; gap: 0; padding: 0; border-top: 1px solid #111; } .punto { display: inline-flex; align-items: center; justify-content: center; min-width: 34px; padding: 3px 4px; font-size: 11px; font-family: 'Courier New', monospace; white-space: nowrap; border-right: 1px solid #ccc; border-bottom: 1px solid #ccc; } @@ -219,5 +224,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) }) })