From 391d5f274244e85580ef9ff9b0400b05077b4f15 Mon Sep 17 00:00:00 2001 From: mihaisc Date: Wed, 13 May 2020 12:17:22 +0300 Subject: [PATCH] partial tests fix,hook implementation fix --- src/components/molecules/Web3Feedback/index.tsx | 14 +++++++++----- src/components/organisms/Consume.tsx | 13 ++++--------- .../templates/AssetDetails/RatingAction.tsx | 2 +- src/components/templates/AssetDetails/index.tsx | 2 +- src/pages/_app.tsx | 6 +++--- tests/unit/__mocks__/web3provider.ts | 15 ++++++++++++++- tests/unit/context/Web3Provider.test.tsx | 2 +- tests/unit/pages/[did].test.tsx | 17 ++++++++++------- tests/unit/pages/publish.test.tsx | 9 ++++++--- 9 files changed, 49 insertions(+), 31 deletions(-) diff --git a/src/components/molecules/Web3Feedback/index.tsx b/src/components/molecules/Web3Feedback/index.tsx index d928245af..5fd223867 100644 --- a/src/components/molecules/Web3Feedback/index.tsx +++ b/src/components/molecules/Web3Feedback/index.tsx @@ -2,7 +2,12 @@ import React from 'react' import Status from '../../atoms/Status' import Wallet from './Wallet' import styles from './index.module.css' -import { useWeb3, useOcean, InjectedProviderStatus, OceanConnectionStatus } from '@oceanprotocol/react' +import { + useWeb3, + useOcean, + InjectedProviderStatus, + OceanConnectionStatus +} from '@oceanprotocol/react' export declare type Web3Error = { status: 'error' | 'warning' | 'success' @@ -15,16 +20,15 @@ export default function Web3Feedback({ }: { isBalanceInsufficient?: boolean }) { - const { ethProviderStatus } = useWeb3() + 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 isOceanDisconnected = status === OceanConnectionStatus.NOT_CONNECTED const isOceanConnectionError = - status === OceanConnectionStatus.OCEAN_CONNECTION_ERROR + status === OceanConnectionStatus.OCEAN_CONNECTION_ERROR const hasSuccess = ethProviderStatus === InjectedProviderStatus.CONNECTED && status === OceanConnectionStatus.CONNECTED diff --git a/src/components/organisms/Consume.tsx b/src/components/organisms/Consume.tsx index 529803de2..955644843 100644 --- a/src/components/organisms/Consume.tsx +++ b/src/components/organisms/Consume.tsx @@ -12,20 +12,19 @@ import styles from './Consume.module.css' import Loader from '../atoms/Loader' import { useWeb3, useOcean, useConsume } from '@oceanprotocol/react' - - export default function Consume({ ddo }: { ddo: DDO | undefined }) { if (!ddo) return null const { web3 } = useWeb3() const { ocean, balanceInOcean } = useOcean() - const { consume,consumeStepText,isLoading } = useConsume() + const { consume, consumeStepText, isLoading } = useConsume() const { attributes } = findServiceByType(ddo, 'metadata') const { price } = attributes.main const file = (attributes as MetaDataDexFreight).main.files[0] const isFree = price === '0' const isBalanceSufficient = - isFree || compareAsBN(balanceInOcean, Web3.utils.fromWei(price), Comparisson.gte) + isFree || + compareAsBN(balanceInOcean, Web3.utils.fromWei(price), Comparisson.gte) const isDisabled = !ocean || !isBalanceSufficient || isLoading const PurchaseButton = () => { @@ -36,11 +35,7 @@ export default function Consume({ ddo }: { ddo: DDO | undefined }) { return isLoading ? ( ) : ( - ) diff --git a/src/components/templates/AssetDetails/RatingAction.tsx b/src/components/templates/AssetDetails/RatingAction.tsx index 143366c78..fce02d567 100644 --- a/src/components/templates/AssetDetails/RatingAction.tsx +++ b/src/components/templates/AssetDetails/RatingAction.tsx @@ -20,7 +20,7 @@ export default function RatingAction({ useEffect(() => { async function getOwnRating() { - if(!account) return + if (!account) return const currentRating = await getAssetRating(did, account) currentRating && setRating(currentRating.vote) } diff --git a/src/components/templates/AssetDetails/index.tsx b/src/components/templates/AssetDetails/index.tsx index 42b4d92a1..8678cd14e 100644 --- a/src/components/templates/AssetDetails/index.tsx +++ b/src/components/templates/AssetDetails/index.tsx @@ -42,7 +42,7 @@ const AssetDetailsPageMeta = ({ } = attributes.additionalInformation const { curation } = attributes - const {getCuration} = useMetadata() + const { getCuration } = useMetadata() const [rating, setRating] = useState(curation ? curation.rating : 0) const [numVotes, setNumVotes] = useState( curation ? curation.numVotes : 0 diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index 54e983d14..cdc21fecc 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -38,7 +38,8 @@ export default function dexfreightApp({ Component, pageProps }: AppProps) { process.env.SECRET_STORE_URI || 'https://secret-store.oceanprotocol.com', faucetUri: process.env.FAUCET_URI || 'https://faucet.oceanprotocol.com', ratingUri: - process.env.RATING_URI || 'https://rating.pacific.dexfreight.dev-ocean.com', + process.env.RATING_URI || + 'https://rating.pacific.dexfreight.dev-ocean.com', verbose: 3 } @@ -70,8 +71,7 @@ export default function dexfreightApp({ Component, pageProps }: AppProps) { /> - - + diff --git a/tests/unit/__mocks__/web3provider.ts b/tests/unit/__mocks__/web3provider.ts index 5ff2cfd58..8ba1e5858 100644 --- a/tests/unit/__mocks__/web3provider.ts +++ b/tests/unit/__mocks__/web3provider.ts @@ -1,9 +1,22 @@ import web3Mock from './web3' +import React from 'react' +import { Web3ProviderValue } from '@oceanprotocol/react' +export const context = React.createContext({ + web3: web3Mock, + ethProviderStatus: -1, + account: '0x0000', + balance: '', + chainId: 1, + web3Connect: {} as any, + enable: () => null as any +}) export default { web3: web3Mock, ethProviderStatus: -1, account: '0x0000', balance: '', - web3Connect: {} as any + chainId: 1, + web3Connect: {} as any, + enable: () => null as any } diff --git a/tests/unit/context/Web3Provider.test.tsx b/tests/unit/context/Web3Provider.test.tsx index 4407646b0..3c5119ad7 100644 --- a/tests/unit/context/Web3Provider.test.tsx +++ b/tests/unit/context/Web3Provider.test.tsx @@ -1,6 +1,6 @@ import React from 'react' import { render } from '@testing-library/react' -import Web3Provider from '../../../src/context/Web3Provider' +import { Web3Provider } from '@oceanprotocol/react' describe('Web3Provider', () => { it('renders without crashing', () => { diff --git a/tests/unit/pages/[did].test.tsx b/tests/unit/pages/[did].test.tsx index 1a208e8da..05205c1c3 100644 --- a/tests/unit/pages/[did].test.tsx +++ b/tests/unit/pages/[did].test.tsx @@ -3,9 +3,10 @@ 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 { context } from '../../../src/context/Web3Context' -import web3ProviderMock from '../__mocks__/web3provider' +import web3ProviderMock, { context } from '../__mocks__/web3provider' import { MetaDataDexFreight } from '../../../src/@types/MetaData' +import { OceanProvider, Config } from '@oceanprotocol/react' +import { config } from '../../../src/config/ocean' const { attributes } = findServiceByType(ddo, 'metadata') @@ -15,11 +16,13 @@ describe('AssetDetails', () => { it('renders without crashing', () => { const { container } = render( - + + + ) expect(container.firstChild).toBeInTheDocument() diff --git a/tests/unit/pages/publish.test.tsx b/tests/unit/pages/publish.test.tsx index 3610e714d..404896feb 100644 --- a/tests/unit/pages/publish.test.tsx +++ b/tests/unit/pages/publish.test.tsx @@ -1,14 +1,17 @@ import React from 'react' import { render } from '@testing-library/react' import Publish from '../../../src/pages/publish' -import web3ProviderMock from '../__mocks__/web3provider' -import { context } from '../../../src/context/Web3Context' +import web3ProviderMock, { context } from '../__mocks__/web3provider' +import { OceanProvider, Config } from '@oceanprotocol/react' +import { config } from '../../../src/config/ocean' describe('Home', () => { it('renders without crashing', () => { const { container } = render( - + + + ) expect(container.firstChild).toBeInTheDocument()