fix tests

pull/1027/head
gabrielburnworth 2018-10-31 16:49:05 -07:00
parent 38adc49714
commit 61926d2415
12 changed files with 38 additions and 55 deletions

View File

@ -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",

View File

@ -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));
};
}

View File

@ -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);
});
});

View File

@ -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", () => {

View File

@ -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));
});
});

View File

@ -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", () => {

View File

@ -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", () => {

View File

@ -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
})
}));
}));
});
});

View File

@ -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", () => {

View File

@ -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");
});

View File

@ -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", () => {

View File

@ -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);
});
});