Tests for moveToPoint()
parent
07bd01c086
commit
529ea9b90f
|
@ -13,7 +13,6 @@ import { FarmBotInternalConfig } from "farmbot/dist/config";
|
|||
import { now } from "../devices/connectivity/qos";
|
||||
|
||||
export const PING_INTERVAL = 2000;
|
||||
// export const ACTIVE_THRESHOLD = PING_INTERVAL * 2;
|
||||
|
||||
export const LAST_IN: keyof FarmBotInternalConfig = "LAST_PING_IN";
|
||||
export const LAST_OUT: keyof FarmBotInternalConfig = "LAST_PING_OUT";
|
||||
|
@ -33,10 +32,6 @@ export function markActive() {
|
|||
dispatchNetworkUp("bot.mqtt", now());
|
||||
}
|
||||
|
||||
// export function isInactive(last: number, now_: number): boolean {
|
||||
// return last ? (now_ - last) > ACTIVE_THRESHOLD : true;
|
||||
// }
|
||||
|
||||
export function sendOutboundPing(bot: Farmbot) {
|
||||
const id = uuid();
|
||||
const ok = () => pingOK(id, now()); markActive();
|
||||
|
|
|
@ -6,12 +6,19 @@ jest.mock("../../../history", () => ({
|
|||
history: { push: jest.fn() }
|
||||
}));
|
||||
|
||||
const mockMoveAbs = jest.fn();
|
||||
|
||||
jest.mock("../../../device", () => {
|
||||
return { getDevice: () => ({ moveAbsolute: mockMoveAbs }) };
|
||||
});
|
||||
|
||||
import * as React from "react";
|
||||
import { mount } from "enzyme";
|
||||
import { EditPoint, EditPointProps, mapStateToProps } from "../point_info";
|
||||
import { EditPoint, EditPointProps, mapStateToProps, moveToPoint } from "../point_info";
|
||||
import { fakePoint } from "../../../__test_support__/fake_state/resources";
|
||||
import { fakeState } from "../../../__test_support__/fake_state";
|
||||
import { buildResourceIndex } from "../../../__test_support__/resource_index_builder";
|
||||
import { getDevice } from "../../../device";
|
||||
|
||||
describe("<EditPoint />", () => {
|
||||
const fakeProps = (): EditPointProps => ({
|
||||
|
@ -42,3 +49,12 @@ describe("mapStateToProps()", () => {
|
|||
expect(props.findPoint(1)).toEqual(point);
|
||||
});
|
||||
});
|
||||
|
||||
describe("moveToPoint()", () => {
|
||||
it("moves the device to a particular point", () => {
|
||||
const coords = { x: 1, y: -2, z: 3 };
|
||||
const mover = moveToPoint(coords);
|
||||
mover();
|
||||
expect(getDevice().moveAbsolute).toHaveBeenCalledWith(coords);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -6,11 +6,14 @@ import {
|
|||
import { t } from "../../i18next_wrapper";
|
||||
import { history, getPathArray } from "../../history";
|
||||
import { Everything } from "../../interfaces";
|
||||
import { TaggedPoint } from "farmbot";
|
||||
import { TaggedPoint, Vector3 } from "farmbot";
|
||||
import { maybeFindPointById } from "../../resources/selectors";
|
||||
import { DeleteButton } from "../../controls/pin_form_fields";
|
||||
import { getDevice } from "../../device";
|
||||
|
||||
export const moveToPoint =
|
||||
(body: Vector3) => () => getDevice().moveAbsolute(body);
|
||||
|
||||
export interface EditPointProps {
|
||||
dispatch: Function;
|
||||
findPoint(id: number): TaggedPoint | undefined;
|
||||
|
@ -51,7 +54,7 @@ export class EditPoint extends React.Component<EditPointProps, {}> {
|
|||
<button
|
||||
className="green fb-button"
|
||||
type="button"
|
||||
onClick={() => getDevice().moveAbsolute(body)}>
|
||||
onClick={moveToPoint(body)}>
|
||||
{t("Move Device to Point")}
|
||||
</button>
|
||||
<DeleteButton
|
||||
|
|
Loading…
Reference in New Issue