From f21a4c8780ab0d921c20d6e0980fc040a9363941 Mon Sep 17 00:00:00 2001 From: mihaisc <mihai.scarlat@smartcontrol.ro> Date: Wed, 13 May 2020 21:07:57 +0300 Subject: [PATCH] fix --- tests/unit/__mocks__/web3provider.tsx | 30 ++++++++++----------------- tests/unit/pages/[did].test.tsx | 21 +++++++------------ tests/unit/pages/publish.test.tsx | 13 ++++-------- 3 files changed, 23 insertions(+), 41 deletions(-) diff --git a/tests/unit/__mocks__/web3provider.tsx b/tests/unit/__mocks__/web3provider.tsx index 475e035fb..8ba1e5858 100644 --- a/tests/unit/__mocks__/web3provider.tsx +++ b/tests/unit/__mocks__/web3provider.tsx @@ -1,8 +1,17 @@ import web3Mock from './web3' -import React, { useContext, createContext } from 'react' +import React from 'react' import { Web3ProviderValue } from '@oceanprotocol/react' -const valueMock = { +export const context = React.createContext<Web3ProviderValue | undefined>({ + web3: web3Mock, + ethProviderStatus: -1, + account: '0x0000', + balance: '', + chainId: 1, + web3Connect: {} as any, + enable: () => null as any +}) +export default { web3: web3Mock, ethProviderStatus: -1, account: '0x0000', @@ -11,20 +20,3 @@ const valueMock = { web3Connect: {} as any, enable: () => null as any } - -const Web3ContextMock = React.createContext<Web3ProviderValue>(valueMock) - -// TODO: this will have to be updated to web3modal -function Web3ProviderMock({ children }: { children: any }): any { - return ( - <Web3ContextMock.Provider value={valueMock}> - {children} - </Web3ContextMock.Provider> - ) -} - -// Helper hook to access the provider values -const useWeb3 = (): Web3ProviderValue => useContext(Web3ContextMock) - -export { Web3ProviderMock, useWeb3 } -export default Web3ProviderMock diff --git a/tests/unit/pages/[did].test.tsx b/tests/unit/pages/[did].test.tsx index b27801388..13670cfa5 100644 --- a/tests/unit/pages/[did].test.tsx +++ b/tests/unit/pages/[did].test.tsx @@ -3,11 +3,8 @@ 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 { MetaDataDexFreight } from '../../../src/@types/MetaData' -import { OceanProvider, Config } from '@oceanprotocol/react' -import { config } from '../../../src/config/ocean' -import { Web3ProviderMock } from '../__mocks__/web3provider' const { attributes } = findServiceByType(ddo, 'metadata') @@ -16,15 +13,13 @@ jest.mock('web3') describe('AssetDetails', () => { it('renders without crashing', () => { const { container } = render( - <Web3ProviderMock> - <OceanProvider config={config as Config}> - <AssetDetails - ddo={JSON.stringify(ddo) as any} - attributes={attributes as MetaDataDexFreight} - title="Hello" - /> - </OceanProvider> - </Web3ProviderMock> + <context.Provider value={web3ProviderMock}> + <AssetDetails + ddo={JSON.stringify(ddo) as any} + attributes={attributes as MetaDataDexFreight} + title="Hello" + /> + </context.Provider> ) expect(container.firstChild).toBeInTheDocument() }) diff --git a/tests/unit/pages/publish.test.tsx b/tests/unit/pages/publish.test.tsx index c6e7bfa4a..c986ee7a6 100644 --- a/tests/unit/pages/publish.test.tsx +++ b/tests/unit/pages/publish.test.tsx @@ -1,19 +1,14 @@ import React from 'react' import { render } from '@testing-library/react' import Publish from '../../../src/pages/publish' - -import { OceanProvider, Config } from '@oceanprotocol/react' -import { config } from '../../../src/config/ocean' -import { Web3ProviderMock } from '../__mocks__/web3provider' +import web3ProviderMock, { context } from '../__mocks__/web3provider' describe('Home', () => { it('renders without crashing', () => { const { container } = render( - <Web3ProviderMock> - <OceanProvider config={config as Config}> - <Publish /> - </OceanProvider> - </Web3ProviderMock> + <context.Provider value={web3ProviderMock}> + <Publish /> + </context.Provider> ) expect(container.firstChild).toBeInTheDocument() })