42 lines
1.6 KiB
TypeScript
42 lines
1.6 KiB
TypeScript
import { rmSync } from "node:fs";
|
|
import { mkdtemp } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { afterEach, describe, expect, test } from "vitest";
|
|
import { dimensionLabDashboardFixture } from "$lib/model/fixtures/dimensionlab";
|
|
import { createDashboardStore, type DashboardStore } from "./db/dashboard-store";
|
|
import { loadDashboardRuntime } from "./dashboard";
|
|
|
|
const stores: DashboardStore[] = [];
|
|
const tempRoots: string[] = [];
|
|
|
|
afterEach(() => {
|
|
stores.splice(0).forEach((store) => store.close());
|
|
tempRoots.splice(0).forEach((path) => rmSync(path, { force: true, recursive: true }));
|
|
});
|
|
|
|
describe("dashboard runtime loader", () => {
|
|
test("seeds and loads the active dashboard from sqlite", async () => {
|
|
const store = await createTestStore();
|
|
|
|
const runtime = loadDashboardRuntime(store);
|
|
|
|
expect(runtime.title).toBe(dimensionLabDashboardFixture.metadata.title);
|
|
expect(runtime.subtitle).toBe(dimensionLabDashboardFixture.metadata.subtitle);
|
|
expect(runtime.status).toBe("building");
|
|
expect(runtime.schemaVersion).toBe(dimensionLabDashboardFixture.schemaVersion);
|
|
expect(runtime.currentRevisionId).toBe(store.getActiveDashboard()?.currentRevisionId);
|
|
expect(store.listRevisions()).toHaveLength(1);
|
|
});
|
|
});
|
|
|
|
async function createTestStore() {
|
|
const root = await mkdtemp(join(tmpdir(), "dimensionlab-dashboard-runtime-"));
|
|
tempRoots.push(root);
|
|
const store = createDashboardStore({
|
|
databaseUrl: `file:${join(root, "dashboard.sqlite")}`,
|
|
});
|
|
stores.push(store);
|
|
|
|
return store;
|
|
}
|