mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-11 17:20:42 +00:00
test: simplify diffs viewer id extraction
This commit is contained in:
@@ -397,7 +397,7 @@ describe("diffs tool", () => {
|
||||
});
|
||||
|
||||
const viewerPath = String((result?.details as Record<string, unknown>).viewerPath);
|
||||
const [id] = viewerPath.split("/").filter(Boolean).slice(-2);
|
||||
const id = extractViewerArtifactId(viewerPath);
|
||||
const html = await store.readHtml(id);
|
||||
expect(html).toContain('body data-theme="light"');
|
||||
expect(html).toContain("--diffs-font-size: 17px;");
|
||||
@@ -446,7 +446,7 @@ describe("diffs tool", () => {
|
||||
expect((result?.details as Record<string, unknown>).fileScale).toBe(2.75);
|
||||
expect((result?.details as Record<string, unknown>).fileMaxWidth).toBe(1320);
|
||||
const viewerPath = String((result?.details as Record<string, unknown>).viewerPath);
|
||||
const [id] = viewerPath.split("/").filter(Boolean).slice(-2);
|
||||
const id = extractViewerArtifactId(viewerPath);
|
||||
const html = await store.readHtml(id);
|
||||
expect(html).toContain('body data-theme="dark"');
|
||||
});
|
||||
@@ -580,6 +580,22 @@ function readDetails(result: unknown): Record<string, unknown> {
|
||||
return details;
|
||||
}
|
||||
|
||||
function extractViewerArtifactId(viewerPath: string): string {
|
||||
let previousSegment: string | undefined;
|
||||
let currentSegment: string | undefined;
|
||||
for (const segment of viewerPath.split("/")) {
|
||||
if (segment.length === 0) {
|
||||
continue;
|
||||
}
|
||||
previousSegment = currentSegment;
|
||||
currentSegment = segment;
|
||||
}
|
||||
if (!previousSegment) {
|
||||
throw new Error(`Missing artifact id in viewer path: ${viewerPath}`);
|
||||
}
|
||||
return previousSegment;
|
||||
}
|
||||
|
||||
function readParametersProperties(parameters: unknown): Record<string, unknown> {
|
||||
if (isRecord(parameters) && isRecord(parameters.properties)) {
|
||||
return parameters.properties;
|
||||
|
||||
Reference in New Issue
Block a user