Add tests for openfarm_search_results
parent
785b007c9a
commit
beba944b97
|
@ -206,10 +206,6 @@ export interface DraggableEvent {
|
|||
};
|
||||
}
|
||||
|
||||
export interface OFSearchProps {
|
||||
cropSearchResults: CropLiveSearchResult[];
|
||||
}
|
||||
|
||||
export interface HoveredPlantPayl {
|
||||
/* Use UUID here to prevent denormalization? */
|
||||
plantUUID: string | undefined;
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
|
@ -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 => {
|
||||
|
|
Loading…
Reference in New Issue