mirror of
https://github.com/oceanprotocol/commons.git
synced 2023-03-15 18:03:00 +01:00
increase test coverage, mock ocean.versions.get()
This commit is contained in:
parent
996d986570
commit
a4178854bb
@ -31,6 +31,34 @@ const oceanMock = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
versions: {
|
||||||
|
get: jest.fn(() =>
|
||||||
|
Promise.resolve({
|
||||||
|
squid: {
|
||||||
|
name: 'Squid-js',
|
||||||
|
status: 'Working'
|
||||||
|
},
|
||||||
|
aquarius: {
|
||||||
|
name: 'Aquarius',
|
||||||
|
status: 'Working'
|
||||||
|
},
|
||||||
|
brizo: {
|
||||||
|
name: 'Brizo',
|
||||||
|
network: 'Nile',
|
||||||
|
status: 'Working',
|
||||||
|
contracts: {
|
||||||
|
hello: 'hello',
|
||||||
|
hello2: 'hello2'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
status: {
|
||||||
|
ok: true,
|
||||||
|
network: true,
|
||||||
|
contracts: true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import { render } from '@testing-library/react'
|
||||||
|
import VersionNumber from './VersionNumber'
|
||||||
|
|
||||||
|
describe('VersionNumber', () => {
|
||||||
|
it('renders without crashing', () => {
|
||||||
|
const { container } = render(<VersionNumber name="Commons" />)
|
||||||
|
expect(container.firstChild).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('renders with all props set', () => {
|
||||||
|
const { container } = render(
|
||||||
|
<VersionNumber
|
||||||
|
name="Commons"
|
||||||
|
version="6.6.6"
|
||||||
|
network="Nile"
|
||||||
|
commit="xxxxxxxxxxx"
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
expect(container.firstChild).toBeInTheDocument()
|
||||||
|
expect(container.firstChild).toHaveTextContent('6.6.6')
|
||||||
|
})
|
||||||
|
})
|
@ -0,0 +1,23 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import { render } from '@testing-library/react'
|
||||||
|
import VersionStatus from './VersionStatus'
|
||||||
|
|
||||||
|
describe('VersionStatus', () => {
|
||||||
|
it('renders without crashing', () => {
|
||||||
|
const { container } = render(
|
||||||
|
<VersionStatus
|
||||||
|
status={{ ok: false, contracts: false, network: false }}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
expect(container.firstChild).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('renders true states', () => {
|
||||||
|
const { container } = render(
|
||||||
|
<VersionStatus
|
||||||
|
status={{ ok: true, contracts: false, network: false }}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
expect(container.firstChild).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
})
|
@ -0,0 +1,40 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import { render } from '@testing-library/react'
|
||||||
|
import { VersionTableContracts } from './VersionTable'
|
||||||
|
|
||||||
|
describe('VersionTableContracts', () => {
|
||||||
|
it('renders without crashing', () => {
|
||||||
|
const { container } = render(
|
||||||
|
<VersionTableContracts
|
||||||
|
contracts={{ hello: 'hello', hello2: 'hello2' }}
|
||||||
|
network="nile"
|
||||||
|
keeperVersion="6.6.6"
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
expect(container.firstChild).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('renders correct Submarine links', () => {
|
||||||
|
const { container, rerender } = render(
|
||||||
|
<VersionTableContracts
|
||||||
|
contracts={{ hello: 'hello', hello2: 'hello2' }}
|
||||||
|
network="duero"
|
||||||
|
keeperVersion="6.6.6"
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
expect(container.querySelector('tr:last-child a').href).toMatch(
|
||||||
|
/submarine.duero.dev-ocean/
|
||||||
|
)
|
||||||
|
|
||||||
|
rerender(
|
||||||
|
<VersionTableContracts
|
||||||
|
contracts={{ hello: 'hello', hello2: 'hello2' }}
|
||||||
|
network="pacific"
|
||||||
|
keeperVersion="6.6.6"
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
expect(container.querySelector('tr:last-child a').href).toMatch(
|
||||||
|
/submarine.pacific.dev-ocean/
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
@ -38,7 +38,7 @@ const VersionTableRow = ({ value }: { value: any }) => {
|
|||||||
value.name || value.software
|
value.name || value.software
|
||||||
)}`}
|
)}`}
|
||||||
>
|
>
|
||||||
<strong>{value.name}</strong>
|
<strong>{value.name || value.software}</strong>
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
@ -1,48 +1,20 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { render, waitForElement } from '@testing-library/react'
|
import { render } from '@testing-library/react'
|
||||||
import mockAxios from 'jest-mock-axios'
|
import mockAxios from 'jest-mock-axios'
|
||||||
import { StateMock } from '@react-mock/state'
|
import { StateMock } from '@react-mock/state'
|
||||||
import { version as versionSquid } from '@oceanprotocol/squid/package.json'
|
import VersionNumbers from '.'
|
||||||
import VersionNumbers, { commonsVersion } from '.'
|
|
||||||
|
import { User } from '../../../context'
|
||||||
|
import { userMockConnected } from '../../../../__mocks__/user-mock'
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
mockAxios.reset()
|
mockAxios.reset()
|
||||||
})
|
})
|
||||||
|
|
||||||
const stateMock = {
|
|
||||||
commons: {
|
|
||||||
name: 'Commons',
|
|
||||||
version: commonsVersion
|
|
||||||
},
|
|
||||||
squid: {
|
|
||||||
name: 'Squid-js',
|
|
||||||
status: 'Loading'
|
|
||||||
},
|
|
||||||
aquarius: {
|
|
||||||
name: 'Aquarius',
|
|
||||||
status: 'Loading'
|
|
||||||
},
|
|
||||||
brizo: {
|
|
||||||
name: 'Brizo',
|
|
||||||
network: 'Nile',
|
|
||||||
status: 'Loading'
|
|
||||||
},
|
|
||||||
faucet: {
|
|
||||||
name: 'Faucet',
|
|
||||||
version: '',
|
|
||||||
status: 'Loading'
|
|
||||||
},
|
|
||||||
status: {
|
|
||||||
ok: false,
|
|
||||||
network: false,
|
|
||||||
contracts: false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const stateMockIncomplete = {
|
const stateMockIncomplete = {
|
||||||
commons: {
|
commons: {
|
||||||
name: 'Commons',
|
name: 'Commons',
|
||||||
version: commonsVersion
|
version: undefined
|
||||||
},
|
},
|
||||||
squid: {
|
squid: {
|
||||||
name: 'Squid-js',
|
name: 'Squid-js',
|
||||||
@ -87,9 +59,9 @@ const mockResponseFaulty = {
|
|||||||
describe('VersionNumbers', () => {
|
describe('VersionNumbers', () => {
|
||||||
it('renders without crashing', () => {
|
it('renders without crashing', () => {
|
||||||
const { container } = render(
|
const { container } = render(
|
||||||
<StateMock state={stateMock}>
|
<User.Provider value={userMockConnected}>
|
||||||
<VersionNumbers />
|
<VersionNumbers />
|
||||||
</StateMock>
|
</User.Provider>
|
||||||
)
|
)
|
||||||
mockAxios.mockResponse(mockResponse)
|
mockAxios.mockResponse(mockResponse)
|
||||||
expect(mockAxios.get).toHaveBeenCalled()
|
expect(mockAxios.get).toHaveBeenCalled()
|
||||||
@ -98,9 +70,11 @@ describe('VersionNumbers', () => {
|
|||||||
|
|
||||||
it('renders without proper component response', () => {
|
it('renders without proper component response', () => {
|
||||||
const { container } = render(
|
const { container } = render(
|
||||||
|
<User.Provider value={userMockConnected}>
|
||||||
<StateMock state={stateMockIncomplete}>
|
<StateMock state={stateMockIncomplete}>
|
||||||
<VersionNumbers />
|
<VersionNumbers />
|
||||||
</StateMock>
|
</StateMock>
|
||||||
|
</User.Provider>
|
||||||
)
|
)
|
||||||
mockAxios.mockResponse(mockResponseFaulty)
|
mockAxios.mockResponse(mockResponseFaulty)
|
||||||
expect(mockAxios.get).toHaveBeenCalled()
|
expect(mockAxios.get).toHaveBeenCalled()
|
||||||
|
Loading…
Reference in New Issue
Block a user