Farmbot-Web-App/frontend/devices/components/__tests__/pin_guard_input_group_test.tsx

35 lines
1.2 KiB
TypeScript
Raw Normal View History

2019-09-23 12:56:35 -06:00
jest.mock("../../actions", () => ({ settingToggle: jest.fn() }));
2018-03-13 21:22:57 -06:00
import * as React from "react";
import { PinGuardMCUInputGroup } from "../pin_guard_input_group";
import { mount } from "enzyme";
import { PinGuardMCUInputGroupProps } from "../interfaces";
import { bot } from "../../../__test_support__/fake_state/bot";
import { settingToggle } from "../../actions";
2019-09-23 12:56:35 -06:00
import {
2020-02-28 09:35:32 -07:00
buildResourceIndex,
2019-09-23 12:56:35 -06:00
} from "../../../__test_support__/resource_index_builder";
2018-03-13 21:22:57 -06:00
describe("<PinGuardMCUInputGroup/>", () => {
const fakeProps = (): PinGuardMCUInputGroupProps => {
return {
2020-02-28 09:34:28 -07:00
label: "Pin Guard 1",
2019-06-21 15:45:44 -06:00
pinNumKey: "pin_guard_1_pin_nr",
timeoutKey: "pin_guard_1_time_out",
activeStateKey: "pin_guard_1_active_state",
2018-03-13 21:22:57 -06:00
dispatch: jest.fn(),
2019-06-21 15:45:44 -06:00
sourceFwConfig: x =>
({ value: bot.hardware.mcu_params[x], consistent: true }),
resources: buildResourceIndex([]).index,
2018-03-13 21:22:57 -06:00
};
};
it("calls toggle action ", () => {
const p = fakeProps();
const wrapper = mount(<PinGuardMCUInputGroup {...p} />);
2019-06-21 15:45:44 -06:00
wrapper.find("button").last().simulate("click");
2018-03-13 21:22:57 -06:00
expect(settingToggle).toHaveBeenCalledWith("pin_guard_1_active_state",
expect.any(Function));
});
});