Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistevam committed Feb 2, 2024
1 parent 062555f commit 38d63f8
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { AdvancedGasFeePopoverContextProvider } from '../../context';
import AdvancedGasFeeGasLimit from '../../advanced-gas-fee-gas-limit';
import BaseFeeInput from './base-fee-input';

const LOW_BASE_FEE = 0.000000001;

jest.mock('../../../../../store/actions', () => ({
disconnectGasFeeEstimatePoller: jest.fn(),
getGasFeeEstimatesAndStartPolling: jest
Expand Down Expand Up @@ -91,6 +93,32 @@ describe('BaseFeeInput', () => {
expect(document.getElementsByTagName('input')[0]).toHaveValue(200);
});

describe('renders baseFee if current estimate used is custom', () => {
const testCases = [
{
description: 'with a high value',
maxFeePerGas: '0x2E90EDD000',
expectedValue: 200,
},
{
description: 'with a low value',
maxFeePerGas: '0x1',
expectedValue: LOW_BASE_FEE,
},
];

it.each(testCases)('$description', ({ maxFeePerGas, expectedValue }) => {
render({
txParams: {
maxFeePerGas,
},
});
expect(document.getElementsByTagName('input')[0]).toHaveValue(
expectedValue,
);
});
});

it('should show current value of estimatedBaseFee in users primary currency in right side of input box', () => {
render({
txParams: {
Expand Down Expand Up @@ -157,13 +185,13 @@ describe('BaseFeeInput', () => {

expect(input.value).toBe('1');
});
it('handles small numbers', () => {
it('handles low numbers', () => {
const { getByTestId } = render(<BaseFeeInput />);
const input = getByTestId('base-fee-input');

fireEvent.change(input, { target: { value: 0.0000000001 } });
fireEvent.change(input, { target: { value: LOW_BASE_FEE } });

expect(input.value).toBe('0.0000000001');
expect(input.value).toBe('0.000000001');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import AdvancedGasFeeGasLimit from '../../advanced-gas-fee-gas-limit';
import { CHAIN_IDS } from '../../../../../../shared/constants/network';
import PriorityfeeInput from './priority-fee-input';

const LOW_PRIORITY_FEE = 0.000000001;

jest.mock('../../../../../store/actions', () => ({
disconnectGasFeeEstimatePoller: jest.fn(),
getGasFeeEstimatesAndStartPolling: jest
Expand Down Expand Up @@ -83,13 +85,33 @@ describe('PriorityfeeInput', () => {
);
});

it('should renders priorityfee value from transaction if current estimate used is custom', () => {
render({
txParams: {
describe('renders priorityFee if current estimate used is custom', () => {
const testCases = [
{
description: 'with a high value',
maxPriorityFeePerGas: '0x77359400',
expectedValue: 2,
},
});
expect(document.getElementsByTagName('input')[0]).toHaveValue(2);
{
description: 'with a low value',
maxPriorityFeePerGas: '0x1',
expectedValue: LOW_PRIORITY_FEE,
},
];

it.each(testCases)(
'$description',
({ maxPriorityFeePerGas, expectedValue }) => {
render({
txParams: {
maxPriorityFeePerGas,
},
});
expect(document.getElementsByTagName('input')[0]).toHaveValue(
expectedValue,
);
},
);
});

it('should show current priority fee range in subtext', () => {
Expand Down Expand Up @@ -149,13 +171,13 @@ describe('PriorityfeeInput', () => {

expect(input.value).toBe('1');
});
it('handles small numbers', () => {
it('handles low numbers', () => {
const { getByTestId } = render(<PriorityfeeInput />);
const input = getByTestId('priority-fee-input');

fireEvent.change(input, { target: { value: 0.0000000001 } });
fireEvent.change(input, { target: { value: LOW_PRIORITY_FEE } });

expect(input.value).toBe('0.0000000001');
expect(input.value).toBe('0.000000001');
});
});
});

0 comments on commit 38d63f8

Please sign in to comment.