mirror of
https://github.com/oceanprotocol/commons.git
synced 2023-03-15 18:03:00 +01:00
fix unit tests
This commit is contained in:
parent
1ab87dea30
commit
69d7295f57
8
client/__mocks__/market-mock.ts
Normal file
8
client/__mocks__/market-mock.ts
Normal file
@ -0,0 +1,8 @@
|
||||
const marketMock = {
|
||||
totalAssets: 1000,
|
||||
categories: ['category'],
|
||||
network: 'Pacific',
|
||||
networkMatch: true
|
||||
}
|
||||
|
||||
export { marketMock }
|
@ -2,15 +2,27 @@ import React from 'react'
|
||||
import { render } from '@testing-library/react'
|
||||
import { toDataUrl } from 'ethereum-blockies'
|
||||
import Account from './Account'
|
||||
import { User } from '../../context'
|
||||
import { userMockConnected } from '../../../__mocks__/user-mock'
|
||||
|
||||
describe('Account', () => {
|
||||
it('renders without crashing', () => {
|
||||
const { container } = render(<Account account={'0xxxxxxxxxxxxxxx'} />)
|
||||
const { container } = render(
|
||||
<User.Provider
|
||||
value={{ ...userMockConnected, account: '0xxxxxxxxxxxxxxx' }}
|
||||
>
|
||||
<Account />
|
||||
</User.Provider>
|
||||
)
|
||||
expect(container.firstChild).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('outputs empty state without account', () => {
|
||||
const { container } = render(<Account account={''} />)
|
||||
const { container } = render(
|
||||
<User.Provider value={{ ...userMockConnected, account: '' }}>
|
||||
<Account />
|
||||
</User.Provider>
|
||||
)
|
||||
expect(container.firstChild).toHaveTextContent('No account selected')
|
||||
})
|
||||
|
||||
@ -18,7 +30,11 @@ describe('Account', () => {
|
||||
const account = '0xxxxxxxxxxxxxxx'
|
||||
const blockies = toDataUrl(account)
|
||||
|
||||
const { container } = render(<Account account={account} />)
|
||||
const { container } = render(
|
||||
<User.Provider value={{ ...userMockConnected, account }}>
|
||||
<Account />
|
||||
</User.Provider>
|
||||
)
|
||||
expect(container.querySelector('.blockies')).toBeInTheDocument()
|
||||
expect(container.querySelector('.blockies')).toHaveAttribute(
|
||||
'src',
|
||||
|
@ -2,7 +2,8 @@ import React from 'react'
|
||||
import { render } from '@testing-library/react'
|
||||
import Popover from './Popover'
|
||||
import { userMock, userMockConnected } from '../../../../__mocks__/user-mock'
|
||||
import { User } from '../../../context'
|
||||
import { marketMock } from '../../../../__mocks__/market-mock'
|
||||
import { User, Market } from '../../../context'
|
||||
|
||||
describe('Popover', () => {
|
||||
it('renders without crashing', () => {
|
||||
@ -25,12 +26,14 @@ describe('Popover', () => {
|
||||
|
||||
it('renders correct network', () => {
|
||||
const { container } = render(
|
||||
<User.Provider value={{ ...userMockConnected, network: 'Nile' }}>
|
||||
<Popover forwardedRef={() => null} style={{}} />
|
||||
<User.Provider value={{ ...userMockConnected, network: 'Pacific' }}>
|
||||
<Market.Provider value={{ ...marketMock }}>
|
||||
<Popover forwardedRef={() => null} style={{}} />
|
||||
</Market.Provider>
|
||||
</User.Provider>
|
||||
)
|
||||
expect(container.firstChild).toBeInTheDocument()
|
||||
expect(container.firstChild).toHaveTextContent('Connected to Nile')
|
||||
expect(container.firstChild).toHaveTextContent('Connected to Pacific')
|
||||
})
|
||||
|
||||
it('renders with wrong network', () => {
|
||||
|
@ -1,14 +1,17 @@
|
||||
import React from 'react'
|
||||
import { render } from '@testing-library/react'
|
||||
import Web3message from './Web3message'
|
||||
import { User } from '../../context'
|
||||
import { User, Market } from '../../context'
|
||||
import { userMock, userMockConnected } from '../../../__mocks__/user-mock'
|
||||
import { marketMock } from '../../../__mocks__/market-mock'
|
||||
|
||||
describe('Web3message', () => {
|
||||
it('renders with burner wallet message', () => {
|
||||
const { container } = render(
|
||||
<User.Provider value={{ ...userMockConnected, isBurner: true }}>
|
||||
<Web3message extended />
|
||||
<Market.Provider value={{ ...marketMock }}>
|
||||
<Web3message extended />
|
||||
</Market.Provider>
|
||||
</User.Provider>
|
||||
)
|
||||
expect(container.firstChild).toHaveTextContent('Burner Wallet')
|
||||
@ -16,28 +19,40 @@ describe('Web3message', () => {
|
||||
|
||||
it('renders with wrongNetwork message', () => {
|
||||
const { container } = render(
|
||||
<User.Provider value={{ ...userMockConnected }}>
|
||||
<Web3message extended />
|
||||
<User.Provider value={{ ...userMockConnected, network: 'Pacific' }}>
|
||||
<Market.Provider
|
||||
value={{
|
||||
...marketMock,
|
||||
networkMatch: false,
|
||||
network: 'Nile'
|
||||
}}
|
||||
>
|
||||
<Web3message extended />
|
||||
</Market.Provider>
|
||||
</User.Provider>
|
||||
)
|
||||
expect(container.firstChild).toHaveTextContent(
|
||||
'Not connected to Pacific network'
|
||||
'Not connected to Nile network'
|
||||
)
|
||||
})
|
||||
|
||||
it('renders with noAccount message', () => {
|
||||
const { container } = render(
|
||||
<User.Provider value={{ ...userMock }}>
|
||||
<Web3message extended />
|
||||
<Market.Provider value={{ ...marketMock }}>
|
||||
<Web3message extended />
|
||||
</Market.Provider>
|
||||
</User.Provider>
|
||||
)
|
||||
expect(container.firstChild).toHaveTextContent('No wallet selected.')
|
||||
expect(container.firstChild).toHaveTextContent('No account selected')
|
||||
})
|
||||
|
||||
it('renders with hasAccount message', () => {
|
||||
const { container } = render(
|
||||
<User.Provider value={userMockConnected}>
|
||||
<Web3message />
|
||||
<Market.Provider value={{ ...marketMock }}>
|
||||
<Web3message />
|
||||
</Market.Provider>
|
||||
</User.Provider>
|
||||
)
|
||||
expect(container.firstChild).toHaveTextContent('0xxxxxx')
|
||||
|
@ -28,16 +28,4 @@ describe('AssetFilesDetails', () => {
|
||||
)
|
||||
expect(container.firstChild).toHaveTextContent('No files attached.')
|
||||
})
|
||||
|
||||
it('hides Web3message when all connected', () => {
|
||||
const { container } = render(
|
||||
<User.Provider value={userMockConnected}>
|
||||
<AssetFilesDetails
|
||||
files={[{ index: 0, url: '' }]}
|
||||
ddo={({} as any) as DDO}
|
||||
/>
|
||||
</User.Provider>
|
||||
)
|
||||
expect(container.querySelector('.status')).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
@ -1,13 +1,21 @@
|
||||
import React from 'react'
|
||||
import { render } from '@testing-library/react'
|
||||
import { MemoryRouter } from 'react-router'
|
||||
import { createMemoryHistory, createLocation } from 'history'
|
||||
import About from './About'
|
||||
|
||||
const history = createMemoryHistory()
|
||||
const location = createLocation('/about')
|
||||
|
||||
describe('About', () => {
|
||||
it('renders without crashing', () => {
|
||||
const { container } = render(
|
||||
<MemoryRouter>
|
||||
<About />
|
||||
<About
|
||||
history={history}
|
||||
location={location}
|
||||
match={{ params: '', path: '', url: '', isExact: true }}
|
||||
/>
|
||||
</MemoryRouter>
|
||||
)
|
||||
expect(container.firstChild).toBeInTheDocument()
|
||||
|
@ -1,16 +1,24 @@
|
||||
import React from 'react'
|
||||
import { MemoryRouter } from 'react-router'
|
||||
import { createMemoryHistory, createLocation } from 'history'
|
||||
import { render } from '@testing-library/react'
|
||||
import Channels from './Channels'
|
||||
import { User } from '../context'
|
||||
import { userMockConnected } from '../../__mocks__/user-mock'
|
||||
|
||||
const history = createMemoryHistory()
|
||||
const location = createLocation('/channels')
|
||||
|
||||
describe('Channels', () => {
|
||||
it('renders without crashing', () => {
|
||||
const { container } = render(
|
||||
<User.Provider value={userMockConnected}>
|
||||
<MemoryRouter>
|
||||
<Channels />
|
||||
<Channels
|
||||
history={history}
|
||||
location={location}
|
||||
match={{ params: '', path: '', url: '', isExact: true }}
|
||||
/>
|
||||
</MemoryRouter>
|
||||
</User.Provider>
|
||||
)
|
||||
|
@ -1,15 +1,23 @@
|
||||
import React from 'react'
|
||||
import { render, fireEvent } from '@testing-library/react'
|
||||
import { MemoryRouter } from 'react-router'
|
||||
import { createMemoryHistory, createLocation } from 'history'
|
||||
import Faucet from './Faucet'
|
||||
import { User } from '../context'
|
||||
import { userMockConnected } from '../../__mocks__/user-mock'
|
||||
|
||||
const history = createMemoryHistory()
|
||||
const location = createLocation('/faucet')
|
||||
|
||||
const setup = () => {
|
||||
const utils = render(
|
||||
<User.Provider value={userMockConnected}>
|
||||
<MemoryRouter>
|
||||
<Faucet />
|
||||
<Faucet
|
||||
history={history}
|
||||
location={location}
|
||||
match={{ params: '', path: '', url: '', isExact: true }}
|
||||
/>
|
||||
</MemoryRouter>
|
||||
</User.Provider>
|
||||
)
|
||||
|
@ -1,13 +1,21 @@
|
||||
import React from 'react'
|
||||
import { render } from '@testing-library/react'
|
||||
import { MemoryRouter } from 'react-router'
|
||||
import { createMemoryHistory, createLocation } from 'history'
|
||||
import History from './History'
|
||||
|
||||
const history = createMemoryHistory()
|
||||
const location = createLocation('/history')
|
||||
|
||||
describe('History', () => {
|
||||
it('renders without crashing', () => {
|
||||
const { container } = render(
|
||||
<MemoryRouter>
|
||||
<History />
|
||||
<History
|
||||
history={history}
|
||||
location={location}
|
||||
match={{ params: '', path: '', url: '', isExact: true }}
|
||||
/>
|
||||
</MemoryRouter>
|
||||
)
|
||||
expect(container.firstChild).toBeInTheDocument()
|
||||
|
@ -1,19 +1,24 @@
|
||||
import React from 'react'
|
||||
import { Router } from 'react-router'
|
||||
import { createBrowserHistory } from 'history'
|
||||
import { createMemoryHistory, createLocation } from 'history'
|
||||
import { render } from '@testing-library/react'
|
||||
import Home from '.'
|
||||
import { userMock } from '../../../__mocks__/user-mock'
|
||||
import { User } from '../../context'
|
||||
|
||||
const history = createBrowserHistory()
|
||||
const history = createMemoryHistory()
|
||||
const location = createLocation('/')
|
||||
|
||||
describe('Home', () => {
|
||||
it('renders without crashing', () => {
|
||||
const { container } = render(
|
||||
<User.Provider value={{ ...userMock }}>
|
||||
<Router history={history}>
|
||||
<Home history={history} />
|
||||
<Home
|
||||
history={history}
|
||||
location={location}
|
||||
match={{ params: '', path: '', url: '', isExact: true }}
|
||||
/>
|
||||
</Router>
|
||||
</User.Provider>
|
||||
)
|
||||
|
@ -1,13 +1,21 @@
|
||||
import React from 'react'
|
||||
import { render } from '@testing-library/react'
|
||||
import { createMemoryHistory, createLocation } from 'history'
|
||||
import NotFound from './NotFound'
|
||||
import { MemoryRouter } from 'react-router'
|
||||
|
||||
const history = createMemoryHistory()
|
||||
const location = createLocation('/whatever')
|
||||
|
||||
describe('NotFound', () => {
|
||||
it('renders without crashing', () => {
|
||||
const { container } = render(
|
||||
<MemoryRouter>
|
||||
<NotFound />
|
||||
<NotFound
|
||||
history={history}
|
||||
location={location}
|
||||
match={{ params: '', path: '', url: '', isExact: true }}
|
||||
/>
|
||||
</MemoryRouter>
|
||||
)
|
||||
expect(container.firstChild).toBeInTheDocument()
|
||||
|
@ -1,16 +1,24 @@
|
||||
import React from 'react'
|
||||
import { MemoryRouter } from 'react-router'
|
||||
import { render, fireEvent } from '@testing-library/react'
|
||||
import { createMemoryHistory, createLocation } from 'history'
|
||||
import Publish from '.'
|
||||
import { User } from '../../context'
|
||||
import { userMockConnected } from '../../../__mocks__/user-mock'
|
||||
|
||||
const history = createMemoryHistory()
|
||||
const location = createLocation('/publish')
|
||||
|
||||
describe('Publish', () => {
|
||||
it('renders without crashing', () => {
|
||||
const { container, getByText } = render(
|
||||
<User.Provider value={userMockConnected}>
|
||||
<MemoryRouter>
|
||||
<Publish />
|
||||
<Publish
|
||||
history={history}
|
||||
location={location}
|
||||
match={{ params: '', path: '', url: '', isExact: true }}
|
||||
/>
|
||||
</MemoryRouter>
|
||||
</User.Provider>
|
||||
)
|
||||
@ -22,7 +30,16 @@ describe('Publish', () => {
|
||||
const { getByText, getByLabelText, getByTestId } = render(
|
||||
<User.Provider value={userMockConnected}>
|
||||
<MemoryRouter>
|
||||
<Publish />
|
||||
<Publish
|
||||
history={history}
|
||||
location={{
|
||||
pathname: '/publish',
|
||||
search: '',
|
||||
hash: '',
|
||||
state: ''
|
||||
}}
|
||||
match={{ params: '', path: '', url: '', isExact: true }}
|
||||
/>
|
||||
</MemoryRouter>
|
||||
</User.Provider>
|
||||
)
|
||||
|
@ -6,10 +6,10 @@ import { createMemoryHistory } from 'history'
|
||||
import { BrowserRouter as Router } from 'react-router-dom'
|
||||
import { userMockConnected } from '../../__mocks__/user-mock'
|
||||
|
||||
const history = createMemoryHistory()
|
||||
|
||||
describe('Search', () => {
|
||||
it('renders without crashing', () => {
|
||||
const history = createMemoryHistory()
|
||||
|
||||
const { container } = render(
|
||||
<User.Provider value={userMockConnected}>
|
||||
<Router>
|
||||
@ -21,6 +21,7 @@ describe('Search', () => {
|
||||
hash: ''
|
||||
}}
|
||||
history={history}
|
||||
match={{ params: '', path: '', url: '', isExact: true }}
|
||||
/>
|
||||
</Router>
|
||||
</User.Provider>
|
||||
|
@ -2,12 +2,20 @@ import React from 'react'
|
||||
import { render } from '@testing-library/react'
|
||||
import Styleguide from './Styleguide'
|
||||
import { MemoryRouter } from 'react-router'
|
||||
import { createMemoryHistory, createLocation } from 'history'
|
||||
|
||||
const history = createMemoryHistory()
|
||||
const location = createLocation('/styleguide')
|
||||
|
||||
describe('Styleguide', () => {
|
||||
it('renders without crashing', () => {
|
||||
const { container } = render(
|
||||
<MemoryRouter>
|
||||
<Styleguide />
|
||||
<Styleguide
|
||||
history={history}
|
||||
location={location}
|
||||
match={{ params: '', path: '', url: '', isExact: true }}
|
||||
/>
|
||||
</MemoryRouter>
|
||||
)
|
||||
expect(container.firstChild).toBeInTheDocument()
|
||||
|
Loading…
Reference in New Issue
Block a user