Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up code
Browse files Browse the repository at this point in the history
- remove unused code
- update FromLedger test, to reflect runtimeIs changes
lubej committed Apr 26, 2024
1 parent 585433e commit 32dbbb9
Showing 5 changed files with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@ import { importAccountsActions } from 'app/state/importaccounts'
import { Box } from 'grommet/es6/components/Box'
import { Button } from 'grommet/es6/components/Button'
import { Heading } from 'grommet/es6/components/Heading'
import React from 'react'
import { useTranslation } from 'react-i18next'
import { useDispatch, useSelector } from 'react-redux'
import {
Original file line number Diff line number Diff line change
@@ -24,15 +24,15 @@ describe('<FromLedger />', () => {
it('should render component in disabled state', async () => {
renderComponent()

await waitFor(async () => {
await waitFor(() => {
expect(screen.queryByText('openWallet.importAccounts.usbLedger')).toBeInTheDocument()
expect(screen.queryByText('openWallet.importAccounts.bluetoothLedger')).toBeInTheDocument()

expect(screen.getByText('errors.usbTransportNotSupported')).toBeInTheDocument()
expect(screen.getByText('errors.bluetoothTransportNotSupported')).toBeInTheDocument()

const usbLedgerBtn = await screen.getByRole('button', { name: 'openWallet.importAccounts.usbLedger' })
const bluetoothLedgerBtn = await screen.getByRole('button', {
const usbLedgerBtn = screen.getByRole('button', { name: 'openWallet.importAccounts.usbLedger' })
const bluetoothLedgerBtn = screen.getByRole('button', {
name: 'openWallet.importAccounts.bluetoothLedger',
})

Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@ import { importAccountsActions } from 'app/state/importaccounts'
import { Box } from 'grommet/es6/components/Box'
import { Button } from 'grommet/es6/components/Button'
import { Heading } from 'grommet/es6/components/Heading'
import React from 'react'
import { useTranslation } from 'react-i18next'
import { useDispatch, useSelector } from 'react-redux'
import { ImportAccountsSelectionModal } from 'app/pages/OpenWalletPage/Features/ImportAccountsSelectionModal'
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react'
import { useTranslation } from 'react-i18next'
import { useDispatch, useSelector } from 'react-redux'
import { AlertBox } from 'app/components/AlertBox'
30 changes: 19 additions & 11 deletions src/app/pages/OpenWalletPage/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import React from 'react'
import { render } from '@testing-library/react'
import { render, screen, waitFor } from '@testing-library/react'
import { MemoryRouter } from 'react-router-dom'
import { useSelector } from 'react-redux'
import { when } from 'jest-when'
import { selectShowAccountsSelectionModal } from 'app/state/importaccounts/selectors'
import { canAccessNavigatorUsb } from 'app/lib/ledger'
import { SelectOpenMethod } from '..'

jest.mock('app/lib/ledger', () => ({
...jest.requireActual('app/lib/ledger'),
canAccessBle: () => jest.fn().mockReturnValue(false),
canAccessNavigatorUsb: () => jest.fn().mockReturnValue(false),
}))
jest.mock('config', () => ({
...jest.requireActual('config'),
runtimeIs: 'extension',
}))
jest.mock('react-redux', () => ({
useSelector: jest.fn(),
}))
@@ -18,31 +26,31 @@ jest.mock('react-router-dom', () => ({
useNavigate: () => mockNavigate,
}))

const renderComponent = (webExtensionLedgerAccess?: () => void) =>
const renderComponent = () =>
render(
<MemoryRouter>
<SelectOpenMethod webExtensionLedgerAccess={webExtensionLedgerAccess} />
<SelectOpenMethod />
</MemoryRouter>,
)

describe('<SelectOpenMethod />', () => {
beforeEach(() => {
jest.mocked(canAccessNavigatorUsb).mockResolvedValue(false)
})

it('should render component', () => {
const { container } = renderComponent()

expect(container).toMatchSnapshot()
})

it('should redirect user to ledger page', () => {
it('should redirect user to ledger page', async () => {
when(useSelector as any)
.calledWith(selectShowAccountsSelectionModal)
.mockReturnValue(true)

renderComponent(() => {})
renderComponent()

await waitFor(() => {
expect(screen.queryByText('openWallet.method.ledger')).toBeInTheDocument()

expect(mockNavigate).toHaveBeenCalledWith('/open-wallet/ledger/usb')
expect(mockNavigate).toHaveBeenCalledWith('/open-wallet/ledger/usb')
})
})
})

0 comments on commit 32dbbb9

Please sign in to comment.