1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

test temp fix

This commit is contained in:
mihaisc 2020-06-05 16:39:17 +03:00
parent c7efdb2001
commit 41fcb2f4c3
7 changed files with 157 additions and 35 deletions

View File

@ -155,10 +155,9 @@ const PublishForm: React.FC<PublishFormProps> = () => {
)
services = [computeService]
}
console.log(metadata as MetaData)
try {
const asset = await ocean.assets.create(
metadata as MetaData,
(metadata as unknown) as MetaData,
account,
services
)

View File

@ -28,7 +28,7 @@ export const NoWeb3Browser = () => {
export const NoAccountConnected = () => {
const mock = {
...web3ProviderMock,
ethProviderStatus: InjectedProviderStatus.NOT_CONNECTED,
ethProviderStatus: 0,
account: ''
}
return (
@ -41,7 +41,7 @@ export const NoAccountConnected = () => {
export const NotConnectedToPacific = () => {
const mock = {
...web3ProviderMock,
ethProviderStatus: InjectedProviderStatus.CONNECTED,
ethProviderStatus: 1,
account: '0x0000000011111111aaaaaaaabbbbbbbb22222222',
balance: '11223.748267896',
web3: {
@ -63,7 +63,7 @@ export const NotConnectedToPacific = () => {
export const ErrorConnectingToOcean = () => {
const mock = {
...web3ProviderMock,
ethProviderStatus: InjectedProviderStatus.CONNECTED,
ethProviderStatus: 1,
account: '0x0000000011111111aaaaaaaabbbbbbbb22222222',
balance: '11223.748267896',
web3: {
@ -84,7 +84,7 @@ export const ErrorConnectingToOcean = () => {
export const ErrorInssuficientBalance = () => {
const mock = {
...web3ProviderMock,
ethProviderStatus: InjectedProviderStatus.CONNECTED,
ethProviderStatus: 1,
account: '0x0000000011111111aaaaaaaabbbbbbbb22222222',
balance: '11223.748267896'
}
@ -98,7 +98,7 @@ export const ErrorInssuficientBalance = () => {
export const ConnectedToOcean = () => {
const mock = {
...web3ProviderMock,
ethProviderStatus: InjectedProviderStatus.CONNECTED,
ethProviderStatus: 1,
account: '0x0000000011111111aaaaaaaabbbbbbbb22222222',
balance: '11223.748267896'
}

View File

@ -22,16 +22,11 @@ export default function Web3Feedback({
}) {
const { ethProviderStatus } = useWeb3()
const { status, balanceInOcean } = useOcean()
const isEthProviderAbsent =
ethProviderStatus === InjectedProviderStatus.NOT_AVAILABLE
const isEthProviderDisconnected =
ethProviderStatus === InjectedProviderStatus.NOT_CONNECTED
const isOceanDisconnected = status === OceanConnectionStatus.NOT_CONNECTED
const isOceanConnectionError =
status === OceanConnectionStatus.OCEAN_CONNECTION_ERROR
const hasSuccess =
ethProviderStatus === InjectedProviderStatus.CONNECTED &&
status === OceanConnectionStatus.CONNECTED
const isEthProviderAbsent = ethProviderStatus === -1
const isEthProviderDisconnected = ethProviderStatus === 0
const isOceanDisconnected = status === 0
const isOceanConnectionError = status === -1
const hasSuccess = ethProviderStatus === 1 && status === 1
const state = isEthProviderAbsent
? 'error'

View File

@ -1,5 +1,5 @@
import React, { useEffect, useState } from 'react'
import { DDO, Aquarius, Logger, Curation } from '@oceanprotocol/squid'
import React, { useState } from 'react'
import { DDO } from '@oceanprotocol/squid'
import Link from 'next/link'
import Layout from '../../../Layout'
import { MetaDataMarket } from '../../../@types/MetaData'

View File

@ -3,23 +3,53 @@ import { render } from '@testing-library/react'
import AssetDetails, { getMetadata } from '../../../src/pages/asset/[did]'
import ddo from '../__fixtures__/ddo'
import { findServiceByType } from '../../../src/utils'
import web3ProviderMock, { context } from '../__mocks__/web3provider'
import { MetaDataMarket } from '../../../src/@types/MetaData'
import oceanMock from '../__mocks__/ocean-mock'
import web3ProviderMock from '../__mocks__/web3'
const { attributes } = findServiceByType(ddo, 'metadata')
// import { useOcean } from '@oceanprotocol/react'
jest.mock('web3')
jest.mock('@oceanprotocol/react')
// eslint-disable-next-line
jest.mock('@oceanprotocol/react', () => ({
useOcean: () => {
return {
ocean: oceanMock
}
},
useWeb3: () => {
return {
web3: web3ProviderMock,
account: '0x0000000011111111aaaaaaaabbbbbbbb22222222',
ethProviderStatus: 1
}
},
useConsume: () => {
return {
consume: () => null as any,
consumeStepText: '',
isLoading: false
}
},
useMetadata: () => {
return {
getCuration: () => {
return Promise.resolve({ rating: 0, numVotes: 0 })
}
}
}
}))
describe('AssetDetails', () => {
it('renders without crashing', () => {
const { container } = render(
<context.Provider value={web3ProviderMock}>
<AssetDetails
ddo={JSON.stringify(ddo) as any}
attributes={attributes as MetaDataMarket}
title="Hello"
/>
</context.Provider>
<AssetDetails
ddo={JSON.stringify(ddo) as any}
attributes={attributes as MetaDataMarket}
title="Hello"
/>
)
expect(container.firstChild).toBeInTheDocument()
})
@ -40,8 +70,8 @@ describe('getMetadata()', () => {
it('Found', async () => {
const response = await getMetadata(
'did:op:ee8532e6e338484cb439043125270bd1caf45a7a25a64e71a55b3a18f647d7da'
'did:op:8898adb69e334755a568738ce3f6c03760f9eb5a4f344c688e483a04cb0855d6'
)
expect(response.title).toBe('Invoices test')
expect(response.title).toBe('compute1')
})
})

View File

@ -2,14 +2,41 @@ import React from 'react'
import { render } from '@testing-library/react'
import Publish from '../../../src/pages/publish'
import web3ProviderMock, { context } from '../__mocks__/web3provider'
import oceanMock from '../__mocks__/ocean-mock'
// eslint-disable-next-line
jest.mock('@oceanprotocol/react', () => ({
useOcean: () => {
return {
ocean: oceanMock
}
},
useWeb3: () => {
return {
web3: web3ProviderMock,
account: '0x0000000011111111aaaaaaaabbbbbbbb22222222',
ethProviderStatus: 1
}
},
useConsume: () => {
return {
consume: () => null as any,
consumeStepText: '',
isLoading: false
}
},
useMetadata: () => {
return {
getCuration: () => {
return Promise.resolve({ rating: 0, numVotes: 0 })
}
}
}
}))
describe('Home', () => {
it('renders without crashing', () => {
const { container } = render(
<context.Provider value={web3ProviderMock}>
<Publish />
</context.Provider>
)
const { container } = render(<Publish />)
expect(container.firstChild).toBeInTheDocument()
})
})

View File

@ -1,10 +1,81 @@
import initStoryshots from '@storybook/addon-storyshots'
import { render, wait } from '@testing-library/react'
import oceanMock from './__mocks__/ocean-mock'
import web3ProviderMock from './__mocks__/web3'
// eslint-disable-next-line
jest.mock('@oceanprotocol/react', () => ({
useOcean: () => {
return {
ocean: oceanMock
}
},
useWeb3: () => {
return {
web3: web3ProviderMock,
account: '0x0000000011111111aaaaaaaabbbbbbbb22222222',
ethProviderStatus: 1
}
},
useConsume: () => {
return {
consume: () => null as any,
consumeStepText: '',
isLoading: false
}
},
useMetadata: () => {
return {
getCuration: () => {
return Promise.resolve({ rating: 0, numVotes: 0 })
}
}
}
}))
// jest.mock('@oceanprotocol/squid')
// Stories are render-tested with @testing-library/react,
// overwriting default snapshot testing behavior
// eslint-disable-next-line
jest.mock('@oceanprotocol/react', () => ({
useOcean: () => {
return {
ocean: oceanMock
}
},
useWeb3: () => {
return {
web3: web3ProviderMock,
account: '0x0000000011111111aaaaaaaabbbbbbbb22222222',
ethProviderStatus: 1
}
},
useConsume: () => {
return {
consume: () => null as any,
consumeStepText: '',
isLoading: false
}
},
useCompute: () => {
return {
compute: () => null as any,
isLoading: false,
computeStepText: 0,
computeError: ''
}
},
useMetadata: () => {
return {
getCuration: () => {
return Promise.resolve({ rating: 0, numVotes: 0 })
}
}
},
computeOptions: ['', '']
}))
initStoryshots({
asyncJest: true,
test: async ({ story, done }) => {