From 645f3c0e13e763b2812283f3caa8ac495ab7cc58 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Tue, 10 Dec 2019 00:58:06 +0100 Subject: [PATCH] DDO updates --- client/src/routes/Search/Results.test.tsx | 28 +++++++++++++++++++++++ client/src/routes/Search/Results.tsx | 3 ++- client/src/routes/Search/Sidebar.tsx | 13 +++++++---- client/src/routes/Search/index.tsx | 2 +- 4 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 client/src/routes/Search/Results.test.tsx diff --git a/client/src/routes/Search/Results.test.tsx b/client/src/routes/Search/Results.test.tsx new file mode 100644 index 0000000..861083e --- /dev/null +++ b/client/src/routes/Search/Results.test.tsx @@ -0,0 +1,28 @@ +import React from 'react' +import { render } from '@testing-library/react' +import Results from './Results' +import { User } from '../../context' +import { userMockConnected } from '../../../__mocks__/user-mock' +import { + results, + totalResults, + totalPages, + currentPage +} from '../../../__fixtures__/search.json' + +describe('Results', () => { + it('renders without crashing', () => { + const { container } = render( + + + + ) + expect(container.firstChild).toBeInTheDocument() + }) +}) diff --git a/client/src/routes/Search/Results.tsx b/client/src/routes/Search/Results.tsx index 65f5bef..fff8347 100644 --- a/client/src/routes/Search/Results.tsx +++ b/client/src/routes/Search/Results.tsx @@ -1,6 +1,7 @@ import React from 'react' import { Link } from 'react-router-dom' import shortid from 'shortid' +import { DDO } from '@oceanprotocol/squid' import AssetTeaser from '../../components/molecules/AssetTeaser' import Pagination from '../../components/molecules/Pagination' import styles from './Results.module.scss' @@ -12,7 +13,7 @@ export default function Results({ currentPage, handlePageClick }: { - results: any[] + results: DDO[] totalResults: number totalPages: number currentPage: number diff --git a/client/src/routes/Search/Sidebar.tsx b/client/src/routes/Search/Sidebar.tsx index e4c38e1..a93394a 100644 --- a/client/src/routes/Search/Sidebar.tsx +++ b/client/src/routes/Search/Sidebar.tsx @@ -25,10 +25,15 @@ function getFilterMetadata(results: any[]) { results.map((asset: DDO) => { if (!asset.findServiceByType) return null - const { metadata } = asset.findServiceByType('Metadata') - const { categories, license } = metadata.base - categories && filterCategories.push(categories[0]) - license && filterLicenses.push(license) + const { attributes } = asset.findServiceByType('metadata') + const { main, additionalInformation } = attributes + main.license && filterLicenses.push(main.license) + + if (additionalInformation) { + const { categories } = additionalInformation + categories && filterCategories.push(categories[0]) + } + return null }) diff --git a/client/src/routes/Search/index.tsx b/client/src/routes/Search/index.tsx index fd1ca1b..53cf95d 100644 --- a/client/src/routes/Search/index.tsx +++ b/client/src/routes/Search/index.tsx @@ -19,7 +19,7 @@ interface SearchProps { } interface SearchState { - results: any[] + results: DDO[] totalResults: number offset: number totalPages: number