From 520d071776146ad238bf34f8744c1cc34f7e92d4 Mon Sep 17 00:00:00 2001 From: Luca Milanese Date: Thu, 16 Mar 2023 18:14:06 +0100 Subject: [PATCH 1/3] fix: tests --- src/@utils/aquarius/index.test.ts | 11 +++++++++-- src/@utils/aquarius/index.ts | 2 +- src/components/@shared/Page/index.test.tsx | 15 +++++++++++---- .../@shared/atoms/Button/index.test.tsx | 2 +- src/components/Header/SearchBar.tsx | 11 +++++------ 5 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/@utils/aquarius/index.test.ts b/src/@utils/aquarius/index.test.ts index 87eb33854..d0f2cbac3 100644 --- a/src/@utils/aquarius/index.test.ts +++ b/src/@utils/aquarius/index.test.ts @@ -9,10 +9,17 @@ const defaultBaseQueryReturn = { query: { bool: { filter: [ - { term: { _index: 'oceanv4' } }, { terms: { chainId: [1, 3] } }, + { term: { _index: 'oceanv4' } }, { term: { 'purgatory.state': false } }, - { bool: { must_not: [{ term: { 'nft.state': 5 } }] } } + { + bool: { + must_not: [ + { term: { 'nft.state': 5 } }, + { term: { 'price.type': 'pool' } } + ] + } + } ] } }, diff --git a/src/@utils/aquarius/index.ts b/src/@utils/aquarius/index.ts index 46a22fe26..d61b610ca 100644 --- a/src/@utils/aquarius/index.ts +++ b/src/@utils/aquarius/index.ts @@ -8,7 +8,7 @@ import { SortTermOptions } from '../../@types/aquarius/SearchQuery' import { transformAssetToAssetSelection } from '../assetConvertor' -import addressConfig from 'address.config' +import addressConfig from '../../../address.config' export interface UserSales { id: string diff --git a/src/components/@shared/Page/index.test.tsx b/src/components/@shared/Page/index.test.tsx index 528969953..07109f235 100644 --- a/src/components/@shared/Page/index.test.tsx +++ b/src/components/@shared/Page/index.test.tsx @@ -1,3 +1,4 @@ +import { SearchBarStatusProvider } from '@context/SearchBarStatus' import { render, screen } from '@testing-library/react' import React from 'react' import Page from './index' @@ -5,9 +6,11 @@ import Page from './index' describe('@shared/Page', () => { it('renders without crashing', () => { render( - - Hello Children - + + + Hello Children + + ) expect(screen.getByText('Hello Children')).toBeInTheDocument() expect(screen.getByText('Hello Title')).toBeInTheDocument() @@ -15,6 +18,10 @@ describe('@shared/Page', () => { }) it('renders without title', () => { - render(Hello Children) + render( + + Hello Children + + ) }) }) diff --git a/src/components/@shared/atoms/Button/index.test.tsx b/src/components/@shared/atoms/Button/index.test.tsx index 3e2369693..e262da48a 100644 --- a/src/components/@shared/atoms/Button/index.test.tsx +++ b/src/components/@shared/atoms/Button/index.test.tsx @@ -7,7 +7,7 @@ test('returns correct markup when href or to is passed', async () => { ) - let button = screen.getByText('Hello Button') + let button = screen.getByText(`Hello Button ${String.fromCharCode(8599)}`) expect(button).toHaveAttribute('href', 'https://oceanprotocol.com') expect(button).toContainHTML('(null) const { isSearchBarVisible, setSearchBarVisible, homeSearchBarFocus, setHomeSearchBarFocus } = useSearchBarStatus() - const isHome = window.location.pathname === '/' - - const searchBarRef = useRef(null) useEffect(() => { - if (text || owner) setValue((text || owner) as string) - }, [text, owner]) + if (parsed?.text || parsed?.owner) + setValue((parsed?.text || parsed?.owner) as string) + }, [parsed?.text, parsed?.owner]) useEffect(() => { setSearchBarVisible(false) From fe19867c493b4cfdc178146559c05c800386218c Mon Sep 17 00:00:00 2001 From: Luca Milanese Date: Fri, 17 Mar 2023 11:29:03 +0100 Subject: [PATCH 2/3] feat: add searchBarStatus context mock and fixture --- .jest/__fixtures__/searchBarStatus.ts | 6 ++++++ .jest/__mocks__/hooksMocks.ts | 5 +++++ 2 files changed, 11 insertions(+) create mode 100644 .jest/__fixtures__/searchBarStatus.ts diff --git a/.jest/__fixtures__/searchBarStatus.ts b/.jest/__fixtures__/searchBarStatus.ts new file mode 100644 index 000000000..f90e77288 --- /dev/null +++ b/.jest/__fixtures__/searchBarStatus.ts @@ -0,0 +1,6 @@ +export default { + isSearchBarVisible: false, + setSearchBarVisible: jest.fn(), + homeSearchBarFocus: false, + setHomeSearchBarFocus: jest.fn() +} diff --git a/.jest/__mocks__/hooksMocks.ts b/.jest/__mocks__/hooksMocks.ts index 6646a7335..e9d586b38 100644 --- a/.jest/__mocks__/hooksMocks.ts +++ b/.jest/__mocks__/hooksMocks.ts @@ -1,5 +1,6 @@ import marketMetadata from '../__fixtures__/marketMetadata' import userPreferences from '../__fixtures__/userPreferences' +import searchBarStatus from '../__fixtures__/searchBarStatus' import web3 from '../__fixtures__/web3' import { asset } from '../__fixtures__/datasetWithAccessDetails' @@ -18,3 +19,7 @@ jest.mock('../../src/@context/Web3', () => ({ jest.mock('../../../@context/Asset', () => ({ useAsset: () => ({ asset }) })) + +jest.mock('../../@context/SearchBarStatus', () => ({ + useSearchBarStatus: () => searchBarStatus +})) From 3635b71cb6a5a91250bff480e0d79ecb985b69ef Mon Sep 17 00:00:00 2001 From: Luca Milanese Date: Fri, 17 Mar 2023 11:29:18 +0100 Subject: [PATCH 3/3] feat: update Page test --- src/components/@shared/Page/index.test.tsx | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/components/@shared/Page/index.test.tsx b/src/components/@shared/Page/index.test.tsx index 07109f235..528969953 100644 --- a/src/components/@shared/Page/index.test.tsx +++ b/src/components/@shared/Page/index.test.tsx @@ -1,4 +1,3 @@ -import { SearchBarStatusProvider } from '@context/SearchBarStatus' import { render, screen } from '@testing-library/react' import React from 'react' import Page from './index' @@ -6,11 +5,9 @@ import Page from './index' describe('@shared/Page', () => { it('renders without crashing', () => { render( - - - Hello Children - - + + Hello Children + ) expect(screen.getByText('Hello Children')).toBeInTheDocument() expect(screen.getByText('Hello Title')).toBeInTheDocument() @@ -18,10 +15,6 @@ describe('@shared/Page', () => { }) it('renders without title', () => { - render( - - Hello Children - - ) + render(Hello Children) }) })