Remove useless guard clauses, test for older code

pull/1455/head
Rick Carlino 2019-09-24 11:48:11 -05:00
parent 9a59395715
commit fc1f80c4fc
5 changed files with 46 additions and 18 deletions

View File

@ -3,18 +3,26 @@ import { fakeWebcamFeed } from "../../../__test_support__/fake_state/resources";
import { mount } from "enzyme";
import { Show, IndexIndicator } from "../show";
import { props } from "../test_helpers";
import { PLACEHOLDER_FARMBOT } from "../../../farmware/images/image_flipper";
describe("<Show/>", () => {
const feed1 = fakeWebcamFeed();
const feed2 = fakeWebcamFeed();
const p = props([feed1, feed2]);
it("Renders feed title", () => {
const feed1 = fakeWebcamFeed();
const feed2 = fakeWebcamFeed();
const p = props([feed1, feed2]);
const el = mount(<Show {...p} />);
expect(el.text()).toContain(feed1.body.name);
el.find(".image-flipper-right").first().simulate("click");
el.render();
expect(el.text()).toContain(feed2.body.name);
});
it("returns a PLACEHOLDER_FEED", () => {
const comp = new Show(p);
const result = comp.getMessage("http://geocities.com/" + PLACEHOLDER_FARMBOT);
expect(result).toEqual("Click the edit button to add or edit a feed URL.");
});
});
describe("<IndexIndicator/>", () => {

View File

@ -27,9 +27,8 @@ export function joinFarmEventsToExecutable(
executable_type: body.executable_type,
executable: executable1.body
};
} else {
throw new Error("Bad executable ID (sequence): " + id);
}
break;
case "Regimen":
const executable2 = regimenById[id];
if (executable2) {
@ -38,12 +37,9 @@ export function joinFarmEventsToExecutable(
executable_type: body.executable_type,
executable: executable2.body
};
} else {
throw new Error("Bad executable ID (regimen): " + id);
}
}
} else {
throw new Error("Farmevent had no ID");
}
throw new Error("Impossible?");
}));
}

View File

@ -38,10 +38,6 @@ export function groupRegimenItemsByWeek(weeks: Week[], OFFSET: number,
})
// Transform the sorted array of values into a regimenItem[] array.
.map<RegimenItem>(time_offset => {
if (seq.id) {
return { time_offset, sequence_id: seq.id };
} else {
throw new Error("Impossible???");
}
return { time_offset, sequence_id: seq.id || -1 };
});
}

View File

@ -0,0 +1,19 @@
jest.mock("../input_unknown", () => ({
InputUnknown: jest.fn(() => { })
}));
import { StepInputBox } from "../step_input_box";
import { DeepPartial } from "redux";
import { StepInputProps } from "../../interfaces";
import { InputUnknown } from "../input_unknown";
describe("StepInputBox", () => {
it("handles unknown `field` via <InputUnknown/>", () => {
const props: DeepPartial<StepInputProps> = {
// tslint:disable-next-line:no-any
field: ("something else" as any)
};
StepInputBox(props as StepInputProps);
expect(InputUnknown).toHaveBeenCalledWith(props);
});
});

View File

@ -6,13 +6,22 @@ import { StepInputProps } from "../interfaces";
export function StepInputBox(props: StepInputProps) {
if (props.fieldOverride) { return <InputDefault {...props} />; }
switch (props.field) {
case "label": case "lhs": case "message": case "milliseconds": case "op":
case "pin_mode": case "pin_number": case "pin_value": case "rhs":
case "label":
case "lhs":
case "message":
case "milliseconds":
case "op":
case "pin_mode":
case "pin_number":
case "pin_value":
case "rhs":
case "sequence_id":
case "x": case "y": case "z":
case "speed":
case "x":
case "y":
case "z":
return <InputDefault {...props} />;
default:
return <InputUnknown {...props} />;
return InputUnknown(props);
}
}