2021-02-04 19:15:23 +01:00
|
|
|
import React from 'react';
|
2022-12-06 17:49:08 +01:00
|
|
|
import { waitFor } from '@testing-library/react';
|
|
|
|
import configureMockStore from 'redux-mock-store';
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2022-12-06 17:49:08 +01:00
|
|
|
import { renderWithProvider } from '../../../../test/lib/render-helpers';
|
|
|
|
import mockSendState from '../../../../test/data/mock-send-state.json';
|
|
|
|
import SendContent from '.';
|
|
|
|
|
|
|
|
jest.mock('../../../store/actions', () => ({
|
|
|
|
disconnectGasFeeEstimatePoller: jest.fn(),
|
|
|
|
getGasFeeEstimatesAndStartPolling: jest.fn().mockResolvedValue(),
|
|
|
|
addPollingTokenToAppState: jest.fn(),
|
|
|
|
removePollingTokenFromAppState: jest.fn(),
|
|
|
|
createTransactionEventFragment: jest.fn(),
|
|
|
|
getGasFeeTimeEstimate: jest.fn().mockResolvedValue('unknown'),
|
|
|
|
}));
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('SendContent Component', () => {
|
2022-12-06 17:49:08 +01:00
|
|
|
describe('render', () => {
|
|
|
|
const mockStore = configureMockStore()(mockSendState);
|
2021-05-20 20:28:25 +02:00
|
|
|
|
2022-12-06 17:49:08 +01:00
|
|
|
it('should match snapshot', async () => {
|
|
|
|
const props = {
|
|
|
|
gasIsExcessive: false,
|
|
|
|
showHexData: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
const { container } = renderWithProvider(
|
|
|
|
<SendContent {...props} />,
|
|
|
|
mockStore,
|
|
|
|
);
|
|
|
|
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2022-12-06 17:49:08 +01:00
|
|
|
describe('SendHexDataRow', () => {
|
|
|
|
const tokenAssetState = {
|
|
|
|
...mockSendState,
|
|
|
|
send: {
|
|
|
|
...mockSendState.send,
|
|
|
|
draftTransactions: {
|
|
|
|
'1-tx': {
|
|
|
|
...mockSendState.send.draftTransactions['1-tx'],
|
|
|
|
asset: {
|
|
|
|
balance: '0x3635c9adc5dea00000',
|
|
|
|
details: {
|
|
|
|
address: '0xAddress',
|
|
|
|
decimals: 18,
|
|
|
|
symbol: 'TST',
|
|
|
|
balance: '1',
|
|
|
|
standard: 'ERC20',
|
|
|
|
},
|
|
|
|
error: null,
|
|
|
|
type: 'TOKEN',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
it('should not render the SendHexDataRow if props.showHexData is false', async () => {
|
|
|
|
const props = {
|
|
|
|
gasIsExcessive: false,
|
|
|
|
showHexData: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
const mockStore = configureMockStore()(mockSendState);
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2022-12-06 17:49:08 +01:00
|
|
|
const { queryByText } = renderWithProvider(
|
|
|
|
<SendContent {...props} />,
|
|
|
|
mockStore,
|
2021-04-15 20:01:46 +02:00
|
|
|
);
|
2022-12-06 17:49:08 +01:00
|
|
|
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(queryByText('Hex data:')).not.toBeInTheDocument();
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2022-12-06 17:49:08 +01:00
|
|
|
it('should not render the SendHexDataRow if the asset type is TOKEN (ERC-20)', async () => {
|
|
|
|
const props = {
|
|
|
|
gasIsExcessive: false,
|
|
|
|
showHexData: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Use token draft transaction asset
|
|
|
|
const mockState = configureMockStore()(tokenAssetState);
|
|
|
|
|
|
|
|
const { queryByText } = renderWithProvider(
|
|
|
|
<SendContent {...props} />,
|
|
|
|
mockState,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2022-12-06 17:49:08 +01:00
|
|
|
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(queryByText('Hex data:')).not.toBeInTheDocument();
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2022-12-06 17:49:08 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('Gas Error', () => {
|
|
|
|
it('should show gas warning when gasIsExcessive prop is true.', async () => {
|
|
|
|
const props = {
|
|
|
|
gasIsExcessive: true,
|
|
|
|
showHexData: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
const mockStore = configureMockStore()(mockSendState);
|
2018-08-16 09:43:13 +02:00
|
|
|
|
2022-12-06 17:49:08 +01:00
|
|
|
const { queryByTestId } = renderWithProvider(
|
|
|
|
<SendContent {...props} />,
|
|
|
|
mockStore,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2022-12-06 17:49:08 +01:00
|
|
|
|
|
|
|
const gasWarning = queryByTestId('gas-warning-message');
|
|
|
|
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(gasWarning).toBeInTheDocument();
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2022-12-06 17:49:08 +01:00
|
|
|
it('should show gas warning for none gasEstimateType in state', async () => {
|
|
|
|
const props = {
|
|
|
|
gasIsExcessive: false,
|
|
|
|
showHexData: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
const noGasPriceState = {
|
|
|
|
...mockSendState,
|
|
|
|
metamask: {
|
|
|
|
...mockSendState.metamask,
|
|
|
|
gasEstimateType: 'none',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const mockStore = configureMockStore()(noGasPriceState);
|
|
|
|
|
|
|
|
const { queryByTestId } = renderWithProvider(
|
|
|
|
<SendContent {...props} />,
|
|
|
|
mockStore,
|
2021-11-03 20:03:54 +01:00
|
|
|
);
|
2022-12-06 17:49:08 +01:00
|
|
|
|
|
|
|
const gasWarning = queryByTestId('gas-warning-message');
|
|
|
|
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(gasWarning).toBeInTheDocument();
|
|
|
|
});
|
2021-11-03 20:03:54 +01:00
|
|
|
});
|
2022-12-06 17:49:08 +01:00
|
|
|
});
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2022-12-06 17:49:08 +01:00
|
|
|
describe('Recipient Warning', () => {
|
|
|
|
it('should show recipient warning with knownAddressRecipient state in draft transaction state', async () => {
|
|
|
|
const props = {
|
|
|
|
gasIsExcessive: false,
|
2019-07-31 21:56:44 +02:00
|
|
|
showHexData: false,
|
2022-12-06 17:49:08 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const knownRecipientWarningState = {
|
|
|
|
...mockSendState,
|
|
|
|
send: {
|
|
|
|
...mockSendState.send,
|
|
|
|
draftTransactions: {
|
|
|
|
'1-tx': {
|
|
|
|
...mockSendState.send.draftTransactions['1-tx'],
|
|
|
|
recipient: {
|
|
|
|
...mockSendState.send.draftTransactions['1-tx'].recipient,
|
|
|
|
warning: 'knownAddressRecipient',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const mockStore = configureMockStore()(knownRecipientWarningState);
|
|
|
|
|
|
|
|
const { queryByTestId } = renderWithProvider(
|
|
|
|
<SendContent {...props} />,
|
|
|
|
mockStore,
|
|
|
|
);
|
|
|
|
|
|
|
|
const sendWarning = queryByTestId('send-warning');
|
|
|
|
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(sendWarning).toBeInTheDocument();
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2019-07-24 01:51:13 +02:00
|
|
|
|
2022-12-06 17:49:08 +01:00
|
|
|
describe('Assert Error', () => {
|
|
|
|
it('should render dialog error with asset error in draft transaction state', async () => {
|
|
|
|
const props = {
|
|
|
|
gasIsExcessive: false,
|
|
|
|
showHexData: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
const assertErrorState = {
|
|
|
|
...mockSendState,
|
|
|
|
send: {
|
|
|
|
...mockSendState.send,
|
|
|
|
draftTransactions: {
|
|
|
|
'1-tx': {
|
|
|
|
...mockSendState.send.draftTransactions['1-tx'],
|
|
|
|
asset: {
|
|
|
|
...mockSendState.send.draftTransactions['1-tx'].asset,
|
|
|
|
error: 'transactionError',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const mockStore = configureMockStore()(assertErrorState);
|
|
|
|
|
|
|
|
const { queryByTestId } = renderWithProvider(
|
|
|
|
<SendContent {...props} />,
|
|
|
|
mockStore,
|
|
|
|
);
|
|
|
|
|
|
|
|
const dialogMessage = queryByTestId('dialog-message');
|
2020-08-28 17:27:07 +02:00
|
|
|
|
2022-12-06 17:49:08 +01:00
|
|
|
await waitFor(() => {
|
|
|
|
expect(dialogMessage).toBeInTheDocument();
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2022-12-06 17:49:08 +01:00
|
|
|
});
|
2020-08-28 17:27:07 +02:00
|
|
|
|
2022-12-06 17:49:08 +01:00
|
|
|
describe('Warning', () => {
|
|
|
|
it('should display warning dialog message from warning prop', async () => {
|
|
|
|
const props = {
|
|
|
|
gasIsExcessive: false,
|
|
|
|
showHexData: false,
|
|
|
|
warning: 'warning',
|
|
|
|
};
|
|
|
|
|
|
|
|
const mockStore = configureMockStore()(mockSendState);
|
|
|
|
|
|
|
|
const { queryByTestId } = renderWithProvider(
|
|
|
|
<SendContent {...props} />,
|
|
|
|
mockStore,
|
|
|
|
);
|
2020-08-28 17:27:07 +02:00
|
|
|
|
2022-12-06 17:49:08 +01:00
|
|
|
const dialogMessage = queryByTestId('dialog-message');
|
|
|
|
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(dialogMessage).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|