feat: complete TASK-WP0-05 storage capacity
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>Dada 容量状态验收探针</title>
|
||||
<style>
|
||||
body { font-family: system-ui, sans-serif; margin: 32px; color: #1f2328; }
|
||||
main { max-width: 720px; }
|
||||
.bar { height: 18px; background: #d0d7de; border-radius: 4px; overflow: hidden; }
|
||||
.bar > span { display: block; height: 100%; background: #cf222e; width: 100%; }
|
||||
table { border-collapse: collapse; margin-top: 24px; width: 100%; }
|
||||
th, td { border-bottom: 1px solid #d8dee4; padding: 8px; text-align: left; }
|
||||
</style>
|
||||
</head>
|
||||
<body><main id="root"></main><script type="module" src="/tests/e2e/fixtures/storage-capacity.ts"></script></body>
|
||||
</html>
|
||||
@@ -0,0 +1,17 @@
|
||||
import { classifyCapacity, decideStorageAction } from "../../../apps/api/src/storage-policy.js";
|
||||
|
||||
const root = document.querySelector<HTMLElement>("#root");
|
||||
if (!root) throw new Error("Fixture root is missing.");
|
||||
const capacity = classifyCapacity(5_368_709_120, 0);
|
||||
const actions = ["project_json_write", "binary_write", "read", "download", "permanent_delete", "explicit_cleanup"] as const;
|
||||
root.innerHTML = `
|
||||
<h1>本机存储容量</h1>
|
||||
<p data-status>${capacity.storage_status}</p>
|
||||
<div class="bar" role="progressbar" aria-valuemin="0" aria-valuemax="5368709120" aria-valuenow="5368709120"><span></span></div>
|
||||
<table><thead><tr><th>操作</th><th>结果</th></tr></thead><tbody>
|
||||
${actions.map((action) => `<tr><td>${action}</td><td>${decideStorageAction("full", true, action)}</td></tr>`).join("")}
|
||||
</tbody></table>
|
||||
<h2>存储不可用</h2>
|
||||
<table data-unavailable><thead><tr><th>操作</th><th>SQLite 可写</th><th>SQLite 不可写</th></tr></thead><tbody>
|
||||
${actions.map((action) => `<tr><td>${action}</td><td>${decideStorageAction("unavailable", true, action)}</td><td>${decideStorageAction("unavailable", false, action)}</td></tr>`).join("")}
|
||||
</tbody></table>`;
|
||||
@@ -0,0 +1,39 @@
|
||||
import { mkdirSync } from "node:fs";
|
||||
import { resolve } from "node:path";
|
||||
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { createServer, type ViteDevServer } from "vite";
|
||||
|
||||
let vite: ViteDevServer;
|
||||
let webUrl: string;
|
||||
|
||||
test.beforeAll(async () => {
|
||||
vite = await createServer({ configFile: false, root: process.cwd(), server: { host: "127.0.0.1", port: 0 } });
|
||||
await vite.listen();
|
||||
const address = vite.httpServer?.address();
|
||||
if (!address || typeof address === "string") throw new Error("Vite did not expose a test port.");
|
||||
webUrl = `http://127.0.0.1:${address.port}`;
|
||||
});
|
||||
|
||||
test.afterAll(async () => vite.close());
|
||||
|
||||
test("TDD-WP0-STO-001 and STO-003 render the exact full action matrix", async ({ page }) => {
|
||||
await page.goto(`${webUrl}/tests/e2e/fixtures/storage-capacity.html`);
|
||||
await expect(page.getByRole("heading", { name: "本机存储容量" })).toBeVisible();
|
||||
await expect(page.locator("[data-status]")).toHaveText("full");
|
||||
await expect(page.getByRole("progressbar")).toHaveAttribute("aria-valuenow", "5368709120");
|
||||
await expect(page.locator("table").first().getByRole("row").filter({ hasText: "binary_write" })).toContainText("reject_capacity");
|
||||
await expect(page.locator("table").first().getByRole("row").filter({ hasText: "project_json_write" })).toContainText("allow");
|
||||
await expect(page.getByRole("heading", { name: "存储不可用" })).toBeVisible();
|
||||
await expect(page.locator("[data-unavailable] tr").filter({ hasText: "explicit_cleanup" })).toContainText("reject_uncommitted");
|
||||
const directory = process.env.DADA_EVIDENCE_DIR_STO_001;
|
||||
if (directory) {
|
||||
mkdirSync(resolve(directory, "screenshots"), { recursive: true });
|
||||
await page.screenshot({ path: resolve(directory, "screenshots", "capacity-bar.png") });
|
||||
}
|
||||
const unavailableDirectory = process.env.DADA_EVIDENCE_DIR_STO_003_UNAVAILABLE;
|
||||
if (unavailableDirectory) {
|
||||
mkdirSync(resolve(unavailableDirectory, "screenshots"), { recursive: true });
|
||||
await page.screenshot({ path: resolve(unavailableDirectory, "screenshots", "unavailable.png"), fullPage: true });
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user