1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-11-15 01:34:57 +01:00
market/tests/unit/pages/[did].test.tsx

78 lines
2.0 KiB
TypeScript
Raw Normal View History

2020-05-07 08:03:30 +02:00
import React from 'react'
import { render } from '@testing-library/react'
import AssetDetails, { getMetadata } from '../../../src/pages/asset/[did]'
import ddo from '../__fixtures__/ddo'
import { findServiceByType } from '../../../src/utils'
2020-06-02 11:15:21 +02:00
import { MetaDataMarket } from '../../../src/@types/MetaData'
2020-06-05 15:39:17 +02:00
import oceanMock from '../__mocks__/ocean-mock'
import web3ProviderMock from '../__mocks__/web3'
2020-05-07 08:03:30 +02:00
const { attributes } = findServiceByType(ddo, 'metadata')
2020-06-05 15:39:17 +02:00
// import { useOcean } from '@oceanprotocol/react'
2020-05-07 08:03:30 +02:00
jest.mock('web3')
2020-06-05 15:39:17 +02:00
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 })
}
}
}
}))
2020-05-07 08:03:30 +02:00
describe('AssetDetails', () => {
it('renders without crashing', () => {
const { container } = render(
2020-06-05 15:39:17 +02:00
<AssetDetails
ddo={JSON.stringify(ddo) as any}
attributes={attributes as MetaDataMarket}
title="Hello"
/>
2020-05-07 08:03:30 +02:00
)
expect(container.firstChild).toBeInTheDocument()
})
})
describe('getMetadata()', () => {
it('not a valid DID', async () => {
const response = await getMetadata('hello')
expect(response.title).toBe('Not a DID')
})
it('Not Found', async () => {
const response = await getMetadata(
'did:op:c678e7e5963d4fdc99afea49ac221d4d4177790f30204417823319d4d35f851f'
)
expect(response.title).toBe('Could not retrieve asset')
})
it('Found', async () => {
const response = await getMetadata(
2020-06-05 15:39:17 +02:00
'did:op:8898adb69e334755a568738ce3f6c03760f9eb5a4f344c688e483a04cb0855d6'
2020-05-07 08:03:30 +02:00
)
2020-06-05 15:39:17 +02:00
expect(response.title).toBe('compute1')
2020-05-07 08:03:30 +02:00
})
})