The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { act, type ReactNode } from "react"; |
| 2 | import { createRoot } from "react-dom/client"; |
| 3 | import { expect, it, vi } from "vite-plus/test"; |
| 4 | |
| 5 | vi.mock("react-native", () => ({ |
| 6 | Pressable: (props: { |
| 7 | readonly children?: ReactNode; |
| 8 | readonly accessibilityLabel?: string; |
| 9 | readonly onPress: () => void; |
| 10 | }) => ( |
| 11 | <button aria-label={props.accessibilityLabel} onClick={props.onPress}> |
| 12 | {props.children} |
| 13 | </button> |
| 14 | ), |
| 15 | })); |
| 16 | vi.mock("./AppText", () => ({ AppText: (props: { children?: ReactNode }) => props.children })); |
| 17 | vi.mock("./ListRowLayout", () => ({ |
| 18 | ListRowLayout: (props: { accessory?: ReactNode }) => props.accessory, |
| 19 | })); |
| 20 | vi.mock("./ThemedSwitch", () => ({ ThemedSwitch: () => null })); |
| 21 | |
| 22 | import { ListToggleRow } from "./ListToggleRow"; |
| 23 | |
| 24 | it("sets a mixed row on, then off when an older environment drops it", () => { |
| 25 | vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true); |
| 26 | const container = document.createElement("div"); |
| 27 | const root = createRoot(container); |
| 28 | const saves: boolean[] = []; |
| 29 | try { |
| 30 | // The older environment dropped the unknown key, so the row stays mixed after every save. |
| 31 | act(() => |
| 32 | root.render( |
| 33 | <ListToggleRow |
| 34 | label="Clone into host folders" |
| 35 | value={null} |
| 36 | onValueChange={(value) => saves.push(value)} |
| 37 | />, |
| 38 | ), |
| 39 | ); |
| 40 | const button = () => container.querySelector("button")!; |
| 41 | |
| 42 | act(() => button().click()); |
| 43 | const offer = { text: button().textContent, label: button().getAttribute("aria-label") }; |
| 44 | act(() => button().click()); |
| 45 | |
| 46 | expect(saves).toEqual([true, false]); |
| 47 | expect(offer).toEqual({ |
| 48 | text: "Mixed · Set off", |
| 49 | label: "Set Clone into host folders off for selected environments", |
| 50 | }); |
| 51 | } finally { |
| 52 | act(() => root.unmount()); |
| 53 | vi.unstubAllGlobals(); |
| 54 | } |
| 55 | }); |