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 = {
|
const userMock = {
|
||||||
isLogged: false,
|
isLogged: false,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
isWeb3: false,
|
isBurner: false,
|
||||||
isOceanNetwork: false,
|
isOceanNetwork: false,
|
||||||
account: '',
|
account: '',
|
||||||
web3: {},
|
web3: {},
|
||||||
@ -11,14 +11,15 @@ const userMock = {
|
|||||||
balance: { eth: 0, ocn: 0 },
|
balance: { eth: 0, ocn: 0 },
|
||||||
network: '',
|
network: '',
|
||||||
requestFromFaucet: jest.fn(),
|
requestFromFaucet: jest.fn(),
|
||||||
unlockAccounts: jest.fn(),
|
loginMetamask: jest.fn(),
|
||||||
|
loginBurnerWallet: jest.fn(),
|
||||||
message: ''
|
message: ''
|
||||||
}
|
}
|
||||||
|
|
||||||
const userMockConnected = {
|
const userMockConnected = {
|
||||||
isLogged: true,
|
isLogged: true,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
isWeb3: true,
|
isBurner: false,
|
||||||
isOceanNetwork: true,
|
isOceanNetwork: true,
|
||||||
account: '0xxxxxx',
|
account: '0xxxxxx',
|
||||||
web3: {},
|
web3: {},
|
||||||
@ -26,7 +27,8 @@ const userMockConnected = {
|
|||||||
balance: { eth: 0, ocn: 0 },
|
balance: { eth: 0, ocn: 0 },
|
||||||
network: '',
|
network: '',
|
||||||
requestFromFaucet: jest.fn(),
|
requestFromFaucet: jest.fn(),
|
||||||
unlockAccounts: jest.fn(),
|
loginMetamask: jest.fn(),
|
||||||
|
loginBurnerWallet: jest.fn(),
|
||||||
message: ''
|
message: ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,18 +5,18 @@ import { User } from '../../context'
|
|||||||
import { userMock, userMockConnected } from '../../../__mocks__/user-mock'
|
import { userMock, userMockConnected } from '../../../__mocks__/user-mock'
|
||||||
|
|
||||||
describe('Web3message', () => {
|
describe('Web3message', () => {
|
||||||
it('renders with noWeb3 message', () => {
|
it('renders with burner wallet message', () => {
|
||||||
const { container } = render(
|
const { container } = render(
|
||||||
<User.Provider value={{ ...userMock }}>
|
<User.Provider value={{ ...userMockConnected, isBurner: true }}>
|
||||||
<Web3message />
|
<Web3message />
|
||||||
</User.Provider>
|
</User.Provider>
|
||||||
)
|
)
|
||||||
expect(container.firstChild).toHaveTextContent('Not a Web3 Browser')
|
expect(container.firstChild).toHaveTextContent('Burner Wallet')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('renders with wrongNetwork message', () => {
|
it('renders with wrongNetwork message', () => {
|
||||||
const { container } = render(
|
const { container } = render(
|
||||||
<User.Provider value={{ ...userMock, isWeb3: true }}>
|
<User.Provider value={{ ...userMockConnected, isOceanNetwork: false }}>
|
||||||
<Web3message />
|
<Web3message />
|
||||||
</User.Provider>
|
</User.Provider>
|
||||||
)
|
)
|
||||||
@ -28,12 +28,12 @@ describe('Web3message', () => {
|
|||||||
it('renders with noAccount message', () => {
|
it('renders with noAccount message', () => {
|
||||||
const { container } = render(
|
const { container } = render(
|
||||||
<User.Provider
|
<User.Provider
|
||||||
value={{ ...userMock, isWeb3: true, isOceanNetwork: true }}
|
value={{ ...userMock, isOceanNetwork: true }}
|
||||||
>
|
>
|
||||||
<Web3message />
|
<Web3message />
|
||||||
</User.Provider>
|
</User.Provider>
|
||||||
)
|
)
|
||||||
expect(container.firstChild).toHaveTextContent('No accounts detected')
|
expect(container.firstChild).toHaveTextContent('No wallet selected.')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('renders with hasAccount message', () => {
|
it('renders with hasAccount message', () => {
|
||||||
@ -44,21 +44,4 @@ describe('Web3message', () => {
|
|||||||
)
|
)
|
||||||
expect(container.firstChild).toHaveTextContent('0xxxxxx')
|
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({
|
export const User = React.createContext({
|
||||||
isLogged: false,
|
isLogged: false,
|
||||||
|
isBurner: false,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
isOceanNetwork: false,
|
isOceanNetwork: false,
|
||||||
account: '',
|
account: '',
|
||||||
|
@ -3,6 +3,7 @@ import { render } from '@testing-library/react'
|
|||||||
import { MemoryRouter } from 'react-router'
|
import { MemoryRouter } from 'react-router'
|
||||||
import { User } from '../context'
|
import { User } from '../context'
|
||||||
import History from './History'
|
import History from './History'
|
||||||
|
import { userMock } from '../../__mocks__/user-mock'
|
||||||
|
|
||||||
describe('History', () => {
|
describe('History', () => {
|
||||||
it('renders without crashing', () => {
|
it('renders without crashing', () => {
|
||||||
@ -14,24 +15,10 @@ describe('History', () => {
|
|||||||
expect(container.firstChild).toBeInTheDocument()
|
expect(container.firstChild).toBeInTheDocument()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('outputs Web3 message when no Web3 detected', () => {
|
it('outputs no wallet selected', () => {
|
||||||
const context = {
|
|
||||||
isLogged: false,
|
|
||||||
isLoading: false,
|
|
||||||
isWeb3: false,
|
|
||||||
isOceanNetwork: false,
|
|
||||||
account: '',
|
|
||||||
web3: {},
|
|
||||||
ocean: {},
|
|
||||||
balance: { eth: 0, ocn: 0 },
|
|
||||||
network: '',
|
|
||||||
requestFromFaucet: () => {},
|
|
||||||
unlockAccounts: () => {},
|
|
||||||
message: ''
|
|
||||||
}
|
|
||||||
|
|
||||||
const { container } = render(
|
const { container } = render(
|
||||||
<User.Provider value={context}>
|
<User.Provider value={{ ...userMock, isOceanNetwork: true }}>
|
||||||
<MemoryRouter>
|
<MemoryRouter>
|
||||||
<History />
|
<History />
|
||||||
</MemoryRouter>
|
</MemoryRouter>
|
||||||
@ -39,7 +26,7 @@ describe('History', () => {
|
|||||||
)
|
)
|
||||||
expect(container.querySelector('.message')).toBeInTheDocument()
|
expect(container.querySelector('.message')).toBeInTheDocument()
|
||||||
expect(container.querySelector('.message')).toHaveTextContent(
|
expect(container.querySelector('.message')).toHaveTextContent(
|
||||||
'Not a Web3 Browser.'
|
'No wallet selected.'
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user