diff --git a/app/components/Views/confirmations/SendFlow/components/CustomNonceModal/__snapshots__/index.test.tsx.snap b/app/components/Views/confirmations/SendFlow/components/CustomNonceModal/__snapshots__/index.test.tsx.snap
index cdda4176a2b..c36a73e7205 100644
--- a/app/components/Views/confirmations/SendFlow/components/CustomNonceModal/__snapshots__/index.test.tsx.snap
+++ b/app/components/Views/confirmations/SendFlow/components/CustomNonceModal/__snapshots__/index.test.tsx.snap
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`CustomNonceModal should render correctly 1`] = `
+exports[`CustomNonceModal renders correctly 1`] = `
-
-
-
- Warning: You may encounter issues with future transactions if you continue. Use with caution.
-
-
{
const { colors, themeAppearance } = useTheme();
const styles = createStyles(colors);
- const incrementDecrementNonce = (decrement) => {
- let newValue = nonce;
- newValue = decrement ? --newValue : ++newValue;
- onChangeText(newValue > 1 ? newValue : 1);
+ const incrementDecrementNonce = (isDecrement) => {
+ const currentNonce = Number(nonce);
+ const updatedValue = isDecrement ? currentNonce - 1 : currentNonce + 1;
+ const clampedValue = Math.max(updatedValue, 0);
+
+ onChangeText(clampedValue);
};
const saveAndClose = () => {
@@ -192,6 +194,7 @@ const CustomModalNonce = ({ proposedNonce, nonceValue, close, save }) => {
incrementDecrementNonce(true)}
+ testID={'decrement-nonce'}
>
{
incrementDecrementNonce(false)}
+ testID={'increment-nonce'}
>
+ shallow(
+ ,
+ );
describe('CustomNonceModal', () => {
- const proposedNonce = 26;
- const customNonce = 28;
- it('should render correctly', () => {
- const noop = () => ({});
- const wrapper = shallow(
- ,
- );
+ it('renders correctly', () => {
+ const wrapper = createWrapper();
expect(wrapper).toMatchSnapshot();
});
- it('should handle only numeric inputs', () => {
- const saveMock = jest.fn();
- const closeMock = jest.fn();
+ it('handles only numeric inputs', () => {
+ const wrapper = createWrapper();
+ const nonceTextInput = wrapper.find('TextInput');
+ nonceTextInput.simulate('changeText', '30c');
+ expect(wrapper.find('TextInput').prop('value')).toBe(
+ String(PROPOSED_NONCE),
+ );
+ nonceTextInput.simulate('changeText', '30');
+ expect(wrapper.find('TextInput').prop('value')).toBe('30');
+ });
+
+ it('increments nonce correctly', () => {
+ const wrapper = createWrapper();
+ const incrementButton = wrapper.find({ testID: 'increment-nonce' });
+
+ incrementButton.simulate('press');
+ expect(wrapper.find('TextInput').prop('value')).toBe(
+ String(PROPOSED_NONCE + 1),
+ );
+ });
+
+ it('decrements nonce correctly', () => {
const wrapper = shallow(
,
);
- const nonceTextInput = wrapper.find('TextInput');
- nonceTextInput.simulate('changeText', '30c');
- expect(wrapper.find('TextInput').prop('value')).toBe(String(proposedNonce));
- nonceTextInput.simulate('changeText', '30');
- expect(wrapper.find('TextInput').prop('value')).toBe('30');
+ const decrementButton = wrapper.find({ testID: 'decrement-nonce' });
+
+ decrementButton.simulate('press');
+ expect(wrapper.find('TextInput').prop('value')).toBe(
+ String(PROPOSED_NONCE - 1),
+ );
+ });
+
+ it('does not decrement the nonce value below 0 when the current nonce is 0', () => {
+ const wrapper = createWrapper();
+ wrapper.setProps({ proposedNonce: 0, nonceValue: 0 });
+ const decrementButton = wrapper.find({ testID: 'decrement-nonce' });
+
+ decrementButton.simulate('press');
+ expect(wrapper.find('TextInput').prop('value')).toBe(String(0));
});
});