Fusion #69 : Alertes unifiées (panneau + pastille, agrégation à la demande) #39
@@ -0,0 +1,82 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* ObsiGate — Alertes unifiées (Fusion #69, chantier 2).
|
||||
*
|
||||
* Tests du module partagé frontend/draco-alertes.js (logique pure,
|
||||
* sans DOM) + vérification du gabarit livré frontend/index.html :
|
||||
* le placeholder « Alertes unifiées : arrive avec la fédération »
|
||||
* a disparu et le module est chargé.
|
||||
*
|
||||
* Usage: node tests/frontend/draco-alertes.test.mjs
|
||||
*/
|
||||
import test from "node:test";
|
||||
import { strict as assert } from "node:assert";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { createRequire } from "node:module";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const REPO_ROOT = path.resolve(__dirname, "..", "..");
|
||||
const require = createRequire(import.meta.url);
|
||||
const t = require(path.join(REPO_ROOT, "frontend", "draco-alertes.js"));
|
||||
|
||||
test("resolveUrls: config explicite > hote -dev > href > defaut prod", () => {
|
||||
assert.equal(
|
||||
t.resolveUrls({ hostname: "og.dracodev.net", tabHrefs: {} }).tiktak,
|
||||
"https://tiktak.dracodev.net/"
|
||||
);
|
||||
assert.equal(
|
||||
t.resolveUrls({ hostname: "og-dev.dracodev.net", tabHrefs: {} }).flowdeck,
|
||||
"https://flowdeck-dev.dracodev.net/"
|
||||
);
|
||||
assert.equal(
|
||||
t.resolveUrls({
|
||||
hostname: "og-dev.dracodev.net",
|
||||
configUrls: { kanbante: "https://kanbante.dracodev.net/" },
|
||||
}).kanbante,
|
||||
"https://kanbante.dracodev.net/"
|
||||
);
|
||||
assert.equal(t.isDevHost("og-dev.dracodev.net.evil.com"), false);
|
||||
});
|
||||
|
||||
test("normalizeFlowdeck/TikTak/Kanbante: actifs = non lus, Kanbante jamais actif", () => {
|
||||
const fd = t.normalizeFlowdeck("https://flowdeck.dracodev.net/", {
|
||||
notifications: [
|
||||
{ id: 1, ntype: "mention", title: "Mention", message: "m", url: "/collections/3", is_read: 0, created_at: "2026-10-28T10:00:00" },
|
||||
],
|
||||
unread: 1,
|
||||
});
|
||||
assert.equal(fd[0].active, true);
|
||||
assert.equal(fd[0].url, "https://flowdeck.dracodev.net/collections/3");
|
||||
const tt = t.normalizeTiktak("https://tiktak.dracodev.net/", [
|
||||
{ id: 7, kind: "reminder", title: "Rappel", body: "", task_id: 42, is_read: 0, created_at: "2026-10-28T08:00:00" },
|
||||
]);
|
||||
assert.equal(tt[0].url, "https://tiktak.dracodev.net/?task=42");
|
||||
const kb = t.normalizeKanbante("https://kanbante.dracodev.net/", {
|
||||
events: [
|
||||
{ id: 9, repo_full_name: "Projets/fusion-trois-apps", issue_number: 69, event_type: "commented", from_column: "", to_column: "", created_at: "2026-10-28T11:50:00" },
|
||||
],
|
||||
});
|
||||
assert.equal(kb[0].active, false);
|
||||
assert.equal(kb[0].url, "https://kanbante.dracodev.net/board/Projets/fusion-trois-apps");
|
||||
assert.equal(t.countActive([...fd, ...tt, ...kb]), 2);
|
||||
});
|
||||
|
||||
test("sortAlerts: actives d'abord, date decroissante", () => {
|
||||
const sorted = t.sortAlerts([
|
||||
{ app: "tiktak", active: false, date: "2026-10-28T12:00:00" },
|
||||
{ app: "flowdeck", active: true, date: "2026-10-26T12:00:00" },
|
||||
{ app: "flowdeck", active: true, date: "2026-10-28T12:00:00" },
|
||||
]);
|
||||
assert.equal(sorted[0].active, true);
|
||||
assert.equal(sorted[0].date, "2026-10-28T12:00:00");
|
||||
});
|
||||
|
||||
test("index.html: placeholder Alertes disparu, module charge", () => {
|
||||
const html = readFileSync(path.join(REPO_ROOT, "frontend", "index.html"), "utf8");
|
||||
assert.equal(html.includes("Alertes unifiées : arrive avec la fédération"), false);
|
||||
assert.equal(html.includes("/static/draco-alertes.js"), true);
|
||||
assert.equal(html.includes("/static/draco-alertes.css"), true);
|
||||
assert.equal(html.includes("DRACO_ALERTES.open()"), true);
|
||||
});
|
||||
Reference in New Issue
Block a user