|
1 | 1 | import { EnvironmentId, type ProjectEntry } from "@t3tools/contracts"; |
2 | 2 | import { describe, expect, it, vi } from "vite-plus/test"; |
| 3 | +import { page, userEvent } from "vite-plus/test/browser"; |
3 | 4 |
|
4 | 5 | import { COMPOSER_MENTION_DRAG_TYPE } from "~/components/chat/composerMentionDrag"; |
| 6 | +import { dismissContextMenu } from "~/contextMenuFallback"; |
5 | 7 | import { render } from "../../../test/render"; |
6 | 8 | import FileBrowserPanel from "./FileBrowserPanel"; |
7 | 9 |
|
@@ -43,6 +45,43 @@ function findTreeRow(path: string): HTMLElement | null { |
43 | 45 | } |
44 | 46 |
|
45 | 47 | describe("FileBrowserPanel", () => { |
| 48 | + it("copies with the pointer and returns to the row after keyboard dismissal", async () => { |
| 49 | + await using _screen = await render( |
| 50 | + <FileBrowserPanel |
| 51 | + environmentId={EnvironmentId.make("env-files")} |
| 52 | + cwd="/repo" |
| 53 | + projectName="repo" |
| 54 | + selectedPath={null} |
| 55 | + selectedPathRevealId={0} |
| 56 | + onOpenFile={() => {}} |
| 57 | + workspaceMutationId={null} |
| 58 | + />, |
| 59 | + ); |
| 60 | + using _menu = { [Symbol.dispose]: () => dismissContextMenu() }; |
| 61 | + using clipboard = vi.spyOn(navigator.clipboard, "writeText").mockResolvedValue(undefined); |
| 62 | + await vi.waitFor(() => expect(findTreeRow("README.md")).not.toBeNull()); |
| 63 | + findTreeRow("README.md")!.dispatchEvent( |
| 64 | + new MouseEvent("contextmenu", { |
| 65 | + bubbles: true, |
| 66 | + cancelable: true, |
| 67 | + composed: true, |
| 68 | + button: 2, |
| 69 | + }), |
| 70 | + ); |
| 71 | + const action = page.getByRole("menuitem", { name: "Copy mention", exact: true }); |
| 72 | + await expect.element(action).toBeVisible(); |
| 73 | + await userEvent.click(action); |
| 74 | + await vi.waitFor(() => expect(clipboard).toHaveBeenCalledWith("[README.md](README.md)")); |
| 75 | + |
| 76 | + const row = findTreeRow("README.md")!; |
| 77 | + await userEvent.keyboard("{Tab}"); |
| 78 | + row.focus(); |
| 79 | + await userEvent.keyboard("{Shift>}{F10}{/Shift}"); |
| 80 | + await expect.element(action).toHaveFocus(); |
| 81 | + await userEvent.keyboard("{Escape}"); |
| 82 | + await vi.waitFor(() => expect((row.getRootNode() as ShadowRoot).activeElement).toBe(row)); |
| 83 | + }); |
| 84 | + |
46 | 85 | it("dragging a file row carries a composer mention without opening it, and dragend releases it", async () => { |
47 | 86 | const onOpenFile = vi.fn(); |
48 | 87 | await using _screen = await render( |
|
0 commit comments