mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
* Creating related assets component * Ensuring that related assets doesn't show the same asset * Adjusting query to show assets from the same publisher but not the exact same asset * modifying search term * Removing logs and unused import * Removing log * Updating query * Fixes * updating query * Updating query to include both related tag assets anbd related owner assests when <3. SHowing results as a list of links * creating minimal asset teaser * removing duplicate filters * Changing minimal to noDescription * Removing unneccessary use of noDescription prop * Adding minimal prop back into Publisher * Removing props from RelatedAssets component * Getting data from asset context * refactor * space-saving asset teaser changes * remove price from output * increase to 4 * refactor for better loading experience * css cleanup * filter out duplicates when merging results * basic render test * try/catch, secure against null query responses * different test tactic Co-authored-by: Matthias Kretschmann <m@kretschmann.io>
68 lines
2.0 KiB
TypeScript
68 lines
2.0 KiB
TypeScript
import { render, screen } from '@testing-library/react'
|
|
import React from 'react'
|
|
import RelatedAssets from '.'
|
|
import { assets } from '../../../../.jest/__fixtures__/assetsWithAccessDetails'
|
|
import { queryMetadata } from '../../../@utils/aquarius'
|
|
// import * as userPreferencesMock from '../../../@context/UserPreferences'
|
|
|
|
jest.mock('../../../@utils/aquarius')
|
|
// jest.mock('../../src/@context/UserPreferences', () => ({
|
|
// useUserPreferences: () => ({ chainIds: [1, 2, 3] })
|
|
// }))
|
|
|
|
const queryMetadataBaseReturn: PagedAssets = {
|
|
results: assets,
|
|
page: 1,
|
|
totalPages: 1,
|
|
totalResults: 10,
|
|
aggregations: {}
|
|
}
|
|
|
|
describe('Asset/RelatedAssets', () => {
|
|
beforeAll(() => jest.resetAllMocks())
|
|
|
|
it('renders with more than 4 queryMetadata() results', async () => {
|
|
;(queryMetadata as jest.Mock).mockReturnValue(queryMetadataBaseReturn)
|
|
render(<RelatedAssets />)
|
|
await screen.findByText(assets[0].metadata.name)
|
|
})
|
|
|
|
it('renders with 4 queryMetadata() results', async () => {
|
|
;(queryMetadata as jest.Mock).mockReturnValue({
|
|
...queryMetadataBaseReturn,
|
|
results: assets.slice(0, 4),
|
|
totalResults: 4
|
|
})
|
|
render(<RelatedAssets />)
|
|
await screen.findByText(assets[0].metadata.name)
|
|
})
|
|
|
|
// TODO: figure out how to overwrite already mocked module
|
|
// it('does nothing when no chainIds selected', async () => {
|
|
// jest
|
|
// .spyOn(userPreferencesMock, 'useUserPreferences')
|
|
// .mockReturnValue({ chainIds: [] } as any)
|
|
|
|
// render(<RelatedAssets />)
|
|
// await screen.findByText('No results found')
|
|
// })
|
|
|
|
it('catches queryMetadata errors', async () => {
|
|
;(queryMetadata as jest.Mock).mockImplementation(() => {
|
|
throw new Error('Hello error')
|
|
})
|
|
|
|
// prevent console error from showing up in test log
|
|
const originalError = console.error
|
|
console.error = jest.fn()
|
|
|
|
try {
|
|
render(<RelatedAssets />)
|
|
} catch (error) {
|
|
expect(error).toEqual({ message: 'Hello error' })
|
|
}
|
|
|
|
console.error = originalError
|
|
})
|
|
})
|