test(plugins/search): complete DefaultResultListItem coverage

Signed-off-by: Camila Belo <camilaibs@gmail.com>
Signed-off-by: Eric Peterson <ericpeterson@spotify.com>
This commit is contained in:
Camila Belo
2021-05-26 21:56:27 +02:00
committed by Eric Peterson
parent c568e721f4
commit 49df6413f3
3 changed files with 52 additions and 9 deletions
@@ -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(<DefaultResultListItem result={result} />);
expect(screen.getByRole('link')).toHaveAttribute('href', result.location);
});
it('Includes primary/secondary text (title / text)', async () => {
await renderInTestApp(<DefaultResultListItem result={result} />);
expect(screen.getByRole('listitem')).toHaveTextContent(
result.title + result.text,
);
});
});
@@ -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 (
<Link to={result.location}>
<ListItem alignItems="flex-start">
@@ -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();