Skip to content

Commit

Permalink
(#192) Expand results with single result should NOTredirect to defini…
Browse files Browse the repository at this point in the history
…tion

changed prop types to func in three different tests to remove console error
added tests for expand, but it does not work

added integration test
fixed expand Home.jsx to display one result

change the title to display singular for one term result
  • Loading branch information
Arce, Paul (NIH/NCI) [C] authored and bryanpizzillo committed Jul 21, 2020
1 parent 10d2e01 commit d15ab54
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 32 deletions.
9 changes: 9 additions & 0 deletions cypress/integration/ViewTermsByLetterGenetics.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,12 @@ Feature: View Terms by letter for Genetics
When user selects letter "Y" from A-Z list
Then the system returns user to the search results page for the search term "Y" URL has "/expand"
When user tries to go to this URL, system should return the Expand "No Matches Found" page for language "en"

Scenario: User clicks on a letter in the A-Z list for results and gets no matches found for the selected letter
Given user is on landing Genetics Terms page
When user selects letter "K" from A-Z list
Then the system returns user to the search results page for the search term "K" URL has "/expand"
Then search results page displays results title "# result found for: K"
And each result in the results listing appears as a link to the term's page
And the audio icon and the pronunciation appear beside the term on the same line as the link
And each result displays its full definition below the link for the term
2 changes: 1 addition & 1 deletion src/components/molecules/search/__tests__/Search.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('<Search /> English', () => {
}

SearchWithLocation.propTypes = {
RenderComponent: PropTypes.node,
RenderComponent: PropTypes.func,
};

beforeEach(async () => {
Expand Down
4 changes: 4 additions & 0 deletions src/utils/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ export const i18n = {
en: 'results found for',
es: 'resultados de',
},
termListTitleSingleResult: {
en: 'result found for',
es: 'resultado de',
},
definitionOf: {
en: 'Definition of',
es: 'Definición de',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function ComponentWithLocation({ RenderComponent }) {
}

ComponentWithLocation.propTypes = {
RenderComponent: PropTypes.node,
RenderComponent: PropTypes.func,
};

test('Ensure page is redirected to the definition page with a pretty URL name', async () => {
Expand Down
59 changes: 35 additions & 24 deletions src/views/Terms/TermList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const getMetaTitle = (dictionaryTitle, siteName) => {
const TermList = ({ matchType, query, type }) => {
const tracking = useTracking();
const location = useLocation();
const navigate = useNavigate();

const queryAction =
type === queryType.SEARCH
? getSearchResults(query, matchType)
Expand All @@ -37,9 +39,9 @@ const TermList = ({ matchType, query, type }) => {
ExpandPath,
ExpandPathSpanish,
SearchPath,
SearchPathSpanish
SearchPathSpanish,
} = useAppPaths();
const navigate = useNavigate();

const { pathname } = location;
const isHome = pathname === HomePath() || pathname === basePath;

Expand All @@ -49,8 +51,11 @@ const TermList = ({ matchType, query, type }) => {

useEffect(() => {
if (!loading && payload) {

if (payload.results && payload.results.length === 1) {
if (
(type === queryType.SEARCH || type === queryType.SEARCH_SPANISH) &&
payload.results &&
payload.results.length === 1
) {
const idOrName = payload.results[0].prettyUrlName
? payload.results[0].prettyUrlName
: payload.results[0].termId;
Expand All @@ -61,7 +66,6 @@ const TermList = ({ matchType, query, type }) => {

trackLoad(payload);
}

}, [loading, payload]);

const trackLoad = (payload) => {
Expand All @@ -77,14 +81,15 @@ const TermList = ({ matchType, query, type }) => {
event: 'GlossaryApp:Load:SearchResults',
name:
canonicalHost.replace('https://', '') +

[language === 'en' ?
SearchPath({
searchText: decodeURIComponent(query)
})
: SearchPathSpanish({
searchText: decodeURIComponent(query)
})],
[
language === 'en'
? SearchPath({
searchText: decodeURIComponent(query),
})
: SearchPathSpanish({
searchText: decodeURIComponent(query),
}),
],
searchType: matchType === 'Begins' ? 'StartsWith' : 'Contains',
searchKeyword: decodeURIComponent(query),
...commonParams,
Expand All @@ -94,14 +99,18 @@ const TermList = ({ matchType, query, type }) => {
event: 'GlossaryApp:Load:ExpandResults',
name:
canonicalHost.replace('https://', '') +
[language === 'en' ?
ExpandPath({
expandChar: decodeURIComponent(query).toLowerCase()
})
: ExpandPathSpanish({
expandChar: decodeURIComponent(query).toLowerCase()
})],
...(isHome && { name: canonicalHost.replace('https://', '') + HomePath() }),
[
language === 'en'
? ExpandPath({
expandChar: decodeURIComponent(query).toLowerCase(),
})
: ExpandPathSpanish({
expandChar: decodeURIComponent(query).toLowerCase(),
}),
],
...(isHome && {
name: canonicalHost.replace('https://', '') + HomePath(),
}),
letter: decodeURIComponent(query).toLocaleLowerCase(),
...commonParams,
};
Expand All @@ -123,15 +132,17 @@ const TermList = ({ matchType, query, type }) => {
<div
className="dictionary-list-container results"
data-dict-type="term">
{payload.results && payload.results.length > 1 ? (
{payload.results && payload.results.length >= 1 ? (
<>
<h4>
{payload.meta.totalResults} {i18n.termListTitle[language]}:{' '}
{payload.meta.totalResults} {payload.results.length === 1 ? i18n.termListTitleSingleResult[language] : i18n.termListTitle[language]}:{' '}
{decodeURIComponent(query)}{' '}
</h4>
<dl className="dictionary-list">
{payload.results.map((result, index) => {
return <Term key={index} resultIndex={index} payload={result} />;
return (
<Term key={index} resultIndex={index} payload={result} />
);
})}
</dl>
</>
Expand Down
2 changes: 1 addition & 1 deletion src/views/Terms/__tests__/Term.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('Term component rendered with English', () => {
return <Term payload={term} />;
}
TermWithLocation.propTypes = {
term: PropTypes.string,
term: PropTypes.object,
};

afterEach(() => {
Expand Down
11 changes: 6 additions & 5 deletions src/views/Terms/__tests__/TermList.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ const queryFile = `${query}.json`;
const { getFixture } = fixtures;
const fixturePath = `/Terms/expand/Cancer.gov/Patient`;

function ComponentWithLocation({ RenderComponent, query }) {
// Used for search termlists
const ComponentWithLocation = ({ RenderComponent, query, type = 'search' }) => {
location = useLocation();
return <RenderComponent query={query} />;
}

return <RenderComponent query={query} type={type} />;
};
ComponentWithLocation.propTypes = {
RenderComponent: PropTypes.node,
RenderComponent: PropTypes.func,
query: PropTypes.string,
type: PropTypes.string,
};

describe('TermList component rendered with English', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"meta": {
"totalResults": 1,
"from": 0
},
"results": [
{
"termId": 460158,
"language": "en",
"dictionary": "Genetics",
"audience": "HealthProfessional",
"termName": "kindred",
"firstLetter": "k",
"prettyUrlName": "kindred",
"pronunciation": {
"key": "(KIN-dred)",
"audio": "https://nci-media-dev.cancer.gov/pdq/media/audio/736952.mp3"
},
"definition": {
"html": "An extended family.",
"text": "An extended family."
},
"otherLanguages": [],
"relatedResources": [],
"media": []
}
],
"links": null
}

0 comments on commit d15ab54

Please sign in to comment.