Skip to content

Commit

Permalink
General testing improvement pass (#953)
Browse files Browse the repository at this point in the history
* profile_needs_selector_mobile tests updated

* profile_needs_selector tests updated

* place_search tests updated

* guided_experience_needs tests updated

* Updated pages/map tests

* Updated pages/benefits-directory tests

* Updated selectors/benefits tests

* Updated selectors/show_filters tests

* Updated pages/guided tests

* Lint error
  • Loading branch information
maxneuvians committed Aug 20, 2018
1 parent 5705231 commit e054e00
Show file tree
Hide file tree
Showing 17 changed files with 591 additions and 53 deletions.
6 changes: 4 additions & 2 deletions __tests__/components/area_office_map_test.js
Expand Up @@ -6,7 +6,7 @@ import WrappedAreaOfficeMap from "../../components/area_office_map";
import { AreaOfficeMap } from "../../components/area_office_map";
import areaOfficesFixture from "../fixtures/area_offices";

const GOOGLE_MAPS_KEY=process.env.GOOGLE_MAPS_KEY
const GOOGLE_MAPS_KEY = process.env.GOOGLE_MAPS_KEY;

const { axe, toHaveNoViolations } = require("jest-axe");
expect.extend(toHaveNoViolations);
Expand All @@ -21,7 +21,9 @@ describe("AreaOfficeMap", () => {
beforeEach(() => {
props = {
googleMapURL:
"https://maps.googleapis.com/maps/api/js?key=" + GOOGLE_MAPS_KEY + "&language=en&v=3.exp&libraries=geometry,drawing,places",
"https://maps.googleapis.com/maps/api/js?key=" +
GOOGLE_MAPS_KEY +
"&language=en&v=3.exp&libraries=geometry,drawing,places",
loadingElement: <div style={{ height: "100%" }} />,
containerElement: <div style={{ height: "400px" }} />,
mapElement: <div style={{ height: "100%" }} />,
Expand Down
8 changes: 8 additions & 0 deletions __tests__/components/guided_experience_needs_test.js
Expand Up @@ -73,4 +73,12 @@ describe("GuidedExperienceNeeds", () => {
.simulate("click");
expect(props.setSelectedNeeds).toBeCalled();
});

it("removes a selectedNeed if it already selected", () => {
props.selectedNeeds[needsFixture[1].id] = "selected";
shallow_GuidedExperienceNeeds()
.instance()
.handleClick(needsFixture[1].id);
expect(props.setSelectedNeeds).toBeCalledWith({});
});
});
26 changes: 26 additions & 0 deletions __tests__/components/place_search_test.js
Expand Up @@ -84,4 +84,30 @@ describe("PlaceSearch", () => {
expect(props.setMapView).toBeCalledWith({ lat: 0, lng: 0, zoom: 10 });
});
});

it("clicking #searchButtonLink toggles the setLocation function", () => {
mounted_PlaceSearch().instance().setLocation = jest.fn();
mounted_PlaceSearch()
.find("#searchButtonLink")
.first()
.simulate("click");
expect(mounted_PlaceSearch().instance().setLocation).toBeCalled();
});

it("keyDown on #inputField toggles onKeyPress", () => {
mounted_PlaceSearch().instance().onKeyPress = jest.fn();
mounted_PlaceSearch()
.find("#inputField")
.first()
.simulate("keydown");
expect(mounted_PlaceSearch().instance().onKeyPress).toBeCalled();
});

it("onKeyPress toggle setLocation is Enter is pressed", () => {
mounted_PlaceSearch().instance().setLocation = jest.fn();
mounted_PlaceSearch()
.instance()
.onKeyPress({ key: "Enter" });
expect(mounted_PlaceSearch().instance().setLocation).toBeCalled();
});
});
44 changes: 44 additions & 0 deletions __tests__/components/profile_needs_selector_mobile_test.js
Expand Up @@ -100,4 +100,48 @@ describe("ProfileNeedsSelectorMobile", () => {
expect(reduxData.setServiceHealthIssue).toBeCalledWith("");
expect(reduxData.setSelectedNeeds).toBeCalledWith({});
});

