Skip to content

Commit ca62eea

Browse files
authored
Merge pull request #487 from CBIIT/INS-1413
INS-1413 filter remove from highlights + updated tests
2 parents 2c5850f + ad38586 commit ca62eea

File tree

2 files changed

+46
-32
lines changed

2 files changed

+46
-32
lines changed

src/pages/dataSets/SearchResult/SearchResult.js

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -349,27 +349,7 @@ const SearchResult = ({
349349
}) => {
350350
const sanitizeSearchTerms = search.search_text.replace(/[^a-zA-Z0-9 ]/g, ' ');
351351
const searchTerms = sanitizeSearchTerms.split(' ').filter((item) => item !== '');
352-
let searchCombination = getCombinations(searchTerms);
353-
354-
if (search.filters) {
355-
if (
356-
search.filters.primary_disease
357-
&& Array.isArray(search.filters.primary_disease)
358-
&& search.filters.primary_disease.length > 0
359-
) {
360-
searchCombination = search.filters.primary_disease.concat(searchCombination);
361-
}
362-
363-
if (
364-
search.filters.dataset_source_repo
365-
&& Array.isArray(search.filters.dataset_source_repo)
366-
&& search.filters.dataset_source_repo.length > 0
367-
) {
368-
searchCombination = search.filters.dataset_source_repo.concat(searchCombination);
369-
}
370-
}
371-
372-
searchCombination.sort((a, b) => b.length - a.length);
352+
const searchCombination = getCombinations(searchTerms).sort((a, b) => b.length - a.length);
373353

374354
const initializePopover = () => {
375355
const popoverTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"]'));

src/pages/dataSets/SearchResult/SearchResult.test.jsx

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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('&lt;b&gt;Cancer&lt;/b&gt;');
291+
expect(matchedContent.innerHTML).not.toContain('&lt;b&gt;Cancer&lt;/b&gt;');
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('&lt;b&gt;Cancer&lt;/b&gt;');
315+
expect(matchedContent.innerHTML).not.toContain('&lt;b&gt;Cancer&lt;/b&gt;');
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(/Other Match in PI name/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('&lt;b&gt;Breast&lt;/b&gt;');
364+
expect(primaryDiseaseMatch.innerHTML).not.toContain('&lt;b&gt;Breast&lt;/b&gt;');
365+
expect(primaryDiseaseMatch.textContent).toContain('Breast');
361366

362367
const dataRepoMatch = screen.getByTestId('dataset-source-repo');
363-
expect(dataRepoMatch.innerHTML).toContain('&lt;b&gt;National&lt;/b&gt;');
368+
expect(dataRepoMatch.innerHTML).not.toContain('&lt;b&gt;National&lt;/b&gt;');
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('&lt;b&gt;Cancer&lt;/b&gt;');
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('&lt;b&gt;dbGaP&lt;/b&gt;');
479+
expect(dataRepoElement.textContent).toContain('dbGaP');
480+
});
447481
});
448482
});
449483

0 commit comments

Comments
 (0)