@@ -268,7 +268,7 @@ describe('Basic Functionality', () => {
268268 } ) ;
269269
270270 describe ( 'Search Filters' , ( ) => {
271- it ( 'should add primary_disease filters to search combination for highlighting ' , ( ) => {
271+ it ( 'should NOT highlight primary_disease filter values in results ' , ( ) => {
272272 const mockResult = createMockResult ( {
273273 primary_disease : 'Breast Cancer' ,
274274 } ) ;
@@ -285,13 +285,15 @@ describe('Basic Functionality', () => {
285285
286286 renderWithRouter ( < SearchResult { ...props } /> ) ;
287287
288- // "Cancer" should be highlighted even though there 's no search_text
289- // because it's in the filters
288+ // "Cancer" should NOT be highlighted because it 's only in filters, not in search_text
289+ // Filters are for filtering results, not for highlighting
290290 const matchedContent = screen . getByTestId ( 'primary-disease' ) ;
291- expect ( matchedContent . innerHTML ) . toContain ( '<b>Cancer</b>' ) ;
291+ expect ( matchedContent . innerHTML ) . not . toContain ( '<b>Cancer</b>' ) ;
292+ // But the plain text should still be there
293+ expect ( matchedContent . textContent ) . toContain ( 'Cancer' ) ;
292294 } ) ;
293295
294- it ( 'should add dataset_source_repo filters to search combination for highlighting ' , ( ) => {
296+ it ( 'should NOT highlight dataset_source_repo filter values in results ' , ( ) => {
295297 const mockResult = createMockResult ( {
296298 dataset_source_repo : 'National Cancer Institute' ,
297299 } ) ;
@@ -308,9 +310,11 @@ describe('Basic Functionality', () => {
308310
309311 renderWithRouter ( < SearchResult { ...props } /> ) ;
310312
311- // "Cancer" should be highlighted even though there 's no search_text
313+ // "Cancer" should NOT be highlighted because it 's only in filters, not in search_text
312314 const matchedContent = screen . getByTestId ( 'dataset-source-repo' ) ;
313- expect ( matchedContent . innerHTML ) . toContain ( '<b>Cancer</b>' ) ;
315+ expect ( matchedContent . innerHTML ) . not . toContain ( '<b>Cancer</b>' ) ;
316+ // But the plain text should still be there
317+ expect ( matchedContent . textContent ) . toContain ( 'Cancer' ) ;
314318 } ) ;
315319
316320 it ( 'should exclude dataset_source_repo filters from hidden field matches' , ( ) => {
@@ -336,7 +340,7 @@ describe('Basic Functionality', () => {
336340 expect ( screen . queryByText ( / O t h e r M a t c h i n P I n a m e / i) ) . not . toBeInTheDocument ( ) ;
337341 } ) ;
338342
339- it ( 'should handle multiple filters from both primary_disease and dataset_source_repo' , ( ) => {
343+ it ( 'should NOT highlight filter values when both primary_disease and dataset_source_repo filters are present ' , ( ) => {
340344 const mockResult = createMockResult ( {
341345 primary_disease : 'Breast Cancer Research' ,
342346 dataset_source_repo : 'National Cancer Institute' ,
@@ -355,12 +359,14 @@ describe('Basic Functionality', () => {
355359
356360 renderWithRouter ( < SearchResult { ...props } /> ) ;
357361
358- // Both "Breast" and "National" should be highlighted
362+ // Neither "Breast" nor "National" should be highlighted (filters don't highlight)
359363 const primaryDiseaseMatch = screen . getByTestId ( 'primary-disease' ) ;
360- expect ( primaryDiseaseMatch . innerHTML ) . toContain ( '<b>Breast</b>' ) ;
364+ expect ( primaryDiseaseMatch . innerHTML ) . not . toContain ( '<b>Breast</b>' ) ;
365+ expect ( primaryDiseaseMatch . textContent ) . toContain ( 'Breast' ) ;
361366
362367 const dataRepoMatch = screen . getByTestId ( 'dataset-source-repo' ) ;
363- expect ( dataRepoMatch . innerHTML ) . toContain ( '<b>National</b>' ) ;
368+ expect ( dataRepoMatch . innerHTML ) . not . toContain ( '<b>National</b>' ) ;
369+ expect ( dataRepoMatch . textContent ) . toContain ( 'National' ) ;
364370 } ) ;
365371
366372 it ( 'should handle empty filters array' , ( ) => {
@@ -444,6 +450,34 @@ describe('Basic Functionality', () => {
444450 // Should not crash
445451 expect ( screen . getByText ( 'Test Dataset' ) ) . toBeInTheDocument ( ) ;
446452 } ) ;
453+
454+ it ( 'should highlight search_text terms but NOT filter values when both are present' , ( ) => {
455+ const mockResult = createMockResult ( {
456+ dataset_source_repo : 'dbGaP Repository' ,
457+ description : 'Cancer study data available through dbGaP' ,
458+ } ) ;
459+ const props = {
460+ ...defaultProps ,
461+ search : {
462+ search_text : 'Cancer' ,
463+ filters : {
464+ dataset_source_repo : [ 'dbGaP' ] ,
465+ } ,
466+ } ,
467+ resultList : [ mockResult ] ,
468+ } ;
469+
470+ renderWithRouter ( < SearchResult { ...props } /> ) ;
471+
472+ // "Cancer" should be highlighted (it's in search_text)
473+ const descriptionElement = screen . getByTestId ( 'description' ) ;
474+ expect ( descriptionElement . innerHTML ) . toContain ( '<b>Cancer</b>' ) ;
475+
476+ // But "dbGaP" should NOT be highlighted (it's only in filters)
477+ const dataRepoElement = screen . getByTestId ( 'dataset-source-repo' ) ;
478+ expect ( dataRepoElement . innerHTML ) . not . toContain ( '<b>dbGaP</b>' ) ;
479+ expect ( dataRepoElement . textContent ) . toContain ( 'dbGaP' ) ;
480+ } ) ;
447481 } ) ;
448482} ) ;
449483
0 commit comments