|
| 1 | +import { describe, expect, it, vi } from "vite-plus/test"; |
| 2 | + |
| 3 | +import { act, render } from "../../test/render"; |
| 4 | +import { TerminalCheckoutModeButton } from "./ThreadTerminalDrawer"; |
| 5 | + |
| 6 | +describe.each(["floating", "sidebar"] as const)("%s terminal controls", (layout) => { |
| 7 | + it("changes the active terminal between Follow and Pin", async () => { |
| 8 | + const onModeChange = vi.fn(); |
| 9 | + await using screen = await render( |
| 10 | + <TerminalCheckoutModeButton |
| 11 | + layout={layout} |
| 12 | + terminalId="terminal-2" |
| 13 | + mode="follow" |
| 14 | + onModeChange={onModeChange} |
| 15 | + />, |
| 16 | + ); |
| 17 | + const { container } = screen; |
| 18 | + |
| 19 | + const button = container.querySelector("button"); |
| 20 | + expect(button?.getAttribute("aria-label")).toBe("Pin terminal checkout"); |
| 21 | + await act(() => button?.click()); |
| 22 | + expect(onModeChange).toHaveBeenCalledWith("terminal-2", "pin"); |
| 23 | + |
| 24 | + await screen.rerender( |
| 25 | + <TerminalCheckoutModeButton |
| 26 | + layout={layout} |
| 27 | + terminalId="terminal-2" |
| 28 | + mode="pin" |
| 29 | + onModeChange={onModeChange} |
| 30 | + />, |
| 31 | + ); |
| 32 | + const followButton = container.querySelector("button"); |
| 33 | + expect(followButton?.getAttribute("aria-label")).toBe("Follow thread checkout"); |
| 34 | + await act(() => followButton?.click()); |
| 35 | + expect(onModeChange).toHaveBeenLastCalledWith("terminal-2", "follow"); |
| 36 | + }); |
| 37 | + |
| 38 | + it("keeps the moving checkout lock visible and inert", async () => { |
| 39 | + const onModeChange = vi.fn(); |
| 40 | + await using screen = await render( |
| 41 | + <TerminalCheckoutModeButton |
| 42 | + layout={layout} |
| 43 | + terminalId="terminal-2" |
| 44 | + mode="follow" |
| 45 | + disabled |
| 46 | + onModeChange={onModeChange} |
| 47 | + />, |
| 48 | + ); |
| 49 | + const { container } = screen; |
| 50 | + |
| 51 | + const button = container.querySelector("button"); |
| 52 | + // Upstream disables terminal actions by `aria-disabled`, so the tooltip still opens on hover. |
| 53 | + expect(button?.getAttribute("aria-disabled")).toBe("true"); |
| 54 | + expect(button?.getAttribute("aria-label")).toBe( |
| 55 | + "Checkout mode is locked while the thread is moving", |
| 56 | + ); |
| 57 | + await act(() => button?.click()); |
| 58 | + expect(onModeChange).not.toHaveBeenCalled(); |
| 59 | + }); |
| 60 | +}); |
0 commit comments