fix tests
parent
38adc49714
commit
61926d2415
|
@ -12,6 +12,15 @@ jest.mock("axios", () => {
|
|||
}
|
||||
};
|
||||
});
|
||||
|
||||
jest.mock("../../resources/reducer_support", () => ({
|
||||
findByUuid: () => arrayUnwrap(newTaggedResource("User", { id: 23 })),
|
||||
// tslint:disable-next-line:no-any
|
||||
afterEach: (s: any) => s,
|
||||
joinKindAndId: jest.fn(),
|
||||
mutateSpecialStatus: jest.fn(),
|
||||
}));
|
||||
|
||||
import { destroy, saveAll, initSave } from "../crud";
|
||||
import { buildResourceIndex } from "../../__test_support__/resource_index_builder";
|
||||
import { createStore, applyMiddleware } from "redux";
|
||||
|
@ -23,10 +32,10 @@ import { API } from "../api";
|
|||
import { betterCompact } from "../../util";
|
||||
import { SpecialStatus, TaggedUser } from "farmbot";
|
||||
import * as _ from "lodash";
|
||||
// import { arrayUnwrap } from "../../resources/util";
|
||||
// import { newTaggedResource } from "../../sync/actions";
|
||||
import { newTaggedResource } from "../../sync/actions";
|
||||
import { arrayUnwrap } from "../../resources/util";
|
||||
|
||||
fdescribe("AJAX data tracking", () => {
|
||||
describe("AJAX data tracking", () => {
|
||||
API.setBaseUrl("http://blah.whatever.party");
|
||||
const initialState = { resources: buildResourceIndex() };
|
||||
const wrappedReducer =
|
||||
|
@ -59,7 +68,7 @@ fdescribe("AJAX data tracking", () => {
|
|||
expect(uuids.length).toEqual(r.length);
|
||||
});
|
||||
|
||||
fit("sets consistency when calling initSave()", () => {
|
||||
it("sets consistency when calling initSave()", () => {
|
||||
// tslint:disable-next-line:no-any
|
||||
const action: any = initSave("User", {
|
||||
name: "tester123",
|
||||
|
|
|
@ -85,13 +85,9 @@ export function init<T extends TaggedResource>(kind: T["kind"],
|
|||
|
||||
export function initSave<T extends TaggedResource>(kind: T["kind"],
|
||||
body: T["body"]) {
|
||||
return function (dispatch: Function, getState: GetState) {
|
||||
return function (dispatch: Function) {
|
||||
const action = init(kind, body);
|
||||
const before = getState().resources.index;
|
||||
dispatch(action);
|
||||
const after = getState().resources.index;
|
||||
console.log(before, after);
|
||||
debugger;
|
||||
return dispatch(save(action.payload.uuid));
|
||||
};
|
||||
}
|
||||
|
|
|
@ -92,13 +92,12 @@ describe("handleCreate", () => {
|
|||
|
||||
describe("asTaggedResource", () => {
|
||||
it("turns MQTT data into FE data", () => {
|
||||
const UUID = "123-456-789";
|
||||
const p = payload();
|
||||
const result = asTaggedResource(p);
|
||||
expect(result.body).toEqual(p.body);
|
||||
expect(result.kind).toEqual(p.kind);
|
||||
expect(result.specialStatus).toEqual(SpecialStatus.SAVED);
|
||||
expect(result.uuid).toEqual(UUID);
|
||||
expect(result.uuid).toContain(p.kind);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -98,15 +98,12 @@ describe("<PinBindingInputGroup/>", () => {
|
|||
wrapper.setState({ pinNumberInput: 1, sequenceIdInput: 2 });
|
||||
buttons.last().simulate("click");
|
||||
expect(mockDevice.registerGpio).not.toHaveBeenCalled();
|
||||
const expectedResult = expect.objectContaining({
|
||||
kind: "PinBinding",
|
||||
body: {
|
||||
expect(initSave).toHaveBeenCalledWith("PinBinding",
|
||||
{
|
||||
pin_num: 1,
|
||||
sequence_id: 2,
|
||||
binding_type: PinBindingType.standard
|
||||
}
|
||||
});
|
||||
expect(initSave).toHaveBeenCalledWith(expectedResult);
|
||||
});
|
||||
});
|
||||
|
||||
it("registers pin: api (special action)", () => {
|
||||
|
@ -124,15 +121,12 @@ describe("<PinBindingInputGroup/>", () => {
|
|||
});
|
||||
buttons.last().simulate("click");
|
||||
expect(mockDevice.registerGpio).not.toHaveBeenCalled();
|
||||
const expectedResult = expect.objectContaining({
|
||||
kind: "PinBinding",
|
||||
body: {
|
||||
expect(initSave).toHaveBeenCalledWith("PinBinding",
|
||||
{
|
||||
pin_num: 2,
|
||||
binding_type: PinBindingType.special,
|
||||
special_action: PinBindingSpecialAction.emergency_lock
|
||||
}
|
||||
});
|
||||
expect(initSave).toHaveBeenCalledWith(expectedResult);
|
||||
});
|
||||
});
|
||||
|
||||
it("sets sequence id", () => {
|
||||
|
|
|
@ -25,8 +25,6 @@ describe("<StockPinBindingsButton />", () => {
|
|||
const wrapper = mount(<StockPinBindingsButton {...p} />);
|
||||
wrapper.find("button").simulate("click");
|
||||
stockPinBindings.map(body =>
|
||||
expect(initSave).toHaveBeenCalledWith(expect.objectContaining({
|
||||
kind: "PinBinding", body
|
||||
})));
|
||||
expect(initSave).toHaveBeenCalledWith("PinBinding", body));
|
||||
});
|
||||
});
|
||||
|
|
|
@ -58,9 +58,8 @@ describe("createPlant", () => {
|
|||
|
||||
it("creates plant", () => {
|
||||
createPlant(fakeProps());
|
||||
expect(initSave).toHaveBeenCalledWith(expect.objectContaining({
|
||||
body: expect.objectContaining({ name: "Mint", x: 10, y: 20 })
|
||||
}));
|
||||
expect(initSave).toHaveBeenCalledWith("Point",
|
||||
expect.objectContaining({ name: "Mint", x: 10, y: 20 }));
|
||||
});
|
||||
|
||||
it("doesn't create plant outside planting area", () => {
|
||||
|
@ -102,9 +101,8 @@ describe("dropPlant", () => {
|
|||
|
||||
it("drops plant", () => {
|
||||
dropPlant(fakeProps());
|
||||
expect(initSave).toHaveBeenCalledWith(expect.objectContaining({
|
||||
body: expect.objectContaining({ name: "Mint", x: 10, y: 20 })
|
||||
}));
|
||||
expect(initSave).toHaveBeenCalledWith("Point",
|
||||
expect.objectContaining({ name: "Mint", x: 10, y: 20 }));
|
||||
});
|
||||
|
||||
it("throws error", () => {
|
||||
|
|
|
@ -36,17 +36,13 @@ describe("<CreatePoints />", () => {
|
|||
const wrapper = mount(<CreatePoints {...fakeProps()} />);
|
||||
wrapper.setState({ cx: 10, cy: 20, r: 30, color: "red" });
|
||||
clickButton(wrapper, 0, "create point");
|
||||
expect(initSave).toHaveBeenCalledWith({
|
||||
body: {
|
||||
expect(initSave).toHaveBeenCalledWith("Point",
|
||||
{
|
||||
meta: { color: "red", created_by: "farm-designer" },
|
||||
name: "Created Point",
|
||||
pointer_type: "GenericPointer",
|
||||
radius: 30, x: 10, y: 20, z: 0
|
||||
},
|
||||
kind: "Point",
|
||||
specialStatus: "",
|
||||
uuid: ""
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("deletes all points", () => {
|
||||
|
|
|
@ -82,13 +82,12 @@ describe("<CropInfo />", () => {
|
|||
const button = wrapper.find("button").last();
|
||||
expect(button.text()).toContain("location (100, 200)");
|
||||
button.simulate("click");
|
||||
expect(initSave).toHaveBeenCalledWith(expect.objectContaining({
|
||||
body: expect.objectContaining({
|
||||
expect(initSave).toHaveBeenCalledWith("Point",
|
||||
expect.objectContaining({
|
||||
name: "Mint",
|
||||
x: 100,
|
||||
y: 200,
|
||||
z: 0
|
||||
})
|
||||
}));
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
|
|
@ -20,11 +20,8 @@ describe("copySequence()", () => {
|
|||
const sequence = fakeSequence();
|
||||
const copy = copySequence(sequence);
|
||||
copy(jest.fn());
|
||||
expect(init).toHaveBeenCalledWith(expect.objectContaining({
|
||||
body: expect.objectContaining({
|
||||
name: "fake copy 1"
|
||||
})
|
||||
}));
|
||||
expect(init).toHaveBeenCalledWith("Sequence",
|
||||
expect.objectContaining({ name: "fake copy 1" }));
|
||||
});
|
||||
|
||||
it("updates current path", () => {
|
||||
|
|
|
@ -77,9 +77,8 @@ describe("<SequencesList />", () => {
|
|||
it("adds new sequence", () => {
|
||||
const wrapper = mount(<SequencesList {...fakeProps()} />);
|
||||
wrapper.find("button").first().simulate("click");
|
||||
expect(init).toHaveBeenCalledWith(expect.objectContaining({
|
||||
kind: "Sequence", body: expect.objectContaining({ body: [] })
|
||||
}));
|
||||
expect(init).toHaveBeenCalledWith("Sequence",
|
||||
expect.objectContaining({ body: [] }));
|
||||
expect(push).toHaveBeenCalledWith("/app/sequences/new_sequence_2");
|
||||
});
|
||||
|
||||
|
|
|
@ -39,9 +39,7 @@ describe("<ToolForm/>", () => {
|
|||
const wrapper = mount(<ToolForm {...fakeProps()} />);
|
||||
expect(wrapper.props().tools.length).toEqual(2);
|
||||
clickButton(wrapper, 2, "");
|
||||
expect(init).toHaveBeenCalledWith(expect.objectContaining({
|
||||
body: { name: "Tool 3" }
|
||||
}));
|
||||
expect(init).toHaveBeenCalledWith("Tool", { name: "Tool 3" });
|
||||
});
|
||||
|
||||
it("adds stock tools", () => {
|
||||
|
|
|
@ -45,6 +45,6 @@ describe("<ToolBayForm/>", () => {
|
|||
it("adds new tool slot", () => {
|
||||
const wrapper = mount(<ToolBayForm {...fakeProps()} />);
|
||||
clickButton(wrapper, 2, "");
|
||||
expect(init).toHaveBeenCalledWith(emptyToolSlot());
|
||||
expect(init).toHaveBeenCalledWith(emptyToolSlot().kind, emptyToolSlot().body);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue