Merge pull request #7640 from kuangp/refactor/searchResultTitles

refactor(search): display entity title for result items if defined
This commit is contained in:
Patrik Oldsberg
2021-10-21 00:21:34 +02:00
committed by GitHub
8 changed files with 66 additions and 2 deletions
@@ -33,6 +33,17 @@ const validResult = {
lifecycle: 'production',
};
const validResultWithTitle = {
location: 'https://backstage.io/docs',
title: 'Documentation',
text: 'Backstage is an open-source developer portal that puts the developer experience first.',
kind: 'library',
namespace: '',
name: 'Backstage',
entityTitle: 'Backstage App',
lifecycle: 'production',
};
describe('DocsResultListItem test', () => {
it('should render search doc passed in', async () => {
const { findByText } = render(<DocsResultListItem result={validResult} />);
@@ -59,4 +70,14 @@ describe('DocsResultListItem test', () => {
),
).toBeInTheDocument();
});
it('should use entity title if defined', async () => {
const { findByText } = render(
<DocsResultListItem result={validResultWithTitle} />,
);
expect(
await findByText('Documentation | Backstage App docs'),
).toBeInTheDocument();
});
});
@@ -47,7 +47,11 @@ export const DocsResultListItem = ({
<ListItemText
className={classes.itemText}
primaryTypographyProps={{ variant: 'h6' }}
primary={title ? title : `${result.title} | ${result.name} docs`}
primary={
title
? title
: `${result.title} | ${result.entityTitle ?? result.name} docs`
}
secondary={
<TextTruncate
line={lineClamp}