gestion_table_tournante_libre/src/impression/imprimante_web.test.js
Mathieu Benoit 8243b7ac73 [UPD] licence: dual AGPL-3.0-or-later or LiLiQ-R+, SPDX headers
The project is offered under either licence, at the user's choice. Every
source header now carries the SPDX expression in place of the AGPL line;
the copyright line is unchanged. LICENSES/ holds both published texts,
pinned by SHA-256 and identical to the copies the page ships. The root
LICENSE becomes a short notice: the full AGPL text there would make
forges and licence scanners report the AGPL alone.
Checked: 685 header lines swapped and nothing else; node 6264, guards
207, build test 8, browser 1420, documentation verifier 0 faults.

--- FR ---

[UPD] licence : double AGPL-3.0-or-later ou LiLiQ-R+, en-têtes SPDX

Le projet est offert sous l'une ou l'autre licence, au choix de
l'utilisateur. Chaque en-tête de source porte l'expression SPDX à la place
de la ligne AGPL ; la ligne de copyright ne change pas. LICENSES/ garde les
deux textes publiés, épinglés par SHA-256 et identiques aux copies que la
page livre. LICENSE devient une courte notice : le texte AGPL entier y
ferait annoncer l'AGPL seule par les forges et les détecteurs de licence.
Vérifié : 685 lignes d'en-tête remplacées, rien d'autre ; node 6264,
gardes 207, construction 8, navigateur 1420, documentation 0 faute.

Assisted-by: Claude Opus 5.5
2026-10-20 09:02:17 -04:00

67 lines
2.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// © 2026 TechnoLibre (http://www.technolibre.ca)
// SPDX-License-Identifier: AGPL-3.0-or-later OR LiLiQ-Rplus-1.1
// L'imprimante de la plateforme web (§ 13.4, § 11.7) : la boîte de dialogue
// du navigateur, sans retour sur ce qu'elle devient. Une fenêtre factice
// compte ses appels à print.
import assert from 'node:assert/strict';
import { describe, test } from '../../test/lanceur.js';
import { PAPIERS } from '../geometrie/papiers.js';
import { creerImprimanteWeb } from './imprimante_web.js';
// Une fenêtre qui ne sait qu'imprimer, et compte ses appels.
function fenetreFactice() {
const fenetre = {
appels: 0,
print() {
fenetre.appels += 1;
},
};
return fenetre;
}
describe('imprimante web (§ 13.4)', () => {
test('imprimer appelle print une fois, et rend l’issue inconnue sans cause, pour chaque papier et chaque orientation', async () => {
for (const papier of Object.keys(PAPIERS)) {
for (const orientation of ['portrait', 'paysage']) {
const fenetre = fenetreFactice();
const issue = await creerImprimanteWeb(fenetre).imprimer({ papier, orientation });
assert.deepEqual(issue, { issue: 'inconnue', cause: null }, `${papier} ${orientation}`);
assert.equal(fenetre.appels, 1, `${papier} ${orientation}`);
}
}
});
test('chaque impression appelle print à nouveau : l’imprimante ne garde aucun état', async () => {
const fenetre = fenetreFactice();
const imprimante = creerImprimanteWeb(fenetre);
await imprimante.imprimer({ papier: 'A4', orientation: 'portrait' });
await imprimante.imprimer({ papier: 'A4', orientation: 'paysage' });
assert.equal(fenetre.appels, 2);
});
test('une option hors domaine rejette TypeError sans appeler print', async () => {
const refusees = [
{ papier: 'A3', orientation: 'portrait' },
{ papier: 'toString', orientation: 'portrait' },
{ papier: undefined, orientation: 'portrait' },
{ papier: 'A4', orientation: 'Portrait' },
{ papier: 'A4', orientation: 'landscape' },
{ papier: 'A4' },
];
for (const options of refusees) {
const fenetre = fenetreFactice();
await assert.rejects(creerImprimanteWeb(fenetre).imprimer(options), TypeError, JSON.stringify(options));
assert.equal(fenetre.appels, 0, JSON.stringify(options));
}
const fenetre = fenetreFactice();
await assert.rejects(creerImprimanteWeb(fenetre).imprimer(), TypeError);
assert.equal(fenetre.appels, 0);
});
test('une fenêtre sans print se refuse à la construction', () => {
for (const fenetre of [null, undefined, {}, { print: 'oui' }]) {
assert.throws(() => creerImprimanteWeb(fenetre), TypeError, String(fenetre));
}
});
});