diff --git a/plugins/search/src/components/DefaultResultListItem/DefaultResultListItem.test.jsx b/plugins/search/src/components/DefaultResultListItem/DefaultResultListItem.test.jsx new file mode 100644 index 0000000000..60ad453597 --- /dev/null +++ b/plugins/search/src/components/DefaultResultListItem/DefaultResultListItem.test.jsx @@ -0,0 +1,41 @@ +/* + * Copyright 2021 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import React from 'react'; +import { screen } from '@testing-library/react'; +import { renderInTestApp } from '@backstage/test-utils'; + +import { DefaultResultListItem } from './DefaultResultListItem'; + +describe('DefaultResultListItem', () => { + const result = { + title: 'title', + text: 'text', + location: '/location', + }; + + it('Links to result.location', async () => { + await renderInTestApp(); + expect(screen.getByRole('link')).toHaveAttribute('href', result.location); + }); + + it('Includes primary/secondary text (title / text)', async () => { + await renderInTestApp(); + expect(screen.getByRole('listitem')).toHaveTextContent( + result.title + result.text, + ); + }); +}); diff --git a/plugins/search/src/components/DefaultResultListItem/DefaultResultListItem.tsx b/plugins/search/src/components/DefaultResultListItem/DefaultResultListItem.tsx index 8571caa49d..5f2d4bf87f 100644 --- a/plugins/search/src/components/DefaultResultListItem/DefaultResultListItem.tsx +++ b/plugins/search/src/components/DefaultResultListItem/DefaultResultListItem.tsx @@ -16,9 +16,14 @@ import React from 'react'; import { Link } from '@backstage/core'; +import { IndexableDocument } from '@backstage/search-common'; import { ListItem, ListItemText, Divider } from '@material-ui/core'; -export const DefaultResultListItem = ({ result }: any) => { +type Props = { + result: IndexableDocument; +}; + +export const DefaultResultListItem = ({ result }: Props) => { return ( diff --git a/plugins/search/src/components/SearchResultNext/SearchResultNext.tsx b/plugins/search/src/components/SearchResultNext/SearchResultNext.tsx index c4e3edaa4c..84d3759ad3 100644 --- a/plugins/search/src/components/SearchResultNext/SearchResultNext.tsx +++ b/plugins/search/src/components/SearchResultNext/SearchResultNext.tsx @@ -13,22 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + +import React from 'react'; import { EmptyState, Progress } from '@backstage/core'; import { SearchResult } from '@backstage/search-common'; import { Alert } from '@material-ui/lab'; -import React from 'react'; import { useSearch } from '../SearchContext'; -type ChildrenArguments = { - results: SearchResult[]; +type Props = { + children: (results: { results: SearchResult[] }) => JSX.Element; }; -export const SearchResultNext = ({ - children, -}: { - children: (results: ChildrenArguments) => JSX.Element; -}) => { +export const SearchResultNext = ({ children }: Props) => { const { result: { loading, error, value }, } = useSearch();