2017-07-26 15:21:48 -06:00
|
|
|
import * as React from "react";
|
|
|
|
import { StepButtonParams } from "../../interfaces";
|
2018-01-12 09:06:14 -07:00
|
|
|
import { StepButton, stepClick } from "../index";
|
2017-08-02 09:14:08 -06:00
|
|
|
import { shallow } from "enzyme";
|
2017-07-26 15:21:48 -06:00
|
|
|
import { fakeSequence } from "../../../__test_support__/fake_state/resources";
|
2017-12-14 16:03:50 -07:00
|
|
|
import { Actions } from "../../../constants";
|
2019-06-24 15:39:49 -06:00
|
|
|
import { error } from "../../../toast/toast";
|
2017-07-26 15:21:48 -06:00
|
|
|
|
2018-01-12 09:06:14 -07:00
|
|
|
function props(): StepButtonParams {
|
|
|
|
return {
|
|
|
|
current: fakeSequence(),
|
|
|
|
step: {
|
|
|
|
kind: "wait",
|
|
|
|
args: {
|
|
|
|
milliseconds: 9,
|
2017-07-26 15:21:48 -06:00
|
|
|
},
|
2018-01-12 09:06:14 -07:00
|
|
|
},
|
|
|
|
dispatch: jest.fn(),
|
2019-04-09 19:45:59 -06:00
|
|
|
color: "blue",
|
|
|
|
index: 1,
|
2018-01-12 09:06:14 -07:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
describe("<StepButton/>", () => {
|
2017-07-26 15:21:48 -06:00
|
|
|
|
|
|
|
it("clicks it", () => {
|
2017-08-28 05:49:13 -06:00
|
|
|
const p = props();
|
2019-04-09 19:45:59 -06:00
|
|
|
const el = shallow(<StepButton {...p} />);
|
2017-07-26 15:21:48 -06:00
|
|
|
el.find("button").simulate("click");
|
2017-12-14 16:03:50 -07:00
|
|
|
expect(p.dispatch).toHaveBeenCalledWith({
|
|
|
|
payload: expect.objectContaining({
|
|
|
|
update: expect.objectContaining({
|
|
|
|
body: [p.step]
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
type: Actions.OVERWRITE_RESOURCE
|
|
|
|
});
|
2019-04-09 19:45:59 -06:00
|
|
|
expect(p.dispatch).toHaveBeenCalledWith({
|
|
|
|
type: Actions.SET_SEQUENCE_STEP_POSITION,
|
|
|
|
payload: undefined,
|
|
|
|
});
|
2017-07-26 15:21:48 -06:00
|
|
|
});
|
|
|
|
});
|
2018-01-12 09:06:14 -07:00
|
|
|
|
|
|
|
describe("stepClick", () => {
|
|
|
|
it("pops a toast notification when you must select a sequence", () => {
|
|
|
|
const p = props();
|
|
|
|
const clicker = stepClick(p.dispatch, p.step, undefined);
|
|
|
|
clicker();
|
|
|
|
expect(error).toHaveBeenCalledWith("Select a sequence first");
|
|
|
|
});
|
|
|
|
});
|