Add tests for openfarm_search_results

pull/421/head
Rick Carlino 2017-08-23 15:49:30 -05:00
parent 785b007c9a
commit beba944b97
3 changed files with 47 additions and 6 deletions

View File

@ -206,10 +206,6 @@ export interface DraggableEvent {
};
}
export interface OFSearchProps {
cropSearchResults: CropLiveSearchResult[];
}
export interface HoveredPlantPayl {
/* Use UUID here to prevent denormalization? */
plantUUID: string | undefined;

View File

@ -0,0 +1,33 @@
import * as React from "react";
import { mount } from "enzyme";
import { OpenFarmResults, SearchResultProps } from "../openfarm_search_results";
describe("<OpenFarmResults/>", () => {
it("renders OpenFarmSearchResults", () => {
let props: SearchResultProps = {
cropSearchResults: [
{
crop: {
slug: "potato",
name: "S. tuberosum"
},
image: "potato.jpg"
},
{
crop: {
slug: "tomato",
name: "Solanum lycopersicum"
},
image: "tomato.jpg"
},
]
};
let el = mount(<OpenFarmResults {...props} />);
let text = el.text();
expect(text).toContain(props.cropSearchResults[0].crop.name);
expect(text).toContain(props.cropSearchResults[1].crop.name);
expect(el.find("Link").length).toEqual(props.cropSearchResults.length);
expect(el.find("Link").first().prop("to"))
.toContain(props.cropSearchResults[0].crop.slug);
});
});

View File

@ -1,8 +1,20 @@
import * as React from "react";
import { Link } from "react-router";
import { OFSearchProps } from "../interfaces";
export class OpenFarmResults extends React.Component<OFSearchProps, {}> {
/** A stripped down version of OFSearchResult */
interface Result {
crop: {
slug: string;
name: string;
};
image: string;
}
export interface SearchResultProps {
cropSearchResults: Result[];
}
export class OpenFarmResults extends React.Component<SearchResultProps, {}> {
render() {
return <div>
{this.props.cropSearchResults.map(resp => {