forked from Dimillian/CodexMonitor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMobileRemoteWorkspacePrompt.test.tsx
More file actions
43 lines (39 loc) · 1.48 KB
/
Copy pathMobileRemoteWorkspacePrompt.test.tsx
File metadata and controls
43 lines (39 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// @vitest-environment jsdom
import { useState } from "react";
import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
import { afterEach, describe, expect, it, vi } from "vitest";
import { MobileRemoteWorkspacePrompt } from "./MobileRemoteWorkspacePrompt";
afterEach(() => {
cleanup();
});
describe("MobileRemoteWorkspacePrompt", () => {
it("focuses paths textarea and moves caret to end after selecting a recent path", async () => {
const recentPath = "/Users/vlad/dev/codex-monitor/cm";
function PromptHarness() {
const [value, setValue] = useState("");
return (
<MobileRemoteWorkspacePrompt
value={value}
error={null}
recentPaths={[recentPath]}
onChange={setValue}
onRecentPathSelect={(path) => {
setValue((prev) => (prev.length > 0 ? `${prev}\n${path}` : path));
}}
onCancel={vi.fn()}
onConfirm={vi.fn()}
/>
);
}
render(<PromptHarness />);
const recentPathButton = screen.getByRole("button", { name: recentPath });
fireEvent.click(recentPathButton);
const textarea = screen.getByLabelText("Paths");
await waitFor(() => {
expect(document.activeElement).toBe(textarea);
const expectedPosition = recentPath.length;
expect((textarea as HTMLTextAreaElement).selectionStart).toBe(expectedPosition);
expect((textarea as HTMLTextAreaElement).selectionEnd).toBe(expectedPosition);
});
});
});