2022-11-29 16:42:59 +01:00
|
|
|
import React from 'react';
|
|
|
|
import { fireEvent } from '@testing-library/react';
|
|
|
|
import configureMockStore from 'redux-mock-store';
|
|
|
|
import thunk from 'redux-thunk';
|
|
|
|
import mockSendState from '../../../../../test/data/mock-send-state.json';
|
|
|
|
import { renderWithProvider } from '../../../../../test/lib/render-helpers';
|
2023-01-18 15:47:29 +01:00
|
|
|
import { AssetType } from '../../../../../shared/constants/transaction';
|
2022-11-29 16:42:59 +01:00
|
|
|
import SendAmountRow from '.';
|
|
|
|
|
|
|
|
const mockUpdateSendAmount = jest.fn();
|
|
|
|
|
|
|
|
jest.mock('../../../../ducks/send', () => ({
|
|
|
|
...jest.requireActual('../../../../ducks/send'),
|
|
|
|
updateSendAmount: () => mockUpdateSendAmount,
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe('SendAmountRow Component', () => {
|
|
|
|
describe('render', () => {
|
|
|
|
describe('Native Asset Type', () => {
|
|
|
|
const mockStore = configureMockStore([thunk])(mockSendState);
|
|
|
|
|
|
|
|
it('should match snapshot for native asset type', () => {
|
|
|
|
const { container } = renderWithProvider(<SendAmountRow />, mockStore);
|
|
|
|
|
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Token Asset Type', () => {
|
|
|
|
const tokenState = {
|
|
|
|
...mockSendState,
|
|
|
|
send: {
|
|
|
|
currentTransactionUUID: '1-tx',
|
|
|
|
draftTransactions: {
|
|
|
|
'1-tx': {
|
|
|
|
asset: {
|
|
|
|
balance: '0x1158e460913d00000', // 20000000000000000000
|
|
|
|
details: {
|
|
|
|
address: '0x617b3f8050a0BD94b6b1da02B4384eE5B4DF13F4',
|
|
|
|
symbol: 'META',
|
|
|
|
balance: '1000000000000000000',
|
|
|
|
decimals: 18,
|
|
|
|
string: '1',
|
|
|
|
balanceError: null,
|
|
|
|
isERC721: false,
|
|
|
|
image: '',
|
|
|
|
standard: 'ERC20',
|
|
|
|
},
|
|
|
|
error: null,
|
2023-01-18 15:47:29 +01:00
|
|
|
type: AssetType.token,
|
2022-11-29 16:42:59 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const mockStore = configureMockStore([thunk])(tokenState);
|
|
|
|
|
|
|
|
it('should match snapshot for token asset type', () => {
|
|
|
|
const { container } = renderWithProvider(<SendAmountRow />, mockStore);
|
|
|
|
|
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
describe('NFT Asset Type', () => {
|
|
|
|
it('should match snapshot for token NFT type', () => {
|
|
|
|
const nftState = {
|
2022-11-29 16:42:59 +01:00
|
|
|
...mockSendState,
|
|
|
|
send: {
|
|
|
|
currentTransactionUUID: '1-tx',
|
|
|
|
draftTransactions: {
|
|
|
|
'1-tx': {
|
|
|
|
asset: {
|
|
|
|
balance: '',
|
|
|
|
details: null,
|
|
|
|
error: null,
|
2023-01-18 15:47:29 +01:00
|
|
|
type: AssetType.NFT,
|
2022-11-29 16:42:59 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
const mockStore = configureMockStore([thunk])(nftState);
|
2022-11-29 16:42:59 +01:00
|
|
|
|
|
|
|
const { container } = renderWithProvider(<SendAmountRow />, mockStore);
|
|
|
|
|
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('updateAmount', () => {
|
|
|
|
const mockStore = configureMockStore([thunk])(mockSendState);
|
|
|
|
|
|
|
|
it('should call updateSendAmount', () => {
|
|
|
|
const { queryByTestId } = renderWithProvider(
|
|
|
|
<SendAmountRow />,
|
|
|
|
mockStore,
|
|
|
|
);
|
|
|
|
queryByTestId('currency-input');
|
|
|
|
|
|
|
|
fireEvent.change(queryByTestId('currency-input'), {
|
|
|
|
target: { value: 0.5 },
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(mockUpdateSendAmount).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|