tests pass

This commit is contained in:
Eason Goodale
2025-04-19 18:49:29 -07:00
parent 0d6a98f9af
commit 35148c2ba9
14 changed files with 783 additions and 6 deletions

View File

@@ -0,0 +1,70 @@
import fs from "node:fs";
import path from "node:path";
import React from "react";
import { beforeAll, afterAll, describe, expect, it, vi } from "vitest";
import { renderTui } from "./ui-test-helpers.js";
vi.mock("../src/utils/input-utils.js", () => ({
createInputItem: vi.fn(async () => ({})),
imageFilenameByDataUrl: new Map(),
}));
import ImagePickerOverlay from "../src/components/chat/image-picker-overlay.js";
async function type(stdin, text, flush) {
stdin.write(text);
await flush();
}
describe("Image picker overlay", () => {
let TMP;
let CHILD;
beforeAll(() => {
TMP = fs.mkdtempSync(path.join(process.cwd(), "overlay-test-"));
CHILD = path.join(TMP, "child");
fs.mkdirSync(CHILD, { recursive: true });
fs.writeFileSync(path.join(TMP, "a.png"), "");
fs.writeFileSync(path.join(TMP, "b.png"), "");
fs.writeFileSync(path.join(CHILD, "nested.png"), "");
});
afterAll(() => {
fs.rmSync(TMP, { recursive: true, force: true });
});
it("shows ../ when below root and selects it", async () => {
const onChangeDir = vi.fn();
const { lastFrameStripped, stdin, flush } = renderTui(
React.createElement(ImagePickerOverlay, {
rootDir: TMP,
cwd: CHILD,
onPick: () => {},
onCancel: () => {},
onChangeDir,
})
);
await flush();
expect(lastFrameStripped()).toContain(" ../");
await type(stdin, "\r", flush);
expect(onChangeDir).toHaveBeenCalledWith(path.dirname(CHILD));
});
it("selecting file calls onPick", async () => {
const onPick = vi.fn();
const { stdin, flush } = renderTui(
React.createElement(ImagePickerOverlay, {
rootDir: TMP,
cwd: TMP,
onPick,
onCancel: () => {},
onChangeDir: () => {},
})
);
await flush();
await type(stdin, "\r", flush);
expect(onPick).toHaveBeenCalledWith(path.join(TMP, "a.png"));
});
});