Skip to content

Commit

Permalink
See more content is now searchable (#1709)
Browse files Browse the repository at this point in the history
  • Loading branch information
smcmurtry committed Jan 16, 2019
1 parent 77965cd commit c29d439
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 16 deletions.
4 changes: 2 additions & 2 deletions __tests__/components/benefit_card_test.js
Expand Up @@ -43,7 +43,6 @@ describe("BenefitCard", () => {
currentLanguage: "en",
veteranBenefitIds: [],
familyBenefitIds: [],
searchString: "",
favouriteBenefits: [],
showFavourite: true
};
Expand All @@ -58,7 +57,8 @@ describe("BenefitCard", () => {
benefitEligibility: benefitEligibilityFixture,
multipleChoiceOptions: multipleChoiceOptionsFixture,
benefitExamples: benefitExamplesFixture,
questions: questionsFixture
questions: questionsFixture,
searchString: ""
};
props.store = mockStore(reduxData);

Expand Down
3 changes: 2 additions & 1 deletion __tests__/components/benefit_expansion_test.js
Expand Up @@ -37,7 +37,8 @@ describe("BenefitExpansion", () => {
patronType: "veteran",
serviceType: "CAF",
statusAndVitals: "",
serviceHealthIssue: ""
serviceHealthIssue: "",
searchString: ""
};
props.reduxState = reduxData;
props.store = mockStore(reduxData);
Expand Down
3 changes: 2 additions & 1 deletion __tests__/components/benefit_list_test.js
Expand Up @@ -34,7 +34,8 @@ describe("BenefitList", () => {
eligibilityPaths: eligibilityPathsFixture,
multipleChoiceOptions: multipleChoiceOptionsFixture,
needs: needsFixture,
selectedNeeds: {}
selectedNeeds: {},
searchString: ""
};
props.store = mockStore(reduxData);
});
Expand Down
3 changes: 2 additions & 1 deletion __tests__/components/example_bullets_test.js
Expand Up @@ -12,7 +12,8 @@ describe("ExampleBullets", () => {
props = {
t: x => x,
benefit: benefitsFixture[0],
benefitExamples: benefitExamplesFixture
benefitExamples: benefitExamplesFixture,
searchString: ""
};
});

Expand Down
3 changes: 2 additions & 1 deletion __tests__/components/favourites_test.js
Expand Up @@ -67,7 +67,8 @@ describe("Favourites", () => {
areaOffices: areaOfficesFixture,
selectedAreaOffice: areaOfficesFixture[0],
closestAreaOffice: areaOfficesFixture[0],
multipleChoiceOptions: multipleChoiceOptionsFixture
multipleChoiceOptions: multipleChoiceOptionsFixture,
searchString: ""
};
props.store = mockStore(reduxData);
});
Expand Down
2 changes: 1 addition & 1 deletion __tests__/fixtures/lunr_index_english.js

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions __tests__/selectors/benefits_test.js
Expand Up @@ -15,6 +15,7 @@ import needsFixture from "../fixtures/needs_complex";
import enIdx from "../fixtures/lunr_index_english";
import frIdx from "../fixtures/lunr_index_french";
import nextStepsFixture from "../fixtures/nextSteps_complex";
import benefitExamplesFixture from "../fixtures/benefitExamples";

describe("Benefits Selectors", () => {
let props;
Expand All @@ -37,6 +38,7 @@ describe("Benefits Selectors", () => {
patronType: "",
searchString: "",
serviceType: "",
benefitExamples: benefitExamplesFixture,
nextSteps: nextStepsFixture
};
});
Expand Down Expand Up @@ -266,6 +268,13 @@ describe("Benefits Selectors", () => {
.reverse()
).toEqual(rankedScores);
});

it("returns a results if user searches see more content", () => {
state.searchString = "inpatient";
expect(getFilteredBenefits(state, props).map(x => x.vacNameEn)).toEqual([
"Disability Benefits"
]);
});
});

describe("getFilteredNextSteps", () => {
Expand Down
1 change: 1 addition & 0 deletions components/benefit_cards.js
Expand Up @@ -152,6 +152,7 @@ const mapStateToProps = reduxState => {
return {
needs: reduxState.needs,
selectedNeeds: reduxState.selectedNeeds,
searchString: reduxState.searchString,
benefits: reduxState.benefits
};
};
Expand Down
1 change: 0 additions & 1 deletion components/benefit_list.js
Expand Up @@ -90,7 +90,6 @@ export class BenefitList extends React.Component {
currentLanguage={currentLanguage}
key={benefit.id}
showFavourite={showFavourites}
searchString={searchString}
store={store}
/>
))
Expand Down
18 changes: 15 additions & 3 deletions components/example_bullets.js
Expand Up @@ -3,6 +3,7 @@ import PropTypes from "prop-types";
import { connect } from "react-redux";
import { css } from "emotion";
import { globalTheme } from "../theme";
import Highlighter from "react-highlight-words";

const margin = css`
padding-left: 20px;
Expand All @@ -21,7 +22,8 @@ const root = css`
`;
export class ExampleBullets extends React.Component {
getExampleBullets = () => {
const { benefitExamples, benefit, t } = this.props;
const { benefitExamples, benefit, t, searchString } = this.props;
const searchWords = searchString.split(/\s+/);
const lang = t("current-language-code") === "en" ? "english" : "french";
return benefitExamples
.filter(x => {
Expand All @@ -31,7 +33,15 @@ export class ExampleBullets extends React.Component {
return false;
})
.map((x, i) => {
return <li key={i}>{x[lang]}</li>;
return (
<li key={i}>
<Highlighter
searchWords={searchWords}
autoEscape={true}
textToHighlight={x[lang]}
/>
</li>
);
});
};

Expand All @@ -53,13 +63,15 @@ export class ExampleBullets extends React.Component {

const mapStateToProps = reduxState => {
return {
benefitExamples: reduxState.benefitExamples
benefitExamples: reduxState.benefitExamples,
searchString: reduxState.searchString
};
};

ExampleBullets.propTypes = {
benefit: PropTypes.object.isRequired,
t: PropTypes.func.isRequired,
searchString: PropTypes.string.isRequired,
benefitExamples: PropTypes.array.isRequired
};

Expand Down
18 changes: 13 additions & 5 deletions store.js
Expand Up @@ -27,19 +27,26 @@ airtableConstants.tableNames.forEach(tableName => {

// REDUCERS
export const reducer = (state = initialState, action) => {
let benefits;
let language;
let enIdx;
let frIdx;
let newState;
let benefits, benefitExamples, language, enIdx, frIdx, newState;

switch (action.type) {
case "INDEX_BENEFITS":
benefits = state.benefits;
benefitExamples = state.benefitExamples;
benefits.forEach(x => {
if (x.benefitExamples) {
const releventExamples = benefitExamples.filter(
y => x.benefitExamples.indexOf(y.id) > -1
);
x.benefitExamplesEn = releventExamples.map(y => y.english).join(" ");
x.benefitExamplesFr = releventExamples.map(y => y.french).join(" ");
}
});
enIdx = lunr(function() {
this.ref("id");
this.field("vacNameEn");
this.field("oneLineDescriptionEn");
this.field("benefitExamplesEn");
benefits.forEach(function(doc) {
this.add(doc);
}, this);
Expand All @@ -50,6 +57,7 @@ export const reducer = (state = initialState, action) => {
this.use(lunr.fr);
this.field("vacNameFr");
this.field("oneLineDescriptionFr");
this.field("benefitExamplesFr");
benefits.forEach(function(doc) {
this.add(doc);
}, this);
Expand Down

0 comments on commit c29d439

Please sign in to comment.