mirror of
https://github.com/oceanprotocol/commons.git
synced 2023-03-15 18:03:00 +01:00
Merge pull request #142 from oceanprotocol/feature/price-string
make price a string, Aquarius 0.2.7 validation updates
This commit is contained in:
commit
c1b32830f7
107
client/package-lock.json
generated
107
client/package-lock.json
generated
@ -1315,6 +1315,17 @@
|
|||||||
"resolved": "https://registry.npmjs.org/@oceanprotocol/typographies/-/typographies-0.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/@oceanprotocol/typographies/-/typographies-0.1.0.tgz",
|
||||||
"integrity": "sha512-kMsZsqvzpz9KzVbVZzllwhPoIC3zbqsdRrClagZL/C2PHzgLrKGC1kYn3gPt0RMIFg9ZjrwieKaxlgIK9i9zzg=="
|
"integrity": "sha512-kMsZsqvzpz9KzVbVZzllwhPoIC3zbqsdRrClagZL/C2PHzgLrKGC1kYn3gPt0RMIFg9ZjrwieKaxlgIK9i9zzg=="
|
||||||
},
|
},
|
||||||
|
"@react-mock/fetch": {
|
||||||
|
"version": "0.3.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@react-mock/fetch/-/fetch-0.3.0.tgz",
|
||||||
|
"integrity": "sha512-q1tqyrqeW4+J0R/rRghK86VG21fFFIMli1kxhi2z9wLAko10YNHB3UuI4fnXc+/kbjne0yVxyTp0s1xdzv+YzA==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"@babel/runtime": "^7.1.2",
|
||||||
|
"fetch-mock": "^7.0.7",
|
||||||
|
"lodash": "^4.17.11"
|
||||||
|
}
|
||||||
|
},
|
||||||
"@react-mock/state": {
|
"@react-mock/state": {
|
||||||
"version": "0.1.8",
|
"version": "0.1.8",
|
||||||
"resolved": "https://registry.npmjs.org/@react-mock/state/-/state-0.1.8.tgz",
|
"resolved": "https://registry.npmjs.org/@react-mock/state/-/state-0.1.8.tgz",
|
||||||
@ -2481,18 +2492,29 @@
|
|||||||
"integrity": "sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ=="
|
"integrity": "sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ=="
|
||||||
},
|
},
|
||||||
"axios": {
|
"axios": {
|
||||||
"version": "0.18.0",
|
"version": "0.19.0",
|
||||||
"resolved": "https://registry.npmjs.org/axios/-/axios-0.18.0.tgz",
|
"resolved": "https://registry.npmjs.org/axios/-/axios-0.19.0.tgz",
|
||||||
"integrity": "sha1-MtU+SFHv3AoRmTts0AB4nXDAUQI=",
|
"integrity": "sha512-1uvKqKQta3KBxIz14F2v06AEHZ/dIoeKfbTRkK1E5oqjDnuEerLmYTgJB5AiQZHJcljpg1TuRzdjDR06qNk0DQ==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"follow-redirects": "^1.3.0",
|
"follow-redirects": "1.5.10",
|
||||||
"is-buffer": "^1.1.5"
|
"is-buffer": "^2.0.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"is-buffer": {
|
"debug": {
|
||||||
"version": "1.1.6",
|
"version": "3.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz",
|
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
|
||||||
"integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w=="
|
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
|
||||||
|
"requires": {
|
||||||
|
"ms": "2.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"follow-redirects": {
|
||||||
|
"version": "1.5.10",
|
||||||
|
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz",
|
||||||
|
"integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==",
|
||||||
|
"requires": {
|
||||||
|
"debug": "=3.1.0"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -2690,6 +2712,31 @@
|
|||||||
"integrity": "sha512-eqj0hVcJUR57/Ug2zE1Yswsw4LhuqqHhD+8v120T1cl3kjg76QwtyBrdIk4WVwK+lAhBJVYCd/v+4nc4y+8JsA==",
|
"integrity": "sha512-eqj0hVcJUR57/Ug2zE1Yswsw4LhuqqHhD+8v120T1cl3kjg76QwtyBrdIk4WVwK+lAhBJVYCd/v+4nc4y+8JsA==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"babel-polyfill": {
|
||||||
|
"version": "6.26.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/babel-polyfill/-/babel-polyfill-6.26.0.tgz",
|
||||||
|
"integrity": "sha1-N5k3q8Z9eJWXCtxiHyhM2WbPIVM=",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"babel-runtime": "^6.26.0",
|
||||||
|
"core-js": "^2.5.0",
|
||||||
|
"regenerator-runtime": "^0.10.5"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"core-js": {
|
||||||
|
"version": "2.6.9",
|
||||||
|
"resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.9.tgz",
|
||||||
|
"integrity": "sha512-HOpZf6eXmnl7la+cUdMnLvUxKNqLUzJvgIziQ0DiF3JwSImNphIqdGqzj6hIKyX04MmV0poclQ7+wjWvxQyR2A==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"regenerator-runtime": {
|
||||||
|
"version": "0.10.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.10.5.tgz",
|
||||||
|
"integrity": "sha1-M2w+/BIgrc7dosn6tntaeVWjNlg=",
|
||||||
|
"dev": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"babel-preset-jest": {
|
"babel-preset-jest": {
|
||||||
"version": "24.6.0",
|
"version": "24.6.0",
|
||||||
"resolved": "https://registry.npmjs.org/babel-preset-jest/-/babel-preset-jest-24.6.0.tgz",
|
"resolved": "https://registry.npmjs.org/babel-preset-jest/-/babel-preset-jest-24.6.0.tgz",
|
||||||
@ -6450,6 +6497,43 @@
|
|||||||
"pend": "~1.2.0"
|
"pend": "~1.2.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"fetch-mock": {
|
||||||
|
"version": "7.3.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/fetch-mock/-/fetch-mock-7.3.3.tgz",
|
||||||
|
"integrity": "sha512-MHKcwZ4n9TmnfnVfelUBrrfxtC9tztafIR+F8l/Yu9N+y48fU1BAwj3iSxhYFYELVw73rCZh2DPWtWCekY/t+w==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"babel-polyfill": "^6.26.0",
|
||||||
|
"glob-to-regexp": "^0.4.0",
|
||||||
|
"path-to-regexp": "^2.2.1",
|
||||||
|
"whatwg-url": "^6.5.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"glob-to-regexp": {
|
||||||
|
"version": "0.4.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/glob-to-regexp/-/glob-to-regexp-0.4.1.tgz",
|
||||||
|
"integrity": "sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"path-to-regexp": {
|
||||||
|
"version": "2.4.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-2.4.0.tgz",
|
||||||
|
"integrity": "sha512-G6zHoVqC6GGTQkZwF4lkuEyMbVOjoBKAEybQUypI1WTkqinCOrq2x6U2+phkJ1XsEMTy4LjtwPI7HW+NVrRR2w==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"whatwg-url": {
|
||||||
|
"version": "6.5.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-6.5.0.tgz",
|
||||||
|
"integrity": "sha512-rhRZRqx/TLJQWUpQ6bmrt2UV4f0HCQ463yQuONJqC6fO2VoEb1pTYddbe59SkYq87aoM5A3bdhMZiUiVws+fzQ==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"lodash.sortby": "^4.7.0",
|
||||||
|
"tr46": "^1.0.1",
|
||||||
|
"webidl-conversions": "^4.0.2"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"figgy-pudding": {
|
"figgy-pudding": {
|
||||||
"version": "3.5.1",
|
"version": "3.5.1",
|
||||||
"resolved": "https://registry.npmjs.org/figgy-pudding/-/figgy-pudding-3.5.1.tgz",
|
"resolved": "https://registry.npmjs.org/figgy-pudding/-/figgy-pudding-3.5.1.tgz",
|
||||||
@ -6620,6 +6704,7 @@
|
|||||||
"version": "1.7.0",
|
"version": "1.7.0",
|
||||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.7.0.tgz",
|
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.7.0.tgz",
|
||||||
"integrity": "sha512-m/pZQy4Gj287eNy94nivy5wchN3Kp+Q5WgUPNy5lJSZ3sgkVKSYV/ZChMAQVIgx1SqfZ2zBZtPA2YlXIWxxJOQ==",
|
"integrity": "sha512-m/pZQy4Gj287eNy94nivy5wchN3Kp+Q5WgUPNy5lJSZ3sgkVKSYV/ZChMAQVIgx1SqfZ2zBZtPA2YlXIWxxJOQ==",
|
||||||
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"debug": "^3.2.6"
|
"debug": "^3.2.6"
|
||||||
},
|
},
|
||||||
@ -6628,6 +6713,7 @@
|
|||||||
"version": "3.2.6",
|
"version": "3.2.6",
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz",
|
"resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz",
|
||||||
"integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==",
|
"integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==",
|
||||||
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"ms": "^2.1.1"
|
"ms": "^2.1.1"
|
||||||
}
|
}
|
||||||
@ -6635,7 +6721,8 @@
|
|||||||
"ms": {
|
"ms": {
|
||||||
"version": "2.1.1",
|
"version": "2.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz",
|
||||||
"integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg=="
|
"integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==",
|
||||||
|
"dev": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
"@oceanprotocol/squid": "^0.5.14",
|
"@oceanprotocol/squid": "^0.5.14",
|
||||||
"@oceanprotocol/typographies": "^0.1.0",
|
"@oceanprotocol/typographies": "^0.1.0",
|
||||||
"@sindresorhus/slugify": "^0.9.1",
|
"@sindresorhus/slugify": "^0.9.1",
|
||||||
"axios": "^0.18.0",
|
"axios": "^0.19.0",
|
||||||
"classnames": "^2.2.6",
|
"classnames": "^2.2.6",
|
||||||
"ethereum-blockies": "MyEtherWallet/blockies",
|
"ethereum-blockies": "MyEtherWallet/blockies",
|
||||||
"filesize": "^4.1.2",
|
"filesize": "^4.1.2",
|
||||||
@ -39,6 +39,7 @@
|
|||||||
"web3": "1.0.0-beta.37"
|
"web3": "1.0.0-beta.37"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@react-mock/fetch": "^0.3.0",
|
||||||
"@react-mock/state": "^0.1.8",
|
"@react-mock/state": "^0.1.8",
|
||||||
"@testing-library/react": "^8.0.1",
|
"@testing-library/react": "^8.0.1",
|
||||||
"@types/classnames": "^2.2.7",
|
"@types/classnames": "^2.2.7",
|
||||||
|
@ -12,22 +12,13 @@ const AssetModel = {
|
|||||||
type: '',
|
type: '',
|
||||||
license: null,
|
license: null,
|
||||||
copyrightHolder: null,
|
copyrightHolder: null,
|
||||||
workExample: null,
|
workExample: '',
|
||||||
files: [],
|
files: [],
|
||||||
categories: [],
|
categories: [],
|
||||||
links: [],
|
links: [],
|
||||||
inLanguage: null,
|
inLanguage: '',
|
||||||
tags: [],
|
tags: [],
|
||||||
price: null
|
price: ''
|
||||||
},
|
|
||||||
curation: {
|
|
||||||
rating: null,
|
|
||||||
numVotes: null,
|
|
||||||
schema: null
|
|
||||||
},
|
|
||||||
additionalInformation: {
|
|
||||||
updateFrequency: null,
|
|
||||||
structuredMarkup: []
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { render, fireEvent, waitForElement } from '@testing-library/react'
|
import { render, fireEvent, waitForElement } from '@testing-library/react'
|
||||||
|
import { FetchMock } from '@react-mock/fetch'
|
||||||
|
import { serviceUri } from '../../../config'
|
||||||
import Files from '.'
|
import Files from '.'
|
||||||
|
|
||||||
const onChange = jest.fn()
|
const onChange = jest.fn()
|
||||||
|
|
||||||
const files = [
|
const files = [
|
||||||
{
|
{
|
||||||
found: true,
|
|
||||||
url: 'https://hello.com',
|
url: 'https://hello.com',
|
||||||
checksum: 'cccccc',
|
checksum: 'cccccc',
|
||||||
checksumType: 'MD5',
|
checksumType: 'MD5',
|
||||||
@ -14,33 +15,48 @@ const files = [
|
|||||||
contentType: 'application/zip',
|
contentType: 'application/zip',
|
||||||
resourceId: 'xxx',
|
resourceId: 'xxx',
|
||||||
encoding: 'UTF-8',
|
encoding: 'UTF-8',
|
||||||
compression: 'zip'
|
compression: 'zip',
|
||||||
|
found: true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
const setup = () => {
|
const renderComponent = () =>
|
||||||
const utils = render(
|
render(
|
||||||
<Files
|
<FetchMock
|
||||||
files={files}
|
mocks={[
|
||||||
placeholder={'Hello'}
|
{
|
||||||
name={'Hello'}
|
matcher: `${serviceUri}/api/v1/urlcheck`,
|
||||||
onChange={onChange}
|
method: 'POST',
|
||||||
/>
|
response: {
|
||||||
|
result: {
|
||||||
|
url: 'https://demo.com',
|
||||||
|
contentType: 'application/zip',
|
||||||
|
contentLength: 237347827,
|
||||||
|
found: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<Files
|
||||||
|
files={files}
|
||||||
|
placeholder={'Hello'}
|
||||||
|
name={'Hello'}
|
||||||
|
onChange={onChange}
|
||||||
|
/>
|
||||||
|
</FetchMock>
|
||||||
)
|
)
|
||||||
const { container } = utils
|
|
||||||
return { container, ...utils }
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('Files', () => {
|
describe('Files', () => {
|
||||||
it('renders without crashing', () => {
|
it('renders without crashing', async () => {
|
||||||
const { container } = setup()
|
const { container } = renderComponent()
|
||||||
|
|
||||||
expect(container.firstChild).toBeInTheDocument()
|
expect(container.firstChild).toBeInTheDocument()
|
||||||
expect(container.querySelector('.itemForm')).not.toBeInTheDocument()
|
expect(container.querySelector('.itemForm')).not.toBeInTheDocument()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('new file form can be opened and closed', async () => {
|
it('new file form can be opened and closed', async () => {
|
||||||
const { container, getByText } = setup()
|
const { container, getByText } = renderComponent()
|
||||||
|
|
||||||
// open
|
// open
|
||||||
fireEvent.click(getByText('+ Add a file'))
|
fireEvent.click(getByText('+ Add a file'))
|
||||||
@ -54,14 +70,14 @@ describe('Files', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('item can be removed', async () => {
|
it('item can be removed', async () => {
|
||||||
const { getByTitle } = setup()
|
const { getByTitle } = renderComponent()
|
||||||
|
|
||||||
fireEvent.click(getByTitle('Remove item'))
|
fireEvent.click(getByTitle('Remove item'))
|
||||||
expect(files.length).toBe(0)
|
expect(files.length).toBe(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('item can be added', async () => {
|
it('item can be added', async () => {
|
||||||
const { getByText, getByPlaceholderText } = setup()
|
const { getByText, getByPlaceholderText } = renderComponent()
|
||||||
|
|
||||||
fireEvent.click(getByText('+ Add a file'))
|
fireEvent.click(getByText('+ Add a file'))
|
||||||
await waitForElement(() => getByText('- Cancel'))
|
await waitForElement(() => getByText('- Cancel'))
|
||||||
|
@ -8,17 +8,18 @@ import styles from './index.module.scss'
|
|||||||
|
|
||||||
import { serviceUri } from '../../../config'
|
import { serviceUri } from '../../../config'
|
||||||
import cleanupContentType from '../../../utils/cleanupContentType'
|
import cleanupContentType from '../../../utils/cleanupContentType'
|
||||||
|
import { Logger } from '@oceanprotocol/squid'
|
||||||
|
|
||||||
interface File {
|
export interface File {
|
||||||
url: string
|
url: string
|
||||||
found: boolean
|
contentType: string
|
||||||
checksum?: string
|
checksum?: string
|
||||||
checksumType?: string
|
checksumType?: string
|
||||||
contentLength?: number
|
contentLength?: number
|
||||||
contentType?: string
|
|
||||||
resourceId?: string
|
resourceId?: string
|
||||||
encoding?: string
|
encoding?: string
|
||||||
compression?: string
|
compression?: string
|
||||||
|
found: boolean // non-standard
|
||||||
}
|
}
|
||||||
|
|
||||||
interface FilesProps {
|
interface FilesProps {
|
||||||
@ -51,20 +52,10 @@ export default class Files extends PureComponent<FilesProps, FilesStates> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private addItem = async (value: string) => {
|
private addItem = async (value: string) => {
|
||||||
let res: {
|
|
||||||
result: {
|
|
||||||
contentLength: number
|
|
||||||
contentType: string
|
|
||||||
found: boolean
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let file: File = {
|
let file: File = {
|
||||||
url: value,
|
url: value,
|
||||||
found: false,
|
|
||||||
contentLength: 0,
|
|
||||||
contentType: '',
|
contentType: '',
|
||||||
compression: ''
|
found: false // non-standard
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -75,13 +66,16 @@ export default class Files extends PureComponent<FilesProps, FilesStates> {
|
|||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
res = await response.json()
|
|
||||||
file.contentLength = res.result.contentLength
|
const json = await response.json()
|
||||||
file.contentType = res.result.contentType
|
const { contentLength, contentType, found } = json.result
|
||||||
file.compression = await cleanupContentType(res.result.contentType)
|
|
||||||
file.found = res.result.found
|
file.contentLength = contentLength
|
||||||
|
file.contentType = contentType
|
||||||
|
file.compression = await cleanupContentType(contentType)
|
||||||
|
file.found = found
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// error
|
Logger.error(error.message)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.props.files.push(file)
|
this.props.files.push(file)
|
||||||
@ -121,6 +115,7 @@ export default class Files extends PureComponent<FilesProps, FilesStates> {
|
|||||||
name={name}
|
name={name}
|
||||||
value={JSON.stringify(files)}
|
value={JSON.stringify(files)}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
|
data-testid="files"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div className={styles.newItems}>
|
<div className={styles.newItems}>
|
||||||
|
@ -12,7 +12,6 @@ const stateMock = {
|
|||||||
|
|
||||||
const propsMock = {
|
const propsMock = {
|
||||||
inputChange: () => null,
|
inputChange: () => null,
|
||||||
inputToArrayChange: () => null,
|
|
||||||
state: stateMock,
|
state: stateMock,
|
||||||
title: 'Hello',
|
title: 'Hello',
|
||||||
description: 'description',
|
description: 'description',
|
||||||
|
@ -28,9 +28,6 @@ interface StepProps {
|
|||||||
| ChangeEvent<HTMLSelectElement>
|
| ChangeEvent<HTMLSelectElement>
|
||||||
| ChangeEvent<HTMLTextAreaElement>
|
| ChangeEvent<HTMLTextAreaElement>
|
||||||
): void
|
): void
|
||||||
inputToArrayChange(
|
|
||||||
event: ChangeEvent<HTMLSelectElement> | ChangeEvent<HTMLInputElement>
|
|
||||||
): void
|
|
||||||
fields?: Fields
|
fields?: Fields
|
||||||
state: any
|
state: any
|
||||||
title: string
|
title: string
|
||||||
|
@ -1,11 +1,44 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { render } from '@testing-library/react'
|
import { render, fireEvent } from '@testing-library/react'
|
||||||
import Publish from '.'
|
import Publish from '.'
|
||||||
|
import { User } from '../../context'
|
||||||
|
import { userMockConnected } from '../../../__mocks__/user-mock'
|
||||||
|
|
||||||
describe('Progress', () => {
|
describe('Publish', () => {
|
||||||
it('renders without crashing', () => {
|
it('renders without crashing', () => {
|
||||||
const { container, getByText } = render(<Publish />)
|
const { container, getByText } = render(
|
||||||
|
<User.Provider value={userMockConnected}>
|
||||||
|
<Publish />
|
||||||
|
</User.Provider>
|
||||||
|
)
|
||||||
expect(container.firstChild).toBeInTheDocument()
|
expect(container.firstChild).toBeInTheDocument()
|
||||||
expect(getByText('Next →')).toHaveAttribute('disabled')
|
expect(getByText('Next →')).toHaveAttribute('disabled')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('next button works', () => {
|
||||||
|
const { getByText, getByLabelText, getByTestId } = render(
|
||||||
|
<User.Provider value={userMockConnected}>
|
||||||
|
<Publish />
|
||||||
|
</User.Provider>
|
||||||
|
)
|
||||||
|
|
||||||
|
// Title
|
||||||
|
const inputName = getByLabelText('Title')
|
||||||
|
fireEvent.change(inputName, {
|
||||||
|
target: { value: 'Hello' }
|
||||||
|
})
|
||||||
|
|
||||||
|
// Files
|
||||||
|
const inputFiles = getByTestId('files')
|
||||||
|
fireEvent.change(inputFiles, {
|
||||||
|
target: {
|
||||||
|
value: JSON.stringify([
|
||||||
|
{ url: 'https://demo.com', contentType: '', found: false }
|
||||||
|
])
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// expect(getByText('Next →')).not.toHaveAttribute('disabled')
|
||||||
|
fireEvent.click(getByText('Next →'))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
@ -11,27 +11,28 @@ import ReactGA from 'react-ga'
|
|||||||
|
|
||||||
import { steps } from '../../data/form-publish.json'
|
import { steps } from '../../data/form-publish.json'
|
||||||
import Content from '../../components/atoms/Content'
|
import Content from '../../components/atoms/Content'
|
||||||
|
import { File } from './Files'
|
||||||
|
|
||||||
type AssetType = 'dataset' | 'algorithm' | 'container' | 'workflow' | 'other'
|
type AssetType = 'dataset' | 'algorithm' | 'container' | 'workflow' | 'other'
|
||||||
|
|
||||||
interface PublishState {
|
interface PublishState {
|
||||||
name?: string
|
name?: string
|
||||||
dateCreated?: string
|
dateCreated?: string
|
||||||
description?: string
|
price?: string
|
||||||
files?: string[]
|
|
||||||
price?: number
|
|
||||||
author?: string
|
author?: string
|
||||||
type?: AssetType
|
|
||||||
license?: string
|
license?: string
|
||||||
|
description?: string
|
||||||
|
files?: File[]
|
||||||
|
type?: AssetType
|
||||||
copyrightHolder?: string
|
copyrightHolder?: string
|
||||||
categories?: string
|
categories?: string[]
|
||||||
tags?: string[]
|
|
||||||
|
currentStep?: number
|
||||||
|
publishingStep?: number
|
||||||
isPublishing?: boolean
|
isPublishing?: boolean
|
||||||
isPublished?: boolean
|
isPublished?: boolean
|
||||||
publishedDid?: string
|
publishedDid?: string
|
||||||
publishingError?: string
|
publishingError?: string
|
||||||
publishingStep?: number
|
|
||||||
currentStep?: number
|
|
||||||
validationStatus?: any
|
validationStatus?: any
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,17 +40,18 @@ export default class Publish extends Component<{}, PublishState> {
|
|||||||
public static contextType = User
|
public static contextType = User
|
||||||
|
|
||||||
public state = {
|
public state = {
|
||||||
currentStep: 1,
|
|
||||||
name: '',
|
name: '',
|
||||||
dateCreated: new Date().toISOString(),
|
dateCreated: new Date().toISOString(),
|
||||||
description: '',
|
description: '',
|
||||||
files: [],
|
files: [],
|
||||||
price: 0,
|
price: '0',
|
||||||
author: '',
|
author: '',
|
||||||
type: 'dataset' as AssetType,
|
type: 'dataset' as AssetType,
|
||||||
license: '',
|
license: '',
|
||||||
copyrightHolder: '',
|
copyrightHolder: '',
|
||||||
categories: '',
|
categories: [],
|
||||||
|
|
||||||
|
currentStep: 1,
|
||||||
isPublishing: false,
|
isPublishing: false,
|
||||||
isPublished: false,
|
isPublished: false,
|
||||||
publishedDid: '',
|
publishedDid: '',
|
||||||
@ -81,16 +83,6 @@ export default class Publish extends Component<{}, PublishState> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private inputToArrayChange = (
|
|
||||||
event: ChangeEvent<HTMLInputElement> | ChangeEvent<HTMLSelectElement>
|
|
||||||
) => {
|
|
||||||
this.validateInputs(event.currentTarget.name, event.currentTarget.value)
|
|
||||||
|
|
||||||
this.setState({
|
|
||||||
[event.currentTarget.name]: [event.currentTarget.value]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
private next = () => {
|
private next = () => {
|
||||||
let { currentStep } = this.state
|
let { currentStep } = this.state
|
||||||
const totalSteps = steps.length
|
const totalSteps = steps.length
|
||||||
@ -122,12 +114,12 @@ export default class Publish extends Component<{}, PublishState> {
|
|||||||
dateCreated: new Date().toISOString(),
|
dateCreated: new Date().toISOString(),
|
||||||
description: '',
|
description: '',
|
||||||
files: [],
|
files: [],
|
||||||
price: 0,
|
price: '0',
|
||||||
author: '',
|
author: '',
|
||||||
type: 'dataset' as AssetType,
|
type: 'dataset' as AssetType,
|
||||||
license: '',
|
license: '',
|
||||||
copyrightHolder: '',
|
copyrightHolder: '',
|
||||||
categories: '',
|
categories: [],
|
||||||
isPublishing: false,
|
isPublishing: false,
|
||||||
isPublished: false,
|
isPublished: false,
|
||||||
publishingStep: 0,
|
publishingStep: 0,
|
||||||
@ -267,28 +259,32 @@ export default class Publish extends Component<{}, PublishState> {
|
|||||||
|
|
||||||
const { ocean } = this.context
|
const { ocean } = this.context
|
||||||
const account = await ocean.accounts.list()
|
const account = await ocean.accounts.list()
|
||||||
|
|
||||||
|
// remove `found` attribute from all File objects
|
||||||
|
// in a new array
|
||||||
|
const files = this.state.files.map(
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
({ found, ...keepAttrs }: { found: boolean }) => keepAttrs
|
||||||
|
)
|
||||||
|
|
||||||
const newAsset = {
|
const newAsset = {
|
||||||
// OEP-08 Attributes
|
// OEP-08 Attributes
|
||||||
// https://github.com/oceanprotocol/OEPs/tree/master/8
|
// https://github.com/oceanprotocol/OEPs/tree/master/8
|
||||||
base: Object.assign(AssetModel.base, {
|
base: Object.assign(AssetModel.base, {
|
||||||
name: this.state.name,
|
name: this.state.name,
|
||||||
description: this.state.description,
|
description: this.state.description,
|
||||||
dateCreated: new Date(this.state.dateCreated).toISOString(),
|
dateCreated:
|
||||||
|
new Date(this.state.dateCreated)
|
||||||
|
.toISOString()
|
||||||
|
.split('.')[0] + 'Z', // remove milliseconds
|
||||||
author: this.state.author,
|
author: this.state.author,
|
||||||
license: this.state.license,
|
license: this.state.license,
|
||||||
copyrightHolder: this.state.copyrightHolder,
|
copyrightHolder: this.state.copyrightHolder,
|
||||||
files: this.state.files,
|
files,
|
||||||
price: this.state.price,
|
price: this.state.price,
|
||||||
type: this.state.type,
|
type: this.state.type,
|
||||||
categories: [this.state.categories],
|
categories: [this.state.categories]
|
||||||
workExample: undefined,
|
})
|
||||||
inLanguage: undefined,
|
|
||||||
tags: ''
|
|
||||||
}),
|
|
||||||
curation: Object.assign(AssetModel.curation),
|
|
||||||
additionalInformation: Object.assign(
|
|
||||||
AssetModel.additionalInformation
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -346,7 +342,6 @@ export default class Publish extends Component<{}, PublishState> {
|
|||||||
currentStep={this.state.currentStep}
|
currentStep={this.state.currentStep}
|
||||||
fields={step.fields}
|
fields={step.fields}
|
||||||
inputChange={this.inputChange}
|
inputChange={this.inputChange}
|
||||||
inputToArrayChange={this.inputToArrayChange}
|
|
||||||
state={this.state}
|
state={this.state}
|
||||||
next={this.next}
|
next={this.next}
|
||||||
prev={this.prev}
|
prev={this.prev}
|
||||||
|
@ -11,11 +11,11 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "brizo",
|
"name": "brizo",
|
||||||
"version": "~0.3.9"
|
"version": "~0.3.10"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "aquarius",
|
"name": "aquarius",
|
||||||
"version": "~0.2.6"
|
"version": "~0.2.9"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "squid-js",
|
"name": "squid-js",
|
||||||
|
@ -31,8 +31,9 @@ export class UrlCheckRouter {
|
|||||||
result.found = true
|
result.found = true
|
||||||
|
|
||||||
if (response.headers['content-length']) {
|
if (response.headers['content-length']) {
|
||||||
result.contentLength =
|
result.contentLength = parseInt(
|
||||||
response.headers['content-length']
|
response.headers['content-length']
|
||||||
|
) // convert to number
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.headers['content-type']) {
|
if (response.headers['content-type']) {
|
||||||
|
Loading…
Reference in New Issue
Block a user