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 { expect, it, vi } from "vite-plus/test"; |
| 2 | |
| 3 | const listeners = vi.hoisted(() => new Map<string, Set<() => void>>()); |
| 4 | |
| 5 | vi.mock("react-native-keyboard-controller", () => ({ |
| 6 | KeyboardController: { isVisible: () => false }, |
| 7 | KeyboardEvents: { |
| 8 | addListener: (name: string, listener: () => void) => { |
| 9 | const named = listeners.get(name) ?? new Set(); |
| 10 | named.add(listener); |
| 11 | listeners.set(name, named); |
| 12 | return { remove: () => named.delete(listener) }; |
| 13 | }, |
| 14 | }, |
| 15 | })); |
| 16 | |
| 17 | import { getKeyboardShowEpoch, subscribeKeyboardShowing } from "./terminalKeyboardShowing"; |
| 18 | |
| 19 | function emit(name: string) { |
| 20 | for (const listener of listeners.get(name) ?? []) listener(); |
| 21 | } |
| 22 | |
| 23 | // Android's syncKeyboardPosition repairs a nonanimated IME inset change with |
| 24 | // keyboardDidHide then keyboardDidShow, and no will-events. |
| 25 | it("keeps the accessory through Android's did-only repair and starts a new show after it", () => { |
| 26 | // Two mounted terminal screens, each reading the snapshot when notified. |
| 27 | const seen = [0, 0]; |
| 28 | const unsubscribes = seen.map((_, index) => { |
| 29 | seen[index] = getKeyboardShowEpoch(); |
| 30 | return subscribeKeyboardShowing(() => { |
| 31 | seen[index] = getKeyboardShowEpoch(); |
| 32 | }); |
| 33 | }); |
| 34 | const trace = [ |
| 35 | "keyboardWillShow", |
| 36 | "keyboardDidShow", |
| 37 | "keyboardDidHide", |
| 38 | "keyboardDidShow", |
| 39 | "keyboardWillHide", |
| 40 | "keyboardWillShow", |
| 41 | ].map((name) => { |
| 42 | emit(name); |
| 43 | return { |
| 44 | epoch: getKeyboardShowEpoch(), |
| 45 | inSync: seen.every((s) => s === getKeyboardShowEpoch()), |
| 46 | }; |
| 47 | }); |
| 48 | |
| 49 | const [shown, settled, repairHidden, repairShown, hidden, reshown] = trace.map((t) => t.epoch); |
| 50 | expect({ |
| 51 | neverHiddenByRepair: [shown, settled, repairHidden, repairShown].every((epoch) => epoch !== 0), |
| 52 | sameShow: settled === shown && repairHidden === shown, |
| 53 | newShow: repairShown !== shown, |
| 54 | hidden, |
| 55 | newShowAfterHide: reshown !== 0 && reshown !== repairShown, |
| 56 | subscribersInSync: trace.every((t) => t.inSync), |
| 57 | }).toEqual({ |
| 58 | neverHiddenByRepair: true, |
| 59 | sameShow: true, |
| 60 | newShow: true, |
| 61 | hidden: 0, |
| 62 | newShowAfterHide: true, |
| 63 | subscribersInSync: true, |
| 64 | }); |
| 65 | for (const unsubscribe of unsubscribes) unsubscribe(); |
| 66 | }); |