@@ -4,28 +4,67 @@ import { expect, it } from "vite-plus/test";
44import { render , stubGlobal } from "../../../test/render" ;
55import { SshPasswordPromptDialog , startSshPasswordPromptQueue } from "./SshPasswordPromptDialog" ;
66
7- it ( "shows a prompt that arrived before the dialog mounted" , async ( ) => {
7+ function stubPromptBridge ( ) {
88 const listeners : Array < ( request : DesktopSshPasswordPromptRequest ) => void > = [ ] ;
9- using _bridge = stubGlobal ( "desktopBridge" , {
9+ const settledListeners : Array < ( requestId : string ) => void > = [ ] ;
10+ const bridge = stubGlobal ( "desktopBridge" , {
1011 onSshPasswordPrompt : ( listener : ( request : DesktopSshPasswordPromptRequest ) => void ) => {
1112 listeners . push ( listener ) ;
1213 return ( ) => listeners . splice ( listeners . indexOf ( listener ) , 1 ) ;
1314 } ,
15+ onSshPasswordPromptSettled : ( listener : ( requestId : string ) => void ) => {
16+ settledListeners . push ( listener ) ;
17+ return ( ) => settledListeners . splice ( settledListeners . indexOf ( listener ) , 1 ) ;
18+ } ,
1419 resolveSshPasswordPrompt : async ( ) => undefined ,
1520 } ) ;
21+ return {
22+ prompt : ( requestId : string , destination : string ) => {
23+ for ( const listener of listeners ) {
24+ listener ( {
25+ requestId,
26+ destination,
27+ username : "julius" ,
28+ prompt : `julius@${ destination } 's password:` ,
29+ expiresAt : "2999-01-01T00:00:00.000Z" ,
30+ } ) ;
31+ }
32+ } ,
33+ settle : ( requestId : string ) => {
34+ for ( const listener of settledListeners ) listener ( requestId ) ;
35+ } ,
36+ [ Symbol . dispose ] : ( ) => bridge [ Symbol . dispose ] ( ) ,
37+ } ;
38+ }
39+
40+ it ( "drops a prompt the desktop ended, whether it is on screen or still waiting" , async ( ) => {
41+ using bridge = stubPromptBridge ( ) ;
42+ const stopQueue = startSshPasswordPromptQueue ( ) ;
43+ using _queue = { [ Symbol . dispose ] : stopQueue } ;
44+ await using screen = await render ( < SshPasswordPromptDialog /> ) ;
45+
46+ bridge . prompt ( "ssh-1" , "first-host" ) ;
47+ bridge . prompt ( "ssh-1" , "first-host" ) ;
48+ bridge . prompt ( "ssh-2" , "second-host" ) ;
49+ bridge . prompt ( "ssh-3" , "third-host" ) ;
50+ await expect . element ( screen . getByText ( "julius@first-host" ) ) . toBeVisible ( ) ;
51+
52+ // ssh-2 ended while it waited behind ssh-1, and ssh-1 ended on screen.
53+ bridge . settle ( "ssh-2" ) ;
54+ bridge . settle ( "ssh-1" ) ;
55+ await expect . element ( screen . getByText ( "julius@third-host" ) ) . toBeVisible ( ) ;
56+
57+ bridge . settle ( "ssh-3" ) ;
58+ await expect . element ( screen . getByText ( "SSH verification required" ) ) . not . toBeInTheDocument ( ) ;
59+ } ) ;
60+
61+ it ( "shows a prompt that arrived before the dialog mounted" , async ( ) => {
62+ using bridge = stubPromptBridge ( ) ;
1663 const stopQueue = startSshPasswordPromptQueue ( ) ;
1764 using _queue = { [ Symbol . dispose ] : stopQueue } ;
1865
1966 // The desktop asks while the app is still on a page without the dialog (pairing, sign-in).
20- for ( const listener of listeners ) {
21- listener ( {
22- requestId : "ssh-1" ,
23- destination : "devbox" ,
24- username : "julius" ,
25- prompt : "julius@devbox's password:" ,
26- expiresAt : "2999-01-01T00:00:00.000Z" ,
27- } ) ;
28- }
67+ bridge . prompt ( "ssh-1" , "devbox" ) ;
2968
3069 await using screen = await render ( < SshPasswordPromptDialog /> ) ;
3170 await expect . element ( screen . getByText ( "SSH verification required" ) ) . toBeVisible ( ) ;
0 commit comments