refactor(search): display entity title for result items if defined
Signed-off-by: Phil Kuang <pkuang@factset.com>
This commit is contained in:
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user