Files

49 lines
1.9 KiB
JavaScript

#!/usr/bin/env node
// Test dei dati finti del prototipo: ruoli coerenti e conteggi che tornano.
const fs = require('fs');
const path = require('path');
const src = fs.readFileSync(path.join(__dirname, '..', 'qml', 'js', 'dati.js'), 'utf8');
eval(src);
let fail = 0;
function check(cond, msg) {
if (!cond) { console.log('FALLITO:', msg); fail++; }
}
// ogni cartella dichiarata esiste in MESSAGES (o e' un account)
MAILBOXES.forEach(m => {
if (m.kind === 'account') return;
check(MESSAGES.hasOwnProperty(m.mailbox), 'cartella senza messaggi: ' + m.mailbox);
});
// i ruoli letti dai delegate devono esserci sempre: un undefined in QML e'
// una riga vuota che nessun lint vede.
const ROLE_KEYS = ['sender', 'address', 'subject', 'date', 'unread',
'junk', 'attachment', 'body'];
for (const box in MESSAGES) {
MESSAGES[box].forEach((msg, i) => {
ROLE_KEYS.forEach(k => {
check(msg.hasOwnProperty(k), `${box}[${i}] manca il ruolo ${k}`);
});
check(typeof msg.unread === 'boolean', `${box}[${i}] unread non booleano`);
});
}
// i non letti dell'account devono essere la somma delle sue cartelle
const acc1 = MAILBOXES.find(m => m.name === 'carlo@example.org');
const somma1 = unreadOf('in') + unreadOf('draft') + unreadOf('junk');
check(acc1.unread === somma1, `non letti account ${acc1.unread} != somma ${somma1}`);
const acc2 = MAILBOXES.find(m => m.name === 'progetti@example.net');
check(acc2.unread === unreadOf('p-in'), 'non letti del secondo account');
check(totalUnread() === acc1.unread + acc2.unread, 'totale non letti');
// casi limite usati dalle schermate
check(messagesOf('trash').length === 0, 'trash deve essere vuota nel prototipo');
check(messagesOf('non-esiste').length === 0, 'cartella inesistente = lista vuota');
console.log(fail === 0 ? 'OK: dati coerenti' : `${fail} controlli falliti`);
process.exit(fail === 0 ? 0 : 1);