diff --git a/client/__mocks__/market-mock.ts b/client/__mocks__/market-mock.ts new file mode 100644 index 0000000..2322f9a --- /dev/null +++ b/client/__mocks__/market-mock.ts @@ -0,0 +1,8 @@ +const marketMock = { + totalAssets: 1000, + categories: ['category'], + network: 'Pacific', + networkMatch: true +} + +export { marketMock } diff --git a/client/src/components/atoms/Account.test.tsx b/client/src/components/atoms/Account.test.tsx index ad44b30..9e81653 100644 --- a/client/src/components/atoms/Account.test.tsx +++ b/client/src/components/atoms/Account.test.tsx @@ -2,15 +2,27 @@ import React from 'react' import { render } from '@testing-library/react' import { toDataUrl } from 'ethereum-blockies' import Account from './Account' +import { User } from '../../context' +import { userMockConnected } from '../../../__mocks__/user-mock' describe('Account', () => { it('renders without crashing', () => { - const { container } = render() + const { container } = render( + + + + ) expect(container.firstChild).toBeInTheDocument() }) it('outputs empty state without account', () => { - const { container } = render() + const { container } = render( + + + + ) expect(container.firstChild).toHaveTextContent('No account selected') }) @@ -18,7 +30,11 @@ describe('Account', () => { const account = '0xxxxxxxxxxxxxxx' const blockies = toDataUrl(account) - const { container } = render() + const { container } = render( + + + + ) expect(container.querySelector('.blockies')).toBeInTheDocument() expect(container.querySelector('.blockies')).toHaveAttribute( 'src', diff --git a/client/src/components/molecules/AccountStatus/Popover.test.tsx b/client/src/components/molecules/AccountStatus/Popover.test.tsx index 68925a0..5edea8f 100644 --- a/client/src/components/molecules/AccountStatus/Popover.test.tsx +++ b/client/src/components/molecules/AccountStatus/Popover.test.tsx @@ -2,7 +2,8 @@ import React from 'react' import { render } from '@testing-library/react' import Popover from './Popover' import { userMock, userMockConnected } from '../../../../__mocks__/user-mock' -import { User } from '../../../context' +import { marketMock } from '../../../../__mocks__/market-mock' +import { User, Market } from '../../../context' describe('Popover', () => { it('renders without crashing', () => { @@ -25,12 +26,14 @@ describe('Popover', () => { it('renders correct network', () => { const { container } = render( - - null} style={{}} /> + + + null} style={{}} /> + ) expect(container.firstChild).toBeInTheDocument() - expect(container.firstChild).toHaveTextContent('Connected to Nile') + expect(container.firstChild).toHaveTextContent('Connected to Pacific') }) it('renders with wrong network', () => { diff --git a/client/src/components/organisms/Web3message.test.tsx b/client/src/components/organisms/Web3message.test.tsx index e530c65..6e7bd43 100644 --- a/client/src/components/organisms/Web3message.test.tsx +++ b/client/src/components/organisms/Web3message.test.tsx @@ -1,14 +1,17 @@ import React from 'react' import { render } from '@testing-library/react' import Web3message from './Web3message' -import { User } from '../../context' +import { User, Market } from '../../context' import { userMock, userMockConnected } from '../../../__mocks__/user-mock' +import { marketMock } from '../../../__mocks__/market-mock' describe('Web3message', () => { it('renders with burner wallet message', () => { const { container } = render( - + + + ) expect(container.firstChild).toHaveTextContent('Burner Wallet') @@ -16,28 +19,40 @@ describe('Web3message', () => { it('renders with wrongNetwork message', () => { const { container } = render( - - + + + + ) expect(container.firstChild).toHaveTextContent( - 'Not connected to Pacific network' + 'Not connected to Nile network' ) }) it('renders with noAccount message', () => { const { container } = render( - + + + ) - expect(container.firstChild).toHaveTextContent('No wallet selected.') + expect(container.firstChild).toHaveTextContent('No account selected') }) it('renders with hasAccount message', () => { const { container } = render( - + + + ) expect(container.firstChild).toHaveTextContent('0xxxxxx') diff --git a/client/src/components/templates/Asset/AssetFilesDetails.test.tsx b/client/src/components/templates/Asset/AssetFilesDetails.test.tsx index 8f109ba..5420c13 100644 --- a/client/src/components/templates/Asset/AssetFilesDetails.test.tsx +++ b/client/src/components/templates/Asset/AssetFilesDetails.test.tsx @@ -28,16 +28,4 @@ describe('AssetFilesDetails', () => { ) expect(container.firstChild).toHaveTextContent('No files attached.') }) - - it('hides Web3message when all connected', () => { - const { container } = render( - - - - ) - expect(container.querySelector('.status')).not.toBeInTheDocument() - }) }) diff --git a/client/src/routes/About.test.tsx b/client/src/routes/About.test.tsx index fc2722d..f5fec51 100644 --- a/client/src/routes/About.test.tsx +++ b/client/src/routes/About.test.tsx @@ -1,13 +1,21 @@ import React from 'react' import { render } from '@testing-library/react' import { MemoryRouter } from 'react-router' +import { createMemoryHistory, createLocation } from 'history' import About from './About' +const history = createMemoryHistory() +const location = createLocation('/about') + describe('About', () => { it('renders without crashing', () => { const { container } = render( - + ) expect(container.firstChild).toBeInTheDocument() diff --git a/client/src/routes/Channels.test.tsx b/client/src/routes/Channels.test.tsx index 9705c72..c5f1e7e 100644 --- a/client/src/routes/Channels.test.tsx +++ b/client/src/routes/Channels.test.tsx @@ -1,16 +1,24 @@ import React from 'react' import { MemoryRouter } from 'react-router' +import { createMemoryHistory, createLocation } from 'history' import { render } from '@testing-library/react' import Channels from './Channels' import { User } from '../context' import { userMockConnected } from '../../__mocks__/user-mock' +const history = createMemoryHistory() +const location = createLocation('/channels') + describe('Channels', () => { it('renders without crashing', () => { const { container } = render( - + ) diff --git a/client/src/routes/Faucet.test.tsx b/client/src/routes/Faucet.test.tsx index 4d219ed..50cb619 100644 --- a/client/src/routes/Faucet.test.tsx +++ b/client/src/routes/Faucet.test.tsx @@ -1,15 +1,23 @@ import React from 'react' import { render, fireEvent } from '@testing-library/react' import { MemoryRouter } from 'react-router' +import { createMemoryHistory, createLocation } from 'history' import Faucet from './Faucet' import { User } from '../context' import { userMockConnected } from '../../__mocks__/user-mock' +const history = createMemoryHistory() +const location = createLocation('/faucet') + const setup = () => { const utils = render( - + ) diff --git a/client/src/routes/History.test.tsx b/client/src/routes/History.test.tsx index b02542f..56200b5 100644 --- a/client/src/routes/History.test.tsx +++ b/client/src/routes/History.test.tsx @@ -1,13 +1,21 @@ import React from 'react' import { render } from '@testing-library/react' import { MemoryRouter } from 'react-router' +import { createMemoryHistory, createLocation } from 'history' import History from './History' +const history = createMemoryHistory() +const location = createLocation('/history') + describe('History', () => { it('renders without crashing', () => { const { container } = render( - + ) expect(container.firstChild).toBeInTheDocument() diff --git a/client/src/routes/Home/index.test.tsx b/client/src/routes/Home/index.test.tsx index e083ad8..1e7aaf1 100644 --- a/client/src/routes/Home/index.test.tsx +++ b/client/src/routes/Home/index.test.tsx @@ -1,19 +1,24 @@ import React from 'react' import { Router } from 'react-router' -import { createBrowserHistory } from 'history' +import { createMemoryHistory, createLocation } from 'history' import { render } from '@testing-library/react' import Home from '.' import { userMock } from '../../../__mocks__/user-mock' import { User } from '../../context' -const history = createBrowserHistory() +const history = createMemoryHistory() +const location = createLocation('/') describe('Home', () => { it('renders without crashing', () => { const { container } = render( - + ) diff --git a/client/src/routes/NotFound.test.tsx b/client/src/routes/NotFound.test.tsx index e0e33a5..a57e444 100644 --- a/client/src/routes/NotFound.test.tsx +++ b/client/src/routes/NotFound.test.tsx @@ -1,13 +1,21 @@ import React from 'react' import { render } from '@testing-library/react' +import { createMemoryHistory, createLocation } from 'history' import NotFound from './NotFound' import { MemoryRouter } from 'react-router' +const history = createMemoryHistory() +const location = createLocation('/whatever') + describe('NotFound', () => { it('renders without crashing', () => { const { container } = render( - + ) expect(container.firstChild).toBeInTheDocument() diff --git a/client/src/routes/Publish/index.test.tsx b/client/src/routes/Publish/index.test.tsx index 0c6462f..e1d8f7b 100644 --- a/client/src/routes/Publish/index.test.tsx +++ b/client/src/routes/Publish/index.test.tsx @@ -1,16 +1,24 @@ import React from 'react' import { MemoryRouter } from 'react-router' import { render, fireEvent } from '@testing-library/react' +import { createMemoryHistory, createLocation } from 'history' import Publish from '.' import { User } from '../../context' import { userMockConnected } from '../../../__mocks__/user-mock' +const history = createMemoryHistory() +const location = createLocation('/publish') + describe('Publish', () => { it('renders without crashing', () => { const { container, getByText } = render( - + ) @@ -22,7 +30,16 @@ describe('Publish', () => { const { getByText, getByLabelText, getByTestId } = render( - + ) diff --git a/client/src/routes/Search.test.tsx b/client/src/routes/Search.test.tsx index dd96676..0541ac7 100644 --- a/client/src/routes/Search.test.tsx +++ b/client/src/routes/Search.test.tsx @@ -6,10 +6,10 @@ import { createMemoryHistory } from 'history' import { BrowserRouter as Router } from 'react-router-dom' import { userMockConnected } from '../../__mocks__/user-mock' +const history = createMemoryHistory() + describe('Search', () => { it('renders without crashing', () => { - const history = createMemoryHistory() - const { container } = render( @@ -21,6 +21,7 @@ describe('Search', () => { hash: '' }} history={history} + match={{ params: '', path: '', url: '', isExact: true }} /> diff --git a/client/src/routes/Styleguide.test.tsx b/client/src/routes/Styleguide.test.tsx index 66ee70d..df1667e 100644 --- a/client/src/routes/Styleguide.test.tsx +++ b/client/src/routes/Styleguide.test.tsx @@ -2,12 +2,20 @@ import React from 'react' import { render } from '@testing-library/react' import Styleguide from './Styleguide' import { MemoryRouter } from 'react-router' +import { createMemoryHistory, createLocation } from 'history' + +const history = createMemoryHistory() +const location = createLocation('/styleguide') describe('Styleguide', () => { it('renders without crashing', () => { const { container } = render( - + ) expect(container.firstChild).toBeInTheDocument()