Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/components/Home/__tests__/Home.test.js
- This file was moved from 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 Home from '../Home'; | ||||
import { | import { | ||||
walletWithBalancesAndTokens, | walletWithBalancesAndTokens, | ||||
walletWithBalancesMock, | walletWithBalancesMock, | ||||
walletWithoutBalancesMock, | walletWithoutBalancesMock, | ||||
walletWithBalancesAndTokensWithCorrectState, | walletWithBalancesAndTokensWithCorrectState, | ||||
} from '../__mocks__/walletAndBalancesMock'; | } from '../__mocks__/walletAndBalancesMock'; | ||||
import { BrowserRouter as Router } from 'react-router-dom'; | import { BrowserRouter as Router } from 'react-router-dom'; | ||||
Show All 9 Lines | afterEach(() => { | ||||
React.useContext = realUseContext; | React.useContext = realUseContext; | ||||
}); | }); | ||||
test('Wallet without BCH balance', () => { | test('Wallet without BCH balance', () => { | ||||
useContextMock.mockReturnValue(walletWithoutBalancesMock); | useContextMock.mockReturnValue(walletWithoutBalancesMock); | ||||
const component = renderer.create( | const component = renderer.create( | ||||
<ThemeProvider theme={theme}> | <ThemeProvider theme={theme}> | ||||
<Router> | <Router> | ||||
<Wallet /> | <Home /> | ||||
</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 component = renderer.create( | const component = renderer.create( | ||||
<ThemeProvider theme={theme}> | <ThemeProvider theme={theme}> | ||||
<Router> | <Router> | ||||
<Wallet /> | <Home /> | ||||
</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 component = renderer.create( | const component = renderer.create( | ||||
<ThemeProvider theme={theme}> | <ThemeProvider theme={theme}> | ||||
<Router> | <Router> | ||||
<Wallet /> | <Home /> | ||||
</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 component = renderer.create( | const component = renderer.create( | ||||
<ThemeProvider theme={theme}> | <ThemeProvider theme={theme}> | ||||
<Router> | <Router> | ||||
<Wallet /> | <Home /> | ||||
</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 }, | ||||
}); | }); | ||||
const component = renderer.create( | const component = renderer.create( | ||||
<ThemeProvider theme={theme}> | <ThemeProvider theme={theme}> | ||||
<Router> | <Router> | ||||
<Wallet /> | <Home /> | ||||
</Router> | </Router> | ||||
</ThemeProvider>, | </ThemeProvider>, | ||||
); | ); | ||||
let tree = component.toJSON(); | let tree = component.toJSON(); | ||||
expect(tree).toMatchSnapshot(); | expect(tree).toMatchSnapshot(); | ||||
}); | }); |