Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/components/Wallet/__tests__/Wallet.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 Wallet from '../Wallet'; | import Wallet from '../Wallet'; | ||||
import { | import { | ||||
walletWithBalancesAndTokens, | walletWithBalancesAndTokens, | ||||
walletWithBalancesMock, | walletWithBalancesMock, | ||||
walletWithoutBalancesMock, | walletWithoutBalancesMock, | ||||
walletWithBalancesAndTokensWithCorrectState, | |||||
walletWithBalancesAndTokensWithEmptyState, | |||||
} from '../__mocks__/walletAndBalancesMock'; | } from '../__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 All 38 Lines | const component = renderer.create( | ||||
<Wallet /> | <Wallet /> | ||||
</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', () => { | |||||
useContextMock.mockReturnValue(walletWithBalancesAndTokensWithCorrectState); | |||||
const component = renderer.create( | |||||
<ThemeProvider theme={theme}> | |||||
<Router> | |||||
<Wallet /> | |||||
</Router> | |||||
</ThemeProvider>, | |||||
); | |||||
let tree = component.toJSON(); | |||||
expect(tree).toMatchSnapshot(); | |||||
}); | |||||
test('Wallet with BCH balances and tokens and state field, but no params in state', () => { | |||||
useContextMock.mockReturnValue(walletWithBalancesAndTokensWithEmptyState); | |||||
const component = renderer.create( | |||||
<ThemeProvider theme={theme}> | |||||
<Router> | |||||
<Wallet /> | |||||
</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 }, | ||||
}); | }); | ||||
const component = renderer.create( | const component = renderer.create( | ||||
<ThemeProvider theme={theme}> | <ThemeProvider theme={theme}> | ||||
<Router> | <Router> | ||||
<Wallet /> | <Wallet /> | ||||
</Router> | </Router> | ||||
</ThemeProvider>, | </ThemeProvider>, | ||||
); | ); | ||||
let tree = component.toJSON(); | let tree = component.toJSON(); | ||||
expect(tree).toMatchSnapshot(); | expect(tree).toMatchSnapshot(); | ||||
}); | }); |