test(frontend): add vitest test suite and apply code formatting

This commit is contained in:
zwitschi committed 2026-08-07 16:05:02 +02:00
1 parent e4ffa0b356
commit 6632df0bc7
23 files changed
+2209 -815

No files matched your search

+8 -30
View File
@@ -32,24 +32,16 @@ function resolveWebSocketBaseUrl() {
function resolveManifestUrl() {
const configuredUrl = import.meta.env.VITE_PUBLIC_HLS_URL?.trim();
const cacheBust = `stream=${Date.now()}`;
const sameOriginManifestUrl = new URL(
"/hls/playlist.m3u8",
window.location.origin,
);
const sameOriginManifestUrl = new URL("/hls/playlist.m3u8", window.location.origin);
sameOriginManifestUrl.searchParams.set("stream", cacheBust);
const allowCrossOriginManifest =
import.meta.env.VITE_PUBLIC_HLS_CROSS_ORIGIN?.trim().toLowerCase() ===
"true";
const allowCrossOriginManifest = import.meta.env.VITE_PUBLIC_HLS_CROSS_ORIGIN?.trim().toLowerCase() === "true";
if (configuredUrl) {
const manifestUrl = new URL(configuredUrl);
manifestUrl.searchParams.set("stream", cacheBust);
if (
!allowCrossOriginManifest &&
manifestUrl.origin !== window.location.origin
) {
if (!allowCrossOriginManifest && manifestUrl.origin !== window.location.origin) {
return sameOriginManifestUrl.toString();
}
@@ -96,12 +88,7 @@ function connectWebSocket(room: string) {
};
}
function addMessage(
type: string,
text: string,
sender = "",
timestamp = new Date(),
) {
function addMessage(type: string, text: string, sender = "", timestamp = new Date()) {
const messages = document.getElementById("messages")!;
const div = document.createElement("div");
div.className = "message-row";
@@ -110,9 +97,7 @@ function addMessage(
div.classList.add("message-system-row");
div.innerHTML = `<div class="message-system">${text}</div>`;
} else {
div.classList.add(
sender === username ? "message-self-row" : "message-other-row",
);
div.classList.add(sender === username ? "message-self-row" : "message-other-row");
div.innerHTML = `
<article class="message-bubble ${sender === username ? "message-self" : "message-other"}">
${sender && sender !== username ? `<div class="message-sender">${sender}</div>` : ""}
@@ -131,10 +116,7 @@ function renderPresence() {
if (!list) return;
const sorted = [...onlineUsers].sort();
list.innerHTML = sorted
.map(
(u) =>
`<span class="presence-dot" title="${u}"><span class="presence-indicator"></span>${u}</span>`,
)
.map((u) => `<span class="presence-dot" title="${u}"><span class="presence-indicator"></span>${u}</span>`)
.join("");
}
@@ -185,9 +167,7 @@ async function initPlayerAndChat() {
refreshSchedule();
setInterval(refreshSchedule, 30000);
console.log(
"Linear Void Frontend initialized - HLS Player + Chat Sidebar ready",
);
console.log("Linear Void Frontend initialized - HLS Player + Chat Sidebar ready");
}
function toggleChatPanel() {
@@ -220,9 +200,7 @@ function sendMessage() {
function switchRoom(room: string) {
currentRoom = room;
document.getElementById("room-name")!.textContent =
room === "main"
? "Main Channel"
: room.charAt(0).toUpperCase() + room.slice(1) + " Room";
room === "main" ? "Main Channel" : room.charAt(0).toUpperCase() + room.slice(1) + " Room";
addMessage("system", `Switched to ${room} room`);
connectWebSocket(room);
}