Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/components/Airdrop/__tests__/Airdrop.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 Airdrop from 'components/Airdrop/Airdrop'; | import Airdrop from 'components/Airdrop/Airdrop'; | ||||
import BCHJS from '@psf/bch-js'; | |||||
import { | import { | ||||
walletWithBalancesAndTokens, | walletWithBalancesAndTokens, | ||||
walletWithBalancesMock, | walletWithBalancesMock, | ||||
walletWithoutBalancesMock, | walletWithoutBalancesMock, | ||||
walletWithBalancesAndTokensWithCorrectState, | walletWithBalancesAndTokensWithCorrectState, | ||||
} from '../../Home/__mocks__/walletAndBalancesMock'; | } from '../../Home/__mocks__/walletAndBalancesMock'; | ||||
import { BrowserRouter as Router } from 'react-router-dom'; | import { BrowserRouter as Router } from 'react-router-dom'; | ||||
import { WalletContext } from 'utils/context'; | import { WalletContext } from 'utils/context'; | ||||
Show All 12 Lines | Object.defineProperty(window, 'matchMedia', { | ||||
addEventListener: jest.fn(), | addEventListener: jest.fn(), | ||||
removeEventListener: jest.fn(), | removeEventListener: jest.fn(), | ||||
dispatchEvent: jest.fn(), | dispatchEvent: jest.fn(), | ||||
})), | })), | ||||
}); | }); | ||||
}); | }); | ||||
test('Wallet without BCH balance', () => { | test('Wallet without BCH balance', () => { | ||||
const testBCH = new BCHJS(); | |||||
const component = renderer.create( | const component = renderer.create( | ||||
<WalletContext.Provider value={walletWithoutBalancesMock}> | <WalletContext.Provider value={walletWithoutBalancesMock}> | ||||
<ThemeProvider theme={theme}> | <ThemeProvider theme={theme}> | ||||
<Router> | <Router> | ||||
<Airdrop jestBCH={testBCH} /> | <Airdrop /> | ||||
</Router> | </Router> | ||||
</ThemeProvider> | </ThemeProvider> | ||||
</WalletContext.Provider>, | </WalletContext.Provider>, | ||||
); | ); | ||||
let tree = component.toJSON(); | let tree = component.toJSON(); | ||||
expect(tree).toMatchSnapshot(); | expect(tree).toMatchSnapshot(); | ||||
}); | }); | ||||
test('Wallet with BCH balances', () => { | test('Wallet with BCH balances', () => { | ||||
const testBCH = new BCHJS(); | |||||
const component = renderer.create( | const component = renderer.create( | ||||
<WalletContext.Provider value={walletWithBalancesMock}> | <WalletContext.Provider value={walletWithBalancesMock}> | ||||
<ThemeProvider theme={theme}> | <ThemeProvider theme={theme}> | ||||
<Router> | <Router> | ||||
<Airdrop jestBCH={testBCH} /> | <Airdrop /> | ||||
</Router> | </Router> | ||||
</ThemeProvider> | </ThemeProvider> | ||||
</WalletContext.Provider>, | </WalletContext.Provider>, | ||||
); | ); | ||||
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', () => { | ||||
const testBCH = new BCHJS(); | |||||
const component = renderer.create( | const component = renderer.create( | ||||
<WalletContext.Provider value={walletWithBalancesAndTokens}> | <WalletContext.Provider value={walletWithBalancesAndTokens}> | ||||
<ThemeProvider theme={theme}> | <ThemeProvider theme={theme}> | ||||
<Router> | <Router> | ||||
<Airdrop jestBCH={testBCH} /> | <Airdrop /> | ||||
</Router> | </Router> | ||||
</ThemeProvider> | </ThemeProvider> | ||||
</WalletContext.Provider>, | </WalletContext.Provider>, | ||||
); | ); | ||||
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', () => { | ||||
const testBCH = new BCHJS(); | |||||
const component = renderer.create( | const component = renderer.create( | ||||
<WalletContext.Provider | <WalletContext.Provider | ||||
value={walletWithBalancesAndTokensWithCorrectState} | value={walletWithBalancesAndTokensWithCorrectState} | ||||
> | > | ||||
<ThemeProvider theme={theme}> | <ThemeProvider theme={theme}> | ||||
<Router> | <Router> | ||||
<Airdrop jestBCH={testBCH} /> | <Airdrop /> | ||||
</Router> | </Router> | ||||
</ThemeProvider> | </ThemeProvider> | ||||
</WalletContext.Provider>, | </WalletContext.Provider>, | ||||
); | ); | ||||
let tree = component.toJSON(); | let tree = component.toJSON(); | ||||
expect(tree).toMatchSnapshot(); | expect(tree).toMatchSnapshot(); | ||||
}); | }); | ||||
test('Without wallet defined', () => { | test('Without wallet defined', () => { | ||||
const withoutWalletDefinedMock = { | const withoutWalletDefinedMock = { | ||||
wallet: {}, | wallet: {}, | ||||
balances: { totalBalance: 0 }, | balances: { totalBalance: 0 }, | ||||
loading: false, | loading: false, | ||||
}; | }; | ||||
const testBCH = new BCHJS(); | |||||
const component = renderer.create( | const component = renderer.create( | ||||
<WalletContext.Provider value={withoutWalletDefinedMock}> | <WalletContext.Provider value={withoutWalletDefinedMock}> | ||||
<ThemeProvider theme={theme}> | <ThemeProvider theme={theme}> | ||||
<Router> | <Router> | ||||
<Airdrop jestBCH={testBCH} /> | <Airdrop /> | ||||
</Router> | </Router> | ||||
</ThemeProvider> | </ThemeProvider> | ||||
</WalletContext.Provider>, | </WalletContext.Provider>, | ||||
); | ); | ||||
let tree = component.toJSON(); | let tree = component.toJSON(); | ||||
expect(tree).toMatchSnapshot(); | expect(tree).toMatchSnapshot(); | ||||
}); | }); |