+
{apiError ||
sendTokenAmountError ||
sendTokenAddressError ? (
<>
Send {token.info.tokenName}
{apiError &&
}
>
) : (
submit()}
>
Send {token.info.tokenName}
)}
{queryStringText && (
)}
{apiError && (
-
+
An error occured on our end.
Reconnecting...
)}
>
)}
>
);
};
export default SendToken;
diff --git a/web/cashtab/src/components/Send/__tests__/SendToken.test.js b/web/cashtab/src/components/Send/__tests__/SendToken.test.js
new file mode 100644
index 000000000..5485bb5f9
--- /dev/null
+++ b/web/cashtab/src/components/Send/__tests__/SendToken.test.js
@@ -0,0 +1,120 @@
+import React from 'react';
+import renderer from 'react-test-renderer';
+import { ThemeProvider } from 'styled-components';
+import { theme } from '@assets/styles/theme';
+import SendToken from '@components/Send/SendToken';
+import BCHJS from '@psf/bch-js';
+import {
+ walletWithBalancesAndTokens,
+ walletWithBalancesAndTokensWithCorrectState,
+ walletWithBalancesAndTokensWithEmptyState,
+} from '../../Wallet/__mocks__/walletAndBalancesMock';
+import { BrowserRouter as Router } from 'react-router-dom';
+
+let realUseContext;
+let useContextMock;
+
+beforeEach(() => {
+ realUseContext = React.useContext;
+ useContextMock = React.useContext = jest.fn();
+
+ // Mock method not implemented in JSDOM
+ // See reference at https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
+ Object.defineProperty(window, 'matchMedia', {
+ writable: true,
+ value: jest.fn().mockImplementation(query => ({
+ matches: false,
+ media: query,
+ onchange: null,
+ addListener: jest.fn(), // Deprecated
+ removeListener: jest.fn(), // Deprecated
+ addEventListener: jest.fn(),
+ removeEventListener: jest.fn(),
+ dispatchEvent: jest.fn(),
+ })),
+ });
+});
+
+afterEach(() => {
+ React.useContext = realUseContext;
+});
+
+test('Wallet with BCH balances and tokens', () => {
+ const testBCH = new BCHJS();
+ useContextMock.mockReturnValue(walletWithBalancesAndTokens);
+ const component = renderer.create(
+
+
+
+
+ ,
+ );
+ let tree = component.toJSON();
+ expect(tree).toMatchSnapshot();
+});
+
+test('Wallet with BCH balances and tokens and state field', () => {
+ const testBCH = new BCHJS();
+ useContextMock.mockReturnValue(walletWithBalancesAndTokensWithCorrectState);
+ const component = renderer.create(
+
+
+
+
+ ,
+ );
+ let tree = component.toJSON();
+ expect(tree).toMatchSnapshot();
+});
+
+test('Wallet with BCH balances and tokens and state field, but no params in state', () => {
+ const testBCH = new BCHJS();
+ useContextMock.mockReturnValue(walletWithBalancesAndTokensWithEmptyState);
+ const component = renderer.create(
+
+
+
+
+ ,
+ );
+ let tree = component.toJSON();
+ expect(tree).toMatchSnapshot();
+});
+
+test('Without wallet defined', () => {
+ const testBCH = new BCHJS();
+ useContextMock.mockReturnValue({
+ wallet: {},
+ balances: { totalBalance: 0 },
+ loading: false,
+ });
+ const component = renderer.create(
+
+
+
+
+ ,
+ );
+ let tree = component.toJSON();
+ expect(tree).toMatchSnapshot();
+});
diff --git a/web/cashtab/src/components/Send/__tests__/__snapshots__/SendToken.test.js.snap b/web/cashtab/src/components/Send/__tests__/__snapshots__/SendToken.test.js.snap
new file mode 100644
index 000000000..ff46a88d4
--- /dev/null
+++ b/web/cashtab/src/components/Send/__tests__/__snapshots__/SendToken.test.js.snap
@@ -0,0 +1,789 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP @generated
+
+exports[`Wallet with BCH balances and tokens 1`] = `
+Array [
+
+
+ Available balance
+
+
+ 6.001
+
+ TBS
+
+
,
+
,
+]
+`;
+
+exports[`Wallet with BCH balances and tokens and state field 1`] = `
+Array [
+
+
+ Available balance
+
+
+ 6.001
+
+ TBS
+
+
,
+
,
+]
+`;
+
+exports[`Wallet with BCH balances and tokens and state field, but no params in state 1`] = `
+Array [
+
+
+ Available balance
+
+
+ 6.001
+
+ TBS
+
+
,
+
,
+]
+`;
+
+exports[`Without wallet defined 1`] = `null`;