58 lines
1.8 KiB
JavaScript
58 lines
1.8 KiB
JavaScript
"use strict";
|
|
|
|
const test = require("node:test");
|
|
const assert = require("node:assert/strict");
|
|
const {
|
|
shell,
|
|
renderLandingPage,
|
|
renderLoginPage,
|
|
renderAppPage,
|
|
renderAudioPage,
|
|
} = require("../src/views/pages");
|
|
|
|
test("shell includes daisyui and pwa tags", () => {
|
|
const html = shell({ title: "t", content: "x" });
|
|
assert.match(html, /\/assets\/styles\.css/);
|
|
assert.match(html, /manifest\.webmanifest/);
|
|
assert.match(html, /serviceWorker/);
|
|
});
|
|
|
|
test("landing page renders hero and flow sections", () => {
|
|
const html = renderLandingPage({ authenticated: false, userId: null });
|
|
assert.match(html, /Listen to X Articles/);
|
|
assert.match(html, /id="how"/);
|
|
assert.match(html, /id="pricing"/);
|
|
});
|
|
|
|
test("login page renders email and x auth forms", () => {
|
|
const html = renderLoginPage({ returnTo: "/audio/1" });
|
|
assert.match(html, /action="\/auth\/x"/);
|
|
assert.match(html, /action="\/auth\/email\/sign-in"/);
|
|
assert.match(html, /action="\/auth\/email\/sign-up"/);
|
|
assert.match(html, /name="email"/);
|
|
assert.match(html, /value="\/audio\/1"/);
|
|
});
|
|
|
|
test("app page renders stats and forms", () => {
|
|
const html = renderAppPage({
|
|
userId: "u1",
|
|
summary: { balance: 4, totalJobs: 2, totalCreditsSpent: 2 },
|
|
jobs: [{ assetId: "1", status: "completed", article: { title: "Hello" }, creditsCharged: 1 }],
|
|
});
|
|
|
|
assert.match(html, /Top Up Credits/);
|
|
assert.match(html, /Simulate Mention/);
|
|
assert.match(html, /Hello/);
|
|
});
|
|
|
|
test("audio page shows unlock action when payment is required", () => {
|
|
const html = renderAudioPage({
|
|
audio: { id: "1", storageKey: "audio/1.mp3", articleTitle: "A", durationSec: 30 },
|
|
accessDecision: { allowed: false, reason: "payment_required", creditsRequired: 3 },
|
|
userId: "u2",
|
|
});
|
|
|
|
assert.match(html, /3 credits/);
|
|
assert.match(html, /Pay & Listen/);
|
|
});
|