feat: chat — suppression de post, messages privés, boîte compacte, link preview #191
This commit is contained in:
@@ -69,10 +69,15 @@ globalThis.fetch = (url) => {
|
||||
const { initI18n } = await import(pathToFileURL(path.join(JS_DIR, "i18n.js")).href);
|
||||
await initI18n();
|
||||
|
||||
// #191 — the delete right needs a logged-in identity
|
||||
const { AuthManager } = await import(pathToFileURL(path.join(JS_DIR, "auth.js")).href);
|
||||
AuthManager.getUser = () => ({ username: "bruno", role: "user" });
|
||||
|
||||
const mod = await import("../../frontend/js/filechat.js");
|
||||
const {
|
||||
renderChatMessages, onChatMessage, openFileChat, closeFileChat, toggleFileChat,
|
||||
followFileChat, openSidebarChat, filterChatMessages, refreshUnreadBadge,
|
||||
onChatDeleted,
|
||||
} = mod;
|
||||
|
||||
let pass = 0;
|
||||
@@ -211,6 +216,68 @@ test("#190 — URL rendered as a link, surrounding text stays plain", async () =
|
||||
assert.ok(msg.textContent.includes("du texte"));
|
||||
});
|
||||
|
||||
test("#191 — preview card rendered with site/title/description", () => {
|
||||
const list = document.createElement("div");
|
||||
renderChatMessages(list, [{
|
||||
id: "p1", user: "alice", text: "voir https://example.com", ts: 40,
|
||||
preview: { url: "https://example.com", title: "Mon site", description: "Le desc", image: "", site: "example.com" },
|
||||
}], "bruno");
|
||||
const card = list.querySelector("a.file-chat-preview");
|
||||
assert.ok(card, "carte preview présente");
|
||||
assert.strictEqual(card.href, "https://example.com/");
|
||||
assert.strictEqual(card.target, "_blank");
|
||||
assert.strictEqual(card.querySelector(".file-chat-preview-title").textContent, "Mon site");
|
||||
assert.strictEqual(card.querySelector(".file-chat-preview-desc").textContent, "Le desc");
|
||||
assert.strictEqual(card.querySelector(".file-chat-preview-site").textContent, "example.com");
|
||||
renderChatMessages(list, [{ id: "p2", user: "alice", text: "https://x.test", ts: 41 }], "bruno");
|
||||
assert.strictEqual(list.querySelector("a.file-chat-preview"), null);
|
||||
});
|
||||
|
||||
test("#191 — delete button hidden without delUrl, shown for own post", () => {
|
||||
const list = document.createElement("div");
|
||||
renderChatMessages(list, [{ id: "d1", user: "bruno", text: "x", ts: 50 }], "bruno");
|
||||
assert.strictEqual(list.querySelector(".file-chat-del"), null);
|
||||
renderChatMessages(list, [{ id: "d2", user: "bruno", text: "x", ts: 51 }], "bruno", "/api/chat");
|
||||
assert.ok(list.querySelector(".file-chat-del"), "bouton suppression visible");
|
||||
renderChatMessages(list, [{ id: "d3", user: "alice", text: "x", ts: 52 }], "bruno", "/api/chat");
|
||||
assert.strictEqual(list.querySelector(".file-chat-del"), null);
|
||||
});
|
||||
|
||||
test("#191 — onChatDeleted removes the message from any list", async () => {
|
||||
await openSidebarChat();
|
||||
const list = document.getElementById("sidebar-panel-chat-list");
|
||||
onChatMessage({ vault: "__global__", path: "general", message: { id: "del1", user: "alice", text: "a bientot", ts: 60 } });
|
||||
assert.strictEqual(list.querySelector('[data-id="del1"]') !== null, true);
|
||||
onChatDeleted({ vault: "__global__", path: "general", id: "del1" });
|
||||
assert.strictEqual(list.querySelector('[data-id="del1"]'), null);
|
||||
});
|
||||
|
||||
test("#191 — unread counters accumulate then reset on open", async () => {
|
||||
localStorage.removeItem("obsigate-chat-unread");
|
||||
const panel = document.getElementById("sidebar-panel-chat");
|
||||
panel.classList.remove("active");
|
||||
onChatMessage({ vault: "__global__", path: "general", message: { id: "u-1", user: "bob", text: "1", ts: 70 } });
|
||||
onChatMessage({ vault: "__global__", path: "general", message: { id: "u-2", user: "bob", text: "2", ts: 71 } });
|
||||
let u = JSON.parse(localStorage.getItem("obsigate-chat-unread"));
|
||||
assert.strictEqual(u.general, 2);
|
||||
refreshUnreadBadge();
|
||||
assert.strictEqual(document.querySelector("#sidebar-tab-chat .chat-unread-badge").textContent, "2");
|
||||
panel.classList.add("active");
|
||||
await openSidebarChat();
|
||||
u = JSON.parse(localStorage.getItem("obsigate-chat-unread"));
|
||||
assert.strictEqual(u.general, 0);
|
||||
assert.strictEqual(document.querySelector("#sidebar-tab-chat .chat-unread-badge"), null);
|
||||
});
|
||||
|
||||
test("#191 — DM routed by pair path, isolated from general", async () => {
|
||||
const list = document.getElementById("sidebar-panel-chat-list");
|
||||
const before = list.querySelectorAll(".file-chat-msg").length;
|
||||
onChatMessage({ vault: "__dm__", path: "alice|bruno", message: { id: "dm-1", user: "alice", text: "prive", ts: 80 } });
|
||||
const u = JSON.parse(localStorage.getItem("obsigate-chat-unread"));
|
||||
assert.strictEqual(u["dm:alice"], 1);
|
||||
assert.strictEqual(list.querySelectorAll(".file-chat-msg").length, before);
|
||||
});
|
||||
|
||||
// Sequential execution: each case depends on panel state left by the previous.
|
||||
for (const [name, fn] of cases) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user