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
This commit is contained in:
Ashley Harrison 2021-09-17 11:59:15 +01:00 committed by GitHub
parent d116b2d71b
commit 06571e0af6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -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();
});
});

View File

@ -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) => (