mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 15:14:57 +00:00
test: consolidate nodes screen helpers
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
|||||||
writeBase64ToFile,
|
writeBase64ToFile,
|
||||||
writeUrlToFile,
|
writeUrlToFile,
|
||||||
} from "./nodes-camera.js";
|
} from "./nodes-camera.js";
|
||||||
|
import { parseScreenRecordPayload, screenRecordTempPath } from "./nodes-screen.js";
|
||||||
|
|
||||||
describe("nodes camera helpers", () => {
|
describe("nodes camera helpers", () => {
|
||||||
it("parses camera.snap payload", () => {
|
it("parses camera.snap payload", () => {
|
||||||
@@ -104,3 +105,52 @@ describe("nodes camera helpers", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("nodes screen helpers", () => {
|
||||||
|
it("parses screen.record payload", () => {
|
||||||
|
const payload = parseScreenRecordPayload({
|
||||||
|
format: "mp4",
|
||||||
|
base64: "Zm9v",
|
||||||
|
durationMs: 1000,
|
||||||
|
fps: 12,
|
||||||
|
screenIndex: 0,
|
||||||
|
hasAudio: true,
|
||||||
|
});
|
||||||
|
expect(payload.format).toBe("mp4");
|
||||||
|
expect(payload.base64).toBe("Zm9v");
|
||||||
|
expect(payload.durationMs).toBe(1000);
|
||||||
|
expect(payload.fps).toBe(12);
|
||||||
|
expect(payload.screenIndex).toBe(0);
|
||||||
|
expect(payload.hasAudio).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("drops invalid optional fields instead of throwing", () => {
|
||||||
|
const payload = parseScreenRecordPayload({
|
||||||
|
format: "mp4",
|
||||||
|
base64: "Zm9v",
|
||||||
|
durationMs: "nope",
|
||||||
|
fps: null,
|
||||||
|
screenIndex: "0",
|
||||||
|
hasAudio: 1,
|
||||||
|
});
|
||||||
|
expect(payload.durationMs).toBeUndefined();
|
||||||
|
expect(payload.fps).toBeUndefined();
|
||||||
|
expect(payload.screenIndex).toBeUndefined();
|
||||||
|
expect(payload.hasAudio).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("rejects invalid screen.record payload", () => {
|
||||||
|
expect(() => parseScreenRecordPayload({ format: "mp4" })).toThrow(
|
||||||
|
/invalid screen\.record payload/i,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("builds screen record temp path", () => {
|
||||||
|
const p = screenRecordTempPath({
|
||||||
|
ext: "mp4",
|
||||||
|
tmpDir: "/tmp",
|
||||||
|
id: "id1",
|
||||||
|
});
|
||||||
|
expect(p).toBe(path.join("/tmp", "openclaw-screen-record-id1.mp4"));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
import path from "node:path";
|
|
||||||
import { describe, expect, it } from "vitest";
|
|
||||||
import { parseScreenRecordPayload, screenRecordTempPath } from "./nodes-screen.js";
|
|
||||||
|
|
||||||
describe("nodes screen helpers", () => {
|
|
||||||
it("parses screen.record payload", () => {
|
|
||||||
const payload = parseScreenRecordPayload({
|
|
||||||
format: "mp4",
|
|
||||||
base64: "Zm9v",
|
|
||||||
durationMs: 1000,
|
|
||||||
fps: 12,
|
|
||||||
screenIndex: 0,
|
|
||||||
hasAudio: true,
|
|
||||||
});
|
|
||||||
expect(payload.format).toBe("mp4");
|
|
||||||
expect(payload.base64).toBe("Zm9v");
|
|
||||||
expect(payload.durationMs).toBe(1000);
|
|
||||||
expect(payload.fps).toBe(12);
|
|
||||||
expect(payload.screenIndex).toBe(0);
|
|
||||||
expect(payload.hasAudio).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("rejects invalid screen.record payload", () => {
|
|
||||||
expect(() => parseScreenRecordPayload({ format: "mp4" })).toThrow(
|
|
||||||
/invalid screen\.record payload/i,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("builds screen record temp path", () => {
|
|
||||||
const p = screenRecordTempPath({
|
|
||||||
ext: "mp4",
|
|
||||||
tmpDir: "/tmp",
|
|
||||||
id: "id1",
|
|
||||||
});
|
|
||||||
expect(p).toBe(path.join("/tmp", "openclaw-screen-record-id1.mp4"));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
Reference in New Issue
Block a user