Dashboard: Don't show SectionHeader unless section has a title (#39336)

* Dashboard: Don't show SectionHeader unless section has a title

* Dashboard: Add unit test to prevent regression
pull/39354/head
Ashley Harrison 4 years ago committed by GitHub
parent d116b2d71b
commit 06571e0af6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      public/app/features/search/components/SearchResults.test.tsx
  2. 4
      public/app/features/search/components/SearchResults.tsx

@ -53,4 +53,13 @@ describe('SearchResults', () => {
expect(mockOnToggleSection).toHaveBeenCalledTimes(1);
expect(mockOnToggleSection).toHaveBeenCalledWith(generalFolder);
});
it('should not throw an error if the search results have an empty title', () => {
const mockOnToggleSection = jest.fn();
const searchResultsEmptyTitle = searchResults.slice();
searchResultsEmptyTitle[0].title = '';
expect(() => {
setup({ results: searchResultsEmptyTitle, onToggleSection: mockOnToggleSection });
}).not.toThrowError();
});
});

@ -33,7 +33,9 @@ export const SearchResults: FC<Props> = memo(
{results.map((section) => {
return (
<div aria-label={sectionLabel} className={styles.section} key={section.id || section.title}>
<SectionHeader onSectionClick={onToggleSection} {...{ onToggleChecked, editable, section }} />
{section.title && (
<SectionHeader onSectionClick={onToggleSection} {...{ onToggleChecked, editable, section }} />
)}
{section.expanded && (
<div aria-label={itemsLabel} className={styles.sectionItems}>
{section.items.map((item) => (

Loading…
Cancel
Save