mirror of
https://github.com/oceanprotocol/commons.git
synced 2023-03-15 18:03:00 +01:00
fix tests
This commit is contained in:
parent
f8cb601eb7
commit
d74a4c0cbc
@ -11,7 +11,7 @@ import AssetFile, { messages } from './AssetFile'
|
||||
const file = {
|
||||
index: 0,
|
||||
url: 'https://hello.com',
|
||||
contentType: 'zip',
|
||||
contentType: 'application/x-zip',
|
||||
contentLength: 100
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,11 @@ describe('Details', () => {
|
||||
state: '',
|
||||
hash: ''
|
||||
}}
|
||||
match={{ params: { did: '' } }}
|
||||
match={{
|
||||
params: {
|
||||
did: ''
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)
|
||||
expect(container.firstChild).toBeInTheDocument()
|
||||
|
@ -51,8 +51,15 @@ export default class Asset extends Component<AssetProps, AssetState> {
|
||||
|
||||
public render() {
|
||||
const { metadata, ddo, error } = this.state
|
||||
const isLoading = metadata.base.name === ''
|
||||
|
||||
return metadata.base.name !== '' ? (
|
||||
return isLoading ? (
|
||||
<div className={stylesApp.loader}>
|
||||
<Spinner message={'Loading asset...'} />
|
||||
</div>
|
||||
) : error !== '' ? (
|
||||
<div className={styles.error}>{error}</div>
|
||||
) : (
|
||||
<Route
|
||||
title={metadata.base.name}
|
||||
image={
|
||||
@ -69,12 +76,6 @@ export default class Asset extends Component<AssetProps, AssetState> {
|
||||
<AssetDetails metadata={metadata} ddo={ddo} />
|
||||
</Content>
|
||||
</Route>
|
||||
) : error !== '' ? (
|
||||
<div className={styles.error}>{error}</div>
|
||||
) : (
|
||||
<div className={stylesApp.loader}>
|
||||
<Spinner message={'Loading asset...'} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import React from 'react'
|
||||
import { render, fireEvent, waitForElement } from 'react-testing-library'
|
||||
import Files, { getFileCompression } from '.'
|
||||
import Files from '.'
|
||||
|
||||
const onChange = jest.fn()
|
||||
|
||||
@ -71,20 +71,3 @@ describe('Files', () => {
|
||||
fireEvent.click(getByText('Add File'))
|
||||
})
|
||||
})
|
||||
|
||||
describe('getFileCompression', () => {
|
||||
it('outputs known compression', async () => {
|
||||
const compression = await getFileCompression('application/zip')
|
||||
expect(compression).toBe('zip')
|
||||
})
|
||||
|
||||
it('outputs known x- compression', async () => {
|
||||
const compression = await getFileCompression('application/x-gtar')
|
||||
expect(compression).toBe('gtar')
|
||||
})
|
||||
|
||||
it('outputs unknown compression', async () => {
|
||||
const compression = await getFileCompression('blabla')
|
||||
expect(compression).toBe('none')
|
||||
})
|
||||
})
|
||||
|
@ -3,6 +3,7 @@ import { render } from 'react-testing-library'
|
||||
import Search from './Search'
|
||||
import { User } from '../context'
|
||||
import { createMemoryHistory } from 'history'
|
||||
import { BrowserRouter as Router } from 'react-router-dom'
|
||||
|
||||
describe('Search', () => {
|
||||
it('renders without crashing', () => {
|
||||
@ -35,15 +36,17 @@ describe('Search', () => {
|
||||
message: ''
|
||||
}}
|
||||
>
|
||||
<Search
|
||||
location={{
|
||||
search: '?text=Hello&page=1',
|
||||
pathname: '/search',
|
||||
state: '',
|
||||
hash: ''
|
||||
}}
|
||||
history={history}
|
||||
/>
|
||||
<Router>
|
||||
<Search
|
||||
location={{
|
||||
search: '?text=Hello&page=1',
|
||||
pathname: '/search',
|
||||
state: '',
|
||||
hash: ''
|
||||
}}
|
||||
history={history}
|
||||
/>
|
||||
</Router>
|
||||
</User.Provider>
|
||||
)
|
||||
expect(container.firstChild).toBeInTheDocument()
|
||||
|
18
client/src/utils/cleanupContentType.test.ts
Normal file
18
client/src/utils/cleanupContentType.test.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import cleanupContentType from './cleanupContentType'
|
||||
|
||||
describe('getFileCompression', () => {
|
||||
it('outputs known compression', async () => {
|
||||
const compression = await cleanupContentType('application/zip')
|
||||
expect(compression).toBe('zip')
|
||||
})
|
||||
|
||||
it('outputs known x- compression', async () => {
|
||||
const compression = await cleanupContentType('application/x-gtar')
|
||||
expect(compression).toBe('gtar')
|
||||
})
|
||||
|
||||
it('pass through unknown compression', async () => {
|
||||
const compression = await cleanupContentType('blabla')
|
||||
expect(compression).toBe('blabla')
|
||||
})
|
||||
})
|
@ -2,6 +2,8 @@ const cleanupContentType = (contentType: string) => {
|
||||
// strip away the 'application/' part
|
||||
const contentTypeSplit = contentType.split('/')[1]
|
||||
|
||||
if (!contentTypeSplit) return contentType
|
||||
|
||||
let contentTypeCleaned
|
||||
|
||||
// TODO: add all the possible archive & compression MIME types
|
||||
|
Loading…
Reference in New Issue
Block a user