-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for ledger wallet in new signature designs
- Loading branch information
Showing
13 changed files
with
391 additions
and
673 deletions.
There are no files selected for viewing
91 changes: 79 additions & 12 deletions
91
app/components/UI/LedgerModals/LedgerMessageSignModal.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,85 @@ | ||
import { renderScreen } from '../../../util/test/renderWithProvider'; | ||
import React from 'react'; | ||
import { Button, Text, View } from 'react-native'; | ||
import { fireEvent } from '@testing-library/react-native'; | ||
|
||
import renderWithProvider from '../../../util/test/renderWithProvider'; | ||
// eslint-disable-next-line import/no-namespace | ||
import * as NavUtils from '../../../util/navigation/navUtils'; | ||
// eslint-disable-next-line import/no-namespace | ||
import * as rpcEventsFuncs from '../../../actions/rpcEvents'; | ||
import { personalSignatureConfirmationState } from '../../../util/test/confirm-data-helpers'; | ||
import LedgerMessageSignModal from './LedgerMessageSignModal'; | ||
import { RPCStageTypes } from '../../../reducers/rpcEvents'; | ||
|
||
const initialState = { | ||
rpcEvents: { signingEvent: RPCStageTypes.IDLE }, | ||
}; | ||
const MockView = View; | ||
const MockText = Text; | ||
const MockButton = Button; | ||
jest.mock('./LedgerConfirmationModal', () => ({ | ||
__esModule: true, | ||
default: ({ | ||
onConfirmation, | ||
onRejection, | ||
deviceId, | ||
}: { | ||
onConfirmation: () => void; | ||
onRejection: () => void; | ||
deviceId: string; | ||
}) => ( | ||
<MockView> | ||
<MockText>Mock LedgerConfirmationModal</MockText> | ||
<MockText>{deviceId}</MockText> | ||
<MockButton onPress={onConfirmation} title="onConfirmation" /> | ||
<MockButton onPress={onRejection} title="onRejection" /> | ||
</MockView> | ||
), | ||
})); | ||
|
||
const DummyDeviceId = 'DummyDeviceId'; | ||
|
||
describe('LedgerMessageSignModal', () => { | ||
it('should render correctly', () => { | ||
const { toJSON } = renderScreen( | ||
LedgerMessageSignModal, | ||
{ name: 'LederMessageSignModal' }, | ||
{ state: initialState }, | ||
); | ||
expect(toJSON()).toMatchSnapshot(); | ||
it('should render LedgerConfirmationModal correctly', () => { | ||
jest | ||
.spyOn(NavUtils, 'useParams') | ||
.mockReturnValue({ deviceId: DummyDeviceId }); | ||
const { getByText } = renderWithProvider(<LedgerMessageSignModal />, { | ||
state: personalSignatureConfirmationState, | ||
}); | ||
expect(getByText('Mock LedgerConfirmationModal')).toBeTruthy(); | ||
expect(getByText(DummyDeviceId)).toBeTruthy(); | ||
}); | ||
|
||
it('should call onConfirmationComplete when request is confirmed', () => { | ||
const mockOnConfirmationComplete = jest.fn(); | ||
jest | ||
.spyOn(NavUtils, 'useParams') | ||
.mockReturnValue({ | ||
onConfirmationComplete: mockOnConfirmationComplete, | ||
deviceId: DummyDeviceId, | ||
}); | ||
const { getByText } = renderWithProvider(<LedgerMessageSignModal />, { | ||
state: personalSignatureConfirmationState, | ||
}); | ||
fireEvent.press(getByText('onConfirmation')); | ||
expect(mockOnConfirmationComplete).toHaveBeenCalledTimes(1); | ||
expect(mockOnConfirmationComplete).toHaveBeenCalledWith(true); | ||
}); | ||
|
||
it('should call onConfirmationComplete when request is rejected', () => { | ||
const mockOnConfirmationComplete = jest.fn(); | ||
jest | ||
.spyOn(NavUtils, 'useParams') | ||
.mockReturnValue({ | ||
onConfirmationComplete: mockOnConfirmationComplete, | ||
deviceId: DummyDeviceId, | ||
}); | ||
jest | ||
.spyOn(rpcEventsFuncs, 'resetEventStage') | ||
.mockImplementation(() => ({ rpcName: 'dummy', type: 'DUMMY' })); | ||
const { getByText } = renderWithProvider(<LedgerMessageSignModal />, { | ||
state: personalSignatureConfirmationState, | ||
}); | ||
fireEvent.press(getByText('onRejection')); | ||
expect(mockOnConfirmationComplete).toHaveBeenCalledTimes(1); | ||
expect(mockOnConfirmationComplete).toHaveBeenCalledWith(false); | ||
expect(rpcEventsFuncs.resetEventStage).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.