-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
2,516 additions
and
41 deletions.
There are no files selected for viewing
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
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
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
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
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
50 changes: 50 additions & 0 deletions
50
app/components/UI/Stake/Views/InputView/StakeInputView.styles.ts
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { StyleSheet } from 'react-native'; | ||
import type { Theme } from '../../../../../util/theme/models'; | ||
|
||
const styleSheet = (params: { theme: Theme }) => { | ||
const { theme } = params; | ||
const { colors } = theme; | ||
|
||
return StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
backgroundColor: colors.background.default, | ||
flexDirection: 'column', | ||
justifyContent: 'center', | ||
}, | ||
inputContainer: { | ||
flex: 1, | ||
backgroundColor: colors.background.default, | ||
justifyContent: 'center', | ||
flexDirection: 'column', | ||
alignItems: 'center', | ||
gap: 16, | ||
}, | ||
amountRow: { | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
flexDirection: 'row', | ||
gap: 4, | ||
}, | ||
amountContainer: { | ||
alignItems: 'center', | ||
}, | ||
stakeButtonText: { | ||
fontSize: 18, | ||
color: colors.text.alternative, | ||
}, | ||
rewardsRateContainer: { | ||
padding: 16, | ||
paddingBottom: 8, | ||
borderColor: colors.border.muted, | ||
}, | ||
reviewButtonContainer: { | ||
padding: 16, | ||
}, | ||
keypad: { | ||
paddingHorizontal: 24, | ||
}, | ||
}); | ||
}; | ||
|
||
export default styleSheet; |
131 changes: 131 additions & 0 deletions
131
app/components/UI/Stake/Views/InputView/StakeInputView.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 |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import React from 'react'; | ||
import { fireEvent, screen } from '@testing-library/react-native'; | ||
import StakeInputView from './StakeInputView'; | ||
import { renderScreen } from '../../../../../util/test/renderWithProvider'; | ||
import Routes from '../../../../../constants/navigation/Routes'; | ||
import { backgroundState } from '../../../../../util/test/initial-root-state'; | ||
import { BN } from 'ethereumjs-util'; | ||
|
||
function render(Component: React.ComponentType) { | ||
return renderScreen( | ||
Component, | ||
{ | ||
name: Routes.STAKE.STAKE, | ||
}, | ||
{ | ||
state: { | ||
engine: { | ||
backgroundState, | ||
}, | ||
}, | ||
}, | ||
); | ||
} | ||
|
||
const mockSetOptions = jest.fn(); | ||
const mockNavigate = jest.fn(); | ||
const mockReset = jest.fn(); | ||
const mockPop = jest.fn(); | ||
|
||
jest.mock('@react-navigation/native', () => { | ||
const actualReactNavigation = jest.requireActual('@react-navigation/native'); | ||
return { | ||
...actualReactNavigation, | ||
useNavigation: () => ({ | ||
navigate: mockNavigate, | ||
setOptions: mockSetOptions.mockImplementation( | ||
actualReactNavigation.useNavigation().setOptions, | ||
), | ||
reset: mockReset, | ||
dangerouslyGetParent: () => ({ | ||
pop: mockPop, | ||
}), | ||
}), | ||
}; | ||
}); | ||
|
||
// Mock necessary modules and hooks | ||
jest.mock('../../../../../selectors/currencyRateController.ts', () => ({ | ||
selectConversionRate: jest.fn(() => 2000), | ||
selectCurrentCurrency: jest.fn(() => 'USD'), | ||
})); | ||
|
||
const mockBalanceBN = new BN('1500000000000000000'); | ||
jest.mock('../../hooks/useBalance', () => ({ | ||
__esModule: true, | ||
default: () => ({ | ||
balance: '1.5', | ||
balanceBN: mockBalanceBN, | ||
balanceFiatNumber: '3000', | ||
}), | ||
})); | ||
|
||
describe('StakeInputView', () => { | ||
it('render matches snapshot', () => { | ||
render(StakeInputView); | ||
expect(screen.toJSON()).toMatchSnapshot(); | ||
}); | ||
|
||
describe('when values are entered in the keypad', () => { | ||
it('updates ETH and fiat values', () => { | ||
render(StakeInputView); | ||
|
||
fireEvent.press(screen.getByText('2')); | ||
|
||
expect(screen.getByText('4000 USD')).toBeTruthy(); | ||
}); | ||
}); | ||
|
||
describe('currency toggle functionality', () => { | ||
it('switches between ETH and fiat correctly', () => { | ||
render(StakeInputView); | ||
|
||
expect(screen.getByText('ETH')).toBeTruthy(); | ||
fireEvent.press(screen.getByText('0 USD')); | ||
|
||
expect(screen.getByText('USD')).toBeTruthy(); | ||
}); | ||
}); | ||
|
||
describe('when calculating rewards', () => { | ||
it('calculates estimated annual rewards based on input', () => { | ||
render(StakeInputView); | ||
|
||
fireEvent.press(screen.getByText('2')); | ||
|
||
expect(screen.getByText('0.052 ETH')).toBeTruthy(); | ||
}); | ||
}); | ||
|
||
describe('quick amount buttons', () => { | ||
it('handles 25% quick amount button press correctly', () => { | ||
render(StakeInputView); | ||
|
||
fireEvent.press(screen.getByText('25%')); | ||
|
||
expect(screen.getByText('0.375')).toBeTruthy(); | ||
}); | ||
}); | ||
|
||
describe('stake button states', () => { | ||
it('displays `Enter amount` if input is 0', () => { | ||
render(StakeInputView); | ||
|
||
expect(screen.getByText('Enter amount')).toBeTruthy(); | ||
}); | ||
|
||
it('displays `Review` on stake button if input is valid', () => { | ||
render(StakeInputView); | ||
|
||
fireEvent.press(screen.getByText('1')); | ||
expect(screen.getByText('Review')).toBeTruthy(); | ||
}); | ||
|
||
it('displays `Not enough ETH` when input exceeds balance', () => { | ||
render(StakeInputView); | ||
|
||
fireEvent.press(screen.getByText('4')); | ||
expect(screen.queryAllByText('Not enough ETH')).toHaveLength(2); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.