diff --git a/src/components/molecules/PublishForm/PublishForm.tsx b/src/components/molecules/PublishForm/PublishForm.tsx index 7fe0e5cb5..4d022a2d2 100644 --- a/src/components/molecules/PublishForm/PublishForm.tsx +++ b/src/components/molecules/PublishForm/PublishForm.tsx @@ -155,10 +155,9 @@ const PublishForm: React.FC = () => { ) services = [computeService] } - console.log(metadata as MetaData) try { const asset = await ocean.assets.create( - metadata as MetaData, + (metadata as unknown) as MetaData, account, services ) diff --git a/src/components/molecules/Web3Feedback/index.stories.tsx b/src/components/molecules/Web3Feedback/index.stories.tsx index 3b4880af0..aa2f36eef 100644 --- a/src/components/molecules/Web3Feedback/index.stories.tsx +++ b/src/components/molecules/Web3Feedback/index.stories.tsx @@ -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' } diff --git a/src/components/molecules/Web3Feedback/index.tsx b/src/components/molecules/Web3Feedback/index.tsx index 5fd223867..03cf4c675 100644 --- a/src/components/molecules/Web3Feedback/index.tsx +++ b/src/components/molecules/Web3Feedback/index.tsx @@ -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' diff --git a/src/components/templates/AssetDetails/index.tsx b/src/components/templates/AssetDetails/index.tsx index 4a29f736b..1ff35543e 100644 --- a/src/components/templates/AssetDetails/index.tsx +++ b/src/components/templates/AssetDetails/index.tsx @@ -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' diff --git a/tests/unit/pages/[did].test.tsx b/tests/unit/pages/[did].test.tsx index 556ee113a..ae7526df2 100644 --- a/tests/unit/pages/[did].test.tsx +++ b/tests/unit/pages/[did].test.tsx @@ -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( - - - + ) 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') }) }) diff --git a/tests/unit/pages/publish.test.tsx b/tests/unit/pages/publish.test.tsx index c986ee7a6..5e6b6735e 100644 --- a/tests/unit/pages/publish.test.tsx +++ b/tests/unit/pages/publish.test.tsx @@ -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( - - - - ) + const { container } = render() expect(container.firstChild).toBeInTheDocument() }) }) diff --git a/tests/unit/storyshots.test.tsx b/tests/unit/storyshots.test.tsx index 770327501..3398df764 100644 --- a/tests/unit/storyshots.test.tsx +++ b/tests/unit/storyshots.test.tsx @@ -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 }) => {