2018-07-19 23:48:32 -06:00
|
|
|
|
import * as React from "react";
|
|
|
|
|
import { mount, shallow } from "enzyme";
|
2018-07-24 21:45:38 -06:00
|
|
|
|
import { LocationSelection, LocationDisplay } from "../location_selection";
|
|
|
|
|
import { LocationSelectionProps } from "../interfaces";
|
2018-07-19 23:48:32 -06:00
|
|
|
|
|
|
|
|
|
describe("<LocationSelection />", () => {
|
|
|
|
|
function fakeProps(): LocationSelectionProps {
|
|
|
|
|
return {
|
2020-02-28 09:34:28 -07:00
|
|
|
|
xyzLocation: undefined,
|
2018-07-19 23:48:32 -06:00
|
|
|
|
deviation: 0,
|
|
|
|
|
setLocation: jest.fn(),
|
|
|
|
|
setDeviation: jest.fn(),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
it("renders", () => {
|
|
|
|
|
const wrapper = mount(<LocationSelection {...fakeProps()} />);
|
|
|
|
|
const txt = wrapper.text().toLowerCase();
|
|
|
|
|
["x", "y", "z", "deviation"]
|
|
|
|
|
.map(string => expect(txt).toContain(string));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("changes location", () => {
|
|
|
|
|
const p = fakeProps();
|
2020-02-28 09:34:28 -07:00
|
|
|
|
p.xyzLocation = { x: 10, y: 20, z: 30 };
|
2018-07-19 23:48:32 -06:00
|
|
|
|
const wrapper = mount(<LocationSelection {...p} />);
|
|
|
|
|
wrapper.find("input").first().simulate("submit");
|
|
|
|
|
expect(p.setLocation).toHaveBeenCalledWith({ x: 10, y: 20, z: 30 });
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("changes location: undefined", () => {
|
|
|
|
|
const p = fakeProps();
|
2020-02-28 09:34:28 -07:00
|
|
|
|
p.xyzLocation = undefined;
|
2018-07-19 23:48:32 -06:00
|
|
|
|
const wrapper = mount(<LocationSelection {...p} />);
|
|
|
|
|
wrapper.find("input").first().simulate("submit");
|
|
|
|
|
expect(p.setLocation).toHaveBeenCalledWith({ x: undefined });
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("changes deviation", () => {
|
|
|
|
|
const p = fakeProps();
|
|
|
|
|
const wrapper = shallow(<LocationSelection {...p} />);
|
|
|
|
|
wrapper.find("BlurableInput").first().simulate("commit",
|
|
|
|
|
{ currentTarget: { value: "100" } });
|
|
|
|
|
expect(p.setDeviation).toHaveBeenCalledWith(100);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("<LocationDisplay />", () => {
|
|
|
|
|
it("renders location ranges", () => {
|
2020-02-28 09:34:28 -07:00
|
|
|
|
const p = { xyzLocation: { x: 10, y: 20, z: 30 }, deviation: 2 };
|
2018-07-19 23:48:32 -06:00
|
|
|
|
const wrapper = mount(<LocationDisplay {...p} />);
|
|
|
|
|
const txt = wrapper.text().toLowerCase();
|
|
|
|
|
["x", "y", "z", "8–12", "18–22", "28–32"]
|
|
|
|
|
.map(string => expect(txt).toContain(string));
|
|
|
|
|
});
|
|
|
|
|
});
|