diff --git a/src/app/pages/OpenWalletPage/Features/FromBleLedger/index.tsx b/src/app/pages/OpenWalletPage/Features/FromBleLedger/index.tsx index 43779ba0c9..172ffba5b9 100644 --- a/src/app/pages/OpenWalletPage/Features/FromBleLedger/index.tsx +++ b/src/app/pages/OpenWalletPage/Features/FromBleLedger/index.tsx @@ -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 { diff --git a/src/app/pages/OpenWalletPage/Features/FromLedger/__tests__/index.test.tsx b/src/app/pages/OpenWalletPage/Features/FromLedger/__tests__/index.test.tsx index 6ec2ffe614..dc93b8b8ae 100644 --- a/src/app/pages/OpenWalletPage/Features/FromLedger/__tests__/index.test.tsx +++ b/src/app/pages/OpenWalletPage/Features/FromLedger/__tests__/index.test.tsx @@ -24,15 +24,15 @@ describe('', () => { 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', }) diff --git a/src/app/pages/OpenWalletPage/Features/FromUsbLedger/index.tsx b/src/app/pages/OpenWalletPage/Features/FromUsbLedger/index.tsx index 107abea426..45d0496f12 100644 --- a/src/app/pages/OpenWalletPage/Features/FromUsbLedger/index.tsx +++ b/src/app/pages/OpenWalletPage/Features/FromUsbLedger/index.tsx @@ -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' diff --git a/src/app/pages/OpenWalletPage/Features/ListBleLedgerDevicesModal/index.tsx b/src/app/pages/OpenWalletPage/Features/ListBleLedgerDevicesModal/index.tsx index 7686fe96d8..e8c18ac12a 100644 --- a/src/app/pages/OpenWalletPage/Features/ListBleLedgerDevicesModal/index.tsx +++ b/src/app/pages/OpenWalletPage/Features/ListBleLedgerDevicesModal/index.tsx @@ -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' diff --git a/src/app/pages/OpenWalletPage/__tests__/index.test.tsx b/src/app/pages/OpenWalletPage/__tests__/index.test.tsx index 3464aa9b65..8e36731f53 100644 --- a/src/app/pages/OpenWalletPage/__tests__/index.test.tsx +++ b/src/app/pages/OpenWalletPage/__tests__/index.test.tsx @@ -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( - + , ) describe('', () => { - 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') + }) }) })