Farmbot-Web-App/frontend/sequences/step_tiles/__tests__/tile_reboot_test.tsx

64 lines
1.8 KiB
TypeScript
Raw Normal View History

2020-01-03 13:13:49 -07:00
jest.mock("../../../api/crud", () => ({ editStep: jest.fn() }));
import { TileReboot, editTheRebootStep, rebootExecutor } from "../tile_reboot";
import { render } from "enzyme";
import React from "react";
2020-01-03 13:13:49 -07:00
import { StepParams } from "../../interfaces";
import { fakeSequence } from "../../../__test_support__/fake_state/resources";
2020-04-28 08:18:04 -06:00
import {
buildResourceIndex,
} from "../../../__test_support__/resource_index_builder";
2020-01-03 13:13:49 -07:00
import { editStep } from "../../../api/crud";
2020-01-03 10:51:24 -07:00
import { Reboot } from "farmbot";
2020-04-28 08:18:04 -06:00
import { Content } from "../../../constants";
2020-04-28 08:18:04 -06:00
const fakeProps = (): StepParams => ({
currentSequence: fakeSequence(),
currentStep: {
kind: "reboot",
args: {
package: "farmbot_os"
}
},
dispatch: jest.fn(),
index: 1,
resources: buildResourceIndex().index,
confirmStepDeletion: false,
});
describe("<TileReboot/>", () => {
it("renders", () => {
2020-04-28 08:18:04 -06:00
const block = render(<TileReboot {...fakeProps()} />);
expect(block.text()).toContain(Content.REBOOT_STEP);
});
it("crashes if the step is of the wrong `kind`", () => {
2020-04-28 08:18:04 -06:00
const p = fakeProps();
p.currentStep = { kind: "sync", args: {} };
const boom = () => TileReboot(p);
expect(boom).toThrowError();
});
it("edits the reboot step", () => {
2020-04-28 08:18:04 -06:00
const p = fakeProps();
const editFn = editTheRebootStep(p);
editFn("arduino_firmware");
2020-04-28 08:18:04 -06:00
expect(p.dispatch).toHaveBeenCalled();
expect(editStep).toHaveBeenCalledWith({
2020-04-28 08:18:04 -06:00
step: p.currentStep,
index: p.index,
sequence: p.currentSequence,
executor: expect.any(Function),
});
});
2020-01-03 10:51:24 -07:00
it("executes the executor", () => {
2020-04-28 08:18:04 -06:00
const p = fakeProps();
const step = p.currentStep as Reboot;
2020-01-03 10:51:24 -07:00
step.args.package = "X";
const fn = rebootExecutor("arduino_firmware");
fn(step);
expect(step.args.package).toBe("arduino_firmware");
});
});