Skip to content

Commit

Permalink
fix: Revert hook changes, adjust test case
Browse files Browse the repository at this point in the history
  • Loading branch information
usame-algan committed Nov 1, 2023
1 parent 356b40b commit eb48a9c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { type PendingSafeData } from '@/components/new-safe/create/types'
import { renderHook } from '@/tests/test-utils'
import useSyncSafeCreationStep from '@/components/new-safe/create/useSyncSafeCreationStep'
import * as wallet from '@/hooks/wallets/useWallet'
Expand Down Expand Up @@ -39,30 +38,22 @@ describe('useSyncSafeCreationStep', () => {
expect(mockPushRoute).toHaveBeenCalledWith({ pathname: AppRoutes.welcome.index, query: undefined })
})

it('should not go to the first step if no wallet is connected but there is a pending safe', async () => {
const mockPushRoute = jest.fn()
jest.spyOn(wallet, 'default').mockReturnValue(null)
jest.spyOn(usePendingSafe, 'usePendingSafe').mockReturnValue([{} as PendingSafeData, setPendingSafeSpy])
jest.spyOn(useRouter, 'useRouter').mockReturnValue({
push: mockPushRoute,
} as unknown as NextRouter)
const mockSetStep = jest.fn()

renderHook(() => useSyncSafeCreationStep(mockSetStep))

expect(mockPushRoute).not.toHaveBeenCalled()
})

it('should go to the fourth step if there is a pending safe', async () => {
const mockPushRoute = jest.fn()
jest.spyOn(localStorage, 'default').mockReturnValue([{}, jest.fn()])
jest.spyOn(wallet, 'default').mockReturnValue({ address: '0x1' } as ConnectedWallet)
jest.spyOn(usePendingSafe, 'usePendingSafe').mockReturnValue([mockPendingSafe, setPendingSafeSpy])
jest.spyOn(useRouter, 'useRouter').mockReturnValue({
push: mockPushRoute,
} as unknown as NextRouter)

const mockSetStep = jest.fn()

renderHook(() => useSyncSafeCreationStep(mockSetStep))

expect(mockSetStep).toHaveBeenCalledWith(3)

expect(mockPushRoute).not.toHaveBeenCalled()
})

it('should go to the second step if the wrong chain is connected', async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/new-safe/create/useSyncSafeCreationStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const useSyncSafeCreationStep = (setStep: StepRenderProps<NewSafeFormData>['setS
return
}

// Jump to the welcome page if there is no wallet and no pending Safe
if (!wallet && !pendingSafe) {
// Jump to the welcome page if there is no wallet
if (!wallet) {
router.push({ pathname: AppRoutes.welcome.index, query: router.query })
}

Expand Down

0 comments on commit eb48a9c

Please sign in to comment.