Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/components/Receive/__tests__/Receive.test.js
- This file was copied from web/cashtab/src/components/Send/__tests__/Send.test.js.
import React from 'react'; | import React from 'react'; | ||||
import renderer from 'react-test-renderer'; | import renderer from 'react-test-renderer'; | ||||
import { ThemeProvider } from 'styled-components'; | import { ThemeProvider } from 'styled-components'; | ||||
import { theme } from '@assets/styles/theme'; | import { theme } from '@assets/styles/theme'; | ||||
import Send from '@components/Send/Send'; | import Receive from '@components/Receive/Receive'; | ||||
import BCHJS from '@psf/bch-js'; | |||||
import { | import { | ||||
walletWithBalancesAndTokens, | walletWithBalancesAndTokens, | ||||
walletWithBalancesMock, | walletWithBalancesMock, | ||||
walletWithoutBalancesMock, | walletWithoutBalancesMock, | ||||
walletWithBalancesAndTokensWithCorrectState, | walletWithBalancesAndTokensWithCorrectState, | ||||
} from '../../Wallet/__mocks__/walletAndBalancesMock'; | } from '../../Home/__mocks__/walletAndBalancesMock'; | ||||
import { BrowserRouter as Router } from 'react-router-dom'; | import { BrowserRouter as Router } from 'react-router-dom'; | ||||
let realUseContext; | let realUseContext; | ||||
let useContextMock; | let useContextMock; | ||||
beforeEach(() => { | beforeEach(() => { | ||||
realUseContext = React.useContext; | realUseContext = React.useContext; | ||||
useContextMock = React.useContext = jest.fn(); | useContextMock = React.useContext = jest.fn(); | ||||
Show All 16 Lines | |||||
}); | }); | ||||
afterEach(() => { | afterEach(() => { | ||||
React.useContext = realUseContext; | React.useContext = realUseContext; | ||||
}); | }); | ||||
test('Wallet without BCH balance', () => { | test('Wallet without BCH balance', () => { | ||||
useContextMock.mockReturnValue(walletWithoutBalancesMock); | useContextMock.mockReturnValue(walletWithoutBalancesMock); | ||||
const testBCH = new BCHJS(); | |||||
const component = renderer.create( | const component = renderer.create( | ||||
<ThemeProvider theme={theme}> | <ThemeProvider theme={theme}> | ||||
<Router> | <Router> | ||||
<Send jestBCH={testBCH} /> | <Receive /> | ||||
</Router> | </Router> | ||||
</ThemeProvider>, | </ThemeProvider>, | ||||
); | ); | ||||
let tree = component.toJSON(); | let tree = component.toJSON(); | ||||
expect(tree).toMatchSnapshot(); | expect(tree).toMatchSnapshot(); | ||||
}); | }); | ||||
test('Wallet with BCH balances', () => { | test('Wallet with BCH balances', () => { | ||||
useContextMock.mockReturnValue(walletWithBalancesMock); | useContextMock.mockReturnValue(walletWithBalancesMock); | ||||
const testBCH = new BCHJS(); | |||||
const component = renderer.create( | const component = renderer.create( | ||||
<ThemeProvider theme={theme}> | <ThemeProvider theme={theme}> | ||||
<Router> | <Router> | ||||
<Send jestBCH={testBCH} /> | <Receive /> | ||||
</Router> | </Router> | ||||
</ThemeProvider>, | </ThemeProvider>, | ||||
); | ); | ||||
let tree = component.toJSON(); | let tree = component.toJSON(); | ||||
expect(tree).toMatchSnapshot(); | expect(tree).toMatchSnapshot(); | ||||
}); | }); | ||||
test('Wallet with BCH balances and tokens', () => { | test('Wallet with BCH balances and tokens', () => { | ||||
useContextMock.mockReturnValue(walletWithBalancesAndTokens); | useContextMock.mockReturnValue(walletWithBalancesAndTokens); | ||||
const testBCH = new BCHJS(); | |||||
const component = renderer.create( | const component = renderer.create( | ||||
<ThemeProvider theme={theme}> | <ThemeProvider theme={theme}> | ||||
<Router> | <Router> | ||||
<Send jestBCH={testBCH} /> | <Receive /> | ||||
</Router> | </Router> | ||||
</ThemeProvider>, | </ThemeProvider>, | ||||
); | ); | ||||
let tree = component.toJSON(); | let tree = component.toJSON(); | ||||
expect(tree).toMatchSnapshot(); | expect(tree).toMatchSnapshot(); | ||||
}); | }); | ||||
test('Wallet with BCH balances and tokens and state field', () => { | test('Wallet with BCH balances and tokens and state field', () => { | ||||
useContextMock.mockReturnValue(walletWithBalancesAndTokensWithCorrectState); | useContextMock.mockReturnValue(walletWithBalancesAndTokensWithCorrectState); | ||||
const testBCH = new BCHJS(); | |||||
const component = renderer.create( | const component = renderer.create( | ||||
<ThemeProvider theme={theme}> | <ThemeProvider theme={theme}> | ||||
<Router> | <Router> | ||||
<Send jestBCH={testBCH} /> | <Receive /> | ||||
</Router> | </Router> | ||||
</ThemeProvider>, | </ThemeProvider>, | ||||
); | ); | ||||
let tree = component.toJSON(); | let tree = component.toJSON(); | ||||
expect(tree).toMatchSnapshot(); | expect(tree).toMatchSnapshot(); | ||||
}); | }); | ||||
test('Without wallet defined', () => { | test('Without wallet defined', () => { | ||||
useContextMock.mockReturnValue({ | useContextMock.mockReturnValue({ | ||||
wallet: {}, | wallet: {}, | ||||
balances: { totalBalance: 0 }, | balances: { totalBalance: 0 }, | ||||
loading: false, | loading: false, | ||||
}); | }); | ||||
const testBCH = new BCHJS(); | |||||
const component = renderer.create( | const component = renderer.create( | ||||
<ThemeProvider theme={theme}> | <ThemeProvider theme={theme}> | ||||
<Router> | <Router> | ||||
<Send jestBCH={testBCH} /> | <Receive /> | ||||
</Router> | </Router> | ||||
</ThemeProvider>, | </ThemeProvider>, | ||||
); | ); | ||||
let tree = component.toJSON(); | let tree = component.toJSON(); | ||||
expect(tree).toMatchSnapshot(); | expect(tree).toMatchSnapshot(); | ||||
}); | }); |