63 lines
2.2 KiB
TypeScript
63 lines
2.2 KiB
TypeScript
import { test, expect } from "bun:test";
|
|
import { readFileSync } from "fs";
|
|
|
|
test("dashboard parses and renders activity payload", () => {
|
|
// 1. Read dashboard.js (the transpiled JavaScript)
|
|
let code = readFileSync("server/src/dashboard.js", "utf8");
|
|
|
|
// Remove the trailing initialization calls that cause side-effects
|
|
code = code.replace("loadVersion();", "");
|
|
code = code.replace("loadActivityHistory();", "");
|
|
code = code.replace("setupWS();", "");
|
|
|
|
// 2. Mock necessary DOM and Browser globals
|
|
const context = {
|
|
window: {},
|
|
document: {
|
|
documentElement: {},
|
|
getElementById: () => null,
|
|
createElement: () => ({ classList: { add: () => {} }, prepend: () => {}, removeChild: () => {}, children: [] }),
|
|
addEventListener: () => {},
|
|
},
|
|
location: { protocol: "http:" },
|
|
MutationObserver: class { observe() {} },
|
|
vis: { DataSet: class {}, Network: class {} },
|
|
console: console,
|
|
fetch: () => Promise.resolve({ json: () => Promise.resolve({}) }),
|
|
WebSocket: class { addEventListener() {} },
|
|
setTimeout: setTimeout,
|
|
Date: Date,
|
|
localStorage: { getItem: () => null, setItem: () => {} },
|
|
};
|
|
|
|
// 3. Create a function that executes the code
|
|
const extractFn = new Function(...Object.keys(context), code + `
|
|
return {
|
|
parseActivityPayload,
|
|
handleIncomingActivity,
|
|
requestDomainRefresh
|
|
};
|
|
`);
|
|
|
|
const exports = extractFn(...Object.values(context));
|
|
|
|
// 4. Test parseActivityPayload normal case
|
|
const payload = {
|
|
category: "CODE_CHANGE",
|
|
message: "Refactored live activity UI",
|
|
};
|
|
|
|
const html = exports.parseActivityPayload(payload);
|
|
expect(html).toContain("CODE_CHANGE");
|
|
expect(html).toContain("Refactored live activity UI");
|
|
|
|
// 5. Test parseActivityPayload with resources/updated
|
|
// It should handle fallback correctly if we pass it directly
|
|
const resPayload = {
|
|
method: "notifications/resources/updated",
|
|
params: { uri: "memory://tasks/active" }
|
|
};
|
|
const htmlRes = exports.parseActivityPayload(resPayload);
|
|
expect(htmlRes).toContain("memory://tasks/active");
|
|
});
|