first commit
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
import { expect, test } from "bun:test";
|
||||
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { compileWireFile } from "@wrnexus/compiler";
|
||||
import { mountHtml } from "@wrnexus/test";
|
||||
|
||||
const root = join(import.meta.dir, "..");
|
||||
const packagePages = join(root, "app", "pages", "packages");
|
||||
const expected = [
|
||||
"ai",
|
||||
"authz",
|
||||
"cli",
|
||||
"compiler",
|
||||
"core",
|
||||
"csr",
|
||||
"db",
|
||||
"dev-server",
|
||||
"encryption",
|
||||
"i18n",
|
||||
"jwt",
|
||||
"mobile",
|
||||
"native",
|
||||
"oauth",
|
||||
"pubsub",
|
||||
"queue",
|
||||
"reactive",
|
||||
"router",
|
||||
"ssr",
|
||||
"styles",
|
||||
"test",
|
||||
"tracking",
|
||||
"ui",
|
||||
"uploader",
|
||||
"validation",
|
||||
];
|
||||
|
||||
test("generates one detailed page for every published package", () => {
|
||||
const generated = readdirSync(packagePages)
|
||||
.filter((file) => file.endsWith(".wrn"))
|
||||
.map((file) => file.replace(/\.wrn$/, ""))
|
||||
.sort();
|
||||
expect(generated).toEqual([...expected].sort());
|
||||
});
|
||||
|
||||
test("every package page contains installation, guide, and complete API sections", () => {
|
||||
for (const name of expected) {
|
||||
const source = readFileSync(join(packagePages, `${name}.wrn`), "utf8");
|
||||
expect(source).toContain(`bun add @wrnexus/${name}@0.2.12`);
|
||||
expect(source).toContain('id="guide"');
|
||||
expect(source).toContain('id="api"');
|
||||
expect(source).toContain("Complete TypeScript API");
|
||||
expect(source).toContain('class="on-this-page"');
|
||||
expect(source).toContain('id="examples"');
|
||||
expect(source).toContain('class="example-card"');
|
||||
}
|
||||
});
|
||||
|
||||
test("site includes core guides and production configuration", () => {
|
||||
for (const route of [
|
||||
"index.wrn",
|
||||
"packages.wrn",
|
||||
"getting-started.wrn",
|
||||
"language.wrn",
|
||||
"architecture.wrn",
|
||||
]) {
|
||||
expect(existsSync(join(root, "app", "pages", route))).toBe(true);
|
||||
}
|
||||
expect(readFileSync(join(root, "wrnexus.config.ts"), "utf8")).toContain(
|
||||
"WRNexusJS Documentation",
|
||||
);
|
||||
});
|
||||
|
||||
test("language reference covers directives, events, loops, and conditionals", () => {
|
||||
const source = readFileSync(join(root, "app", "pages", "language.wrn"), "utf8");
|
||||
for (const section of [
|
||||
"events",
|
||||
"directives",
|
||||
"conditionals",
|
||||
"loops",
|
||||
"components",
|
||||
"forms",
|
||||
"realtime",
|
||||
"native",
|
||||
]) {
|
||||
expect(source).toContain(`id="${section}"`);
|
||||
}
|
||||
expect(source).toContain("data-show");
|
||||
expect(source).toContain("@mobile-click");
|
||||
});
|
||||
|
||||
test("package index includes searchable category filters", () => {
|
||||
const source = readFileSync(join(root, "app", "pages", "packages.wrn"), "utf8");
|
||||
expect(source).toContain('state category = "All"');
|
||||
expect(source).toContain("category = 'Security'");
|
||||
expect(source).toContain("category = 'Native'");
|
||||
expect(source).toContain("category === 'All'");
|
||||
expect(source).not.toContain("category === 'All' ||");
|
||||
expect(source).not.toContain(") && (query");
|
||||
expect(source.match(/class="package-card"/g)).toHaveLength(25);
|
||||
});
|
||||
|
||||
test("clicking a category hides packages from other categories", async () => {
|
||||
const source = readFileSync(join(root, "app", "pages", "packages.wrn"), "utf8");
|
||||
const directory = join(tmpdir(), "wrnexus-doc-tests");
|
||||
mkdirSync(directory, { recursive: true });
|
||||
const modulePath = join(directory, `packages-${Date.now()}.ts`);
|
||||
writeFileSync(modulePath, compileWireFile(source));
|
||||
const page = (await import(pathToFileURL(modulePath).href)).default as () => string;
|
||||
const mounted = mountHtml(page());
|
||||
const dataButton = mounted
|
||||
.querySelectorAll(".category-row button")
|
||||
.find((button) => button.textContent?.startsWith("Data"));
|
||||
expect(dataButton).toBeDefined();
|
||||
(dataButton as HTMLElement).click();
|
||||
const visible = mounted
|
||||
.querySelectorAll(".package-card")
|
||||
.filter((card) => (card as HTMLElement).style.display !== "none")
|
||||
.map((card) => card.getAttribute("href"));
|
||||
expect(visible).toEqual(["/packages/db", "/packages/queue", "/packages/uploader"]);
|
||||
});
|
||||
Reference in New Issue
Block a user