feat: add dashboard persistence store
This commit is contained in:
parent
5eeec0dcb5
commit
5e42ee8869
18 changed files with 1181 additions and 19 deletions
42
src/lib/server/dashboard.test.ts
Normal file
42
src/lib/server/dashboard.test.ts
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue