1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-11-14 17:24:51 +01:00

more fixes

This commit is contained in:
Matthias Kretschmann 2020-07-10 13:19:04 +02:00
parent 2b813dbaaa
commit 818a399a97
Signed by: m
GPG Key ID: 606EEEF3C479A91F
11 changed files with 30 additions and 131 deletions

View File

@ -12,7 +12,7 @@ export interface FormFieldProps {
export interface FormContent {
title: string
description: string
description?: string
success: string
data: FormFieldProps[]
}

View File

@ -1,6 +1,6 @@
import React from 'react'
import { Center } from '../../../.storybook/helpers'
import { Alert } from './Alert'
import Alert from './Alert'
export default {
title: 'Atoms/Alert',

View File

@ -12,7 +12,3 @@ export const Normal = () => <Loader />
export const WithMessage = () => (
<Loader message="Crunching all the tech for you..." />
)
export const WithMessageHorizontal = () => (
<Loader message="Crunching all the tech for you..." isHorizontal />
)

View File

@ -1,4 +1,4 @@
import React from 'react'
import React, { ReactElement } from 'react'
import Eye from '../../../images/eye.svg'
import Button from '../Button'
import Tooltip from '../Tooltip'
@ -10,7 +10,7 @@ export declare type ActionsCellProps = {
export default function ActionsCell({
handleOnClickViewJobDetails
}: ActionsCellProps) {
}: ActionsCellProps): ReactElement {
return (
<>
{handleOnClickViewJobDetails && (

View File

@ -7,4 +7,9 @@ export default {
title: 'Molecules/Asset Teaser'
}
export const Default = () => <AssetTeaser ddo={new DDO(ddo)} />
export const Default = () => (
<AssetTeaser
did={ddo.id}
metadata={new DDO(ddo).findServiceByType('metadata').attributes as any}
/>
)

View File

@ -1,9 +1,9 @@
import React, { ReactElement } from 'react'
import isUrl from 'is-url-superb'
import Button from '../../atoms/Button'
import Input from '../../atoms/Input'
import { useField } from 'formik'
import Loader from '../../atoms/Loader'
import InputElement from '../../atoms/Input/InputElement'
export default function FileInput({
handleButtonClick,
@ -17,7 +17,7 @@ export default function FileInput({
return (
<>
<Input type="url" name="url" placeholder="e.g." {...field} />
<InputElement {...field} {...props} type="url" />
<Button
size="small"

View File

@ -42,6 +42,7 @@ export default function FilesInput(
<FileInfo file={field.value[0]} removeItem={removeItem} />
) : (
<FileInput
{...props}
{...field}
isLoading={isLoading}
handleButtonClick={handleButtonClick}

View File

@ -1,6 +1,6 @@
import { PublishFormData } from '../../../src/models/PublishForm'
import { MetaDataPublishForm } from '../../../src/@types/MetaData'
const testFormData: PublishFormData = {
const testFormData: MetaDataPublishForm = {
author: '',
files: [],
license: '',
@ -8,8 +8,8 @@ const testFormData: PublishFormData = {
name: '',
description: 'description',
termsAndConditions: true,
access: 'Download',
links: []
access: 'Download'
// links: []
}
export default testFormData

View File

@ -1,55 +0,0 @@
import React from 'react'
import { render, act } from '@testing-library/react'
import DateRangeWidget, {
getWidgetValue
} from '../../../src/components/atoms/FormWidgets/DateRangeWidget'
import { PublishFormSchema } from '../../../src/models/PublishForm'
describe('Date Range Widget', () => {
it('renders without crashing', () => {
act(() => {
const { container } = render(
<DateRangeWidget
schema={PublishFormSchema}
id="1"
autofocus={false}
disabled={false}
label="Date Range"
formContext={{}}
readonly={false}
value={'["2020-03-15T15:13:30Z", "2020-03-18T15:13:30Z"]'}
onBlur={() => {
/* */
}}
onFocus={() => {
/* */
}}
onChange={() => {
/* */
}}
options={{}}
required={false}
/>
)
expect(container.firstChild).toBeInTheDocument()
})
})
it('getWidgetValue returns a correctly encoded string', () => {
expect(
getWidgetValue(
new Date('2020-03-15T15:13:30.123Z'),
new Date('2020-03-18T15:13:30.456Z'),
false
)
).toEqual('["2020-03-15T15:13:30Z","2020-03-15T15:13:30Z"]')
expect(
getWidgetValue(
new Date('2020-03-15T15:13:30.123Z'),
new Date('2020-03-18T18:13:30.456Z'),
true
)
).toEqual('["2020-03-15T15:13:30Z","2020-03-18T18:13:30Z"]')
})
})

View File

@ -12,7 +12,9 @@ describe('Layout', () => {
testRender(
<LocationProvider history={history}>
<Layout location={{ href: 'https://demo.com' } as Location}>Hello</Layout>
<Layout title="Hello" uri={history.location.href}>
Hello
</Layout>
</LocationProvider>
)
})

View File

@ -1,80 +1,30 @@
import React from 'react'
import { render } from '@testing-library/react'
import Form, {
transformErrors
} from '../../../src/components/molecules/FilesInput'
import {
publishFormData,
PublishFormDataInterface,
PublishFormSchema,
PublishFormUiSchema
} from '../../../src/models/PublishForm'
import testFormData from '../__fixtures__/testFormData'
import { transformPublishFormToMetadata } from '../../../src/components/pages/Publish/utils'
import { MetaDataMarket } from '../../../src/@types/MetaData'
import {
MetaDataMarket,
MetaDataPublishForm
} from '../../../src/@types/MetaData'
import PublishForm from '../../../src/components/pages/Publish/PublishForm'
import publishFormData from '../__fixtures__/testFormData'
import content from '../../../content/pages/publish.json'
describe('PublishForm', () => {
it('renders without crashing', async () => {
const { container } = render(
<Form
schema={PublishFormSchema}
formData={testFormData}
uiSchema={PublishFormUiSchema}
onChange={() => null}
onSubmit={() => null}
onError={() => null}
>
Hello
</Form>
)
const { container } = render(<PublishForm content={content.form} />)
expect(container.firstChild).toBeInTheDocument()
})
it('transformErrors() passes through data', () => {
const errorsMock = [
{
message: 'Hello',
name: 'Hello',
params: 'Hello',
property: 'Hello',
stack: 'Hello'
}
]
const error = transformErrors(errorsMock)
expect(error[0].message).toBe('Hello')
})
it('transformErrors() transforms data', () => {
const errorsMock = [
{
message: 'Hello',
name: 'Hello',
params: 'Hello',
property: '.termsAndConditions',
stack: 'Hello'
}
]
const error = transformErrors(errorsMock)
expect(error[0].message).not.toBe('Hello')
})
it('Form data is correctly transformed to asset MetaData', () => {
const data: PublishFormDataInterface = publishFormData
const data: MetaDataPublishForm = publishFormData
let metadata: MetaDataMarket = transformPublishFormToMetadata(data)
expect(metadata.additionalInformation).toBeDefined()
expect(metadata.main).toBeDefined()
data.price = 1.3
data.dateRange = '["2020-03-05T15:17:31Z","2020-03-10T16:00:00Z"]'
data.price = '1.3'
metadata = transformPublishFormToMetadata(data)
expect(metadata.main.price).toBe('1300000000000000000')
expect(metadata.additionalInformation.dateRange).toEqual([
'2020-03-05T15:17:31Z',
'2020-03-10T16:00:00Z'
])
})
})