it("clicking #ClearFiltersMobile toggles the clearFilters function", () => {
reduxData.selectedNeeds = { foo: "bar" };
const mounted = mount(
<ProfileNeedsSelectorMobile {...props} {...reduxData} />
);
mounted.instance().clearFilters = jest.fn();
mounted
.find("#ClearFiltersMobile")
.first()
.simulate("click");
expect(mounted.instance().clearFilters).toBeCalled();
});

it("clicking ExpansionPanelSummary toggles the toggleOpenState function", () => {
const mounted = mount(
<ProfileNeedsSelectorMobile {...props} {...reduxData} />
);
mounted.instance().toggleOpenState = jest.fn();
mounted
.find("ExpansionPanelSummary")
.first()
.simulate("click");
expect(mounted.instance().toggleOpenState).toBeCalled();
});

it("returns 1 if a profile is selected", () => {
reduxData.selectedPatronType = "organization";
props.store = mockStore(reduxData);
expect(
mount(<ProfileNeedsSelectorMobile {...props} {...reduxData} />)
.instance()
.countSelected()
).toEqual(1);
});

it("toggles the state with toggleOpenState", () => {
const mounted = mount(
<ProfileNeedsSelectorMobile {...props} {...reduxData} />
);
mounted.setState({ open: true });
mounted.instance().toggleOpenState();
expect(mounted.state("open")).toEqual(false);
});
});
21 changes: 21 additions & 0 deletions __tests__/components/profile_needs_selector_test.js
Expand Up @@ -98,4 +98,25 @@ describe("ProfileNeedsSelector", () => {
expect(reduxData.setServiceHealthIssue).toBeCalledWith("");
expect(reduxData.setSelectedNeeds).toBeCalledWith({});
});

it("clicking #ClearFilters toggles the clearFilters function", () => {
reduxData.selectedNeeds = { foo: "bar" };
const mounted = mount(<ProfileNeedsSelector {...props} {...reduxData} />);
mounted.instance().clearFilters = jest.fn();
mounted
.find("#ClearFilters")
.first()
.simulate("click");
expect(mounted.instance().clearFilters).toBeCalled();
});

it("returns 1 if a profile is selected", () => {
reduxData.selectedPatronType = "organization";
props.store = mockStore(reduxData);
expect(
mount(<ProfileNeedsSelector {...props} {...reduxData} />)
.instance()
.countSelected()
).toEqual(1);
});
});
12 changes: 12 additions & 0 deletions __tests__/fixtures/eligibilityPaths.js
Expand Up @@ -10,6 +10,18 @@ const eligibilityPathsFixture = [
statusAndVitals: "na",
serviceType: "RCMP",
benefits: ["1"]
},
{
patronType: "service-person",
statusAndVitals: "deceased",
serviceType: "WSV (WWII or Korea)",
benefits: ["1"]
},
{
patronType: "service-person",
statusAndVitals: "stillServing",
serviceType: "WSV (WWII or Korea)",
benefits: ["1"]
}
];

Expand Down
10 changes: 9 additions & 1 deletion __tests__/pages/benefits_directory_test.js
@@ -1,6 +1,6 @@
/* eslint-env jest */

import { shallow } from "enzyme";
import { mount, shallow } from "enzyme";
import Router from "next/router";

import React from "react";
Expand Down Expand Up @@ -112,6 +112,14 @@ describe("BenefitsDirectory", () => {
expect(await axe(html)).toHaveNoViolations();
});

it("calls window.removeEventListener when it unmounts", () => {
window.removeEventListener = jest.fn();
const mounted = mount(<BenefitsDirectory {...props} {...reduxData} />);
mounted.setProps({ foo: "bar" });
mounted.unmount();
expect(window.removeEventListener).toBeCalled();
});

it("has a correct setURL function", () => {
reduxData.selectedNeeds = { health: "health", financial: "financial" };
reduxData.searchString = "foo";
Expand Down

0 comments on commit e054e00

Please sign in to comment.