diff --git a/frontend/src/__tests__/components/SearchResults.test.tsx b/frontend/src/__tests__/components/SearchResults.test.tsx index 463e7f6a..d6c65431 100644 --- a/frontend/src/__tests__/components/SearchResults.test.tsx +++ b/frontend/src/__tests__/components/SearchResults.test.tsx @@ -749,6 +749,55 @@ describe('SearchResults Component', () => { screen.getByText('Tufts University, Cambridge Grid') ).toBeInTheDocument(); }); + + it('displays resource types and themes as filter chips instead of subjects', () => { + const resultWithChips: GeoDocument = { + ...mockFixtureData[0], + attributes: { + ogm: { + ...mockFixtureData[0].attributes.ogm, + gbl_resourceType_sm: ['Topographic maps', 'Digital maps'], + dcat_theme_sm: ['Elevation'], + dct_subject_sm: ['A long, unnormalized subject heading'], + dct_subjects_sm: ['Another subject heading'], + }, + }, + }; + + render( + + + + ); + + expect( + screen.getByRole('link', { name: 'Topographic maps' }) + ).toHaveAttribute( + 'href', + '/search?include_filters%5Bgbl_resourceType_sm%5D%5B%5D=Topographic+maps' + ); + expect( + screen.getByRole('link', { name: 'Digital maps' }) + ).toHaveAttribute( + 'href', + '/search?include_filters%5Bgbl_resourceType_sm%5D%5B%5D=Digital+maps' + ); + expect(screen.getByRole('link', { name: 'Elevation' })).toHaveAttribute( + 'href', + '/search?include_filters%5Bdcat_theme_sm%5D%5B%5D=Elevation' + ); + expect( + screen.queryByText('A long, unnormalized subject heading') + ).not.toBeInTheDocument(); + expect( + screen.queryByText('Another subject heading') + ).not.toBeInTheDocument(); + }); }); describe('Links and Navigation', () => { diff --git a/frontend/src/components/SearchResults.tsx b/frontend/src/components/SearchResults.tsx index 25b5b0f5..ba46fa6f 100644 --- a/frontend/src/components/SearchResults.tsx +++ b/frontend/src/components/SearchResults.tsx @@ -278,23 +278,17 @@ export function SearchResults({ ) : null} - {/* Subject and Theme tags */} + {/* Resource Type and Theme tags */} {!isCompact && ( <>
{(() => { - // Get subjects from dct_subjects_sm or dct_subject_sm - const subjects = - (ogm?.dct_subjects_sm && - Array.isArray(ogm.dct_subjects_sm) && - ogm.dct_subjects_sm.length > 0 - ? ogm.dct_subjects_sm - : null) || - (ogm?.dct_subject_sm && - Array.isArray(ogm.dct_subject_sm) && - ogm.dct_subject_sm.length > 0 - ? ogm.dct_subject_sm - : null); + const resourceTypes = + ogm?.gbl_resourceType_sm && + Array.isArray(ogm.gbl_resourceType_sm) && + ogm.gbl_resourceType_sm.length > 0 + ? ogm.gbl_resourceType_sm + : null; // Get themes from dcat_theme_sm const themes = @@ -317,25 +311,20 @@ export function SearchResults({ return `/search?${params.toString()}`; }; - // Determine which field name to use for subjects - const subjectField = ogm?.dct_subjects_sm - ? 'dct_subjects_sm' - : 'dct_subject_sm'; - - return (subjects && subjects.length > 0) || + return (resourceTypes && resourceTypes.length > 0) || (themes && themes.length > 0) ? (
- {subjects?.map((subject, index) => { - const subjectValue = - typeof subject === 'string' - ? subject - : String(subject); + {resourceTypes?.map((resourceType, index) => { + const resourceTypeValue = + typeof resourceType === 'string' + ? resourceType + : String(resourceType); return ( { @@ -343,7 +332,7 @@ export function SearchResults({ e.stopPropagation(); }} > - {subjectValue} + {resourceTypeValue} ); })}