Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/components/Tokens/__tests__/Tokens.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 Tokens from '@components/Tokens/Tokens'; | import Tokens from '@components/Tokens/Tokens'; | ||||
import BCHJS from '@psf/bch-js'; | import BCHJS from '@psf/bch-js'; | ||||
import { | import { | ||||
walletWithBalancesAndTokens, | walletWithBalancesAndTokens, | ||||
walletWithBalancesMock, | walletWithBalancesMock, | ||||
walletWithoutBalancesMock, | walletWithoutBalancesMock, | ||||
walletWithBalancesAndTokensWithCorrectState, | walletWithBalancesAndTokensWithCorrectState, | ||||
walletWithBalancesAndTokensWithEmptyState, | |||||
} from '../../Wallet/__mocks__/walletAndBalancesMock'; | } from '../../Wallet/__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; | ||||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | const component = renderer.create( | ||||
<Tokens jestBCH={testBCH} /> | <Tokens jestBCH={testBCH} /> | ||||
</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, but no params in state', () => { | |||||
useContextMock.mockReturnValue(walletWithBalancesAndTokensWithEmptyState); | |||||
const testBCH = new BCHJS(); | |||||
const component = renderer.create( | |||||
<ThemeProvider theme={theme}> | |||||
<Router> | |||||
<Tokens jestBCH={testBCH} /> | |||||
</Router> | |||||
</ThemeProvider>, | |||||
); | |||||
let tree = component.toJSON(); | |||||
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 testBCH = new BCHJS(); | ||||
const component = renderer.create( | const component = renderer.create( | ||||
Show All 9 Lines |