/
sequence_editor_middle_active_test.tsx
192 lines (172 loc) · 5.89 KB
/
sequence_editor_middle_active_test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
jest.mock("../../api/crud", () => ({
destroy: jest.fn(),
save: jest.fn(),
edit: jest.fn()
}));
jest.mock("../actions", () => ({
copySequence: jest.fn(),
editCurrentSequence: jest.fn()
}));
jest.mock("../step_tiles/index", () => ({
splice: jest.fn(),
move: jest.fn()
}));
jest.mock("../../devices/actions", () => ({
execSequence: jest.fn()
}));
jest.mock("../locals_list/locals_list", () => ({
LocalsList: () => <div />,
localListCallback: jest.fn(() => jest.fn()),
isParameterDeclaration: jest.fn(),
}));
import * as React from "react";
import {
SequenceEditorMiddleActive, onDrop, SequenceNameAndColor
} from "../sequence_editor_middle_active";
import { mount, shallow } from "enzyme";
import { ActiveMiddleProps } from "../interfaces";
import {
FAKE_RESOURCES, buildResourceIndex
} from "../../__test_support__/resource_index_builder";
import { fakeSequence } from "../../__test_support__/fake_state/resources";
import { destroy, save, edit } from "../../api/crud";
import {
fakeHardwareFlags
} from "../../__test_support__/sequence_hardware_settings";
import { SpecialStatus } from "farmbot";
import { move, splice } from "../step_tiles";
import { copySequence, editCurrentSequence } from "../actions";
import { execSequence } from "../../devices/actions";
import { clickButton } from "../../__test_support__/helpers";
import { fakeVariableNameSet } from "../../__test_support__/fake_variables";
describe("<SequenceEditorMiddleActive/>", () => {
const fakeProps = (): ActiveMiddleProps => {
const sequence = fakeSequence();
sequence.specialStatus = SpecialStatus.DIRTY;
return {
dispatch: jest.fn(),
sequence,
resources: buildResourceIndex(FAKE_RESOURCES).index,
syncStatus: "synced",
hardwareFlags: fakeHardwareFlags(),
farmwareInfo: {
farmwareNames: [],
firstPartyFarmwareNames: [],
showFirstPartyFarmware: false,
farmwareConfigs: {},
},
shouldDisplay: jest.fn(),
confirmStepDeletion: false,
menuOpen: false,
};
};
it("saves", () => {
const wrapper = mount(<SequenceEditorMiddleActive {...fakeProps()} />);
clickButton(wrapper, 0, "Save * ");
expect(save).toHaveBeenCalledWith(expect.stringContaining("Sequence"));
});
it("tests", () => {
const p = fakeProps();
p.syncStatus = "synced";
p.sequence.specialStatus = SpecialStatus.SAVED;
const wrapper = mount(<SequenceEditorMiddleActive {...p} />);
clickButton(wrapper, 1, "Test");
expect(execSequence).toHaveBeenCalledWith(p.sequence.body.id);
});
it("deletes", () => {
const p = fakeProps();
p.dispatch = jest.fn(() => Promise.resolve());
const wrapper = mount(<SequenceEditorMiddleActive {...p} />);
clickButton(wrapper, 2, "Delete");
expect(destroy).toHaveBeenCalledWith(expect.stringContaining("Sequence"));
});
it("copies", () => {
const wrapper = mount(<SequenceEditorMiddleActive {...fakeProps()} />);
clickButton(wrapper, 3, "Copy");
expect(copySequence).toHaveBeenCalledWith(expect.objectContaining({
uuid: expect.stringContaining("Sequence")
}));
});
it("has drag area", () => {
const wrapper = mount(<SequenceEditorMiddleActive {...fakeProps()} />);
expect(wrapper.find(".drag-drop-area").text()).toEqual("DRAG COMMAND HERE");
});
it("has correct height", () => {
const wrapper = mount(<SequenceEditorMiddleActive {...fakeProps()} />);
expect(wrapper.find(".sequence").props().style).toEqual({
height: "calc(100vh - 25rem)"
});
});
it("has correct height without variable form", () => {
const p = fakeProps();
p.resources.sequenceMetas = { [p.sequence.uuid]: {} };
p.shouldDisplay = () => true;
const wrapper = mount(<SequenceEditorMiddleActive {...p} />);
expect(wrapper.find(".sequence").props().style).toEqual({
height: "calc(100vh - 25rem)"
});
});
it("has correct height with variable form", () => {
const p = fakeProps();
p.resources.sequenceMetas = { [p.sequence.uuid]: fakeVariableNameSet() };
p.shouldDisplay = () => true;
const wrapper = mount(<SequenceEditorMiddleActive {...p} />);
expect(wrapper.find(".sequence").props().style)
.toEqual({ height: "calc(100vh - 38rem)" });
});
});
describe("onDrop()", () => {
it("step_splice", () => {
const dispatch = jest.fn();
onDrop(dispatch, fakeSequence())(0, "fakeUuid");
dispatch.mock.calls[0][0](() => {
return { value: 1, intent: "step_splice", draggerId: 2 };
});
expect(splice).toHaveBeenCalledWith(expect.objectContaining({
step: 1,
index: 0
}));
});
it("step_move", () => {
const dispatch = jest.fn();
onDrop(dispatch, fakeSequence())(3, "fakeUuid");
dispatch.mock.calls[0][0](() => {
return { value: 4, intent: "step_move", draggerId: 5 };
});
expect(move).toHaveBeenCalledWith(expect.objectContaining({
step: 4,
to: 3,
from: 5
}));
});
it("not a valid step object", () => {
const dispatch = jest.fn();
onDrop(dispatch, fakeSequence())(0, "");
expect(dispatch).not.toHaveBeenCalled();
});
});
describe("<SequenceNameAndColor />", () => {
const fakeProps = () => ({
dispatch: jest.fn(),
sequence: fakeSequence(),
});
it("edits name", () => {
const p = fakeProps();
const wrapper = shallow(<SequenceNameAndColor {...p} />);
wrapper.find("BlurableInput").simulate("commit", {
currentTarget: { value: "new name" }
});
expect(edit).toHaveBeenCalledWith(
expect.objectContaining({ uuid: p.sequence.uuid }),
{ name: "new name" });
});
it("edits color", () => {
const p = fakeProps();
const wrapper = shallow(<SequenceNameAndColor {...p} />);
wrapper.find("ColorPicker").simulate("change", "red");
expect(editCurrentSequence).toHaveBeenCalledWith(
expect.any(Function),
expect.objectContaining({ uuid: p.sequence.uuid }),
{ color: "red" });
});
});