11import { RegistryProvider } from "@effect/atom-react" ;
2- import { userEvent } from "vite-plus/test/browser " ;
3- import { expect , it , vi } from "vite-plus/test" ;
2+ import { describe , expect , it , vi } from "vite-plus/test" ;
3+ import { page , userEvent , type Locator } from "vite-plus/test/browser " ;
44
55import { render } from "../../../test/render" ;
66
7+ vi . mock ( import ( "../../state/session" ) , async ( original ) => ( {
8+ ...( await original ( ) ) ,
9+ useEnvironmentScope : ( ) => true ,
10+ useEnvironmentsWithScope : ( ( environments : ReadonlyArray < { environmentId : string } > ) =>
11+ new Set ( environments . map ( ( { environmentId } ) => environmentId ) ) ) as never ,
12+ readEnvironmentScope : ( ) => true ,
13+ } ) ) ;
14+ vi . mock ( import ( "../../state/use-atom-command" ) , async ( original ) => ( {
15+ ...( await original ( ) ) ,
16+ useAtomCommand : ( ( ) => vi . fn ( ) ) as never ,
17+ } ) ) ;
718vi . mock ( import ( "./SettingsScopeContext" ) , async ( original ) => ( {
819 ...( await original ( ) ) ,
920 useSettingsScope : ( ( ) => {
@@ -22,16 +33,78 @@ vi.mock(import("./SettingsScopeContext"), async (original) => ({
2233 } ;
2334 } ) as never ,
2435} ) ) ;
25- vi . mock ( import ( "../../state/session" ) , async ( original ) => ( {
26- ...( await original ( ) ) ,
27- useEnvironmentScope : ( ) => true ,
28- useEnvironmentsWithScope : ( ( environments : ReadonlyArray < { environmentId : string } > ) =>
29- new Set ( environments . map ( ( environment ) => environment . environmentId ) ) ) as never ,
30- readEnvironmentScope : ( ) => true ,
31- } ) ) ;
3236
37+ import { Dialog , DialogPopup , DialogTitle } from "../ui/dialog" ;
3338import { KeybindingsSettingsPanel } from "./KeybindingsSettings" ;
3439
40+ // The modal dialog's inert layer swallows pointer events in this harness, so drive the DOM.
41+ async function activate ( locator : Locator , action : "click" | "focus" ) {
42+ await expect . element ( locator ) . toBeVisible ( ) ;
43+ ( locator . element ( ) as HTMLElement ) [ action ] ( ) ;
44+ }
45+
46+ const existingField = page . getByRole ( "textbox" , { name : "Keybinding for Sidebar: Toggle" } ) ;
47+ const existingPill = page . getByRole ( "button" , { name : / ^ E d i t s h o r t c u t f o r S i d e b a r : T o g g l e : / } ) ;
48+ const newField = page . getByRole ( "textbox" , { name : "Keybinding for new keybinding" } ) ;
49+
50+ describe ( "Esc in a shortcut recorder" , ( ) => {
51+ it . each < {
52+ name : string ;
53+ field : Locator ;
54+ open : ( ) => Promise < void > ;
55+ expectReset : ( ) => Promise < void > ;
56+ } > ( [
57+ {
58+ name : "existing binding" ,
59+ field : existingField ,
60+ open : ( ) => activate ( existingPill , "click" ) ,
61+ expectReset : async ( ) => {
62+ await expect . element ( existingField ) . not . toBeInTheDocument ( ) ;
63+ await expect . element ( existingPill ) . toHaveFocus ( ) ;
64+ await expect . element ( page . getByRole ( "button" , { name : "Save" } ) ) . not . toBeInTheDocument ( ) ;
65+ } ,
66+ } ,
67+ {
68+ name : "new binding" ,
69+ field : newField ,
70+ open : async ( ) => {
71+ await activate ( page . getByRole ( "button" , { name : "Add keybinding" } ) , "click" ) ;
72+ await activate ( newField , "focus" ) ;
73+ } ,
74+ expectReset : async ( ) => {
75+ await expect . element ( newField ) . toHaveValue ( "" ) ;
76+ await expect . element ( newField ) . toHaveAttribute ( "placeholder" , "Unassigned" ) ;
77+ } ,
78+ } ,
79+ ] ) ( "leaves the $name field without closing Settings" , async ( { field, open, expectReset } ) => {
80+ const onOpenChange = vi . fn ( ) ;
81+ await using _screen = await render (
82+ < Dialog open onOpenChange = { onOpenChange } >
83+ < DialogPopup >
84+ < DialogTitle > Settings</ DialogTitle >
85+ < KeybindingsSettingsPanel />
86+ </ DialogPopup >
87+ </ Dialog > ,
88+ ) ;
89+
90+ await open ( ) ;
91+ await userEvent . keyboard ( "{Control>}k{/Control}" ) ;
92+ await expect . element ( field ) . not . toHaveValue ( "" ) ;
93+ await userEvent . tab ( ) ;
94+ await activate ( field , "focus" ) ;
95+ await expect . element ( field ) . toHaveAttribute ( "placeholder" , "Press shortcut" ) ;
96+
97+ await userEvent . keyboard ( "{Escape}" ) ;
98+
99+ expect ( onOpenChange ) . not . toHaveBeenCalled ( ) ;
100+ expect ( document . activeElement ?. matches ( "[data-keybinding-capture]" ) ) . toBe ( false ) ;
101+ await expectReset ( ) ;
102+
103+ await userEvent . keyboard ( "{Escape}" ) ;
104+ expect ( onOpenChange ) . toHaveBeenCalledWith ( false , expect . anything ( ) ) ;
105+ } ) ;
106+ } ) ;
107+
35108it ( "re-enables Save when a When editor closes on an expression it could not parse" , async ( ) => {
36109 await using screen = await render (
37110 < RegistryProvider >
0 commit comments