Farmbot-Web-App/frontend/farm_designer/__tests__/settings_test.tsx

71 lines
2.4 KiB
TypeScript
Raw Normal View History

2019-06-10 15:43:11 -06:00
jest.mock("../../config_storage/actions", () => ({
2019-06-14 16:59:11 -06:00
getWebAppConfigValue: jest.fn(x => { x(); return jest.fn(() => true); }),
2019-06-10 15:43:11 -06:00
setWebAppConfigValue: jest.fn(),
}));
import * as React from "react";
2019-06-14 17:00:42 -06:00
import { mount, ReactWrapper } from "enzyme";
2019-06-10 15:43:11 -06:00
import {
2019-09-23 12:56:35 -06:00
RawDesignerSettings as DesignerSettings, DesignerSettingsProps,
mapStateToProps,
2019-06-10 15:43:11 -06:00
} from "../settings";
import { fakeState } from "../../__test_support__/fake_state";
2019-06-14 16:59:11 -06:00
import { BooleanSetting, NumericSetting } from "../../session_keys";
2019-06-10 15:43:11 -06:00
import { setWebAppConfigValue } from "../../config_storage/actions";
2019-06-14 17:00:42 -06:00
const getSetting =
(wrapper: ReactWrapper, position: number, containsString: string) => {
const setting = wrapper.find(".designer-setting").at(position);
expect(setting.text().toLowerCase())
.toContain(containsString.toLowerCase());
return setting;
};
2019-09-23 12:56:35 -06:00
describe("<DesignerSettings />", () => {
2019-06-10 15:43:11 -06:00
const fakeProps = (): DesignerSettingsProps => ({
dispatch: jest.fn(),
getConfigValue: jest.fn(),
});
it("renders settings", () => {
2019-09-23 12:56:35 -06:00
const wrapper = mount(<DesignerSettings {...fakeProps()} />);
2019-06-10 15:43:11 -06:00
expect(wrapper.text()).toContain("size");
2019-06-14 17:00:42 -06:00
const settings = wrapper.find(".designer-setting");
expect(settings.length).toEqual(7);
});
it("renders defaultOn setting", () => {
const p = fakeProps();
p.getConfigValue = () => undefined;
2019-09-23 12:56:35 -06:00
const wrapper = mount(<DesignerSettings {...p} />);
2019-06-14 17:00:42 -06:00
const confirmDeletion = getSetting(wrapper, 6, "confirm plant");
expect(confirmDeletion.find("button").text()).toEqual("on");
2019-06-10 15:43:11 -06:00
});
it("toggles setting", () => {
2019-09-23 12:56:35 -06:00
const wrapper = mount(<DesignerSettings {...fakeProps()} />);
2019-06-14 17:00:42 -06:00
const trailSetting = getSetting(wrapper, 1, "trail");
trailSetting.find("button").simulate("click");
2019-06-10 15:43:11 -06:00
expect(setWebAppConfigValue)
.toHaveBeenCalledWith(BooleanSetting.display_trail, true);
});
2019-06-14 16:59:11 -06:00
it("changes origin", () => {
const p = fakeProps();
p.getConfigValue = () => 2;
2019-09-23 12:56:35 -06:00
const wrapper = mount(<DesignerSettings {...p} />);
2019-06-14 17:00:42 -06:00
const originSetting = getSetting(wrapper, 5, "origin");
originSetting.find("div").last().simulate("click");
2019-06-14 16:59:11 -06:00
expect(setWebAppConfigValue).toHaveBeenCalledWith(
NumericSetting.bot_origin_quadrant, 4);
});
2019-06-10 15:43:11 -06:00
});
describe("mapStateToProps()", () => {
it("returns props", () => {
const props = mapStateToProps(fakeState());
const value = props.getConfigValue(BooleanSetting.show_plants);
expect(value).toEqual(true);
});
});