Skip to content

Commit 0aabca0

Browse files
committed
Added basic, component level tests
1 parent 4f67a50 commit 0aabca0

27 files changed

+959
-4
lines changed

package-lock.json

Lines changed: 326 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,15 @@
2424
"postinstall": "npm-run-all build-css"
2525
},
2626
"devDependencies": {
27+
"enzyme": "^3.4.4",
28+
"enzyme-adapter-react-16": "^1.2.0",
29+
"enzyme-to-json": "^3.3.4",
2730
"node-sass-chokidar": "^1.3.3",
2831
"npm-run-all": "^4.1.3"
32+
},
33+
"jest": {
34+
"snapshotSerializers": [
35+
"enzyme-to-json/serializer"
36+
]
2937
}
3038
}

src/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class App extends Component {
2828
render() {
2929
const config = getConfig();
3030

31-
if (!config) {
31+
if (!config.engineName) {
3232
return (
3333
<div>
3434
No config found. Be sure to provide configuration by either including

src/components/Body.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import React from "react";
2+
import Body from "./Body";
3+
import { shallow } from "enzyme";
4+
5+
it("renders correctly", () => {
6+
const wrapper = shallow(<Body />);
7+
expect(wrapper).toMatchSnapshot();
8+
});

src/components/Facet.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import PropTypes from "prop-types";
22
import React from "react";
33

4+
import FacetOption from "../types/FacetOption";
5+
46
function Facet({ name, onRemove, onSelect, options, value }) {
57
return (
68
<div className="facet">
@@ -47,7 +49,7 @@ Facet.propTypes = {
4749
name: PropTypes.string.isRequired,
4850
onRemove: PropTypes.func.isRequired,
4951
onSelect: PropTypes.func.isRequired,
50-
options: PropTypes.arrayOf(PropTypes.object).isRequired,
52+
options: PropTypes.arrayOf(FacetOption).isRequired,
5153
value: PropTypes.string
5254
};
5355

src/components/Facet.test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React from "react";
2+
import Facet from "./Facet";
3+
import { shallow } from "enzyme";
4+
5+
it("renders correctly when a value is selected", () => {
6+
const wrapper = shallow(
7+
<Facet
8+
name="Facet"
9+
onRemove={() => {}}
10+
onSelect={() => {}}
11+
options={[{ value: "1", count: 1 }, { value: "2", count: 1 }]}
12+
value="value"
13+
/>
14+
);
15+
expect(wrapper).toMatchSnapshot();
16+
});
17+
18+
it("renders correctly when a value is not selected", () => {
19+
const wrapper = shallow(
20+
<Facet
21+
name="Facet"
22+
onRemove={() => {}}
23+
onSelect={() => {}}
24+
options={[{ value: "1", count: 1 }, { value: "2", count: 1 }]}
25+
/>
26+
);
27+
expect(wrapper).toMatchSnapshot();
28+
});

src/components/Facets.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ function Facets({ children }) {
66
}
77

88
Facets.propTypes = {
9-
children: PropTypes.arrayOf(PropTypes.element).isRequired
9+
children: PropTypes.oneOfType([
10+
PropTypes.arrayOf(PropTypes.element),
11+
PropTypes.element
12+
]).isRequired
1013
};
1114

1215
export default Facets;

src/components/Facets.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from "react";
2+
import Facets from "./Facets";
3+
import { shallow } from "enzyme";
4+
5+
it("renders correctly", () => {
6+
const wrapper = shallow(
7+
<Facets>
8+
<div>Children</div>
9+
</Facets>
10+
);
11+
expect(wrapper).toMatchSnapshot();
12+
});

src/components/PagingInfo.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from "react";
2+
import PagingInfo from "./PagingInfo";
3+
import { shallow } from "enzyme";
4+
5+
it("renders correctly", () => {
6+
const wrapper = shallow(
7+
<PagingInfo end={20} searchTerm="grok" start={0} totalResults={1000} />
8+
);
9+
expect(wrapper).toMatchSnapshot();
10+
});

src/components/Result.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React from "react";
2+
import Result from "./Result";
3+
import { shallow } from "enzyme";
4+
5+
it("renders correctly when there is a URL", () => {
6+
const wrapper = shallow(
7+
<Result
8+
fields={{ field: "value" }}
9+
title="Title"
10+
url="http://www.example.com"
11+
/>
12+
);
13+
expect(wrapper).toMatchSnapshot();
14+
});
15+
16+
it("renders correctly when there is not a URL", () => {
17+
const wrapper = shallow(<Result fields={{ field: "value" }} title="Title" />);
18+
expect(wrapper).toMatchSnapshot();
19+
});

0 commit comments

Comments
 (0)