mirror of
https://github.com/oceanprotocol/commons.git
synced 2023-03-15 18:03:00 +01:00
some test fixes
This commit is contained in:
parent
7cc2de7d8b
commit
84c0877c43
@ -3,7 +3,7 @@ import oceanMock from './ocean-mock'
|
||||
const userMock = {
|
||||
isLogged: false,
|
||||
isLoading: false,
|
||||
isWeb3: false,
|
||||
isBurner: false,
|
||||
isOceanNetwork: false,
|
||||
account: '',
|
||||
web3: {},
|
||||
@ -11,14 +11,15 @@ const userMock = {
|
||||
balance: { eth: 0, ocn: 0 },
|
||||
network: '',
|
||||
requestFromFaucet: jest.fn(),
|
||||
unlockAccounts: jest.fn(),
|
||||
loginMetamask: jest.fn(),
|
||||
loginBurnerWallet: jest.fn(),
|
||||
message: ''
|
||||
}
|
||||
|
||||
const userMockConnected = {
|
||||
isLogged: true,
|
||||
isLoading: false,
|
||||
isWeb3: true,
|
||||
isBurner: false,
|
||||
isOceanNetwork: true,
|
||||
account: '0xxxxxx',
|
||||
web3: {},
|
||||
@ -26,7 +27,8 @@ const userMockConnected = {
|
||||
balance: { eth: 0, ocn: 0 },
|
||||
network: '',
|
||||
requestFromFaucet: jest.fn(),
|
||||
unlockAccounts: jest.fn(),
|
||||
loginMetamask: jest.fn(),
|
||||
loginBurnerWallet: jest.fn(),
|
||||
message: ''
|
||||
}
|
||||
|
||||
|
@ -5,18 +5,18 @@ import { User } from '../../context'
|
||||
import { userMock, userMockConnected } from '../../../__mocks__/user-mock'
|
||||
|
||||
describe('Web3message', () => {
|
||||
it('renders with noWeb3 message', () => {
|
||||
it('renders with burner wallet message', () => {
|
||||
const { container } = render(
|
||||
<User.Provider value={{ ...userMock }}>
|
||||
<User.Provider value={{ ...userMockConnected, isBurner: true }}>
|
||||
<Web3message />
|
||||
</User.Provider>
|
||||
)
|
||||
expect(container.firstChild).toHaveTextContent('Not a Web3 Browser')
|
||||
expect(container.firstChild).toHaveTextContent('Burner Wallet')
|
||||
})
|
||||
|
||||
it('renders with wrongNetwork message', () => {
|
||||
const { container } = render(
|
||||
<User.Provider value={{ ...userMock, isWeb3: true }}>
|
||||
<User.Provider value={{ ...userMockConnected, isOceanNetwork: false }}>
|
||||
<Web3message />
|
||||
</User.Provider>
|
||||
)
|
||||
@ -28,12 +28,12 @@ describe('Web3message', () => {
|
||||
it('renders with noAccount message', () => {
|
||||
const { container } = render(
|
||||
<User.Provider
|
||||
value={{ ...userMock, isWeb3: true, isOceanNetwork: true }}
|
||||
value={{ ...userMock, isOceanNetwork: true }}
|
||||
>
|
||||
<Web3message />
|
||||
</User.Provider>
|
||||
)
|
||||
expect(container.firstChild).toHaveTextContent('No accounts detected')
|
||||
expect(container.firstChild).toHaveTextContent('No wallet selected.')
|
||||
})
|
||||
|
||||
it('renders with hasAccount message', () => {
|
||||
@ -44,21 +44,4 @@ describe('Web3message', () => {
|
||||
)
|
||||
expect(container.firstChild).toHaveTextContent('0xxxxxx')
|
||||
})
|
||||
|
||||
it('button click fires unlockAccounts', () => {
|
||||
const { getByText } = render(
|
||||
<User.Provider
|
||||
value={{
|
||||
...userMock,
|
||||
isWeb3: true,
|
||||
isOceanNetwork: true
|
||||
}}
|
||||
>
|
||||
<Web3message />
|
||||
</User.Provider>
|
||||
)
|
||||
|
||||
fireEvent.click(getByText('Unlock Account'))
|
||||
expect(userMock.unlockAccounts).toBeCalled()
|
||||
})
|
||||
})
|
||||
|
@ -2,6 +2,7 @@ import React from 'react'
|
||||
|
||||
export const User = React.createContext({
|
||||
isLogged: false,
|
||||
isBurner: false,
|
||||
isLoading: false,
|
||||
isOceanNetwork: false,
|
||||
account: '',
|
||||
|
@ -3,6 +3,7 @@ import { render } from '@testing-library/react'
|
||||
import { MemoryRouter } from 'react-router'
|
||||
import { User } from '../context'
|
||||
import History from './History'
|
||||
import { userMock } from '../../__mocks__/user-mock'
|
||||
|
||||
describe('History', () => {
|
||||
it('renders without crashing', () => {
|
||||
@ -14,24 +15,10 @@ describe('History', () => {
|
||||
expect(container.firstChild).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('outputs Web3 message when no Web3 detected', () => {
|
||||
const context = {
|
||||
isLogged: false,
|
||||
isLoading: false,
|
||||
isWeb3: false,
|
||||
isOceanNetwork: false,
|
||||
account: '',
|
||||
web3: {},
|
||||
ocean: {},
|
||||
balance: { eth: 0, ocn: 0 },
|
||||
network: '',
|
||||
requestFromFaucet: () => {},
|
||||
unlockAccounts: () => {},
|
||||
message: ''
|
||||
}
|
||||
it('outputs no wallet selected', () => {
|
||||
|
||||
const { container } = render(
|
||||
<User.Provider value={context}>
|
||||
<User.Provider value={{ ...userMock, isOceanNetwork: true }}>
|
||||
<MemoryRouter>
|
||||
<History />
|
||||
</MemoryRouter>
|
||||
@ -39,7 +26,7 @@ describe('History', () => {
|
||||
)
|
||||
expect(container.querySelector('.message')).toBeInTheDocument()
|
||||
expect(container.querySelector('.message')).toHaveTextContent(
|
||||
'Not a Web3 Browser.'
|
||||
'No wallet selected.'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user