@@ -255,6 +255,94 @@ describe(AuthPage.name, () => {
255255 } ) ;
256256 } ) ;
257257
258+ describe ( "when deploy button flow is active" , ( ) => {
259+ it ( "renders ConnectWalletButton when deploy button flow is active" , ( ) => {
260+ const ConnectWalletButtonMock = jest . fn ( ( ) => < button data-testid = "connect-wallet-btn" > Connect Wallet</ button > ) ;
261+ setup ( {
262+ searchParams : {
263+ tab : "login" ,
264+ from : "/new-deployment?repoUrl=https://github.com/test/repo.git"
265+ } ,
266+ dependencies : {
267+ useDeployButtonFlow : ( ) => ( {
268+ isDeployButtonFlow : true ,
269+ params : {
270+ repoUrl : "https://github.com/test/repo.git" ,
271+ branch : null ,
272+ buildCommand : null ,
273+ startCommand : null ,
274+ installCommand : null ,
275+ buildDirectory : null ,
276+ nodeVersion : null ,
277+ templateId : null
278+ } ,
279+ buildReturnUrl : ( ) => "/new-deployment" ,
280+ buildUrlParams : ( ) => ( { repoUrl : "https://github.com/test/repo.git" } )
281+ } ) ,
282+ ConnectWalletButton : ConnectWalletButtonMock
283+ }
284+ } ) ;
285+
286+ expect ( screen . queryByTestId ( "connect-wallet-btn" ) ) . toBeInTheDocument ( ) ;
287+ } ) ;
288+
289+ it ( "does not render ConnectWalletButton when deploy button flow is inactive" , ( ) => {
290+ setup ( {
291+ searchParams : {
292+ tab : "login"
293+ }
294+ } ) ;
295+
296+ expect ( screen . queryByTestId ( "connect-wallet-btn" ) ) . not . toBeInTheDocument ( ) ;
297+ } ) ;
298+
299+ it ( "redirects to returnUrl when wallet connects during deploy button flow" , async ( ) => {
300+ const { router } = setup ( {
301+ searchParams : {
302+ tab : "login" ,
303+ from : "/new-deployment?repoUrl=https://github.com/test/repo.git"
304+ } ,
305+ dependencies : {
306+ useDeployButtonFlow : ( ) => ( {
307+ isDeployButtonFlow : true ,
308+ params : {
309+ repoUrl : "https://github.com/test/repo.git" ,
310+ branch : null ,
311+ buildCommand : null ,
312+ startCommand : null ,
313+ installCommand : null ,
314+ buildDirectory : null ,
315+ nodeVersion : null ,
316+ templateId : null
317+ } ,
318+ buildReturnUrl : ( ) => "/new-deployment?repoUrl=https://github.com/test/repo.git" ,
319+ buildUrlParams : ( ) => ( { repoUrl : "https://github.com/test/repo.git" } )
320+ } ) ,
321+ useWallet : ( ) => ( {
322+ address : "akash1test" ,
323+ walletName : "test" ,
324+ isWalletConnected : true ,
325+ isWalletLoaded : true ,
326+ connectManagedWallet : jest . fn ( ) ,
327+ logout : jest . fn ( ) ,
328+ signAndBroadcastTx : jest . fn ( ) ,
329+ isManaged : false ,
330+ isCustodial : false ,
331+ isWalletLoading : false ,
332+ isTrialing : false ,
333+ isOnboarding : false ,
334+ switchWalletType : jest . fn ( ) ,
335+ hasManagedWallet : false
336+ } )
337+ }
338+ } ) ;
339+
340+ await waitFor ( ( ) => {
341+ expect ( router . push ) . toHaveBeenCalledWith ( "/new-deployment?repoUrl=https://github.com/test/repo.git" ) ;
342+ } ) ;
343+ } ) ;
344+ } ) ;
345+
258346 function setup ( input : {
259347 searchParams ?: {
260348 tab ?: "login" | "signup" | "forgot-password" ;
@@ -269,16 +357,50 @@ describe(AuthPage.name, () => {
269357 replace : jest . fn ( url => {
270358 setRouterPageParams ?.( new URL ( url as string , "http://localunittest:8080" ) . searchParams ) ;
271359 return Promise . resolve ( true ) ;
272- } )
360+ } ) ,
361+ push : jest . fn ( ) . mockResolvedValue ( true )
273362 } ) ;
274363 const checkSession = jest . fn ( async ( ) => undefined ) ;
275- const useUserMock : typeof DEPENDENCIES . useUser = ( ) => ( {
364+ const useUser : typeof DEPENDENCIES . useUser = ( ) => ( {
276365 checkSession,
277366 isLoading : false ,
278367 error : undefined ,
279368 user : { }
280369 } ) ;
281370
371+ const useDeployButtonFlow : typeof DEPENDENCIES . useDeployButtonFlow = ( ) => ( {
372+ isDeployButtonFlow : false ,
373+ params : {
374+ repoUrl : null ,
375+ branch : null ,
376+ buildCommand : null ,
377+ startCommand : null ,
378+ installCommand : null ,
379+ buildDirectory : null ,
380+ nodeVersion : null ,
381+ templateId : null
382+ } ,
383+ buildReturnUrl : ( ) => "/" ,
384+ buildUrlParams : ( ) => ( { } )
385+ } ) ;
386+
387+ const useWallet : typeof DEPENDENCIES . useWallet = ( ) => ( {
388+ address : "" ,
389+ walletName : "" ,
390+ isWalletConnected : false ,
391+ isWalletLoaded : false ,
392+ connectManagedWallet : jest . fn ( ) ,
393+ logout : jest . fn ( ) ,
394+ signAndBroadcastTx : jest . fn ( ) ,
395+ isManaged : false ,
396+ isCustodial : false ,
397+ isWalletLoading : false ,
398+ isTrialing : false ,
399+ isOnboarding : false ,
400+ switchWalletType : jest . fn ( ) ,
401+ hasManagedWallet : false
402+ } ) ;
403+
282404 const params = new URLSearchParams ( ) ;
283405 params . set ( "tab" , input . searchParams ?. tab || "login" ) ;
284406 if ( input . searchParams ?. from ) {
@@ -287,13 +409,13 @@ describe(AuthPage.name, () => {
287409 if ( input . searchParams ?. returnTo ) {
288410 params . set ( "returnTo" , input . searchParams . returnTo ) ;
289411 }
290- const useSearchParamsMock = ( ) => {
412+ const useSearchParams = ( ) => {
291413 const [ pageParams , setPageParams ] = useState ( params ) ;
292414 setRouterPageParams = setPageParams ;
293415 return pageParams as ReadonlyURLSearchParams ;
294416 } ;
295417
296- const TurnstileMock = jest . fn ( ( { turnstileRef } : { turnstileRef ?: RefObject < TurnstileRef > } ) => {
418+ const Turnstile = jest . fn ( ( { turnstileRef } : { turnstileRef ?: RefObject < TurnstileRef > } ) => {
297419 if ( turnstileRef ) {
298420 ( turnstileRef as { current : TurnstileRef } ) . current = {
299421 renderAndWaitResponse : jest . fn ( ) . mockResolvedValue ( { token : "test-captcha-token" } )
@@ -307,10 +429,12 @@ describe(AuthPage.name, () => {
307429 < AuthPage
308430 dependencies = { {
309431 ...MockComponents ( DEPENDENCIES ) ,
310- useUser : useUserMock ,
311- useSearchParams : useSearchParamsMock ,
432+ useUser,
433+ useSearchParams,
312434 useRouter : ( ) => router ,
313- Turnstile : TurnstileMock ,
435+ useDeployButtonFlow : input . dependencies ?. useDeployButtonFlow || useDeployButtonFlow ,
436+ useWallet : input . dependencies ?. useWallet || useWallet ,
437+ Turnstile,
314438 ...input . dependencies
315439 } }
316440 />
0 commit comments