mirror of
https://github.com/oceanprotocol/commons.git
synced 2023-03-15 18:03:00 +01:00
merge and test fixes
This commit is contained in:
parent
f17b93003e
commit
fc57f360d4
@ -2,7 +2,7 @@ import React from 'react'
|
||||
import { render } from 'react-testing-library'
|
||||
import { DDO, MetaData } from '@oceanprotocol/squid'
|
||||
import { BrowserRouter as Router } from 'react-router-dom'
|
||||
import AssetDetails, { datafilesLine } from './AssetDetails'
|
||||
import AssetDetails, { renderDatafilesLine } from './AssetDetails'
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
describe('AssetDetails', () => {
|
||||
@ -10,7 +10,7 @@ describe('AssetDetails', () => {
|
||||
const { container } = render(
|
||||
<AssetDetails
|
||||
metadata={({ base: { name: '' } } as any) as MetaData}
|
||||
ddo={({} as any) as DDO}
|
||||
ddo={({ proof: { creator: '0xxxxx' } } as any) as DDO}
|
||||
/>
|
||||
)
|
||||
expect(container.firstChild).toBeInTheDocument()
|
||||
@ -30,7 +30,7 @@ describe('AssetDetails', () => {
|
||||
}
|
||||
} as any) as MetaData
|
||||
}
|
||||
ddo={({} as any) as DDO}
|
||||
ddo={({ proof: { creator: '0xxxxx' } } as any) as DDO}
|
||||
/>
|
||||
</Router>
|
||||
)
|
||||
@ -40,18 +40,18 @@ describe('AssetDetails', () => {
|
||||
expect(container.firstChild).toHaveTextContent('Category')
|
||||
})
|
||||
|
||||
it('datafilesLine renders correctly for one file', () => {
|
||||
it('renderDatafilesLine renders correctly for one file', () => {
|
||||
const files = [
|
||||
{
|
||||
index: 0,
|
||||
url: 'https://hello.com'
|
||||
}
|
||||
]
|
||||
const { container } = render(datafilesLine(files))
|
||||
const { container } = render(renderDatafilesLine(files))
|
||||
expect(container.firstChild).toHaveTextContent('1 data file')
|
||||
})
|
||||
|
||||
it('datafilesLine renders correctly for multiple files', () => {
|
||||
it('renderDatafilesLine renders correctly for multiple files', () => {
|
||||
const files = [
|
||||
{
|
||||
index: 0,
|
||||
@ -62,7 +62,7 @@ describe('AssetDetails', () => {
|
||||
url: 'https://hello2.com'
|
||||
}
|
||||
]
|
||||
const { container } = render(datafilesLine(files))
|
||||
const { container } = render(renderDatafilesLine(files))
|
||||
expect(container.firstChild).toHaveTextContent('2 data files')
|
||||
})
|
||||
})
|
||||
|
@ -13,6 +13,13 @@ import { serviceHost, servicePort, serviceScheme } from '../../config'
|
||||
|
||||
const { steps } = require('../../data/form-publish.json') // eslint-disable-line
|
||||
|
||||
export const renderDatafilesLine = (files: any) =>
|
||||
files.length === 1 ? (
|
||||
<span>{files.length} data file</span>
|
||||
) : (
|
||||
<span>{files.length} data files</span>
|
||||
)
|
||||
|
||||
interface AssetDetailsProps {
|
||||
metadata: MetaData
|
||||
ddo: DDO
|
||||
@ -154,13 +161,6 @@ export default class AssetDetails extends PureComponent<
|
||||
this.setState({ isLoading: false })
|
||||
}
|
||||
|
||||
private renderDatafilesLine = (files: any) =>
|
||||
files.length === 1 ? (
|
||||
<span>{files.length} data file</span>
|
||||
) : (
|
||||
<span>{files.length} data files</span>
|
||||
)
|
||||
|
||||
private CopyrightHolder = ({ value }: { value: string }) =>
|
||||
this.state.isEditMode ? (
|
||||
<Input
|
||||
@ -308,7 +308,7 @@ export default class AssetDetails extends PureComponent<
|
||||
|
||||
{base.files &&
|
||||
!isEditMode &&
|
||||
this.renderDatafilesLine(base.files)}
|
||||
renderDatafilesLine(base.files)}
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
|
@ -35,42 +35,38 @@ const contextConnectedMock = {
|
||||
ReactGA.initialize('foo', { testMode: true })
|
||||
|
||||
describe('AssetFile', () => {
|
||||
const Component = <AssetFile file={file} ddo={ddo} />
|
||||
|
||||
it('renders without crashing', () => {
|
||||
const { container } = render(<AssetFile file={file} ddo={ddo} />)
|
||||
const { container } = render(Component)
|
||||
expect(container.firstChild).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('button to be disabled when not connected', () => {
|
||||
const { container } = render(<AssetFile file={file} ddo={ddo} />)
|
||||
const { container } = render(Component)
|
||||
expect(container.querySelector('button')).toHaveAttribute('disabled')
|
||||
})
|
||||
|
||||
it('button to be enabled when connected', async () => {
|
||||
const { getByText } = render(
|
||||
<User.Provider value={contextConnectedMock}>
|
||||
<AssetFile file={file} ddo={ddo} />
|
||||
{Component}
|
||||
</User.Provider>
|
||||
)
|
||||
const button = getByText('Get file')
|
||||
expect(button).not.toHaveAttribute('disabled')
|
||||
|
||||
fireEvent.click(button)
|
||||
})
|
||||
|
||||
it('renders loading state', async () => {
|
||||
const { container } = render(
|
||||
<StateMock state={{ isLoading: true }}>
|
||||
<AssetFile file={file} ddo={ddo} />
|
||||
</StateMock>
|
||||
<StateMock state={{ isLoading: true }}>{Component}</StateMock>
|
||||
)
|
||||
expect(container.querySelector('.spinner')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders error', async () => {
|
||||
const { container } = render(
|
||||
<StateMock state={{ error: 'Hello Error' }}>
|
||||
<AssetFile file={file} ddo={ddo} />
|
||||
</StateMock>
|
||||
<StateMock state={{ error: 'Hello Error' }}>{Component}</StateMock>
|
||||
)
|
||||
expect(container.querySelector('.error')).toBeInTheDocument()
|
||||
expect(container.querySelector('.error')).toHaveTextContent(
|
||||
|
Loading…
Reference in New Issue
Block a user