1
0
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:
Matthias Kretschmann 2019-07-12 00:24:29 +02:00
parent 1ab87dea30
commit 69d7295f57
Signed by: m
GPG Key ID: 606EEEF3C479A91F
14 changed files with 141 additions and 40 deletions

View File

@ -0,0 +1,8 @@
const marketMock = {
totalAssets: 1000,
categories: ['category'],
network: 'Pacific',
networkMatch: true
}
export { marketMock }

View File

@ -2,15 +2,27 @@ import React from 'react'
import { render } from '@testing-library/react' import { render } from '@testing-library/react'
import { toDataUrl } from 'ethereum-blockies' import { toDataUrl } from 'ethereum-blockies'
import Account from './Account' import Account from './Account'
import { User } from '../../context'
import { userMockConnected } from '../../../__mocks__/user-mock'
describe('Account', () => { describe('Account', () => {
it('renders without crashing', () => { 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() expect(container.firstChild).toBeInTheDocument()
}) })
it('outputs empty state without account', () => { 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') expect(container.firstChild).toHaveTextContent('No account selected')
}) })
@ -18,7 +30,11 @@ describe('Account', () => {
const account = '0xxxxxxxxxxxxxxx' const account = '0xxxxxxxxxxxxxxx'
const blockies = toDataUrl(account) 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')).toBeInTheDocument()
expect(container.querySelector('.blockies')).toHaveAttribute( expect(container.querySelector('.blockies')).toHaveAttribute(
'src', 'src',

View File

@ -2,7 +2,8 @@ import React from 'react'
import { render } from '@testing-library/react' import { render } from '@testing-library/react'
import Popover from './Popover' import Popover from './Popover'
import { userMock, userMockConnected } from '../../../../__mocks__/user-mock' import { userMock, userMockConnected } from '../../../../__mocks__/user-mock'
import { User } from '../../../context' import { marketMock } from '../../../../__mocks__/market-mock'
import { User, Market } from '../../../context'
describe('Popover', () => { describe('Popover', () => {
it('renders without crashing', () => { it('renders without crashing', () => {
@ -25,12 +26,14 @@ describe('Popover', () => {
it('renders correct network', () => { it('renders correct network', () => {
const { container } = render( const { container } = render(
<User.Provider value={{ ...userMockConnected, network: 'Nile' }}> <User.Provider value={{ ...userMockConnected, network: 'Pacific' }}>
<Popover forwardedRef={() => null} style={{}} /> <Market.Provider value={{ ...marketMock }}>
<Popover forwardedRef={() => null} style={{}} />
</Market.Provider>
</User.Provider> </User.Provider>
) )
expect(container.firstChild).toBeInTheDocument() expect(container.firstChild).toBeInTheDocument()
expect(container.firstChild).toHaveTextContent('Connected to Nile') expect(container.firstChild).toHaveTextContent('Connected to Pacific')
}) })
it('renders with wrong network', () => { it('renders with wrong network', () => {

View File

@ -1,14 +1,17 @@
import React from 'react' import React from 'react'
import { render } from '@testing-library/react' import { render } from '@testing-library/react'
import Web3message from './Web3message' import Web3message from './Web3message'
import { User } from '../../context' import { User, Market } from '../../context'
import { userMock, userMockConnected } from '../../../__mocks__/user-mock' import { userMock, userMockConnected } from '../../../__mocks__/user-mock'
import { marketMock } from '../../../__mocks__/market-mock'
describe('Web3message', () => { describe('Web3message', () => {
it('renders with burner wallet message', () => { it('renders with burner wallet message', () => {
const { container } = render( const { container } = render(
<User.Provider value={{ ...userMockConnected, isBurner: true }}> <User.Provider value={{ ...userMockConnected, isBurner: true }}>
<Web3message extended /> <Market.Provider value={{ ...marketMock }}>
<Web3message extended />
</Market.Provider>
</User.Provider> </User.Provider>
) )
expect(container.firstChild).toHaveTextContent('Burner Wallet') expect(container.firstChild).toHaveTextContent('Burner Wallet')
@ -16,28 +19,40 @@ describe('Web3message', () => {
it('renders with wrongNetwork message', () => { it('renders with wrongNetwork message', () => {
const { container } = render( const { container } = render(
<User.Provider value={{ ...userMockConnected }}> <User.Provider value={{ ...userMockConnected, network: 'Pacific' }}>
<Web3message extended /> <Market.Provider
value={{
...marketMock,
networkMatch: false,
network: 'Nile'
}}
>
<Web3message extended />
</Market.Provider>
</User.Provider> </User.Provider>
) )
expect(container.firstChild).toHaveTextContent( expect(container.firstChild).toHaveTextContent(
'Not connected to Pacific network' 'Not connected to Nile network'
) )
}) })
it('renders with noAccount message', () => { it('renders with noAccount message', () => {
const { container } = render( const { container } = render(
<User.Provider value={{ ...userMock }}> <User.Provider value={{ ...userMock }}>
<Web3message extended /> <Market.Provider value={{ ...marketMock }}>
<Web3message extended />
</Market.Provider>
</User.Provider> </User.Provider>
) )
expect(container.firstChild).toHaveTextContent('No wallet selected.') expect(container.firstChild).toHaveTextContent('No account selected')
}) })
it('renders with hasAccount message', () => { it('renders with hasAccount message', () => {
const { container } = render( const { container } = render(
<User.Provider value={userMockConnected}> <User.Provider value={userMockConnected}>
<Web3message /> <Market.Provider value={{ ...marketMock }}>
<Web3message />
</Market.Provider>
</User.Provider> </User.Provider>
) )
expect(container.firstChild).toHaveTextContent('0xxxxxx') expect(container.firstChild).toHaveTextContent('0xxxxxx')

View File

@ -28,16 +28,4 @@ describe('AssetFilesDetails', () => {
) )
expect(container.firstChild).toHaveTextContent('No files attached.') 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()
})
}) })

View File

@ -1,13 +1,21 @@
import React from 'react' import React from 'react'
import { render } from '@testing-library/react' import { render } from '@testing-library/react'
import { MemoryRouter } from 'react-router' import { MemoryRouter } from 'react-router'
import { createMemoryHistory, createLocation } from 'history'
import About from './About' import About from './About'
const history = createMemoryHistory()
const location = createLocation('/about')
describe('About', () => { describe('About', () => {
it('renders without crashing', () => { it('renders without crashing', () => {
const { container } = render( const { container } = render(
<MemoryRouter> <MemoryRouter>
<About /> <About
history={history}
location={location}
match={{ params: '', path: '', url: '', isExact: true }}
/>
</MemoryRouter> </MemoryRouter>
) )
expect(container.firstChild).toBeInTheDocument() expect(container.firstChild).toBeInTheDocument()

View File

@ -1,16 +1,24 @@
import React from 'react' import React from 'react'
import { MemoryRouter } from 'react-router' import { MemoryRouter } from 'react-router'
import { createMemoryHistory, createLocation } from 'history'
import { render } from '@testing-library/react' import { render } from '@testing-library/react'
import Channels from './Channels' import Channels from './Channels'
import { User } from '../context' import { User } from '../context'
import { userMockConnected } from '../../__mocks__/user-mock' import { userMockConnected } from '../../__mocks__/user-mock'
const history = createMemoryHistory()
const location = createLocation('/channels')
describe('Channels', () => { describe('Channels', () => {
it('renders without crashing', () => { it('renders without crashing', () => {
const { container } = render( const { container } = render(
<User.Provider value={userMockConnected}> <User.Provider value={userMockConnected}>
<MemoryRouter> <MemoryRouter>
<Channels /> <Channels
history={history}
location={location}
match={{ params: '', path: '', url: '', isExact: true }}
/>
</MemoryRouter> </MemoryRouter>
</User.Provider> </User.Provider>
) )

View File

@ -1,15 +1,23 @@
import React from 'react' import React from 'react'
import { render, fireEvent } from '@testing-library/react' import { render, fireEvent } from '@testing-library/react'
import { MemoryRouter } from 'react-router' import { MemoryRouter } from 'react-router'
import { createMemoryHistory, createLocation } from 'history'
import Faucet from './Faucet' import Faucet from './Faucet'
import { User } from '../context' import { User } from '../context'
import { userMockConnected } from '../../__mocks__/user-mock' import { userMockConnected } from '../../__mocks__/user-mock'
const history = createMemoryHistory()
const location = createLocation('/faucet')
const setup = () => { const setup = () => {
const utils = render( const utils = render(
<User.Provider value={userMockConnected}> <User.Provider value={userMockConnected}>
<MemoryRouter> <MemoryRouter>
<Faucet /> <Faucet
history={history}
location={location}
match={{ params: '', path: '', url: '', isExact: true }}
/>
</MemoryRouter> </MemoryRouter>
</User.Provider> </User.Provider>
) )

View File

@ -1,13 +1,21 @@
import React from 'react' import React from 'react'
import { render } from '@testing-library/react' import { render } from '@testing-library/react'
import { MemoryRouter } from 'react-router' import { MemoryRouter } from 'react-router'
import { createMemoryHistory, createLocation } from 'history'
import History from './History' import History from './History'
const history = createMemoryHistory()
const location = createLocation('/history')
describe('History', () => { describe('History', () => {
it('renders without crashing', () => { it('renders without crashing', () => {
const { container } = render( const { container } = render(
<MemoryRouter> <MemoryRouter>
<History /> <History
history={history}
location={location}
match={{ params: '', path: '', url: '', isExact: true }}
/>
</MemoryRouter> </MemoryRouter>
) )
expect(container.firstChild).toBeInTheDocument() expect(container.firstChild).toBeInTheDocument()

View File

@ -1,19 +1,24 @@
import React from 'react' import React from 'react'
import { Router } from 'react-router' import { Router } from 'react-router'
import { createBrowserHistory } from 'history' import { createMemoryHistory, createLocation } from 'history'
import { render } from '@testing-library/react' import { render } from '@testing-library/react'
import Home from '.' import Home from '.'
import { userMock } from '../../../__mocks__/user-mock' import { userMock } from '../../../__mocks__/user-mock'
import { User } from '../../context' import { User } from '../../context'
const history = createBrowserHistory() const history = createMemoryHistory()
const location = createLocation('/')
describe('Home', () => { describe('Home', () => {
it('renders without crashing', () => { it('renders without crashing', () => {
const { container } = render( const { container } = render(
<User.Provider value={{ ...userMock }}> <User.Provider value={{ ...userMock }}>
<Router history={history}> <Router history={history}>
<Home history={history} /> <Home
history={history}
location={location}
match={{ params: '', path: '', url: '', isExact: true }}
/>
</Router> </Router>
</User.Provider> </User.Provider>
) )

View File

@ -1,13 +1,21 @@
import React from 'react' import React from 'react'
import { render } from '@testing-library/react' import { render } from '@testing-library/react'
import { createMemoryHistory, createLocation } from 'history'
import NotFound from './NotFound' import NotFound from './NotFound'
import { MemoryRouter } from 'react-router' import { MemoryRouter } from 'react-router'
const history = createMemoryHistory()
const location = createLocation('/whatever')
describe('NotFound', () => { describe('NotFound', () => {
it('renders without crashing', () => { it('renders without crashing', () => {
const { container } = render( const { container } = render(
<MemoryRouter> <MemoryRouter>
<NotFound /> <NotFound
history={history}
location={location}
match={{ params: '', path: '', url: '', isExact: true }}
/>
</MemoryRouter> </MemoryRouter>
) )
expect(container.firstChild).toBeInTheDocument() expect(container.firstChild).toBeInTheDocument()

View File

@ -1,16 +1,24 @@
import React from 'react' import React from 'react'
import { MemoryRouter } from 'react-router' import { MemoryRouter } from 'react-router'
import { render, fireEvent } from '@testing-library/react' import { render, fireEvent } from '@testing-library/react'
import { createMemoryHistory, createLocation } from 'history'
import Publish from '.' import Publish from '.'
import { User } from '../../context' import { User } from '../../context'
import { userMockConnected } from '../../../__mocks__/user-mock' import { userMockConnected } from '../../../__mocks__/user-mock'
const history = createMemoryHistory()
const location = createLocation('/publish')
describe('Publish', () => { describe('Publish', () => {
it('renders without crashing', () => { it('renders without crashing', () => {
const { container, getByText } = render( const { container, getByText } = render(
<User.Provider value={userMockConnected}> <User.Provider value={userMockConnected}>
<MemoryRouter> <MemoryRouter>
<Publish /> <Publish
history={history}
location={location}
match={{ params: '', path: '', url: '', isExact: true }}
/>
</MemoryRouter> </MemoryRouter>
</User.Provider> </User.Provider>
) )
@ -22,7 +30,16 @@ describe('Publish', () => {
const { getByText, getByLabelText, getByTestId } = render( const { getByText, getByLabelText, getByTestId } = render(
<User.Provider value={userMockConnected}> <User.Provider value={userMockConnected}>
<MemoryRouter> <MemoryRouter>
<Publish /> <Publish
history={history}
location={{
pathname: '/publish',
search: '',
hash: '',
state: ''
}}
match={{ params: '', path: '', url: '', isExact: true }}
/>
</MemoryRouter> </MemoryRouter>
</User.Provider> </User.Provider>
) )

View File

@ -6,10 +6,10 @@ import { createMemoryHistory } from 'history'
import { BrowserRouter as Router } from 'react-router-dom' import { BrowserRouter as Router } from 'react-router-dom'
import { userMockConnected } from '../../__mocks__/user-mock' import { userMockConnected } from '../../__mocks__/user-mock'
const history = createMemoryHistory()
describe('Search', () => { describe('Search', () => {
it('renders without crashing', () => { it('renders without crashing', () => {
const history = createMemoryHistory()
const { container } = render( const { container } = render(
<User.Provider value={userMockConnected}> <User.Provider value={userMockConnected}>
<Router> <Router>
@ -21,6 +21,7 @@ describe('Search', () => {
hash: '' hash: ''
}} }}
history={history} history={history}
match={{ params: '', path: '', url: '', isExact: true }}
/> />
</Router> </Router>
</User.Provider> </User.Provider>

View File

@ -2,12 +2,20 @@ import React from 'react'
import { render } from '@testing-library/react' import { render } from '@testing-library/react'
import Styleguide from './Styleguide' import Styleguide from './Styleguide'
import { MemoryRouter } from 'react-router' import { MemoryRouter } from 'react-router'
import { createMemoryHistory, createLocation } from 'history'
const history = createMemoryHistory()
const location = createLocation('/styleguide')
describe('Styleguide', () => { describe('Styleguide', () => {
it('renders without crashing', () => { it('renders without crashing', () => {
const { container } = render( const { container } = render(
<MemoryRouter> <MemoryRouter>
<Styleguide /> <Styleguide
history={history}
location={location}
match={{ params: '', path: '', url: '', isExact: true }}
/>
</MemoryRouter> </MemoryRouter>
) )
expect(container.firstChild).toBeInTheDocument() expect(container.firstChild).toBeInTheDocument()