1
0
mirror of https://github.com/oceanprotocol/commons.git synced 2023-03-15 18:03:00 +01:00

fix tests

This commit is contained in:
Matthias Kretschmann 2019-05-27 19:37:51 +02:00
parent f8cb601eb7
commit d74a4c0cbc
Signed by: m
GPG Key ID: 606EEEF3C479A91F
7 changed files with 47 additions and 36 deletions

View File

@ -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
}

View File

@ -12,7 +12,11 @@ describe('Details', () => {
state: '',
hash: ''
}}
match={{ params: { did: '' } }}
match={{
params: {
did: ''
}
}}
/>
)
expect(container.firstChild).toBeInTheDocument()

View File

@ -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>
)
}
}

View File

@ -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')
})
})

View File

@ -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()

View 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')
})
})

View File

@ -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