Run tslinst --fix
parent
fc92cd503e
commit
d385531f8d
|
@ -48,7 +48,6 @@
|
|||
"curly": true,
|
||||
"eofline": true,
|
||||
"no-angle-bracket-type-assertion": true,
|
||||
"no-any": true,
|
||||
"no-arg": true,
|
||||
"no-bitwise": true,
|
||||
"no-conditional-assignment": true,
|
||||
|
|
|
@ -3,14 +3,14 @@ import { ControlsPopup } from "../controls_popup";
|
|||
import { mount } from "enzyme";
|
||||
|
||||
describe("<ControlsPopup />", () => {
|
||||
let wrapper = mount(<ControlsPopup dispatch={jest.fn()} />);
|
||||
const wrapper = mount(<ControlsPopup dispatch={jest.fn()} />);
|
||||
|
||||
it("Has a false initial state", () => {
|
||||
expect(wrapper.state("isOpen")).toBeFalsy();
|
||||
});
|
||||
|
||||
it("Toggles state", () => {
|
||||
let parent = wrapper.find("div").first();
|
||||
const parent = wrapper.find("div").first();
|
||||
parent.simulate("click");
|
||||
expect(wrapper.state("isOpen")).toBeTruthy();
|
||||
});
|
||||
|
|
|
@ -20,19 +20,19 @@ const STUB_RESOURCE: TaggedFarmEvent = {
|
|||
};
|
||||
|
||||
test("buildResourceIndex - base case", () => {
|
||||
let result1 = buildResourceIndex(FAKE_RESOURCES);
|
||||
let { index } = result1;
|
||||
const result1 = buildResourceIndex(FAKE_RESOURCES);
|
||||
const { index } = result1;
|
||||
const OK_LENGTH = FAKE_RESOURCES.length;
|
||||
expect(index.all.length).toBe(OK_LENGTH);
|
||||
expect(Object.keys(index.references).length).toBe(OK_LENGTH);
|
||||
});
|
||||
|
||||
test("buildResourceIndex - add a FarmEvent", () => {
|
||||
let db = buildResourceIndex([STUB_RESOURCE]);
|
||||
let fe = db.index.references[db.index.byKind.farm_events[0]];
|
||||
const db = buildResourceIndex([STUB_RESOURCE]);
|
||||
const fe = db.index.references[db.index.byKind.farm_events[0]];
|
||||
expect(fe).toBeTruthy();
|
||||
if (fe && fe.kind === "farm_events") {
|
||||
let { body } = fe;
|
||||
const { body } = fe;
|
||||
expect(body).toEqual(STUB_RESOURCE.body);
|
||||
} else {
|
||||
fail("fe was falsy or not a farm event.");
|
||||
|
|
|
@ -4,8 +4,8 @@ import { render } from "enzyme";
|
|||
|
||||
describe("spinner", () => {
|
||||
it("renders a circle", () => {
|
||||
let spinner = render(<Spinner radius={5} strokeWidth={5} />);
|
||||
let circles = spinner.find("circle");
|
||||
const spinner = render(<Spinner radius={5} strokeWidth={5} />);
|
||||
const circles = spinner.find("circle");
|
||||
expect(circles.length).toEqual(1);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -4,7 +4,7 @@ import { FourOhFour } from "../404";
|
|||
|
||||
describe("<FourOhFour/>", function () {
|
||||
it("renders helpful text", function () {
|
||||
let dom = mount(<FourOhFour />);
|
||||
const dom = mount(<FourOhFour />);
|
||||
expect(dom.html()).toContain("Page Not Found");
|
||||
});
|
||||
});
|
||||
|
|
|
@ -3,7 +3,7 @@ import { history, push } from "../history";
|
|||
describe("push()", () => {
|
||||
it("calls history with a URL", () => {
|
||||
const URL = "/wow.html";
|
||||
let oldFn = history.push;
|
||||
const oldFn = history.push;
|
||||
history.push = jest.fn();
|
||||
push(URL);
|
||||
expect(history.push).toHaveBeenCalledWith(URL);
|
||||
|
|
|
@ -10,7 +10,7 @@ import {
|
|||
} from "../util";
|
||||
describe("util", () => {
|
||||
describe("safeStringFetch", () => {
|
||||
let data = {
|
||||
const data = {
|
||||
// tslint:disable-next-line:no-null-keyword
|
||||
"null": null,
|
||||
"undefined": undefined,
|
||||
|
@ -47,8 +47,8 @@ describe("util", () => {
|
|||
|
||||
describe("betterCompact", () => {
|
||||
it("removes falsy values", () => {
|
||||
let before = [{}, {}, undefined];
|
||||
let after = betterCompact(before);
|
||||
const before = [{}, {}, undefined];
|
||||
const after = betterCompact(before);
|
||||
expect(after.length).toBe(2);
|
||||
expect(after).not.toContain(undefined);
|
||||
});
|
||||
|
@ -56,8 +56,8 @@ describe("util", () => {
|
|||
|
||||
describe("defensiveClone", () => {
|
||||
it("deep clones any serializable object", () => {
|
||||
let origin = { a: "b", c: 2, d: [{ e: { f: "g" } }] };
|
||||
let child = defensiveClone(origin);
|
||||
const origin = { a: "b", c: 2, d: [{ e: { f: "g" } }] };
|
||||
const child = defensiveClone(origin);
|
||||
origin.a = "--";
|
||||
origin.c = 0;
|
||||
origin.d[0].e.f = "--";
|
||||
|
@ -82,7 +82,7 @@ describe("util", () => {
|
|||
|
||||
describe("prettyPrintApiErrors", () => {
|
||||
it("handles properly formatted API error messages", () => {
|
||||
let result = prettyPrintApiErrors({
|
||||
const result = prettyPrintApiErrors({
|
||||
response: {
|
||||
data: {
|
||||
email: "can't be blank"
|
||||
|
|
|
@ -16,13 +16,13 @@ describe("deleteUser()", () => {
|
|||
it("cancels the account", (done) => {
|
||||
expect.assertions(2);
|
||||
API.setBaseUrl("http://example.com:80");
|
||||
let thunk = deleteUser({ password: "Foo!" });
|
||||
let dispatch = jest.fn();
|
||||
let getState = jest.fn();
|
||||
const thunk = deleteUser({ password: "Foo!" });
|
||||
const dispatch = jest.fn();
|
||||
const getState = jest.fn();
|
||||
getState.mockImplementation(() => ({ auth: {} }));
|
||||
thunk(dispatch, getState);
|
||||
moxios.wait(function () {
|
||||
let request = moxios.requests.mostRecent();
|
||||
const request = moxios.requests.mostRecent();
|
||||
request.respondWith({
|
||||
status: 200,
|
||||
response: {}
|
||||
|
|
|
@ -8,7 +8,7 @@ import { API } from "../../api/api";
|
|||
describe("<ChangePassword/>", function () {
|
||||
|
||||
function testCase() {
|
||||
let el = mount(<ChangePassword />);
|
||||
const el = mount(<ChangePassword />);
|
||||
return {
|
||||
el,
|
||||
instance(): ChangePassword { return el.instance() as ChangePassword; }
|
||||
|
@ -16,7 +16,7 @@ describe("<ChangePassword/>", function () {
|
|||
}
|
||||
|
||||
it("clears the form", function () {
|
||||
let { el, instance } = testCase();
|
||||
const { el, instance } = testCase();
|
||||
// let inst = el.instance() as ChangePassword;
|
||||
el.setState({
|
||||
status: SpecialStatus.DIRTY,
|
||||
|
@ -31,7 +31,7 @@ describe("<ChangePassword/>", function () {
|
|||
});
|
||||
|
||||
it("doesnt fire maybeClearForm() if form is filled", () => {
|
||||
let { el, instance } = testCase();
|
||||
const { el, instance } = testCase();
|
||||
el.setState({
|
||||
status: SpecialStatus.DIRTY,
|
||||
form: { ...instance().state.form, password: "X" }
|
||||
|
@ -45,7 +45,7 @@ describe("<ChangePassword/>", function () {
|
|||
});
|
||||
|
||||
it("it does fire maybeClearForm() when form is empty.", () => {
|
||||
let { el, instance } = testCase();
|
||||
const { el, instance } = testCase();
|
||||
el.setState({
|
||||
status: SpecialStatus.DIRTY,
|
||||
form: {
|
||||
|
@ -60,7 +60,7 @@ describe("<ChangePassword/>", function () {
|
|||
});
|
||||
|
||||
it("sets a field", () => {
|
||||
let { el, instance } = testCase();
|
||||
const { el, instance } = testCase();
|
||||
instance().set("password")({ currentTarget: { value: "foo" } } as any);
|
||||
el.update();
|
||||
expect(instance().state.form.password).toBe("foo");
|
||||
|
@ -77,11 +77,11 @@ describe("<ChangePassword/>", function () {
|
|||
});
|
||||
|
||||
it("saves (KO)", (done) => {
|
||||
let { instance } = testCase();
|
||||
const { instance } = testCase();
|
||||
API.setBaseUrl("localhost");
|
||||
instance().save();
|
||||
moxios.wait(function () {
|
||||
let request = moxios.requests.mostRecent();
|
||||
const request = moxios.requests.mostRecent();
|
||||
request.respondWith({
|
||||
status: 422,
|
||||
response: { bad: "data" }
|
||||
|
@ -95,11 +95,11 @@ describe("<ChangePassword/>", function () {
|
|||
});
|
||||
|
||||
it("saves (OK)", (done) => {
|
||||
let { instance } = testCase();
|
||||
const { instance } = testCase();
|
||||
API.setBaseUrl("localhost");
|
||||
instance().save();
|
||||
moxios.wait(function () {
|
||||
let request = moxios.requests.mostRecent();
|
||||
const request = moxios.requests.mostRecent();
|
||||
request.respondWith({
|
||||
status: 200,
|
||||
response: {}
|
||||
|
|
|
@ -6,12 +6,12 @@ import { fakeUser } from "../../__test_support__/fake_state/resources";
|
|||
|
||||
describe("<Settings/>", function () {
|
||||
it("saves user settings", function () {
|
||||
let props: SettingsPropTypes = {
|
||||
const props: SettingsPropTypes = {
|
||||
user: fakeUser(),
|
||||
onChange: jest.fn(),
|
||||
onSave: jest.fn()
|
||||
};
|
||||
let dom = mount(<Settings {...props} />);
|
||||
const dom = mount(<Settings {...props} />);
|
||||
expect(props.onSave).not.toHaveBeenCalled();
|
||||
dom.find("button").simulate("click");
|
||||
expect(props.onSave).toHaveBeenCalled();
|
||||
|
|
|
@ -8,7 +8,7 @@ import { UnsafeError } from "../interfaces";
|
|||
|
||||
export function deleteUser(payload: DeletionRequest): Thunk {
|
||||
return (dispatch, getState) => {
|
||||
let state = getState().auth;
|
||||
const state = getState().auth;
|
||||
if (state) {
|
||||
axios({
|
||||
method: "delete",
|
||||
|
|
|
@ -44,7 +44,7 @@ export class ChangePassword extends React.Component<{}, ChangePWState> {
|
|||
|
||||
set = (key: keyof PasswordForm) =>
|
||||
(e: React.SyntheticEvent<HTMLInputElement>) => {
|
||||
let wow = {
|
||||
const wow = {
|
||||
status: SpecialStatus.DIRTY,
|
||||
form: { ...this.state.form, [key]: e.currentTarget.value }
|
||||
};
|
||||
|
|
|
@ -5,7 +5,7 @@ import { SettingsPropTypes } from "../interfaces";
|
|||
|
||||
export class Settings extends React.Component<SettingsPropTypes, {}> {
|
||||
render() {
|
||||
let { user, onChange, onSave } = this.props;
|
||||
const { user, onChange, onSave } = this.props;
|
||||
return <Widget>
|
||||
<WidgetHeader title="Account Settings">
|
||||
<SaveBtn
|
||||
|
|
|
@ -3,7 +3,7 @@ import { Props } from "./interfaces";
|
|||
import { getUserAccountSettings } from "../resources/selectors";
|
||||
|
||||
export function mapStateToProps(props: Everything): Props {
|
||||
let user = getUserAccountSettings(props.resources.index);
|
||||
const user = getUserAccountSettings(props.resources.index);
|
||||
|
||||
return {
|
||||
user,
|
||||
|
|
|
@ -48,7 +48,7 @@ export class API {
|
|||
|
||||
static parseURL(url: string): UrlInfo {
|
||||
// Such an amazing hack!
|
||||
let info = document.createElement("a");
|
||||
const info = document.createElement("a");
|
||||
info.href = url;
|
||||
return info;
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ export class API {
|
|||
private readonly host: string;
|
||||
|
||||
constructor(input: string) {
|
||||
let url = API.parseURL(input);
|
||||
const url = API.parseURL(input);
|
||||
this.protocol = url.protocol as ProtocolString;
|
||||
this.hostname = url.hostname;
|
||||
this.port = url.port;
|
||||
|
|
|
@ -53,8 +53,8 @@ interface EditStepProps {
|
|||
* of `edit()` or `overwrite`. */
|
||||
export function editStep({ step, sequence, index, executor }: EditStepProps) {
|
||||
// https://en.wikipedia.org/wiki/NeXTSTEP
|
||||
let nextStep = defensiveClone(step);
|
||||
let nextSeq = defensiveClone(sequence);
|
||||
const nextStep = defensiveClone(step);
|
||||
const nextSeq = defensiveClone(sequence);
|
||||
// Let the developer safely perform mutations here:
|
||||
executor(nextStep);
|
||||
nextSeq.body.body = nextSeq.body.body || [];
|
||||
|
@ -73,18 +73,18 @@ export function init(resource: TaggedResource): ReduxAction<TaggedResource> {
|
|||
|
||||
export function initSave(resource: TaggedResource) {
|
||||
return function (dispatch: Function, getState: GetState) {
|
||||
let action = init(resource);
|
||||
const action = init(resource);
|
||||
if (resource.body.id === 0) { delete resource.body.id; }
|
||||
dispatch(action);
|
||||
let nextState = getState().resources.index;
|
||||
let tr = findByUuid(nextState, action.payload.uuid);
|
||||
const nextState = getState().resources.index;
|
||||
const tr = findByUuid(nextState, action.payload.uuid);
|
||||
return dispatch(save(tr.uuid));
|
||||
};
|
||||
}
|
||||
|
||||
export function save(uuid: string) {
|
||||
return function (dispatch: Function, getState: GetState) {
|
||||
let resource = findByUuid(getState().resources.index, uuid);
|
||||
const resource = findByUuid(getState().resources.index, uuid);
|
||||
dispatch({ type: "SAVE_RESOURCE_START", payload: resource });
|
||||
return dispatch(update(uuid));
|
||||
};
|
||||
|
@ -98,8 +98,8 @@ function update(uuid: string) {
|
|||
|
||||
export function destroy(uuid: string) {
|
||||
return function (dispatch: Function, getState: GetState) {
|
||||
let resource = findByUuid(getState().resources.index, uuid);
|
||||
let maybeProceed = confirmationChecker(resource);
|
||||
const resource = findByUuid(getState().resources.index, uuid);
|
||||
const maybeProceed = confirmationChecker(resource);
|
||||
return maybeProceed(() => {
|
||||
if (resource.body.id) {
|
||||
return axios
|
||||
|
@ -123,7 +123,7 @@ export function saveAll(input: TaggedResource[],
|
|||
callback: () => void = _.noop,
|
||||
errBack: (err: UnsafeError) => void = _.noop) {
|
||||
return function (dispatch: Function, getState: GetState) {
|
||||
let p = input
|
||||
const p = input
|
||||
.filter(x => x.specialStatus === SpecialStatus.DIRTY)
|
||||
.map(tts => dispatch(save(tts.uuid)));
|
||||
Promise.all(p).then(callback, errBack);
|
||||
|
@ -144,7 +144,7 @@ export function urlFor(tag: ResourceName) {
|
|||
logs: API.current.logsPath,
|
||||
webcam_feed: API.current.webcamFeedPath
|
||||
};
|
||||
let url = OPTIONS[tag];
|
||||
const url = OPTIONS[tag];
|
||||
if (url) {
|
||||
return url;
|
||||
} else {
|
||||
|
@ -157,8 +157,8 @@ export function urlFor(tag: ResourceName) {
|
|||
function updateViaAjax(index: ResourceIndex,
|
||||
uuid: string,
|
||||
dispatch: Function) {
|
||||
let resource = findByUuid(index, uuid);
|
||||
let { body, kind } = resource;
|
||||
const resource = findByUuid(index, uuid);
|
||||
const { body, kind } = resource;
|
||||
let verb: "post" | "put";
|
||||
let url = urlFor(kind);
|
||||
if (body.id) {
|
||||
|
@ -169,9 +169,9 @@ function updateViaAjax(index: ResourceIndex,
|
|||
}
|
||||
return axios[verb](url, body)
|
||||
.then(function (resp: HttpData<typeof resource.body>) {
|
||||
let r1 = defensiveClone(resource);
|
||||
let r2 = { body: defensiveClone(resp.data) };
|
||||
let newTR = _.assign({}, r1, r2);
|
||||
const r1 = defensiveClone(resource);
|
||||
const r2 = { body: defensiveClone(resp.data) };
|
||||
const newTR = _.assign({}, r1, r2);
|
||||
if (isTaggedResource(newTR)) {
|
||||
dispatch(updateOK(newTR));
|
||||
} else {
|
||||
|
@ -184,14 +184,14 @@ function updateViaAjax(index: ResourceIndex,
|
|||
});
|
||||
}
|
||||
|
||||
let MUST_CONFIRM_LIST: ResourceName[] = [
|
||||
const MUST_CONFIRM_LIST: ResourceName[] = [
|
||||
"farm_events",
|
||||
"points",
|
||||
"sequences",
|
||||
"regimens"
|
||||
];
|
||||
|
||||
let confirmationChecker = (resource: TaggedResource) =>
|
||||
const confirmationChecker = (resource: TaggedResource) =>
|
||||
<T>(proceed: () => T): T | undefined => {
|
||||
if (MUST_CONFIRM_LIST.includes(resource.kind)) {
|
||||
if (confirm("Are you sure you want to delete this item?")) {
|
||||
|
|
|
@ -29,7 +29,7 @@ export function didLogin(authState: AuthState, dispatch: Function) {
|
|||
// We need to handle OK logins for numerous use cases (Ex: login & registration)
|
||||
function onLogin(dispatch: Function) {
|
||||
return (response: HttpData<AuthState>) => {
|
||||
let { data } = response;
|
||||
const { data } = response;
|
||||
Session.replace(data);
|
||||
didLogin(data, dispatch);
|
||||
push("/app/controls");
|
||||
|
@ -70,7 +70,7 @@ export function register(name: string,
|
|||
confirmation: string,
|
||||
url: string): Thunk {
|
||||
return dispatch => {
|
||||
let p = requestRegistration(name,
|
||||
const p = requestRegistration(name,
|
||||
email,
|
||||
password,
|
||||
confirmation,
|
||||
|
@ -98,7 +98,7 @@ function requestRegistration(name: string,
|
|||
password: string,
|
||||
confirmation: string,
|
||||
url: string) {
|
||||
let form = {
|
||||
const form = {
|
||||
user: {
|
||||
email: email,
|
||||
password: password,
|
||||
|
@ -113,7 +113,7 @@ function requestRegistration(name: string,
|
|||
function requestToken(email: string,
|
||||
password: string,
|
||||
url: string) {
|
||||
let payload = { user: { email: email, password: password } };
|
||||
const payload = { user: { email: email, password: password } };
|
||||
// Set the base URL once here.
|
||||
// It will get set once more when we get the "iss" claim from the JWT.
|
||||
API.setBaseUrl(url);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
jest.unmock("../../auth/actions");
|
||||
const actions = require("../../auth/actions");
|
||||
let didLogin = jest.fn();
|
||||
const didLogin = jest.fn();
|
||||
jest.mock("../../session", () => ({
|
||||
Session: {
|
||||
getNum: () => undefined,
|
||||
|
@ -14,9 +14,9 @@ import { ready } from "../actions";
|
|||
const STUB_STATE = { auth: "FOO BAR BAZ" };
|
||||
describe("Actions", () => {
|
||||
it("fetches configs and calls didLogin()", () => {
|
||||
let dispatch = jest.fn();
|
||||
let getState = jest.fn(() => STUB_STATE);
|
||||
let thunk = ready();
|
||||
const dispatch = jest.fn();
|
||||
const getState = jest.fn(() => STUB_STATE);
|
||||
const thunk = ready();
|
||||
thunk(dispatch, getState);
|
||||
expect(didLogin.mock.calls.length).toBe(1);
|
||||
});
|
||||
|
|
|
@ -5,7 +5,7 @@ import { Session } from "../session";
|
|||
/** Lets Redux know that the app is ready to bootstrap. */
|
||||
export function ready(): Thunk {
|
||||
return (dispatch, getState) => {
|
||||
let state = Session.getAll() || getState().auth;
|
||||
const state = Session.getAll() || getState().auth;
|
||||
if (state) { didLogin(state, dispatch); }
|
||||
};
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ import { ChangeApiHost, ChangeApiPort, ConfigState } from "./interfaces";
|
|||
import { API } from "../api";
|
||||
import { Actions } from "../constants";
|
||||
|
||||
let initialState: ConfigState = {
|
||||
const initialState: ConfigState = {
|
||||
host: location.hostname,
|
||||
// It gets annoying to manually change the port # in dev mode.
|
||||
// I automatically point to port 3000 on local.
|
||||
|
|
|
@ -2,11 +2,11 @@ import { mount } from "enzyme";
|
|||
import { AxisDisplayGroup } from "../axis_display_group";
|
||||
|
||||
describe("<AxisDisplayGroup />", () => {
|
||||
let params = {
|
||||
const params = {
|
||||
position: { x: undefined, y: undefined, z: undefined },
|
||||
label: "Heyoo"
|
||||
};
|
||||
let wrapper = mount(AxisDisplayGroup(params));
|
||||
const wrapper = mount(AxisDisplayGroup(params));
|
||||
|
||||
it("has 3 inputs and a label", () => {
|
||||
expect(wrapper.find("input").length).toEqual(3);
|
||||
|
@ -14,8 +14,8 @@ describe("<AxisDisplayGroup />", () => {
|
|||
});
|
||||
|
||||
it("renders '' for falsy values", () => {
|
||||
let inputs = wrapper.find("input");
|
||||
let label = wrapper.find("label");
|
||||
const inputs = wrapper.find("input");
|
||||
const label = wrapper.find("label");
|
||||
expect(inputs.at(0).props().value).toBe("");
|
||||
expect(inputs.at(1).props().value).toBe("");
|
||||
expect(inputs.at(2).props().value).toBe("");
|
||||
|
@ -23,7 +23,7 @@ describe("<AxisDisplayGroup />", () => {
|
|||
});
|
||||
|
||||
it("renders real values for ... real values", () => {
|
||||
let props = {
|
||||
const props = {
|
||||
position: { x: 0, y: 0, z: 0 },
|
||||
label: "Heyoo"
|
||||
};
|
||||
|
@ -32,9 +32,9 @@ describe("<AxisDisplayGroup />", () => {
|
|||
y: 2,
|
||||
z: 3
|
||||
};
|
||||
let el = mount(AxisDisplayGroup(props));
|
||||
let inputs = el.find("input");
|
||||
let label = el.find("label");
|
||||
const el = mount(AxisDisplayGroup(props));
|
||||
const inputs = el.find("input");
|
||||
const label = el.find("label");
|
||||
|
||||
expect(inputs.at(0).props().value).toBe(1);
|
||||
expect(inputs.at(1).props().value).toBe(2);
|
||||
|
|
|
@ -7,16 +7,16 @@ describe("<AxisInputBoxGroup />", () => {
|
|||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
let props = {
|
||||
const props = {
|
||||
position: { x: undefined, y: undefined, z: undefined },
|
||||
onCommit: jest.fn(),
|
||||
disabled: false
|
||||
};
|
||||
|
||||
it("has 3 inputs and a button", () => {
|
||||
let wrapper = mount(<AxisInputBoxGroup {...props} />);
|
||||
const wrapper = mount(<AxisInputBoxGroup {...props} />);
|
||||
expect(wrapper.find("input").length).toEqual(3);
|
||||
let buttons = wrapper.find("button");
|
||||
const buttons = wrapper.find("button");
|
||||
expect(buttons.length).toEqual(1);
|
||||
expect(buttons.text().toLowerCase()).toEqual("go");
|
||||
buttons.simulate("click");
|
||||
|
@ -26,7 +26,7 @@ describe("<AxisInputBoxGroup />", () => {
|
|||
|
||||
it("button is disabled", () => {
|
||||
props.disabled = true;
|
||||
let wrapper = mount(<AxisInputBoxGroup {...props} />);
|
||||
const wrapper = mount(<AxisInputBoxGroup {...props} />);
|
||||
wrapper.find("button").simulate("click");
|
||||
expect(props.onCommit).not.toHaveBeenCalled();
|
||||
});
|
||||
|
|
|
@ -5,19 +5,19 @@ import { Xyz } from "farmbot/dist";
|
|||
|
||||
describe("<AxisInputBox/>", () => {
|
||||
function inputBoxWithValue(value: number | undefined) {
|
||||
let axis: Xyz = "x";
|
||||
let props = { axis, value, onChange: jest.fn() };
|
||||
const axis: Xyz = "x";
|
||||
const props = { axis, value, onChange: jest.fn() };
|
||||
return mount(<AxisInputBox {...props } />);
|
||||
}
|
||||
|
||||
it("renders 0 if 0", () => {
|
||||
// HISTORIC CONTEXT: We hit a bug where entering "0" resulting in -1.
|
||||
let el = inputBoxWithValue(0);
|
||||
const el = inputBoxWithValue(0);
|
||||
expect(el.find("input").first().props().value).toBe(0);
|
||||
});
|
||||
|
||||
it("renders '' if undefined", () => {
|
||||
let el = inputBoxWithValue(undefined);
|
||||
const el = inputBoxWithValue(undefined);
|
||||
expect(el.find("input").first().props().value).toBe("");
|
||||
});
|
||||
});
|
||||
|
|
|
@ -5,7 +5,7 @@ jest.mock("../../device", () => ({
|
|||
}
|
||||
}
|
||||
}));
|
||||
let mockOk = jest.fn();
|
||||
const mockOk = jest.fn();
|
||||
jest.mock("farmbot-toastr", () => ({ success: mockOk }));
|
||||
|
||||
import * as React from "react";
|
||||
|
@ -19,7 +19,7 @@ describe("<DirectionButton/>", function () {
|
|||
jest.clearAllMocks();
|
||||
buttonProps.disabled = false;
|
||||
});
|
||||
let buttonProps: DirectionButtonProps = {
|
||||
const buttonProps: DirectionButtonProps = {
|
||||
axis: "y",
|
||||
direction: "up",
|
||||
isInverted: false,
|
||||
|
@ -28,25 +28,25 @@ describe("<DirectionButton/>", function () {
|
|||
};
|
||||
|
||||
it("calls move command", () => {
|
||||
let { mock } = devices.current.moveRelative as jest.Mock<{}>;
|
||||
let btn = mount(<DirectionButton {...buttonProps} />);
|
||||
const { mock } = devices.current.moveRelative as jest.Mock<{}>;
|
||||
const btn = mount(<DirectionButton {...buttonProps} />);
|
||||
btn.simulate("click");
|
||||
expect(mock.calls.length).toEqual(1);
|
||||
});
|
||||
|
||||
it("is disabled", () => {
|
||||
let { mock } = devices.current.moveRelative as jest.Mock<{}>;
|
||||
const { mock } = devices.current.moveRelative as jest.Mock<{}>;
|
||||
buttonProps.disabled = true;
|
||||
let btn = mount(<DirectionButton {...buttonProps} />);
|
||||
const btn = mount(<DirectionButton {...buttonProps} />);
|
||||
btn.simulate("click");
|
||||
expect(mock.calls.length).toEqual(0);
|
||||
});
|
||||
|
||||
it("call has correct args", () => {
|
||||
let { mock } = devices.current.moveRelative as jest.Mock<{}>;
|
||||
let btn = mount(<DirectionButton {...buttonProps} />);
|
||||
const { mock } = devices.current.moveRelative as jest.Mock<{}>;
|
||||
const btn = mount(<DirectionButton {...buttonProps} />);
|
||||
btn.simulate("click");
|
||||
let argList = mock.calls[0][0];
|
||||
const argList = mock.calls[0][0];
|
||||
expect(argList.x).toEqual(0);
|
||||
expect(argList.y).toEqual(-1000);
|
||||
expect(argList.z).toEqual(0);
|
||||
|
|
|
@ -5,7 +5,7 @@ jest.mock("../../device", () => ({
|
|||
}
|
||||
}
|
||||
}));
|
||||
let mockOk = jest.fn();
|
||||
const mockOk = jest.fn();
|
||||
jest.mock("farmbot-toastr", () => ({ success: mockOk }));
|
||||
|
||||
import * as React from "react";
|
||||
|
@ -20,7 +20,7 @@ describe("<JogButtons/>", function () {
|
|||
jest.clearAllMocks();
|
||||
jogButtonProps.disabled = false;
|
||||
});
|
||||
let jogButtonProps: JogMovementControlsProps = {
|
||||
const jogButtonProps: JogMovementControlsProps = {
|
||||
bot: bot,
|
||||
x_axis_inverted: false,
|
||||
y_axis_inverted: false,
|
||||
|
@ -29,25 +29,25 @@ describe("<JogButtons/>", function () {
|
|||
};
|
||||
|
||||
it("calls home command", () => {
|
||||
let { mock } = devices.current.home as jest.Mock<{}>;
|
||||
let jogButtons = mount(<JogButtons {...jogButtonProps} />);
|
||||
const { mock } = devices.current.home as jest.Mock<{}>;
|
||||
const jogButtons = mount(<JogButtons {...jogButtonProps} />);
|
||||
jogButtons.find("button").at(2).simulate("click");
|
||||
expect(mock.calls.length).toEqual(1);
|
||||
});
|
||||
|
||||
it("is disabled", () => {
|
||||
let { mock } = devices.current.home as jest.Mock<{}>;
|
||||
const { mock } = devices.current.home as jest.Mock<{}>;
|
||||
jogButtonProps.disabled = true;
|
||||
let jogButtons = mount(<JogButtons {...jogButtonProps} />);
|
||||
const jogButtons = mount(<JogButtons {...jogButtonProps} />);
|
||||
jogButtons.find("button").at(2).simulate("click");
|
||||
expect(mock.calls.length).toEqual(0);
|
||||
});
|
||||
|
||||
it("call has correct args", () => {
|
||||
let { mock } = devices.current.home as jest.Mock<{}>;
|
||||
let jogButtons = mount(<JogButtons {...jogButtonProps} />);
|
||||
const { mock } = devices.current.home as jest.Mock<{}>;
|
||||
const jogButtons = mount(<JogButtons {...jogButtonProps} />);
|
||||
jogButtons.find("button").at(2).simulate("click");
|
||||
let argList = mock.calls[0][0];
|
||||
const argList = mock.calls[0][0];
|
||||
expect(argList.axis).toEqual("all");
|
||||
expect(argList.speed).toEqual(100);
|
||||
});
|
||||
|
|
|
@ -9,7 +9,7 @@ describe("<ToggleButton/>", function () {
|
|||
|
||||
it("calls toggle action", () => {
|
||||
const toggle = jest.fn();
|
||||
let toggleButton = mount(<ToggleButton
|
||||
const toggleButton = mount(<ToggleButton
|
||||
toggleValue={0}
|
||||
toggleAction={() => toggle()} />);
|
||||
toggleButton.simulate("click");
|
||||
|
@ -17,21 +17,21 @@ describe("<ToggleButton/>", function () {
|
|||
});
|
||||
|
||||
it("displays no", () => {
|
||||
let toggleButton = mount(<ToggleButton
|
||||
const toggleButton = mount(<ToggleButton
|
||||
toggleValue={0}
|
||||
toggleAction={jest.fn()} />);
|
||||
expect(toggleButton.text()).toBe("no");
|
||||
});
|
||||
|
||||
it("displays yes", () => {
|
||||
let toggleButton = mount(<ToggleButton
|
||||
const toggleButton = mount(<ToggleButton
|
||||
toggleValue={1}
|
||||
toggleAction={jest.fn()} />);
|
||||
expect(toggleButton.text()).toBe("yes");
|
||||
});
|
||||
|
||||
it("displays off", () => {
|
||||
let toggleButton = mount(<ToggleButton
|
||||
const toggleButton = mount(<ToggleButton
|
||||
toggleValue={0}
|
||||
toggleAction={jest.fn()}
|
||||
noYes={false} />);
|
||||
|
@ -39,7 +39,7 @@ describe("<ToggleButton/>", function () {
|
|||
});
|
||||
|
||||
it("displays on", () => {
|
||||
let toggleButton = mount(<ToggleButton
|
||||
const toggleButton = mount(<ToggleButton
|
||||
toggleValue={1}
|
||||
toggleAction={jest.fn()}
|
||||
noYes={false} />);
|
||||
|
@ -47,7 +47,7 @@ describe("<ToggleButton/>", function () {
|
|||
});
|
||||
|
||||
it("displays 🚫", () => {
|
||||
let toggleButton = mount(<ToggleButton
|
||||
const toggleButton = mount(<ToggleButton
|
||||
toggleValue={undefined}
|
||||
toggleAction={jest.fn()}
|
||||
noYes={false} />);
|
||||
|
|
|
@ -4,7 +4,7 @@ import { PeripheralForm } from "../peripheral_form";
|
|||
import { TaggedPeripheral } from "../../../resources/tagged_resources";
|
||||
|
||||
describe("<PeripheralForm/>", function () {
|
||||
let dispatch = jest.fn();
|
||||
const dispatch = jest.fn();
|
||||
const peripherals: TaggedPeripheral[] = [
|
||||
{
|
||||
uuid: "peripherals.2.2",
|
||||
|
@ -29,10 +29,10 @@ describe("<PeripheralForm/>", function () {
|
|||
];
|
||||
|
||||
it("renders a list of editable peripherals, in sorted order", function () {
|
||||
let form = mount(<PeripheralForm dispatch={dispatch}
|
||||
const form = mount(<PeripheralForm dispatch={dispatch}
|
||||
peripherals={peripherals} />);
|
||||
let inputs = form.find("input");
|
||||
let buttons = form.find("button");
|
||||
const inputs = form.find("input");
|
||||
const buttons = form.find("button");
|
||||
expect(inputs.at(0).props().value).toEqual("GPIO 2");
|
||||
inputs.at(0).simulate("change");
|
||||
expect(inputs.at(1).props().value).toEqual("2");
|
||||
|
|
|
@ -53,29 +53,29 @@ describe("<PeripheralList/>", function () {
|
|||
};
|
||||
|
||||
it("renders a list of peripherals, in sorted order", function () {
|
||||
let wrapper = mount(<PeripheralList dispatch={() => { }}
|
||||
const wrapper = mount(<PeripheralList dispatch={() => { }}
|
||||
peripherals={peripherals}
|
||||
pins={pins}
|
||||
disabled={false} />);
|
||||
let labels = wrapper.find("label");
|
||||
let buttons = wrapper.find("button");
|
||||
let first = labels.first();
|
||||
const labels = wrapper.find("label");
|
||||
const buttons = wrapper.find("button");
|
||||
const first = labels.first();
|
||||
expect(first.text()).toBeTruthy();
|
||||
expect(first.text()).toEqual("GPIO 2");
|
||||
expect(buttons.first().text()).toEqual("off");
|
||||
let last = labels.last();
|
||||
const last = labels.last();
|
||||
expect(last.text()).toBeTruthy();
|
||||
expect(last.text()).toEqual("GPIO 13 - LED");
|
||||
expect(buttons.last().text()).toEqual("on");
|
||||
});
|
||||
|
||||
it("toggles pins", () => {
|
||||
let { mock } = devices.current.togglePin as jest.Mock<{}>;
|
||||
let wrapper = mount(<PeripheralList dispatch={() => { }}
|
||||
const { mock } = devices.current.togglePin as jest.Mock<{}>;
|
||||
const wrapper = mount(<PeripheralList dispatch={() => { }}
|
||||
peripherals={peripherals}
|
||||
pins={pins}
|
||||
disabled={false} />);
|
||||
let toggle = wrapper.find("ToggleButton");
|
||||
const toggle = wrapper.find("ToggleButton");
|
||||
toggle.first().simulate("click");
|
||||
expect(mock.calls.length).toEqual(1);
|
||||
expect(mock.calls[0][0].pin_number).toEqual(2);
|
||||
|
@ -85,12 +85,12 @@ describe("<PeripheralList/>", function () {
|
|||
});
|
||||
|
||||
it("pins toggles are disabled", () => {
|
||||
let { mock } = devices.current.togglePin as jest.Mock<{}>;
|
||||
let wrapper = mount(<PeripheralList dispatch={() => { }}
|
||||
const { mock } = devices.current.togglePin as jest.Mock<{}>;
|
||||
const wrapper = mount(<PeripheralList dispatch={() => { }}
|
||||
peripherals={peripherals}
|
||||
pins={pins}
|
||||
disabled={true} />);
|
||||
let toggle = wrapper.find("ToggleButton");
|
||||
const toggle = wrapper.find("ToggleButton");
|
||||
toggle.first().simulate("click");
|
||||
toggle.last().simulate("click");
|
||||
expect(mock.calls.length).toEqual(0);
|
||||
|
|
|
@ -22,14 +22,14 @@ export class Peripherals extends React.Component<PeripheralsProps, PeripheralSta
|
|||
}
|
||||
|
||||
maybeSave = () => {
|
||||
let { peripherals } = this.props;
|
||||
let pinNums = peripherals.map(x => x.body.pin);
|
||||
let positivePins = pinNums.filter(x => x && x > 0);
|
||||
let smallPins = pinNums.filter(x => x && x < 1000);
|
||||
const { peripherals } = this.props;
|
||||
const pinNums = peripherals.map(x => x.body.pin);
|
||||
const positivePins = pinNums.filter(x => x && x > 0);
|
||||
const smallPins = pinNums.filter(x => x && x < 1000);
|
||||
// I hate adding client side validation, but this is a wonky endpoint - RC.
|
||||
let allAreUniq = _.uniq(pinNums).length === pinNums.length;
|
||||
let allArePositive = positivePins.length === pinNums.length;
|
||||
let allAreSmall = smallPins.length === pinNums.length;
|
||||
const allAreUniq = _.uniq(pinNums).length === pinNums.length;
|
||||
const allArePositive = positivePins.length === pinNums.length;
|
||||
const allAreSmall = smallPins.length === pinNums.length;
|
||||
if (allAreUniq && allArePositive) {
|
||||
if (allAreSmall) {
|
||||
this.props.dispatch(saveAll(this.props.peripherals, this.toggle));
|
||||
|
@ -42,9 +42,9 @@ export class Peripherals extends React.Component<PeripheralsProps, PeripheralSta
|
|||
}
|
||||
|
||||
showPins = () => {
|
||||
let { peripherals, dispatch, bot, disabled } = this.props;
|
||||
const { peripherals, dispatch, bot, disabled } = this.props;
|
||||
|
||||
let pins = bot.hardware.pins;
|
||||
const pins = bot.hardware.pins;
|
||||
if (this.state.isEditing) {
|
||||
return <PeripheralForm peripherals={peripherals}
|
||||
dispatch={dispatch} />;
|
||||
|
@ -66,10 +66,10 @@ export class Peripherals extends React.Component<PeripheralsProps, PeripheralSta
|
|||
}
|
||||
|
||||
render() {
|
||||
let { dispatch, peripherals } = this.props;
|
||||
let { isEditing } = this.state;
|
||||
const { dispatch, peripherals } = this.props;
|
||||
const { isEditing } = this.state;
|
||||
|
||||
let status = getArrayStatus(peripherals);
|
||||
const status = getArrayStatus(peripherals);
|
||||
|
||||
return <Widget className="peripherals-widget">
|
||||
<WidgetHeader title={"Peripherals"} helpText={ToolTips.PERIPHERALS}>
|
||||
|
|
|
@ -5,7 +5,7 @@ import { PeripheralFormProps } from "./interfaces";
|
|||
import { sortResourcesById } from "../../util";
|
||||
|
||||
export function PeripheralForm(props: PeripheralFormProps) {
|
||||
let { dispatch, peripherals } = props;
|
||||
const { dispatch, peripherals } = props;
|
||||
|
||||
return <div>
|
||||
{sortResourcesById(peripherals).map(p => {
|
||||
|
@ -15,7 +15,7 @@ export function PeripheralForm(props: PeripheralFormProps) {
|
|||
placeholder="Label"
|
||||
value={p.body.label}
|
||||
onChange={(e) => {
|
||||
let { value } = e.currentTarget;
|
||||
const { value } = e.currentTarget;
|
||||
dispatch(edit(p, { label: value }));
|
||||
}} />
|
||||
</Col>
|
||||
|
@ -24,8 +24,8 @@ export function PeripheralForm(props: PeripheralFormProps) {
|
|||
value={(p.body.pin || "").toString()}
|
||||
placeholder="Pin #"
|
||||
onChange={(e) => {
|
||||
let { value } = e.currentTarget;
|
||||
let update: Partial<typeof p.body> = { pin: parseInt(value, 10) };
|
||||
const { value } = e.currentTarget;
|
||||
const update: Partial<typeof p.body> = { pin: parseInt(value, 10) };
|
||||
dispatch(edit(p, update));
|
||||
}} />
|
||||
</Col>
|
||||
|
|
|
@ -6,10 +6,10 @@ import { PeripheralListProps } from "./interfaces";
|
|||
import { sortResourcesById } from "../../util";
|
||||
|
||||
export function PeripheralList(props: PeripheralListProps) {
|
||||
let { pins, disabled } = props;
|
||||
const { pins, disabled } = props;
|
||||
return <div>
|
||||
{sortResourcesById(props.peripherals).map(p => {
|
||||
let value = (pins[p.body.pin || -1] || { value: undefined }).value;
|
||||
const value = (pins[p.body.pin || -1] || { value: undefined }).value;
|
||||
return <Row key={p.uuid}>
|
||||
<Col xs={4}>
|
||||
<label>{p.body.label}</label>
|
||||
|
|
|
@ -8,8 +8,8 @@ import { maybeFetchUser } from "../resources/selectors";
|
|||
import * as _ from "lodash";
|
||||
|
||||
export function mapStateToProps(props: Everything): Props {
|
||||
let peripherals = _.uniq(selectAllPeripherals(props.resources.index));
|
||||
let resources = props.resources;
|
||||
const peripherals = _.uniq(selectAllPeripherals(props.resources.index));
|
||||
const resources = props.resources;
|
||||
|
||||
return {
|
||||
feed: getFeed(resources.index),
|
||||
|
|
|
@ -5,7 +5,7 @@ import * as _ from "lodash";
|
|||
|
||||
export class StepSizeSelector extends Component<StepSizeSelectorProps, {}> {
|
||||
cssForIndex(num: number) {
|
||||
let choices = this.props.choices;
|
||||
const choices = this.props.choices;
|
||||
let css = "move-amount no-radius fb-button ";
|
||||
if (num === _.first(choices)) {
|
||||
css += "leftmost ";
|
||||
|
|
|
@ -5,10 +5,10 @@ import { isUndefined } from "util";
|
|||
|
||||
export class ToggleButton extends React.Component<ToggleButtonProps, {}> {
|
||||
caption() {
|
||||
let useNoYes = isUndefined(this.props.noYes) ? true : this.props.noYes;
|
||||
let noOff = useNoYes ? t("no") : t("off");
|
||||
let yesOn = useNoYes ? t("yes") : t("on");
|
||||
let captions: { [s: string]: string | undefined } = {
|
||||
const useNoYes = isUndefined(this.props.noYes) ? true : this.props.noYes;
|
||||
const noOff = useNoYes ? t("no") : t("off");
|
||||
const yesOn = useNoYes ? t("yes") : t("on");
|
||||
const captions: { [s: string]: string | undefined } = {
|
||||
"0": noOff,
|
||||
"false": noOff,
|
||||
"off": noOff,
|
||||
|
@ -18,18 +18,18 @@ export class ToggleButton extends React.Component<ToggleButtonProps, {}> {
|
|||
"undefined": "🚫",
|
||||
"-1": "🚫"
|
||||
};
|
||||
let togval = String(this.props.toggleValue);
|
||||
const togval = String(this.props.toggleValue);
|
||||
return captions[togval] || "---";
|
||||
}
|
||||
|
||||
css() {
|
||||
let css = "fb-toggle-button fb-button";
|
||||
const css = "fb-toggle-button fb-button";
|
||||
if (this.props.disabled) { return css + " gray"; }
|
||||
let redCSS = css + " red";
|
||||
let greenCSS = css + " green";
|
||||
let yellowCSS = css + " yellow";
|
||||
const redCSS = css + " red";
|
||||
const greenCSS = css + " green";
|
||||
const yellowCSS = css + " yellow";
|
||||
|
||||
let cssClasses: { [s: string]: string | undefined } = {
|
||||
const cssClasses: { [s: string]: string | undefined } = {
|
||||
"0": redCSS,
|
||||
"false": redCSS,
|
||||
"off": redCSS,
|
||||
|
@ -43,7 +43,7 @@ export class ToggleButton extends React.Component<ToggleButtonProps, {}> {
|
|||
}
|
||||
|
||||
render() {
|
||||
let cb = () => !this.props.disabled && this.props.toggleAction();
|
||||
const cb = () => !this.props.disabled && this.props.toggleAction();
|
||||
return (
|
||||
<button
|
||||
disabled={!!this.props.disabled}
|
||||
|
|
|
@ -30,9 +30,9 @@ export class WebcamPanel extends
|
|||
}
|
||||
|
||||
render() {
|
||||
let url = this.props.feed.body.url || PLACEHOLDER_FARMBOT;
|
||||
let dirty = !!this.props.bot.dirty;
|
||||
let { isEditing } = this.state;
|
||||
const url = this.props.feed.body.url || PLACEHOLDER_FARMBOT;
|
||||
const dirty = !!this.props.bot.dirty;
|
||||
const { isEditing } = this.state;
|
||||
|
||||
return (
|
||||
<Widget>
|
||||
|
|
|
@ -16,8 +16,8 @@ jest.mock("../../device", () => ({
|
|||
}
|
||||
}
|
||||
}));
|
||||
let mockOk = jest.fn();
|
||||
let mockInfo = jest.fn();
|
||||
const mockOk = jest.fn();
|
||||
const mockInfo = jest.fn();
|
||||
jest.mock("farmbot-toastr", () => ({ success: mockOk, info: mockInfo }));
|
||||
|
||||
import * as actions from "../actions";
|
||||
|
@ -31,7 +31,7 @@ describe("checkControllerUpdates()", function () {
|
|||
});
|
||||
|
||||
it("calls checkUpdates", () => {
|
||||
let { mock } = devices.current.checkUpdates as jest.Mock<{}>;
|
||||
const { mock } = devices.current.checkUpdates as jest.Mock<{}>;
|
||||
actions.checkControllerUpdates();
|
||||
expect(mock.calls.length).toEqual(1);
|
||||
// TODO: It would be nice if this worked to check for sent toasts.
|
||||
|
@ -46,7 +46,7 @@ describe("powerOff()", function () {
|
|||
});
|
||||
|
||||
it("calls powerOff", () => {
|
||||
let { mock } = devices.current.powerOff as jest.Mock<{}>;
|
||||
const { mock } = devices.current.powerOff as jest.Mock<{}>;
|
||||
actions.powerOff();
|
||||
expect(mock.calls.length).toEqual(1);
|
||||
// expect(mockOk.mock.calls.length).toEqual(1);
|
||||
|
@ -59,7 +59,7 @@ describe("reboot()", function () {
|
|||
});
|
||||
|
||||
it("calls reboot", () => {
|
||||
let { mock } = devices.current.reboot as jest.Mock<{}>;
|
||||
const { mock } = devices.current.reboot as jest.Mock<{}>;
|
||||
actions.reboot();
|
||||
expect(mock.calls.length).toEqual(1);
|
||||
// expect(mockOk.mock.calls.length).toEqual(1);
|
||||
|
@ -72,13 +72,13 @@ describe("emergencyLock() / emergencyUnlock", function () {
|
|||
});
|
||||
|
||||
it("calls emergencyLock", () => {
|
||||
let { mock } = devices.current.emergencyLock as jest.Mock<{}>;
|
||||
const { mock } = devices.current.emergencyLock as jest.Mock<{}>;
|
||||
actions.emergencyLock();
|
||||
expect(mock.calls.length).toEqual(1);
|
||||
});
|
||||
|
||||
it("calls emergencyUnlock", () => {
|
||||
let { mock } = devices.current.emergencyUnlock as jest.Mock<{}>;
|
||||
const { mock } = devices.current.emergencyUnlock as jest.Mock<{}>;
|
||||
window.confirm = jest.fn(() => true);
|
||||
actions.emergencyUnlock();
|
||||
expect(mock.calls.length).toEqual(1);
|
||||
|
@ -91,11 +91,11 @@ describe("sync()", function () {
|
|||
});
|
||||
|
||||
it("doesn't call sync: disconnected", () => {
|
||||
let { mock } = devices.current.sync as jest.Mock<{}>;
|
||||
let getState = () => fakeState();
|
||||
const { mock } = devices.current.sync as jest.Mock<{}>;
|
||||
const getState = () => fakeState();
|
||||
actions.sync()(jest.fn(), getState);
|
||||
expect(mock.calls.length).toEqual(0);
|
||||
let expectedMessage = ["FarmBot is not connected.", "Disconnected", "red"];
|
||||
const expectedMessage = ["FarmBot is not connected.", "Disconnected", "red"];
|
||||
expect(mockInfo).toBeCalledWith(...expectedMessage);
|
||||
});
|
||||
});
|
||||
|
@ -106,8 +106,8 @@ describe("execSequence()", function () {
|
|||
});
|
||||
|
||||
it("calls execSequence", () => {
|
||||
let { mock } = devices.current.execSequence as jest.Mock<{}>;
|
||||
let s = fakeSequence().body;
|
||||
const { mock } = devices.current.execSequence as jest.Mock<{}>;
|
||||
const s = fakeSequence().body;
|
||||
actions.execSequence(s);
|
||||
expect(mock.calls.length).toEqual(1);
|
||||
expect(mock.calls[0][0]).toEqual(s.id);
|
||||
|
@ -115,8 +115,8 @@ describe("execSequence()", function () {
|
|||
});
|
||||
|
||||
it("implodes when executing unsaved sequences", () => {
|
||||
let { mock } = devices.current.execSequence as jest.Mock<{}>;
|
||||
let ok = fakeSequence().body;
|
||||
const { mock } = devices.current.execSequence as jest.Mock<{}>;
|
||||
const ok = fakeSequence().body;
|
||||
ok.id = undefined;
|
||||
expect(() => actions.execSequence(ok)).toThrow();
|
||||
expect(mock.calls.length).toEqual(0);
|
||||
|
@ -129,7 +129,7 @@ describe("MCUFactoryReset()", function () {
|
|||
});
|
||||
|
||||
it("calls resetMCU", () => {
|
||||
let { mock } = devices.current.resetMCU as jest.Mock<{}>;
|
||||
const { mock } = devices.current.resetMCU as jest.Mock<{}>;
|
||||
actions.MCUFactoryReset();
|
||||
expect(mock.calls.length).toEqual(1);
|
||||
// expect(mockOk.mock.calls.length).toEqual(1);
|
||||
|
@ -142,7 +142,7 @@ describe("botConfigChange()", function () {
|
|||
});
|
||||
|
||||
it("calls updateMcu", () => {
|
||||
let { mock } = devices.current.updateMcu as jest.Mock<{}>;
|
||||
const { mock } = devices.current.updateMcu as jest.Mock<{}>;
|
||||
actions.botConfigChange("encoder_enabled_x", 0);
|
||||
expect(mock.calls.length).toEqual(1);
|
||||
expect(mock.calls[0][0]).toEqual({ "encoder_enabled_x": 0 });
|
||||
|
@ -156,10 +156,10 @@ describe("pinToggle()", function () {
|
|||
});
|
||||
|
||||
it("calls togglePin", () => {
|
||||
let { mock } = devices.current.togglePin as jest.Mock<{}>;
|
||||
const { mock } = devices.current.togglePin as jest.Mock<{}>;
|
||||
actions.pinToggle(5);
|
||||
expect(mock.calls.length).toEqual(1);
|
||||
let argList = mock.calls[0];
|
||||
const argList = mock.calls[0];
|
||||
expect(argList[0].pin_number).toEqual(5);
|
||||
// expect(mockOk.mock.calls.length).toEqual(0);
|
||||
});
|
||||
|
@ -171,10 +171,10 @@ describe("homeAll()", function () {
|
|||
});
|
||||
|
||||
it("calls home", () => {
|
||||
let { mock } = devices.current.home as jest.Mock<{}>;
|
||||
const { mock } = devices.current.home as jest.Mock<{}>;
|
||||
actions.homeAll(100);
|
||||
expect(mock.calls.length).toEqual(1);
|
||||
let argList = mock.calls[0];
|
||||
const argList = mock.calls[0];
|
||||
expect(argList[0].axis).toEqual("all");
|
||||
expect(argList[0].speed).toEqual(100);
|
||||
// expect(mockOk.mock.calls.length).toEqual(1);
|
||||
|
@ -190,7 +190,7 @@ describe("isLog()", function () {
|
|||
|
||||
describe("toggleControlPanel()", function () {
|
||||
it("toggles", () => {
|
||||
let action = actions.toggleControlPanel("homing_and_calibration");
|
||||
const action = actions.toggleControlPanel("homing_and_calibration");
|
||||
expect(action.payload).toEqual("homing_and_calibration");
|
||||
});
|
||||
});
|
||||
|
|
|
@ -4,27 +4,27 @@ import { MustBeOnline } from "../must_be_online";
|
|||
|
||||
describe("<MustBeOnline/>", function () {
|
||||
it("Does not render when status is 'unknown'", function () {
|
||||
let elem = <MustBeOnline status="unknown">
|
||||
const elem = <MustBeOnline status="unknown">
|
||||
<span>Invisible</span>
|
||||
</MustBeOnline>;
|
||||
let text = render(elem).text();
|
||||
const text = render(elem).text();
|
||||
expect(text).not.toContain("Invisible");
|
||||
});
|
||||
|
||||
it("Does not render when status is undefined", function () {
|
||||
let elem = <MustBeOnline status={undefined} fallback="NOPE!">
|
||||
const elem = <MustBeOnline status={undefined} fallback="NOPE!">
|
||||
<span>Invisible</span>
|
||||
</MustBeOnline>;
|
||||
let text = render(elem).text();
|
||||
const text = render(elem).text();
|
||||
expect(text).not.toContain("Invisible");
|
||||
expect(text).toContain("NOPE!");
|
||||
});
|
||||
|
||||
it("Renders when locked open", function () {
|
||||
let elem = <MustBeOnline status="unknown" lockOpen={true}>
|
||||
const elem = <MustBeOnline status="unknown" lockOpen={true}>
|
||||
<span>Visible</span>
|
||||
</MustBeOnline>;
|
||||
let text = render(elem).text();
|
||||
const text = render(elem).text();
|
||||
expect(text).toContain("Visible");
|
||||
});
|
||||
});
|
||||
|
|
|
@ -39,18 +39,18 @@ function incomingStatus(statusMessage: HardwareState) {
|
|||
export function isLog(x: object): x is Log {
|
||||
return _.isObject(x) && _.isString(_.get(x, "message" as keyof Log));
|
||||
}
|
||||
let commandErr = (noun = "Command") => (x: any) => {
|
||||
const commandErr = (noun = "Command") => (x: any) => {
|
||||
console.dir(x);
|
||||
console.info("Took longer than 6 seconds: " + noun);
|
||||
};
|
||||
|
||||
let commandOK = (noun = "Command") => () => {
|
||||
let msg = noun + " request sent to device.";
|
||||
const commandOK = (noun = "Command") => () => {
|
||||
const msg = noun + " request sent to device.";
|
||||
success(msg, t("Request sent"));
|
||||
};
|
||||
|
||||
export function checkControllerUpdates() {
|
||||
let noun = "Check for Updates";
|
||||
const noun = "Check for Updates";
|
||||
devices
|
||||
.current
|
||||
.checkUpdates()
|
||||
|
@ -58,7 +58,7 @@ export function checkControllerUpdates() {
|
|||
}
|
||||
|
||||
export function powerOff() {
|
||||
let noun = "Power Off Bot";
|
||||
const noun = "Power Off Bot";
|
||||
devices
|
||||
.current
|
||||
.powerOff()
|
||||
|
@ -76,7 +76,7 @@ export function factoryReset() {
|
|||
}
|
||||
|
||||
export function reboot() {
|
||||
let noun = "Reboot Bot";
|
||||
const noun = "Reboot Bot";
|
||||
devices
|
||||
.current
|
||||
.reboot()
|
||||
|
@ -84,7 +84,7 @@ export function reboot() {
|
|||
}
|
||||
|
||||
export function emergencyLock() {
|
||||
let noun = "Emergency stop";
|
||||
const noun = "Emergency stop";
|
||||
devices
|
||||
.current
|
||||
.emergencyLock()
|
||||
|
@ -92,7 +92,7 @@ export function emergencyLock() {
|
|||
}
|
||||
|
||||
export function emergencyUnlock() {
|
||||
let noun = "Emergency unlock";
|
||||
const noun = "Emergency unlock";
|
||||
if (confirm(`Are you sure you want to unlock the device?`)) {
|
||||
devices
|
||||
.current
|
||||
|
@ -102,9 +102,9 @@ export function emergencyUnlock() {
|
|||
}
|
||||
|
||||
export function sync(): Thunk {
|
||||
let noun = "Sync";
|
||||
const noun = "Sync";
|
||||
return function (dispatch, getState) {
|
||||
let IS_OK = versionOK(getState()
|
||||
const IS_OK = versionOK(getState()
|
||||
.bot
|
||||
.hardware
|
||||
.informational_settings
|
||||
|
@ -156,8 +156,8 @@ export let fetchReleases =
|
|||
axios
|
||||
.get(url)
|
||||
.then((resp: HttpData<GithubRelease>) => {
|
||||
let version = resp.data.tag_name;
|
||||
let versionWithoutV = version.toLowerCase().replace("v", "");
|
||||
const version = resp.data.tag_name;
|
||||
const versionWithoutV = version.toLowerCase().replace("v", "");
|
||||
dispatch({
|
||||
type: "FETCH_OS_UPDATE_INFO_OK",
|
||||
payload: versionWithoutV
|
||||
|
@ -194,7 +194,7 @@ export function MCUFactoryReset() {
|
|||
}
|
||||
|
||||
export function botConfigChange(key: configKey, value: number) {
|
||||
let noun = "Setting toggle";
|
||||
const noun = "Setting toggle";
|
||||
|
||||
return devices
|
||||
.current
|
||||
|
@ -206,7 +206,7 @@ export function settingToggle(
|
|||
name: configKey, bot: BotState, displayAlert: string | undefined
|
||||
) {
|
||||
if (displayAlert) { alert(displayAlert.replace(/\s+/g, " ")); }
|
||||
let noun = "Setting toggle";
|
||||
const noun = "Setting toggle";
|
||||
return devices
|
||||
.current
|
||||
.updateMcu({
|
||||
|
@ -239,7 +239,7 @@ export function pinToggle(pin_number: number) {
|
|||
}
|
||||
|
||||
export function homeAll(speed: number) {
|
||||
let noun = "'Home All' command";
|
||||
const noun = "'Home All' command";
|
||||
devices
|
||||
.current
|
||||
.home({ axis: "all", speed })
|
||||
|
@ -247,7 +247,7 @@ export function homeAll(speed: number) {
|
|||
}
|
||||
|
||||
function readStatus() {
|
||||
let noun = "'Read Status' command";
|
||||
const noun = "'Read Status' command";
|
||||
return devices
|
||||
.current
|
||||
.readStatus()
|
||||
|
@ -262,8 +262,8 @@ type ConnectDeviceReturn = {} | ((dispatch: Function) => void);
|
|||
const BAD_WORDS = ["WPA", "PSK", "PASSWORD", "NERVES"];
|
||||
export function connectDevice(token: string): ConnectDeviceReturn {
|
||||
return (dispatch: Function, getState: GetState) => {
|
||||
let secure = location.protocol === "https:";
|
||||
let bot = new Farmbot({ token, secure });
|
||||
const secure = location.protocol === "https:";
|
||||
const bot = new Farmbot({ token, secure });
|
||||
bot.on("online", () => dispatch(setMqttStatus(true)));
|
||||
bot.on("offline", () => {
|
||||
dispatch(setMqttStatus(false));
|
||||
|
@ -298,7 +298,7 @@ export function connectDevice(token: string): ConnectDeviceReturn {
|
|||
bot.on("status", _.throttle(function (msg: BotStateTree) {
|
||||
dispatch(incomingStatus(msg));
|
||||
if (NEED_VERSION_CHECK) {
|
||||
let IS_OK = versionOK(getState()
|
||||
const IS_OK = versionOK(getState()
|
||||
.bot
|
||||
.hardware
|
||||
.informational_settings
|
||||
|
@ -328,22 +328,22 @@ function fetchDeviceErr(err: Error) {
|
|||
};
|
||||
}
|
||||
|
||||
let startUpdate = (dispatch: Function) => {
|
||||
const startUpdate = (dispatch: Function) => {
|
||||
dispatch({ type: "SETTING_UPDATE_START", payload: undefined });
|
||||
};
|
||||
|
||||
let updateOK = (dispatch: Function, noun: string) => {
|
||||
const updateOK = (dispatch: Function, noun: string) => {
|
||||
dispatch({ type: "SETTING_UPDATE_END", payload: undefined });
|
||||
commandOK(noun);
|
||||
};
|
||||
|
||||
let updateNO = (dispatch: Function, noun: string) => {
|
||||
const updateNO = (dispatch: Function, noun: string) => {
|
||||
dispatch({ type: "SETTING_UPDATE_END", payload: undefined });
|
||||
commandErr(noun);
|
||||
};
|
||||
|
||||
export function updateMCU(key: configKey, val: string) {
|
||||
let noun = "configuration update";
|
||||
const noun = "configuration update";
|
||||
return function (dispatch: Function) {
|
||||
startUpdate(dispatch);
|
||||
devices
|
||||
|
@ -355,7 +355,7 @@ export function updateMCU(key: configKey, val: string) {
|
|||
}
|
||||
|
||||
export function updateConfig(config: Configuration) {
|
||||
let noun = "Update Config";
|
||||
const noun = "Update Config";
|
||||
return function (dispatch: Function) {
|
||||
devices
|
||||
.current
|
||||
|
@ -376,8 +376,8 @@ const CHANNELS: keyof Log = "channels";
|
|||
const TOAST: ALLOWED_CHANNEL_NAMES = "toast";
|
||||
|
||||
function maybeShowLog(log: Log) {
|
||||
let chanList = _.get(log, CHANNELS, ["ERROR FETCHING CHANNELS"]);
|
||||
let m = log.meta.type as ALLOWED_MESSAGE_TYPES;
|
||||
const chanList = _.get(log, CHANNELS, ["ERROR FETCHING CHANNELS"]);
|
||||
const m = log.meta.type as ALLOWED_MESSAGE_TYPES;
|
||||
const TITLE = "New message from bot";
|
||||
if (chanList.includes(TOAST)) {
|
||||
switch (m) {
|
||||
|
|
|
@ -19,7 +19,7 @@ const expected =
|
|||
|
||||
describe("axisTrackingStatus()", () => {
|
||||
it("returns axis status", () => {
|
||||
let result = axisTrackingStatus(bot.hardware.mcu_params);
|
||||
const result = axisTrackingStatus(bot.hardware.mcu_params);
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -16,8 +16,8 @@ describe("<HomingRow />", () => {
|
|||
jest.clearAllMocks();
|
||||
});
|
||||
it("calls device", () => {
|
||||
let { mock } = devices.current.calibrate as jest.Mock<{}>;
|
||||
let result = mount(<CalibrationRow hardware={bot.hardware.mcu_params} />);
|
||||
const { mock } = devices.current.calibrate as jest.Mock<{}>;
|
||||
const result = mount(<CalibrationRow hardware={bot.hardware.mcu_params} />);
|
||||
result.find("LockableButton").at(0).simulate("click");
|
||||
result.find("LockableButton").at(1).simulate("click");
|
||||
result.find("LockableButton").at(2).simulate("click");
|
||||
|
|
|
@ -5,8 +5,8 @@ jest.mock("../../../device", () => ({
|
|||
}
|
||||
}
|
||||
}));
|
||||
let mockInfo = jest.fn();
|
||||
let mockError = jest.fn();
|
||||
const mockInfo = jest.fn();
|
||||
const mockError = jest.fn();
|
||||
jest.mock("farmbot-toastr", () => ({ info: mockInfo, error: mockError }));
|
||||
|
||||
import * as React from "react";
|
||||
|
@ -20,20 +20,20 @@ describe("<CameraSelection/>", () => {
|
|||
});
|
||||
|
||||
it("doesn't render camera", () => {
|
||||
let cameraSelection = mount(<CameraSelection
|
||||
const cameraSelection = mount(<CameraSelection
|
||||
env={{}} />);
|
||||
expect(cameraSelection.find("button").text()).toEqual("None");
|
||||
});
|
||||
|
||||
it("renders camera", () => {
|
||||
let cameraSelection = mount(<CameraSelection
|
||||
const cameraSelection = mount(<CameraSelection
|
||||
env={{ "camera": "\"RPI\"" }} />);
|
||||
expect(cameraSelection.find("button").text()).toEqual("Raspberry Pi Camera");
|
||||
});
|
||||
|
||||
it("changes camera", () => {
|
||||
let { mock } = devices.current.setUserEnv as jest.Mock<{}>;
|
||||
let cameraSelection = shallow(<CameraSelection
|
||||
const { mock } = devices.current.setUserEnv as jest.Mock<{}>;
|
||||
const cameraSelection = shallow(<CameraSelection
|
||||
env={{}} />);
|
||||
cameraSelection.find("FBSelect")
|
||||
.simulate("change", { label: "My Camera", value: "mycamera" });
|
||||
|
|
|
@ -8,7 +8,7 @@ import { AuthState } from "../../../auth/interfaces";
|
|||
|
||||
describe("<FarmbotOsSettings/>", () => {
|
||||
it("renders settings", () => {
|
||||
let osSettings = mount(<FarmbotOsSettings
|
||||
const osSettings = mount(<FarmbotOsSettings
|
||||
account={fakeResource("device", { id: 0, name: "" })}
|
||||
dispatch={jest.fn()}
|
||||
bot={bot}
|
||||
|
|
|
@ -4,8 +4,8 @@ import { shallow } from "enzyme";
|
|||
|
||||
describe("<Header/>", () => {
|
||||
it("renders", () => {
|
||||
let fn = jest.fn();
|
||||
let el = shallow(<Header
|
||||
const fn = jest.fn();
|
||||
const el = shallow(<Header
|
||||
title="FOO"
|
||||
bool={true}
|
||||
name={"motors"}
|
||||
|
|
|
@ -28,8 +28,8 @@ describe("<HomingRow />", () => {
|
|||
// });
|
||||
// });
|
||||
it("calls device", () => {
|
||||
let { mock } = devices.current.findHome as jest.Mock<{}>;
|
||||
let result = mount(<HomingRow hardware={bot.hardware.mcu_params} />);
|
||||
const { mock } = devices.current.findHome as jest.Mock<{}>;
|
||||
const result = mount(<HomingRow hardware={bot.hardware.mcu_params} />);
|
||||
result.find("LockableButton").at(0).simulate("click");
|
||||
result.find("LockableButton").at(1).simulate("click");
|
||||
result.find("LockableButton").at(2).simulate("click");
|
||||
|
|
|
@ -4,31 +4,31 @@ import { LastSeen } from "../last_seen_widget";
|
|||
import { mount } from "enzyme";
|
||||
import { SpecialStatus } from "../../../resources/tagged_resources";
|
||||
describe("<LastSeen/>", () => {
|
||||
let resource = () => fakeResource("device", {
|
||||
const resource = () => fakeResource("device", {
|
||||
id: 1,
|
||||
name: "foo",
|
||||
last_seen: ""
|
||||
});
|
||||
it("blinks when loading", () => {
|
||||
let r = resource();
|
||||
const r = resource();
|
||||
r.specialStatus = SpecialStatus.SAVING;
|
||||
let cb = jest.fn();
|
||||
let el = mount(<LastSeen device={r} onClick={cb} />);
|
||||
const cb = jest.fn();
|
||||
const el = mount(<LastSeen device={r} onClick={cb} />);
|
||||
expect(el.text()).toContain("Loading");
|
||||
});
|
||||
|
||||
it("tells you the device has never been seen", () => {
|
||||
let r = resource();
|
||||
let cb = jest.fn();
|
||||
let el = mount(<LastSeen device={r} onClick={cb} />);
|
||||
const r = resource();
|
||||
const cb = jest.fn();
|
||||
const el = mount(<LastSeen device={r} onClick={cb} />);
|
||||
expect(el.text()).toContain("network connectivity issue");
|
||||
});
|
||||
|
||||
it("tells you when the device was last seen", () => {
|
||||
let r = resource();
|
||||
let cb = jest.fn();
|
||||
const r = resource();
|
||||
const cb = jest.fn();
|
||||
r.body.last_seen = "2017-08-07T19:40:01.487Z";
|
||||
let el = mount(<LastSeen device={r} onClick={cb} />);
|
||||
const el = mount(<LastSeen device={r} onClick={cb} />);
|
||||
expect(el.text()).toContain("FarmBot was last seen");
|
||||
});
|
||||
|
||||
|
|
|
@ -4,14 +4,14 @@ import { mount } from "enzyme";
|
|||
|
||||
describe("<LockableButton/>", () => {
|
||||
it("does not trigger callback when clicked and disabled", () => {
|
||||
let fakeCB = jest.fn();
|
||||
let btn = mount(<LockableButton disabled={true} onClick={fakeCB} />);
|
||||
const fakeCB = jest.fn();
|
||||
const btn = mount(<LockableButton disabled={true} onClick={fakeCB} />);
|
||||
btn.simulate("click");
|
||||
expect(fakeCB.mock.calls.length).toEqual(0);
|
||||
});
|
||||
it("does trigger callback when clicked and enabled", () => {
|
||||
let fakeCB = jest.fn();
|
||||
let btn = mount(<LockableButton disabled={false} onClick={fakeCB} />);
|
||||
const fakeCB = jest.fn();
|
||||
const btn = mount(<LockableButton disabled={false} onClick={fakeCB} />);
|
||||
btn.simulate("click");
|
||||
expect(fakeCB.mock.calls.length).toEqual(1);
|
||||
});
|
||||
|
|
|
@ -5,7 +5,7 @@ jest.mock("../../../device", () => ({
|
|||
}
|
||||
}
|
||||
}));
|
||||
let mockOk = jest.fn();
|
||||
const mockOk = jest.fn();
|
||||
jest.mock("farmbot-toastr", () => ({ success: mockOk }));
|
||||
|
||||
import * as React from "react";
|
||||
|
@ -20,75 +20,75 @@ describe("<OsUpdateButton/>", () => {
|
|||
jest.clearAllMocks();
|
||||
});
|
||||
it("renders buttons: not connected", () => {
|
||||
let buttons = mount(<OsUpdateButton bot={bot} />);
|
||||
const buttons = mount(<OsUpdateButton bot={bot} />);
|
||||
expect(buttons.find("button").length).toBe(2);
|
||||
let autoUpdate = buttons.find("button").first();
|
||||
const autoUpdate = buttons.find("button").first();
|
||||
expect(autoUpdate.hasClass("yellow")).toBeTruthy();
|
||||
let osUpdateButton = buttons.find("button").last();
|
||||
const osUpdateButton = buttons.find("button").last();
|
||||
expect(osUpdateButton.text()).toBe("Can't Connect to release server");
|
||||
});
|
||||
it("up to date", () => {
|
||||
bot.hardware.informational_settings.controller_version = "3.1.6";
|
||||
let buttons = mount(<OsUpdateButton bot={bot} />);
|
||||
let osUpdateButton = buttons.find("button").last();
|
||||
const buttons = mount(<OsUpdateButton bot={bot} />);
|
||||
const osUpdateButton = buttons.find("button").last();
|
||||
expect(osUpdateButton.text()).toBe("UP TO DATE");
|
||||
});
|
||||
it("update available", () => {
|
||||
bot.hardware.informational_settings.controller_version = "3.1.5";
|
||||
let buttons = mount(<OsUpdateButton bot={bot} />);
|
||||
let osUpdateButton = buttons.find("button").last();
|
||||
const buttons = mount(<OsUpdateButton bot={bot} />);
|
||||
const osUpdateButton = buttons.find("button").last();
|
||||
expect(osUpdateButton.text()).toBe("UPDATE");
|
||||
});
|
||||
it("calls checkUpdates", () => {
|
||||
let { mock } = devices.current.checkUpdates as jest.Mock<{}>;
|
||||
let buttons = mount(<OsUpdateButton bot={bot} />);
|
||||
let osUpdateButton = buttons.find("button").last();
|
||||
const { mock } = devices.current.checkUpdates as jest.Mock<{}>;
|
||||
const buttons = mount(<OsUpdateButton bot={bot} />);
|
||||
const osUpdateButton = buttons.find("button").last();
|
||||
osUpdateButton.simulate("click");
|
||||
expect(mock.calls.length).toEqual(1);
|
||||
});
|
||||
it("shows update progress: bytes", () => {
|
||||
bot.hardware.jobs = { "FBOS_OTA": { status: "working", bytes: 300, unit: "bytes" } };
|
||||
let buttons = mount(<OsUpdateButton bot={bot} />);
|
||||
let osUpdateButton = buttons.find("button").last();
|
||||
const buttons = mount(<OsUpdateButton bot={bot} />);
|
||||
const osUpdateButton = buttons.find("button").last();
|
||||
expect(osUpdateButton.text()).toBe("300B");
|
||||
});
|
||||
it("shows update progress: kilobytes", () => {
|
||||
bot.hardware.jobs = { "FBOS_OTA": { status: "working", bytes: 30000, unit: "bytes" } };
|
||||
let buttons = mount(<OsUpdateButton bot={bot} />);
|
||||
let osUpdateButton = buttons.find("button").last();
|
||||
const buttons = mount(<OsUpdateButton bot={bot} />);
|
||||
const osUpdateButton = buttons.find("button").last();
|
||||
expect(osUpdateButton.text()).toBe("29kB");
|
||||
});
|
||||
it("shows update progress: megabytes", () => {
|
||||
bot.hardware.jobs = { "FBOS_OTA": { status: "working", bytes: 3e6, unit: "bytes" } };
|
||||
let buttons = mount(<OsUpdateButton bot={bot} />);
|
||||
let osUpdateButton = buttons.find("button").last();
|
||||
const buttons = mount(<OsUpdateButton bot={bot} />);
|
||||
const osUpdateButton = buttons.find("button").last();
|
||||
expect(osUpdateButton.text()).toBe("3MB");
|
||||
});
|
||||
it("shows update progress: percent", () => {
|
||||
bot.hardware.jobs = { "FBOS_OTA": { status: "working", percent: 10, unit: "percent" } };
|
||||
let buttons = mount(<OsUpdateButton bot={bot} />);
|
||||
let osUpdateButton = buttons.find("button").last();
|
||||
const buttons = mount(<OsUpdateButton bot={bot} />);
|
||||
const osUpdateButton = buttons.find("button").last();
|
||||
expect(osUpdateButton.text()).toBe("10%");
|
||||
});
|
||||
it("update success", () => {
|
||||
bot.hardware.jobs = { "FBOS_OTA": { status: "complete", percent: 100, unit: "percent" } };
|
||||
bot.hardware.informational_settings.controller_version = "3.1.6";
|
||||
let buttons = mount(<OsUpdateButton bot={bot} />);
|
||||
let osUpdateButton = buttons.find("button").last();
|
||||
const buttons = mount(<OsUpdateButton bot={bot} />);
|
||||
const osUpdateButton = buttons.find("button").last();
|
||||
expect(osUpdateButton.text()).toBe("UP TO DATE");
|
||||
});
|
||||
it("update failed", () => {
|
||||
bot.hardware.jobs = { "FBOS_OTA": { status: "error", percent: 10, unit: "percent" } };
|
||||
bot.hardware.informational_settings.controller_version = "3.1.5";
|
||||
let buttons = mount(<OsUpdateButton bot={bot} />);
|
||||
let osUpdateButton = buttons.find("button").last();
|
||||
const buttons = mount(<OsUpdateButton bot={bot} />);
|
||||
const osUpdateButton = buttons.find("button").last();
|
||||
expect(osUpdateButton.text()).toBe("UPDATE");
|
||||
});
|
||||
it("is disabled", () => {
|
||||
let { mock } = devices.current.checkUpdates as jest.Mock<{}>;
|
||||
const { mock } = devices.current.checkUpdates as jest.Mock<{}>;
|
||||
bot.hardware.jobs = { "FBOS_OTA": { status: "working", percent: 10, unit: "percent" } };
|
||||
let buttons = mount(<OsUpdateButton bot={bot} />);
|
||||
let osUpdateButton = buttons.find("button").last();
|
||||
const buttons = mount(<OsUpdateButton bot={bot} />);
|
||||
const osUpdateButton = buttons.find("button").last();
|
||||
osUpdateButton.simulate("click");
|
||||
expect(mock.calls.length).toEqual(0);
|
||||
});
|
||||
|
|
|
@ -4,8 +4,8 @@ import { SpacePanelHeader } from "../hardware_settings/space_panel_header";
|
|||
|
||||
describe("<SpacePanelHeader/>", () => {
|
||||
it("has children", () => {
|
||||
let result = render(<SpacePanelHeader />);
|
||||
let txt = result.text();
|
||||
const result = render(<SpacePanelHeader />);
|
||||
const txt = result.text();
|
||||
["X", "Y", "Z"].map(function (axis) {
|
||||
expect(txt).toContain(`${axis} AXIS`);
|
||||
});
|
||||
|
|
|
@ -15,8 +15,8 @@ describe("<HomingRow />", () => {
|
|||
jest.clearAllMocks();
|
||||
});
|
||||
it("calls device", () => {
|
||||
let { mock } = devices.current.setZero as jest.Mock<{}>;
|
||||
let result = mount(<ZeroRow />);
|
||||
const { mock } = devices.current.setZero as jest.Mock<{}>;
|
||||
const result = mount(<ZeroRow />);
|
||||
result.find("ZeroButton").at(0).simulate("click");
|
||||
result.find("ZeroButton").at(1).simulate("click");
|
||||
result.find("ZeroButton").at(2).simulate("click");
|
||||
|
|
|
@ -19,8 +19,8 @@ interface AxisStatus {
|
|||
* to proceed with certain actions that could damage the bot.
|
||||
*/
|
||||
export function axisTrackingStatus(h: McuParams): AxisStatus[] {
|
||||
let stats = enabledAxisMap(h);
|
||||
let mapper = (a: keyof typeof stats) => ({ axis: a, disabled: !stats[a] });
|
||||
const stats = enabledAxisMap(h);
|
||||
const mapper = (a: keyof typeof stats) => ({ axis: a, disabled: !stats[a] });
|
||||
return Object.keys(stats).map(mapper);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import { BooleanMCUInputGroupProps } from "./interfaces";
|
|||
|
||||
export function BooleanMCUInputGroup(props: BooleanMCUInputGroupProps) {
|
||||
|
||||
let {
|
||||
const {
|
||||
bot,
|
||||
tooltip,
|
||||
name,
|
||||
|
@ -21,7 +21,7 @@ export function BooleanMCUInputGroup(props: BooleanMCUInputGroupProps) {
|
|||
displayAlert
|
||||
} = props;
|
||||
|
||||
let { mcu_params } = bot.hardware;
|
||||
const { mcu_params } = bot.hardware;
|
||||
|
||||
return (
|
||||
<Row>
|
||||
|
|
|
@ -16,7 +16,7 @@ function calibrate(axis: Axis) {
|
|||
|
||||
export function CalibrationRow(props: CalibrationRowProps) {
|
||||
|
||||
let { hardware } = props;
|
||||
const { hardware } = props;
|
||||
|
||||
return <Row>
|
||||
<Col xs={6}>
|
||||
|
@ -32,7 +32,7 @@ export function CalibrationRow(props: CalibrationRowProps) {
|
|||
</Col>
|
||||
{axisTrackingStatus(hardware)
|
||||
.map(row => {
|
||||
let { axis, disabled } = row;
|
||||
const { axis, disabled } = row;
|
||||
return <Col xs={2} key={axis}>
|
||||
<LockableButton
|
||||
disabled={disabled}
|
||||
|
|
|
@ -32,7 +32,7 @@ export class CameraSelection
|
|||
|
||||
selectedCamera(): DropDownItem | undefined {
|
||||
let cameraSelection = undefined;
|
||||
let camera = this.props.env["camera"];
|
||||
const camera = this.props.env["camera"];
|
||||
if (camera) {
|
||||
cameraSelection = CAMERA_CHOICES_DDI[JSON.parse(camera)];
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ export class CameraSelection
|
|||
}
|
||||
|
||||
sendOffConfig = (selectedCamera: DropDownItem) => {
|
||||
let message = { "camera": JSON.stringify(selectedCamera.value) };
|
||||
const message = { "camera": JSON.stringify(selectedCamera.value) };
|
||||
info(t("Sending camera configuration..."), t("Sending"));
|
||||
devices
|
||||
.current
|
||||
|
|
|
@ -9,14 +9,14 @@ const LOCKED: SyncStatus = "locked";
|
|||
|
||||
export class EStopButton extends React.Component<EStopButtonProps, {}> {
|
||||
render() {
|
||||
let i = this.props.bot.hardware.informational_settings;
|
||||
let { sync_status } = i;
|
||||
let lock1 = !!i.locked;
|
||||
let lock2 = sync_status === LOCKED;
|
||||
let isLocked = lock1 || lock2;
|
||||
let toggleEmergencyLock = isLocked ? emergencyUnlock : emergencyLock;
|
||||
let emergencyLockStatusColor = isLocked ? "yellow" : "red";
|
||||
let emergencyLockStatusText = isLocked ? "UNLOCK" : "E-STOP";
|
||||
const i = this.props.bot.hardware.informational_settings;
|
||||
const { sync_status } = i;
|
||||
const lock1 = !!i.locked;
|
||||
const lock2 = sync_status === LOCKED;
|
||||
const isLocked = lock1 || lock2;
|
||||
const toggleEmergencyLock = isLocked ? emergencyUnlock : emergencyLock;
|
||||
const emergencyLockStatusColor = isLocked ? "yellow" : "red";
|
||||
const emergencyLockStatusText = isLocked ? "UNLOCK" : "E-STOP";
|
||||
|
||||
if (this.props.user) {
|
||||
return <button
|
||||
|
|
|
@ -30,9 +30,9 @@ function findByType(input: number | string | undefined) {
|
|||
}
|
||||
|
||||
export function EncoderType(props: EncoderTypeProps) {
|
||||
let { hardware } = props;
|
||||
let handleChange = (key: McuParamName) => (d: DropDownItem) => {
|
||||
let val = d.value;
|
||||
const { hardware } = props;
|
||||
const handleChange = (key: McuParamName) => (d: DropDownItem) => {
|
||||
const val = d.value;
|
||||
if (isEncoderValue(val)) {
|
||||
props.onChange(key, val);
|
||||
} else {
|
||||
|
|
|
@ -28,7 +28,7 @@ export class FarmbotOsSettings
|
|||
extends React.Component<FarmbotOsProps> {
|
||||
|
||||
changeBot = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
let { account, dispatch } = this.props;
|
||||
const { account, dispatch } = this.props;
|
||||
dispatch(edit(account, { name: e.currentTarget.value }));
|
||||
}
|
||||
|
||||
|
@ -42,13 +42,13 @@ export class FarmbotOsSettings
|
|||
}
|
||||
|
||||
handleTimezone = (timezone: string) => {
|
||||
let { account, dispatch } = this.props;
|
||||
const { account, dispatch } = this.props;
|
||||
dispatch(edit(account, { timezone }));
|
||||
dispatch(save(account.uuid));
|
||||
}
|
||||
|
||||
maybeWarnTz = () => {
|
||||
let wrongTZ = timezoneMismatch(this.props.account.body.timezone);
|
||||
const wrongTZ = timezoneMismatch(this.props.account.body.timezone);
|
||||
if (wrongTZ) {
|
||||
return `Note: The selected timezone for your FarmBot is different than
|
||||
your local browser time.`;
|
||||
|
@ -64,7 +64,7 @@ export class FarmbotOsSettings
|
|||
}
|
||||
|
||||
render() {
|
||||
let { account } = this.props;
|
||||
const { account } = this.props;
|
||||
|
||||
return <Widget className="device-widget">
|
||||
<form onSubmit={this.saveBot.bind(this)}>
|
||||
|
|
|
@ -18,7 +18,7 @@ export class HardwareSettings extends
|
|||
React.Component<HardwareSettingsProps, {}> {
|
||||
|
||||
render() {
|
||||
let { bot, dispatch } = this.props;
|
||||
const { bot, dispatch } = this.props;
|
||||
|
||||
return (
|
||||
<Widget className="hardware-widget">
|
||||
|
|
|
@ -7,8 +7,8 @@ import { Collapse } from "@blueprintjs/core";
|
|||
|
||||
export function DangerZone(props: DangerZoneProps) {
|
||||
|
||||
let { dispatch, bot, onReset } = props;
|
||||
let { danger_zone } = bot.controlPanelState;
|
||||
const { dispatch, bot, onReset } = props;
|
||||
const { danger_zone } = bot.controlPanelState;
|
||||
|
||||
return <section>
|
||||
<Header
|
||||
|
|
|
@ -9,8 +9,8 @@ import { Collapse } from "@blueprintjs/core";
|
|||
|
||||
export function EncodersAndEndStops(props: EncodersProps) {
|
||||
|
||||
let { encoders_and_endstops } = props.bot.controlPanelState;
|
||||
let { dispatch, bot } = props;
|
||||
const { encoders_and_endstops } = props.bot.controlPanelState;
|
||||
const { dispatch, bot } = props;
|
||||
|
||||
return <section>
|
||||
<Header
|
||||
|
|
|
@ -11,8 +11,8 @@ interface Props {
|
|||
}
|
||||
|
||||
export let Header = (props: Props) => {
|
||||
let { dispatch, name, title, bool } = props;
|
||||
let icon_string = bool ? "minus" : "plus";
|
||||
const { dispatch, name, title, bool } = props;
|
||||
const icon_string = bool ? "minus" : "plus";
|
||||
return <h4 onClick={() => dispatch(toggleControlPanel(name))}>
|
||||
{t(title)}
|
||||
<span className="icon-toggle">
|
||||
|
|
|
@ -13,15 +13,15 @@ import { Collapse } from "@blueprintjs/core";
|
|||
|
||||
export function HomingAndCalibration(props: HomingAndCalibrationProps) {
|
||||
|
||||
let { dispatch, bot } = props;
|
||||
let { mcu_params } = bot.hardware;
|
||||
let { homing_and_calibration } = props.bot.controlPanelState;
|
||||
const { dispatch, bot } = props;
|
||||
const { mcu_params } = bot.hardware;
|
||||
const { homing_and_calibration } = props.bot.controlPanelState;
|
||||
|
||||
/**
|
||||
* Tells us if X/Y/Z have a means of checking their position.
|
||||
* FARMBOT WILL CRASH INTO WALLS IF THIS IS WRONG! BE CAREFUL.
|
||||
*/
|
||||
let enabled = enabledAxisMap(mcu_params);
|
||||
const enabled = enabledAxisMap(mcu_params);
|
||||
|
||||
return <section>
|
||||
<Header
|
||||
|
|
|
@ -15,8 +15,8 @@ import { McuInputBox } from "../mcu_input_box";
|
|||
|
||||
export function Motors({ dispatch, bot }: MotorsProps) {
|
||||
|
||||
let { mcu_params } = bot.hardware;
|
||||
let { motors } = bot.controlPanelState;
|
||||
const { mcu_params } = bot.hardware;
|
||||
const { motors } = bot.controlPanelState;
|
||||
|
||||
return <section>
|
||||
<Header
|
||||
|
|
|
@ -11,10 +11,10 @@ import { SpacePanelToolTip } from "./space_panel_tool_tip";
|
|||
import { Row, Col } from "../../ui/index";
|
||||
|
||||
const speed = Farmbot.defaults.speed;
|
||||
let findHome = (axis: Axis) => devices.current.findHome({ speed, axis });
|
||||
const findHome = (axis: Axis) => devices.current.findHome({ speed, axis });
|
||||
|
||||
export function HomingRow(props: HomingRowProps) {
|
||||
let { hardware } = props;
|
||||
const { hardware } = props;
|
||||
|
||||
return <Row>
|
||||
<Col xs={6}>
|
||||
|
@ -25,7 +25,7 @@ export function HomingRow(props: HomingRowProps) {
|
|||
</Col>
|
||||
{axisTrackingStatus(hardware)
|
||||
.map((row) => {
|
||||
let { axis, disabled } = row;
|
||||
const { axis, disabled } = row;
|
||||
return <Col xs={2} key={axis}>
|
||||
<LockableButton disabled={disabled} onClick={() => findHome(axis)}>
|
||||
{t("HOME {{axis}}", { axis })}
|
||||
|
|
|
@ -17,8 +17,8 @@ export class LastSeen extends React.Component<LastSeenProps, {}> {
|
|||
}
|
||||
|
||||
if (this.lastSeen) {
|
||||
let text = " FarmBot was last seen {{ lastSeen }}";
|
||||
let data = {
|
||||
const text = " FarmBot was last seen {{ lastSeen }}";
|
||||
const data = {
|
||||
lastSeen: moment(this.lastSeen).local().format("MMMM D, h:mma")
|
||||
};
|
||||
return t(text, data);
|
||||
|
|
|
@ -8,7 +8,7 @@ interface Props {
|
|||
}
|
||||
|
||||
export function LockableButton({ onClick, disabled, children }: Props) {
|
||||
let className = disabled ? "gray" : "yellow";
|
||||
const className = disabled ? "gray" : "yellow";
|
||||
return <button
|
||||
className={"fb-button " + className}
|
||||
disabled={disabled}
|
||||
|
|
|
@ -12,15 +12,15 @@ export class McuInputBox extends React.Component<McuInputBoxProps, {}> {
|
|||
get key() { return this.props.setting; }
|
||||
|
||||
get value() {
|
||||
let v = this.props.bot.hardware.mcu_params[this.key];
|
||||
const v = this.props.bot.hardware.mcu_params[this.key];
|
||||
return _.isUndefined(v) ? "" : (v || 0).toString();
|
||||
}
|
||||
|
||||
commit = (e: React.SyntheticEvent<HTMLInputElement>) => {
|
||||
let { value } = e.currentTarget;
|
||||
let actuallyDifferent = this.value !== value;
|
||||
const { value } = e.currentTarget;
|
||||
const actuallyDifferent = this.value !== value;
|
||||
if (actuallyDifferent) {
|
||||
let result = clampUnsignedInteger(value);
|
||||
const result = clampUnsignedInteger(value);
|
||||
switch (result.outcome) {
|
||||
case "ok":
|
||||
break;
|
||||
|
|
|
@ -7,7 +7,7 @@ import { Col } from "../../ui/index";
|
|||
|
||||
export function NumericMCUInputGroup(props: NumericMCUInputGroupProps) {
|
||||
|
||||
let { bot, dispatch, tooltip, name, x, y, z } = props;
|
||||
const { bot, dispatch, tooltip, name, x, y, z } = props;
|
||||
|
||||
return <Row>
|
||||
<Col xs={6}>
|
||||
|
|
|
@ -9,11 +9,11 @@ import * as _ from "lodash";
|
|||
import { Row, Col } from "../../ui/index";
|
||||
|
||||
export let OsUpdateButton = ({ bot }: BotProp) => {
|
||||
let osUpdateBool = bot.hardware.configuration.os_auto_update;
|
||||
const osUpdateBool = bot.hardware.configuration.os_auto_update;
|
||||
let buttonStr = "Can't Connect to bot";
|
||||
let buttonColor = "yellow";
|
||||
let { currentOSVersion } = bot;
|
||||
let { controller_version } = bot.hardware.informational_settings;
|
||||
const { currentOSVersion } = bot;
|
||||
const { controller_version } = bot.hardware.informational_settings;
|
||||
if (_.isString(currentOSVersion) && _.isString(controller_version)) {
|
||||
switch (semverCompare(currentOSVersion, controller_version)) {
|
||||
case SemverResult.RIGHT_IS_GREATER:
|
||||
|
@ -28,18 +28,18 @@ export let OsUpdateButton = ({ bot }: BotProp) => {
|
|||
} else {
|
||||
buttonStr = "Can't Connect to release server";
|
||||
}
|
||||
let toggleVal = isUndefined(osUpdateBool) ? "undefined" : ("" + osUpdateBool);
|
||||
const toggleVal = isUndefined(osUpdateBool) ? "undefined" : ("" + osUpdateBool);
|
||||
let downloadProgress = "";
|
||||
let disabled = false;
|
||||
// DONT TOUCH THIS!!! SERIOUSLY -- RC 8 August
|
||||
// DO NOT REMOVE `|| {}` UNTIL SEPTEMBER.
|
||||
let job = (bot.hardware.jobs || {})["FBOS_OTA"];
|
||||
const job = (bot.hardware.jobs || {})["FBOS_OTA"];
|
||||
if (job) {
|
||||
if (job.status == "working") {
|
||||
disabled = true;
|
||||
if (job.unit == "bytes") {
|
||||
let kiloBytes = Math.round(job.bytes / 1024);
|
||||
let megaBytes = Math.round(job.bytes / 1048576);
|
||||
const kiloBytes = Math.round(job.bytes / 1024);
|
||||
const megaBytes = Math.round(job.bytes / 1048576);
|
||||
if (kiloBytes < 1) {
|
||||
downloadProgress = job.bytes + "B";
|
||||
} else if (megaBytes < 1) {
|
||||
|
@ -62,7 +62,7 @@ export let OsUpdateButton = ({ bot }: BotProp) => {
|
|||
<Col xs={1}>
|
||||
<ToggleButton toggleValue={toggleVal}
|
||||
toggleAction={() => {
|
||||
let os_auto_update = !osUpdateBool ? 1 : 0;
|
||||
const os_auto_update = !osUpdateBool ? 1 : 0;
|
||||
updateConfig({ os_auto_update })(noop);
|
||||
}} />
|
||||
</Col>
|
||||
|
|
|
@ -18,8 +18,8 @@ export class BotConfigInputBox extends React.Component<StepsPerMMBoxProps, {}> {
|
|||
|
||||
change = (key: ConfigurationName, dispatch: Function) => {
|
||||
return (event: React.FormEvent<HTMLInputElement>) => {
|
||||
let next = parseInt(event.currentTarget.value, 10);
|
||||
let current = this.config[this.setting];
|
||||
const next = parseInt(event.currentTarget.value, 10);
|
||||
const current = this.config[this.setting];
|
||||
if (!_.isNaN(next) && (next !== current)) {
|
||||
dispatch(updateConfig({ [key]: next }));
|
||||
}
|
||||
|
@ -27,8 +27,8 @@ export class BotConfigInputBox extends React.Component<StepsPerMMBoxProps, {}> {
|
|||
}
|
||||
|
||||
render() {
|
||||
let hmm = this.config[this.setting];
|
||||
let value = (_.isNumber(hmm) || _.isBoolean(hmm)) ? hmm.toString() : "";
|
||||
const hmm = this.config[this.setting];
|
||||
const value = (_.isNumber(hmm) || _.isBoolean(hmm)) ? hmm.toString() : "";
|
||||
|
||||
return <BlurableInput
|
||||
type="number"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import * as _ from "lodash";
|
||||
/** Remove this in October 2017 - RC */
|
||||
let ONLY_ONCE = {
|
||||
const ONLY_ONCE = {
|
||||
need_to_talk: true
|
||||
};
|
||||
|
||||
|
@ -8,7 +8,7 @@ export function inferTimezone(current: string | undefined): string {
|
|||
if (current) {
|
||||
return current;
|
||||
}
|
||||
let browserTime = maybeResolveTZ();
|
||||
const browserTime = maybeResolveTZ();
|
||||
if (browserTime) {
|
||||
if (ONLY_ONCE.need_to_talk) {
|
||||
alert("This account did not have a timezone set. " +
|
||||
|
|
|
@ -18,7 +18,7 @@ export class TimezoneSelector extends React.Component<TZSelectorProps, {}> {
|
|||
}
|
||||
|
||||
componentDidMount() {
|
||||
let tz = inferTimezone(this.props.currentTimezone);
|
||||
const tz = inferTimezone(this.props.currentTimezone);
|
||||
if (!this.props.currentTimezone) {
|
||||
// Nasty hack to prepopulate data of users who have yet to set a TZ.
|
||||
this.props.onUpdate(tz);
|
||||
|
@ -26,7 +26,7 @@ export class TimezoneSelector extends React.Component<TZSelectorProps, {}> {
|
|||
}
|
||||
|
||||
selectedItem = (): DropDownItem => {
|
||||
let tz = inferTimezone(this.props.currentTimezone);
|
||||
const tz = inferTimezone(this.props.currentTimezone);
|
||||
return { label: tz, value: tz };
|
||||
}
|
||||
|
||||
|
|
|
@ -20,19 +20,19 @@ describe("draggableReducer", () => {
|
|||
}
|
||||
|
||||
it("puts a step", () => {
|
||||
let payload = { uuid: "FOO" };
|
||||
let action = { type: Actions.PUT_DATA_XFER, payload };
|
||||
let nextState = draggableReducer(emptyState(), action);
|
||||
let dt = nextState.dataTransfer;
|
||||
const payload = { uuid: "FOO" };
|
||||
const action = { type: Actions.PUT_DATA_XFER, payload };
|
||||
const nextState = draggableReducer(emptyState(), action);
|
||||
const dt = nextState.dataTransfer;
|
||||
expect(Object.keys(dt)).toContain(payload.uuid);
|
||||
let entry = dt[payload.uuid];
|
||||
const entry = dt[payload.uuid];
|
||||
expect(entry && entry.uuid).toEqual(payload.uuid);
|
||||
});
|
||||
|
||||
it("drops a step", () => {
|
||||
let payload = "BAR";
|
||||
let action = { type: Actions.DROP_DATA_XFER, payload };
|
||||
let nextState = draggableReducer(emptyState(), action);
|
||||
const payload = "BAR";
|
||||
const action = { type: Actions.DROP_DATA_XFER, payload };
|
||||
const nextState = draggableReducer(emptyState(), action);
|
||||
expect(Object.keys(nextState.dataTransfer).length)
|
||||
.toEqual(0);
|
||||
});
|
||||
|
|
|
@ -15,7 +15,7 @@ export function stepPut(value: Step,
|
|||
intent: DataXferIntent,
|
||||
draggerId: number):
|
||||
ReduxAction<DataXferBase> {
|
||||
let uuid = id();
|
||||
const uuid = id();
|
||||
ev.dataTransfer.setData(STEP_DATATRANSFER_IDENTIFER, uuid);
|
||||
return {
|
||||
type: Actions.PUT_DATA_XFER,
|
||||
|
@ -35,7 +35,7 @@ export function stepGet(uuid: string) {
|
|||
return function (dispatch: Function,
|
||||
getState: () => Everything):
|
||||
DataXfer {
|
||||
let obj = getState().draggable.dataTransfer[uuid];
|
||||
const obj = getState().draggable.dataTransfer[uuid];
|
||||
if (obj && obj.intent) {
|
||||
dispatch({ type: "DROP_DATA_XFER", payload: uuid });
|
||||
return obj;
|
||||
|
|
|
@ -8,7 +8,7 @@ export function addGhostImage(
|
|||
ev: React.DragEvent<HTMLElement>,
|
||||
/** Optional CSS class to add to drag image. */
|
||||
cssClass = "") {
|
||||
let el = ev.currentTarget.cloneNode(true) as HTMLElement;
|
||||
const el = ev.currentTarget.cloneNode(true) as HTMLElement;
|
||||
// RELEVANT READING:
|
||||
// https://www.kryogenix.org/code/browser/custom-drag-image.html
|
||||
el.classList.add(cssClass);
|
||||
|
@ -21,7 +21,7 @@ export function addGhostImage(
|
|||
// Because of MS Edge.
|
||||
// I really could care less about IE, but edge seems
|
||||
// to be OK aside from this one issue.
|
||||
let dt = ev.dataTransfer;
|
||||
const dt = ev.dataTransfer;
|
||||
if (dt && dt.setDragImage) {
|
||||
dt.setDragImage(el, 0, 0);
|
||||
}
|
||||
|
|
|
@ -12,8 +12,8 @@ export class DropArea extends React.Component<DropAreaProps, DropAreaState> {
|
|||
|
||||
drop = (e: React.DragEvent<HTMLElement>) => {
|
||||
e.preventDefault();
|
||||
let key = e.dataTransfer.getData(STEP_DATATRANSFER_IDENTIFER);
|
||||
let fn = this.props.callback;
|
||||
const key = e.dataTransfer.getData(STEP_DATATRANSFER_IDENTIFER);
|
||||
const fn = this.props.callback;
|
||||
if (fn) {
|
||||
fn(key);
|
||||
}
|
||||
|
@ -25,8 +25,8 @@ export class DropArea extends React.Component<DropAreaProps, DropAreaState> {
|
|||
};
|
||||
|
||||
render() {
|
||||
let isVisible = this.props.isLocked || this.state.isHovered;
|
||||
let klass = isVisible ? "drag-drop-area" : "";
|
||||
const isVisible = this.props.isLocked || this.state.isHovered;
|
||||
const klass = isVisible ? "drag-drop-area" : "";
|
||||
return <div
|
||||
className={klass}
|
||||
onDragLeave={this.toggle}
|
||||
|
|
|
@ -3,8 +3,8 @@ import { defensiveClone } from "../util";
|
|||
import { edit } from "../api/crud";
|
||||
|
||||
export function movePlant(payload: MovePlantProps) {
|
||||
let tr = payload.plant;
|
||||
let update = defensiveClone(payload.plant).body;
|
||||
const tr = payload.plant;
|
||||
const update = defensiveClone(payload.plant).body;
|
||||
update.x += payload.deltaX;
|
||||
update.y += payload.deltaY;
|
||||
return edit(tr, update);
|
||||
|
|
|
@ -7,7 +7,7 @@ import { repeatOptions } from "../map_state_to_props_add_edit";
|
|||
import { SpecialStatus } from "../../../resources/tagged_resources";
|
||||
|
||||
describe("<FarmEventForm/>", () => {
|
||||
let props = (): EditFEForm["props"] => ({
|
||||
const props = (): EditFEForm["props"] => ({
|
||||
deviceTimezone: undefined,
|
||||
executableOptions: [],
|
||||
repeatOptions: [],
|
||||
|
@ -20,7 +20,7 @@ describe("<FarmEventForm/>", () => {
|
|||
function instance(p: EditFEProps) {
|
||||
return mount<EditFEProps>(<EditFEForm {...p } />).instance() as EditFEForm;
|
||||
}
|
||||
let context = { form: new EditFEForm(props()) };
|
||||
const context = { form: new EditFEForm(props()) };
|
||||
|
||||
beforeEach(() => {
|
||||
context.form = new EditFEForm(props());
|
||||
|
@ -31,7 +31,7 @@ describe("<FarmEventForm/>", () => {
|
|||
});
|
||||
|
||||
it("determines if it is a one time event", () => {
|
||||
let i = instance(props());
|
||||
const i = instance(props());
|
||||
expect(i.isOneTime).toBe(true);
|
||||
i.mergeState("timeUnit", "daily");
|
||||
i.forceUpdate();
|
||||
|
@ -39,19 +39,19 @@ describe("<FarmEventForm/>", () => {
|
|||
});
|
||||
|
||||
it("has a dispatch", () => {
|
||||
let p = props();
|
||||
let i = instance(p);
|
||||
const p = props();
|
||||
const i = instance(p);
|
||||
expect(i.dispatch).toBe(p.dispatch);
|
||||
i.dispatch();
|
||||
expect((p.dispatch as jest.Mock<{}>).mock.calls.length).toBe(1);
|
||||
});
|
||||
|
||||
it("has a view model", () => {
|
||||
let p = props();
|
||||
let i = instance(p);
|
||||
const p = props();
|
||||
const i = instance(p);
|
||||
i.forceUpdate();
|
||||
let vm = i.viewModel;
|
||||
let KEYS: (keyof FarmEventViewModel)[] = [
|
||||
const vm = i.viewModel;
|
||||
const KEYS: (keyof FarmEventViewModel)[] = [
|
||||
"startDate",
|
||||
"startTime",
|
||||
"endDate",
|
||||
|
@ -67,16 +67,16 @@ describe("<FarmEventForm/>", () => {
|
|||
});
|
||||
|
||||
it("has an executable", () => {
|
||||
let p = props();
|
||||
let i = instance(p);
|
||||
const p = props();
|
||||
const i = instance(p);
|
||||
i.forceUpdate();
|
||||
expect(i.executableGet().value).toEqual(fakeSequence().body.id);
|
||||
expect(i.executableGet().label).toEqual(fakeSequence().body.name);
|
||||
});
|
||||
|
||||
it("sets the executable", () => {
|
||||
let p = props();
|
||||
let i = instance(p);
|
||||
const p = props();
|
||||
const i = instance(p);
|
||||
i.forceUpdate();
|
||||
i.executableSet({ value: "wow", label: "hey", headingId: "Sequence" });
|
||||
i.forceUpdate();
|
||||
|
@ -85,18 +85,18 @@ describe("<FarmEventForm/>", () => {
|
|||
});
|
||||
|
||||
it("gets executable info", () => {
|
||||
let p = props();
|
||||
let i = instance(p);
|
||||
const p = props();
|
||||
const i = instance(p);
|
||||
i.forceUpdate();
|
||||
let exe = i.executableGet();
|
||||
const exe = i.executableGet();
|
||||
expect(exe.label).toBe("fake");
|
||||
expect(exe.value).toBe(12);
|
||||
expect(exe.headingId).toBe("Sequence");
|
||||
});
|
||||
|
||||
it("sets a subfield of state.fe", () => {
|
||||
let p = props();
|
||||
let i = instance(p);
|
||||
const p = props();
|
||||
const i = instance(p);
|
||||
i.forceUpdate();
|
||||
i.fieldSet("repeat")(({ currentTarget: { value: "4" } } as any));
|
||||
i.forceUpdate();
|
||||
|
@ -104,7 +104,7 @@ describe("<FarmEventForm/>", () => {
|
|||
});
|
||||
|
||||
it("sets regimen repeat to `never` as needed", () => {
|
||||
let result = recombine({
|
||||
const result = recombine({
|
||||
"startDate": "2017-08-01",
|
||||
"startTime": "08:35",
|
||||
"endDate": "2017-08-01",
|
||||
|
@ -119,7 +119,7 @@ describe("<FarmEventForm/>", () => {
|
|||
});
|
||||
|
||||
it("Recombines local state back into a Partial<TaggedFarmEvent[\"body\"]>", () => {
|
||||
let result = recombine({
|
||||
const result = recombine({
|
||||
"startDate": "2017-08-01",
|
||||
"startTime": "08:35",
|
||||
"endDate": "2017-08-01",
|
||||
|
@ -140,10 +140,10 @@ describe("<FarmEventForm/>", () => {
|
|||
});
|
||||
|
||||
it("renders the correct save button text when adding", () => {
|
||||
let seq = fakeSequence();
|
||||
let fe = fakeFarmEvent("Sequence", seq.body.id || 0);
|
||||
const seq = fakeSequence();
|
||||
const fe = fakeFarmEvent("Sequence", seq.body.id || 0);
|
||||
fe.specialStatus = SpecialStatus.DIRTY;
|
||||
let el = mount(<EditFEForm
|
||||
const el = mount(<EditFEForm
|
||||
farmEvent={fe}
|
||||
title=""
|
||||
deviceTimezone="America/Chicago"
|
||||
|
@ -158,7 +158,7 @@ describe("<FarmEventForm/>", () => {
|
|||
dispatch={jest.fn()}
|
||||
repeatOptions={repeatOptions} />);
|
||||
el.update();
|
||||
let txt = el.text().replace(/\s+/g, " ");
|
||||
const txt = el.text().replace(/\s+/g, " ");
|
||||
expect(txt).toContain("Save *");
|
||||
});
|
||||
});
|
||||
|
|
|
@ -35,8 +35,8 @@ function getProp(el: ShallowWrapper<{}, {}>, query: string, prop: string) {
|
|||
|
||||
describe("<FarmEventRepeatForm/>", () => {
|
||||
it("shows proper values", () => {
|
||||
let p = props();
|
||||
let el = shallow<RepeatFormProps>(<FarmEventRepeatForm {...p } />);
|
||||
const p = props();
|
||||
const el = shallow<RepeatFormProps>(<FarmEventRepeatForm {...p } />);
|
||||
expect(formVal(el, Selectors.REPEAT)).toEqual(p.repeat);
|
||||
expect(formVal(el, Selectors.END_DATE)).toEqual(p.endDate);
|
||||
expect(formVal(el, Selectors.END_TIME)).toEqual(p.endTime);
|
||||
|
@ -44,17 +44,17 @@ describe("<FarmEventRepeatForm/>", () => {
|
|||
});
|
||||
|
||||
it("defaults to `daily` when a bad input it passed", () => {
|
||||
let p = props();
|
||||
const p = props();
|
||||
p.timeUnit = "never";
|
||||
let el = shallow<RepeatFormProps>(<FarmEventRepeatForm {...p } />);
|
||||
const el = shallow<RepeatFormProps>(<FarmEventRepeatForm {...p } />);
|
||||
expect(formVal(el, Selectors.REPEAT)).toEqual(p.repeat);
|
||||
expect(getProp(el, "FBSelect", "selectedItem.value")).toEqual("daily");
|
||||
});
|
||||
|
||||
it("disables all inputs via the `disabled` prop", () => {
|
||||
let p = props();
|
||||
const p = props();
|
||||
p.disabled = true;
|
||||
let el = shallow<RepeatFormProps>(<FarmEventRepeatForm {...p } />);
|
||||
const el = shallow<RepeatFormProps>(<FarmEventRepeatForm {...p } />);
|
||||
expect(getProp(el, Selectors.END_DATE, "disabled")).toBeTruthy();
|
||||
expect(getProp(el, Selectors.END_TIME, "disabled")).toBeTruthy();
|
||||
expect(getProp(el, Selectors.REPEAT, "disabled")).toBeTruthy();
|
||||
|
@ -62,9 +62,9 @@ describe("<FarmEventRepeatForm/>", () => {
|
|||
});
|
||||
|
||||
it("hides", () => {
|
||||
let p = props();
|
||||
const p = props();
|
||||
p.hidden = true;
|
||||
let el = render(<FarmEventRepeatForm {...p } />);
|
||||
const el = render(<FarmEventRepeatForm {...p } />);
|
||||
expect(el.text()).toEqual("");
|
||||
});
|
||||
});
|
||||
|
|
|
@ -8,10 +8,10 @@ import { get } from "lodash";
|
|||
|
||||
describe("<PureFarmEvents/>", () => {
|
||||
it("sorts items correctly", () => {
|
||||
let push = jest.fn();
|
||||
let results = render(<PureFarmEvents push={push}
|
||||
const push = jest.fn();
|
||||
const results = render(<PureFarmEvents push={push}
|
||||
calendarRows={calendarRows} />);
|
||||
let rows = results
|
||||
const rows = results
|
||||
.find(".farm-event-data-time")
|
||||
.toArray()
|
||||
.map(x => x.children)
|
||||
|
|
|
@ -44,11 +44,11 @@ export class AddFarmEvent
|
|||
|
||||
componentDidMount() {
|
||||
if (this.executable) {
|
||||
let executable_type: ExecutableType =
|
||||
const executable_type: ExecutableType =
|
||||
(this.executable.kind === "sequences") ? "Sequence" : "Regimen";
|
||||
let executable_id = this.executable.body.id || 1;
|
||||
let NOW = moment().toISOString();
|
||||
let action = init({
|
||||
const executable_id = this.executable.body.id || 1;
|
||||
const NOW = moment().toISOString();
|
||||
const action = init({
|
||||
kind: "farm_events",
|
||||
specialStatus: SpecialStatus.DIRTY,
|
||||
uuid: "---",
|
||||
|
@ -94,11 +94,11 @@ export class AddFarmEvent
|
|||
}
|
||||
|
||||
render() {
|
||||
let { uuid } = this.state;
|
||||
const { uuid } = this.state;
|
||||
// Legacy leftover from pre-TaggedResource era.
|
||||
// TODO: Proper fix where we add a `findFarmEvent` selector
|
||||
// to mapStateToProps instead of juggling arrays.
|
||||
let fe = uuid && this.props.farmEvents.filter(x => x.uuid === uuid)[0];
|
||||
const fe = uuid && this.props.farmEvents.filter(x => x.uuid === uuid)[0];
|
||||
if (fe) {
|
||||
return (
|
||||
<EditFEForm
|
||||
|
|
|
@ -7,13 +7,13 @@ import {
|
|||
|
||||
describe("calendar", () => {
|
||||
it("constructs itself with defaults", () => {
|
||||
let calendar = new Calendar();
|
||||
const calendar = new Calendar();
|
||||
expect(calendar.getAll().length).toEqual(0);
|
||||
expect(calendar.value).toEqual({});
|
||||
});
|
||||
|
||||
it("inserts dates", () => {
|
||||
let calendar = new Calendar();
|
||||
const calendar = new Calendar();
|
||||
calendar.insert(occurrence(TIME.MONDAY, fakeFarmEventWithExecutable()));
|
||||
calendar.insert(occurrence(TIME.TUESDAY, fakeFarmEventWithExecutable()));
|
||||
expect(calendar.getAll().length).toEqual(2);
|
||||
|
@ -23,8 +23,8 @@ describe("calendar", () => {
|
|||
});
|
||||
|
||||
it("finds by date", () => {
|
||||
let calendar = new Calendar();
|
||||
let wow = occurrence(TIME.MONDAY, fakeFarmEventWithExecutable());
|
||||
const calendar = new Calendar();
|
||||
const wow = occurrence(TIME.MONDAY, fakeFarmEventWithExecutable());
|
||||
calendar.insert(wow);
|
||||
expect(calendar.findByDate(TIME.FRIDAY)).toBeInstanceOf(Array);
|
||||
expect(calendar.findByDate(TIME.MONDAY)).toContain(wow);
|
||||
|
|
|
@ -7,8 +7,8 @@ import {
|
|||
|
||||
describe("occurrence", () => {
|
||||
it("builds a single entry for the calendar", () => {
|
||||
let fe = fakeFarmEventWithExecutable();
|
||||
let t = occurrence(TIME.MONDAY, fe);
|
||||
const fe = fakeFarmEventWithExecutable();
|
||||
const t = occurrence(TIME.MONDAY, fe);
|
||||
expect(t.executableId).toBe(fe.executable_id);
|
||||
expect(t.mmddyy).toBe("061917");
|
||||
expect(t.sortKey).toBe(moment(TIME.MONDAY).unix());
|
||||
|
|
|
@ -5,17 +5,17 @@ import { TimeUnit } from "../../../interfaces";
|
|||
describe("scheduler", () => {
|
||||
it("runs every 4 hours, starting Tu, until Th w/ origin of Mo", () => {
|
||||
// 8am Monday
|
||||
let monday = moment()
|
||||
const monday = moment()
|
||||
.add(14, "days")
|
||||
.startOf("isoWeek")
|
||||
.startOf("day")
|
||||
.add(8, "hours");
|
||||
// 3am Tuesday
|
||||
let tuesday = monday.clone().add(19, "hours");
|
||||
const tuesday = monday.clone().add(19, "hours");
|
||||
// 18pm Thursday
|
||||
let thursday = monday.clone().add(3, "days").add(10, "hours");
|
||||
let interval = moment.duration(4, "hours").asSeconds();
|
||||
let result1 = scheduler({
|
||||
const thursday = monday.clone().add(3, "days").add(10, "hours");
|
||||
const interval = moment.duration(4, "hours").asSeconds();
|
||||
const result1 = scheduler({
|
||||
originTime: monday,
|
||||
intervalSeconds: interval,
|
||||
lowerBound: tuesday,
|
||||
|
@ -50,7 +50,7 @@ describe("scheduler", () => {
|
|||
});
|
||||
|
||||
it("schedules a FarmEvent", () => {
|
||||
let fakeEvent: TimeLine = {
|
||||
const fakeEvent: TimeLine = {
|
||||
"start_time": "2017-08-01T17:30:00.000Z",
|
||||
"end_time": "2017-08-07T05:00:00.000Z",
|
||||
"repeat": 2,
|
||||
|
@ -61,7 +61,7 @@ it("schedules a FarmEvent", () => {
|
|||
moment("2017-08-03T17:30:00.000Z"),
|
||||
moment("2017-08-05T17:30:00.000Z")
|
||||
];
|
||||
let result = scheduleForFarmEvent(fakeEvent);
|
||||
const result = scheduleForFarmEvent(fakeEvent);
|
||||
expect(result.length).toEqual(3);
|
||||
EXPECTED.map((expectation, index) => {
|
||||
expect(expectation.isSame(result[index])).toBeTruthy();
|
||||
|
@ -76,7 +76,7 @@ describe("farmEventIntervalSeconds", () => {
|
|||
unit: TimeUnit;
|
||||
}
|
||||
|
||||
let tests: TestBarage[] = [
|
||||
const tests: TestBarage[] = [
|
||||
{ count: 9, unit: "daily", result: 777600 },
|
||||
{ count: 8, unit: "hourly", result: 28800 },
|
||||
{ count: 1, unit: "daily", result: 86400 },
|
||||
|
|
|
@ -26,19 +26,19 @@ export class Calendar {
|
|||
constructor(public value: Dictionary<CalendarOccurrence[]> = {}) { }
|
||||
|
||||
insert(occur: CalendarOccurrence) {
|
||||
let k = occur.mmddyy;
|
||||
const k = occur.mmddyy;
|
||||
this.value[k] = this.value[k] || [];
|
||||
this.value[k].push(occur);
|
||||
}
|
||||
|
||||
getAll(): CalendarDay[] {
|
||||
let all = Object
|
||||
const all = Object
|
||||
.keys(this.value)
|
||||
.map(x => this.value[x])
|
||||
.filter(x => !!x) // Poor man's compact() function.
|
||||
.filter(x => !!x.length) // Don't bother rendering empty days.
|
||||
.map((items): CalendarDay => {
|
||||
let item = items[0];
|
||||
const item = items[0];
|
||||
return {
|
||||
sortKey: item.sortKey,
|
||||
year: parseInt(item.mmddyy.slice(4, 6)),
|
||||
|
|
|
@ -11,7 +11,7 @@ interface SchedulerProps {
|
|||
upperBound?: Moment;
|
||||
}
|
||||
|
||||
let nextYear = () => moment(moment().add(1, "year"));
|
||||
const nextYear = () => moment(moment().add(1, "year"));
|
||||
|
||||
export function scheduler({ originTime,
|
||||
intervalSeconds,
|
||||
|
@ -22,18 +22,18 @@ export function scheduler({ originTime,
|
|||
}
|
||||
upperBound = upperBound || nextYear();
|
||||
// # How many items must we skip to get to the first occurence?
|
||||
let skip_intervals =
|
||||
const skip_intervals =
|
||||
Math.ceil((lowerBound.unix() - originTime.unix()) / intervalSeconds);
|
||||
// # At what time does the first event occur?
|
||||
let first_item = originTime
|
||||
const first_item = originTime
|
||||
.clone()
|
||||
.add((skip_intervals * intervalSeconds), "seconds");
|
||||
let list = [first_item];
|
||||
const list = [first_item];
|
||||
|
||||
times(60, () => {
|
||||
let x = last(list);
|
||||
const x = last(list);
|
||||
if (x) {
|
||||
let item = x.clone().add(intervalSeconds, "seconds");
|
||||
const item = x.clone().add(intervalSeconds, "seconds");
|
||||
if (item.isBefore(upperBound)) {
|
||||
list.push(item);
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ const LOOKUP: Record<TimeUnit, unitOfTime.Base> = {
|
|||
* EXAMPLE: f(2, "minutely") => 120;
|
||||
*/
|
||||
export function farmEventIntervalSeconds(repeat: number, unit: TimeUnit) {
|
||||
let momentUnit = LOOKUP[unit];
|
||||
const momentUnit = LOOKUP[unit];
|
||||
if ((unit === NEVER) || !(momentUnit)) {
|
||||
return 0;
|
||||
} else {
|
||||
|
@ -79,9 +79,9 @@ export interface TimeLine {
|
|||
/** Takes a subset of FarmEvent<Sequence> data and generates a list of dates. */
|
||||
export function scheduleForFarmEvent({ start_time, end_time, repeat, time_unit }:
|
||||
TimeLine): Moment[] {
|
||||
let i = repeat && farmEventIntervalSeconds(repeat, time_unit);
|
||||
const i = repeat && farmEventIntervalSeconds(repeat, time_unit);
|
||||
if (i && (time_unit !== NEVER)) {
|
||||
let hmm = scheduler({
|
||||
const hmm = scheduler({
|
||||
originTime: moment(start_time),
|
||||
lowerBound: moment(start_time),
|
||||
upperBound: end_time ? moment(end_time) : nextYear(),
|
||||
|
|
|
@ -8,17 +8,17 @@ import {
|
|||
import { betterCompact } from "../../../util";
|
||||
|
||||
export function joinFarmEventsToExecutable(input: ResourceIndex): FarmEventWithExecutable[] {
|
||||
let farmEvents = selectAllFarmEvents(input);
|
||||
let sequenceById = indexSequenceById(input);
|
||||
let regimenById = indexRegimenById(input);
|
||||
const farmEvents = selectAllFarmEvents(input);
|
||||
const sequenceById = indexSequenceById(input);
|
||||
const regimenById = indexRegimenById(input);
|
||||
|
||||
return betterCompact(farmEvents.map(function (fe) {
|
||||
let body = fe.body;
|
||||
let id = fe.body.executable_id;
|
||||
const body = fe.body;
|
||||
const id = fe.body.executable_id;
|
||||
if (id) {
|
||||
switch (body.executable_type) {
|
||||
case "Sequence":
|
||||
let executable1 = sequenceById[id];
|
||||
const executable1 = sequenceById[id];
|
||||
if (executable1) {
|
||||
return {
|
||||
...body,
|
||||
|
@ -29,7 +29,7 @@ export function joinFarmEventsToExecutable(input: ResourceIndex): FarmEventWithE
|
|||
throw new Error("Bad executable ID (sequence): " + id);
|
||||
}
|
||||
case "Regimen":
|
||||
let executable2 = regimenById[id];
|
||||
const executable2 = regimenById[id];
|
||||
if (executable2) {
|
||||
return {
|
||||
...body,
|
||||
|
|
|
@ -25,7 +25,7 @@ export class EditFarmEvent extends React.Component<AddEditFarmEventProps, {}> {
|
|||
}
|
||||
|
||||
render() {
|
||||
let fe = this.props.getFarmEvent();
|
||||
const fe = this.props.getFarmEvent();
|
||||
return fe ? this.renderForm(fe) : this.redirect();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ function destructureFarmEvent(fe: TaggedFarmEvent): FarmEventViewModel {
|
|||
* that can be used to apply updates (such as a PUT request to the API). */
|
||||
export function recombine(vm: FarmEventViewModel): Partial<TaggedFarmEvent["body"]> {
|
||||
// Make sure that `repeat` is set to `never` when dealing with regimens.
|
||||
let isReg = vm.executable_type === "Regimen";
|
||||
const isReg = vm.executable_type === "Regimen";
|
||||
return {
|
||||
start_time: moment(vm.startDate + " " + vm.startTime).toISOString(),
|
||||
end_time: moment(vm.endDate + " " + vm.endTime).toISOString(),
|
||||
|
@ -115,8 +115,8 @@ export class EditFEForm extends React.Component<EditFEProps, State> {
|
|||
get viewModel() { return destructureFarmEvent(this.props.farmEvent); }
|
||||
|
||||
get executable() {
|
||||
let et = this.fieldGet("executable_type");
|
||||
let id = parseInt(this.fieldGet("executable_id"));
|
||||
const et = this.fieldGet("executable_type");
|
||||
const id = parseInt(this.fieldGet("executable_id"));
|
||||
if (et === "Sequence" || et === "Regimen") {
|
||||
return this.props.findExecutable(et, id);
|
||||
} else {
|
||||
|
@ -126,7 +126,7 @@ export class EditFEForm extends React.Component<EditFEProps, State> {
|
|||
|
||||
executableSet = (e: DropDownItem) => {
|
||||
if (e.value) {
|
||||
let update: Partial<State> = {
|
||||
const update: Partial<State> = {
|
||||
fe: {
|
||||
executable_type: executableType(e.headingId),
|
||||
executable_id: (e.value || "").toString()
|
||||
|
@ -138,7 +138,7 @@ export class EditFEForm extends React.Component<EditFEProps, State> {
|
|||
}
|
||||
|
||||
executableGet = (): DropDownItem => {
|
||||
let headingId: ExecutableType =
|
||||
const headingId: ExecutableType =
|
||||
(this.executable.kind === "sequences") ?
|
||||
"Sequence" : "Regimen";
|
||||
return {
|
||||
|
@ -167,20 +167,20 @@ export class EditFEForm extends React.Component<EditFEProps, State> {
|
|||
}
|
||||
|
||||
toggleRepeat = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
let { checked } = e.currentTarget;
|
||||
const { checked } = e.currentTarget;
|
||||
this.mergeState("timeUnit", (!checked || this.isReg) ? "never" : "daily");
|
||||
};
|
||||
|
||||
commitViewModel = () => {
|
||||
let partial = recombine(betterMerge(this.viewModel, this.state.fe));
|
||||
const partial = recombine(betterMerge(this.viewModel, this.state.fe));
|
||||
this.dispatch(edit(this.props.farmEvent, partial));
|
||||
this
|
||||
.dispatch(save(this.props.farmEvent.uuid))
|
||||
.then(() => {
|
||||
this.setState({ specialStatusLocal: undefined });
|
||||
history.push("/app/designer/farm_events");
|
||||
let frmEvnt = this.props.farmEvent;
|
||||
let nextRun = _.first(scheduleForFarmEvent(frmEvnt.body));
|
||||
const frmEvnt = this.props.farmEvent;
|
||||
const nextRun = _.first(scheduleForFarmEvent(frmEvnt.body));
|
||||
if (nextRun) {
|
||||
// TODO: Internationalizing this will be a challenge.
|
||||
success(`This Farm Event will run ${nextRun.fromNow()}, but
|
||||
|
@ -207,9 +207,9 @@ export class EditFEForm extends React.Component<EditFEProps, State> {
|
|||
}
|
||||
|
||||
render() {
|
||||
let fe = this.props.farmEvent;
|
||||
let repeats = this.fieldGet("timeUnit") !== NEVER;
|
||||
let allowRepeat = (!this.isReg && repeats);
|
||||
const fe = this.props.farmEvent;
|
||||
const repeats = this.fieldGet("timeUnit") !== NEVER;
|
||||
const allowRepeat = (!this.isReg && repeats);
|
||||
return (
|
||||
<div className="panel-container magenta-panel add-farm-event-panel">
|
||||
<div className="panel-header magenta-panel">
|
||||
|
|
|
@ -22,12 +22,12 @@ export interface RepeatFormProps {
|
|||
endTime: string;
|
||||
}
|
||||
|
||||
let indexKey: keyof DropDownItem = "value";
|
||||
const indexKey: keyof DropDownItem = "value";
|
||||
const OPTN_LOOKUP = keyBy(repeatOptions, indexKey);
|
||||
|
||||
export function FarmEventRepeatForm(props: RepeatFormProps) {
|
||||
let { disabled, onChange, repeat, endDate, endTime, timeUnit } = props;
|
||||
let changeHandler =
|
||||
const { disabled, onChange, repeat, endDate, endTime, timeUnit } = props;
|
||||
const changeHandler =
|
||||
(key: Key) => (e: Ev) => onChange(key, e.currentTarget.value);
|
||||
if (props.hidden) {
|
||||
return <div />;
|
||||
|
|
|
@ -15,7 +15,7 @@ export class PureFarmEvents extends React.Component<FarmEventProps, {}> {
|
|||
.sortBy(x => x.sortKey)
|
||||
.value()
|
||||
.map((farmEvent, index) => {
|
||||
let url = `/app/designer/farm_events/` + (farmEvent.id || "UNSAVED_EVENT").toString();
|
||||
const url = `/app/designer/farm_events/` + (farmEvent.id || "UNSAVED_EVENT").toString();
|
||||
let heading: string;
|
||||
let subHeading: JSX.Element;
|
||||
|
||||
|
@ -71,7 +71,7 @@ export class PureFarmEvents extends React.Component<FarmEventProps, {}> {
|
|||
}
|
||||
|
||||
renderCalendarRows() {
|
||||
let years = _.uniq(_.map(this.props.calendarRows, "year"));
|
||||
const years = _.uniq(_.map(this.props.calendarRows, "year"));
|
||||
return years.map(year => {
|
||||
return (
|
||||
<div key={moment(year, "YY").unix()}>
|
||||
|
|
|
@ -11,17 +11,17 @@ import { scheduleForFarmEvent } from "./calendar/scheduler";
|
|||
|
||||
/** Prepares a FarmEvent[] for use with <FBSelect /> */
|
||||
export function mapStateToProps(state: Everything): FarmEventProps {
|
||||
let push = (state && state.router && state.router.push) || (() => { });
|
||||
let calendar = mapResourcesToCalendar(state.resources.index, moment.now());
|
||||
let calendarRows = calendar.getAll();
|
||||
const push = (state && state.router && state.router.push) || (() => { });
|
||||
const calendar = mapResourcesToCalendar(state.resources.index, moment.now());
|
||||
const calendarRows = calendar.getAll();
|
||||
return { calendarRows, push };
|
||||
}
|
||||
|
||||
/** TODO: Reduce complexity, but write *good* unit tests *before* refactoring.*/
|
||||
export function mapResourcesToCalendar(ri: ResourceIndex, unixNow = moment.now()): Calendar {
|
||||
let x = joinFarmEventsToExecutable(ri);
|
||||
let calendar = new Calendar();
|
||||
let addRegimenToCalendar = regimenCalendarAdder(ri);
|
||||
const x = joinFarmEventsToExecutable(ri);
|
||||
const calendar = new Calendar();
|
||||
const addRegimenToCalendar = regimenCalendarAdder(ri);
|
||||
|
||||
x.map(function (fe) {
|
||||
switch (fe.executable_type) {
|
||||
|
@ -35,20 +35,20 @@ export function mapResourcesToCalendar(ri: ResourceIndex, unixNow = moment.now()
|
|||
}
|
||||
export let regimenCalendarAdder = (index: ResourceIndex) =>
|
||||
(f: FarmEventWithRegimen, c: Calendar) => {
|
||||
let { regimen_items } = f.executable;
|
||||
let now = moment();
|
||||
let fromEpoch = (ms: number) => moment(f.start_time)
|
||||
const { regimen_items } = f.executable;
|
||||
const now = moment();
|
||||
const fromEpoch = (ms: number) => moment(f.start_time)
|
||||
.startOf("day")
|
||||
.add(ms, "ms");
|
||||
let o = occurrence(moment(f.start_time), f);
|
||||
const o = occurrence(moment(f.start_time), f);
|
||||
o.heading = f.executable.name;
|
||||
o.subheading = "";
|
||||
c.insert(o);
|
||||
regimen_items.map(ri => {
|
||||
let time = fromEpoch(ri.time_offset);
|
||||
const time = fromEpoch(ri.time_offset);
|
||||
if (time.isAfter(now) && time.isAfter(moment(f.start_time))) {
|
||||
let oo = occurrence(time, f);
|
||||
let seq = findSequenceById(index, ri.sequence_id);
|
||||
const oo = occurrence(time, f);
|
||||
const seq = findSequenceById(index, ri.sequence_id);
|
||||
oo.heading = f.executable.name;
|
||||
oo.subheading = seq.body.name;
|
||||
c.insert(oo);
|
||||
|
|
|
@ -25,12 +25,12 @@ import {
|
|||
import { DropDownItem } from "../../ui/fb_select";
|
||||
|
||||
export let formatTime = (input: string) => {
|
||||
let iso = new Date(input).toISOString();
|
||||
const iso = new Date(input).toISOString();
|
||||
return moment(iso).format("HH:mm");
|
||||
};
|
||||
|
||||
export let formatDate = (input: string) => {
|
||||
let iso = new Date(input).toISOString();
|
||||
const iso = new Date(input).toISOString();
|
||||
return moment(iso).format("YYYY-MM-DD");
|
||||
};
|
||||
|
||||
|
@ -44,19 +44,19 @@ export let repeatOptions = [
|
|||
];
|
||||
|
||||
export function mapStateToPropsAddEdit(props: Everything): AddEditFarmEventProps {
|
||||
let handleTime = (e: React.SyntheticEvent<HTMLInputElement>, currentISO: string) => {
|
||||
let incomingTime = e.currentTarget.value.split(":");
|
||||
let hours = parseInt(incomingTime[0]) || 0;
|
||||
let minutes = parseInt(incomingTime[1]) || 0;
|
||||
const handleTime = (e: React.SyntheticEvent<HTMLInputElement>, currentISO: string) => {
|
||||
const incomingTime = e.currentTarget.value.split(":");
|
||||
const hours = parseInt(incomingTime[0]) || 0;
|
||||
const minutes = parseInt(incomingTime[1]) || 0;
|
||||
|
||||
switch (e.currentTarget.name) {
|
||||
case "start_time":
|
||||
// Put the current ISO established by the date field into a var
|
||||
let currentStartISO = new Date((currentISO || "").toString())
|
||||
const currentStartISO = new Date((currentISO || "").toString())
|
||||
.toISOString();
|
||||
|
||||
// Set the time of the already existing iso string
|
||||
let newStartISO = moment(currentStartISO)
|
||||
const newStartISO = moment(currentStartISO)
|
||||
.set("hours", hours)
|
||||
.set("minutes", minutes)
|
||||
.toISOString();
|
||||
|
@ -64,10 +64,10 @@ export function mapStateToPropsAddEdit(props: Everything): AddEditFarmEventProps
|
|||
return newStartISO;
|
||||
|
||||
case "end_time":
|
||||
let currentEndISO = new Date((currentISO || "").toString())
|
||||
const currentEndISO = new Date((currentISO || "").toString())
|
||||
.toISOString();
|
||||
|
||||
let newEndISO = moment(currentEndISO)
|
||||
const newEndISO = moment(currentEndISO)
|
||||
.set("hours", hours)
|
||||
.set("minutes", minutes)
|
||||
.toISOString();
|
||||
|
@ -79,7 +79,7 @@ export function mapStateToPropsAddEdit(props: Everything): AddEditFarmEventProps
|
|||
}
|
||||
};
|
||||
|
||||
let executableOptions: DropDownItem[] = [];
|
||||
const executableOptions: DropDownItem[] = [];
|
||||
|
||||
executableOptions.push({
|
||||
label: t("REGIMENS"),
|
||||
|
@ -127,7 +127,7 @@ export function mapStateToPropsAddEdit(props: Everything): AddEditFarmEventProps
|
|||
* better. I think it would be better to handle this at the source and keep
|
||||
* the ui logic less involved. -CV 8/3/2017
|
||||
* -------------------------- BEGIN -------------------------------------*/
|
||||
let newExecutableOptions = executableOptions
|
||||
const newExecutableOptions = executableOptions
|
||||
.filter(x => !x.heading)
|
||||
.map(x => {
|
||||
return {
|
||||
|
@ -137,15 +137,15 @@ export function mapStateToPropsAddEdit(props: Everything): AddEditFarmEventProps
|
|||
};
|
||||
});
|
||||
|
||||
let regimensById = indexRegimenById(props.resources.index);
|
||||
let sequencesById = indexSequenceById(props.resources.index);
|
||||
let farmEventsById = indexFarmEventById(props.resources.index);
|
||||
const regimensById = indexRegimenById(props.resources.index);
|
||||
const sequencesById = indexSequenceById(props.resources.index);
|
||||
const farmEventsById = indexFarmEventById(props.resources.index);
|
||||
|
||||
let farmEvents = selectAllFarmEvents(props.resources.index);
|
||||
const farmEvents = selectAllFarmEvents(props.resources.index);
|
||||
|
||||
let getFarmEvent = (): TaggedFarmEvent | undefined => {
|
||||
let url = history.getCurrentLocation().pathname;
|
||||
let id = parseInt(url.split("/")[4]);
|
||||
const getFarmEvent = (): TaggedFarmEvent | undefined => {
|
||||
const url = history.getCurrentLocation().pathname;
|
||||
const id = parseInt(url.split("/")[4]);
|
||||
if (id && hasId(props.resources.index, "farm_events", id)) {
|
||||
return findFarmEventById(props.resources.index, id);
|
||||
} else {
|
||||
|
@ -153,7 +153,7 @@ export function mapStateToPropsAddEdit(props: Everything): AddEditFarmEventProps
|
|||
}
|
||||
};
|
||||
|
||||
let findExecutable = (kind: ExecutableType, id: number):
|
||||
const findExecutable = (kind: ExecutableType, id: number):
|
||||
TaggedSequence | TaggedRegimen => {
|
||||
switch (kind) {
|
||||
case "Sequence": return findSequenceById(props.resources.index, id);
|
||||
|
|
|
@ -15,13 +15,13 @@ import * as moment from "moment";
|
|||
*/
|
||||
export function maybeWarnAboutMissedTasks(tfe: TaggedFarmEvent, cb: Function) {
|
||||
return function (dispatch: Function, getState: GetState) {
|
||||
let fe = tfe.body;
|
||||
const fe = tfe.body;
|
||||
// STEP 1: Only do this check if it is a Regimen -
|
||||
// sequences don't have this issue.
|
||||
if (fe.executable_type === "Regimen") {
|
||||
let NOW = moment();
|
||||
let START_TIME = moment(fe.start_time);
|
||||
let TIMEFMT = "YYYY-MM-DD";
|
||||
const NOW = moment();
|
||||
const START_TIME = moment(fe.start_time);
|
||||
const TIMEFMT = "YYYY-MM-DD";
|
||||
|
||||
// STEP 2: Continue checking if the farm event is supposed to run today.
|
||||
// since running a farmevent the day it is scheduled runs a risk
|
||||
|
|
|
@ -36,7 +36,7 @@ export class FarmDesigner extends React.Component<Props, Partial<State>> {
|
|||
this.props.dispatch({ type: "UPDATE_MAP_ZOOM_LEVEL", payload });
|
||||
|
||||
childComponent(props: Props) {
|
||||
let fallback = isMobile() ? undefined : React.createElement(Plants, props);
|
||||
const fallback = isMobile() ? undefined : React.createElement(Plants, props);
|
||||
return this.props.children || fallback;
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ export class FarmDesigner extends React.Component<Props, Partial<State>> {
|
|||
document.body.classList.remove("designer-tab");
|
||||
}
|
||||
|
||||
let {
|
||||
const {
|
||||
legendMenuOpen,
|
||||
showPlants,
|
||||
showPoints,
|
||||
|
@ -60,7 +60,7 @@ export class FarmDesigner extends React.Component<Props, Partial<State>> {
|
|||
showFarmbot
|
||||
} = this.state;
|
||||
|
||||
let designerTabClasses: string[] = ["active", "visible-xs"];
|
||||
const designerTabClasses: string[] = ["active", "visible-xs"];
|
||||
|
||||
return <div className="farm-designer">
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ describe("<GardenPlant/>", () => {
|
|||
}
|
||||
|
||||
it("renders plant", () => {
|
||||
let wrapper = shallow(<GardenPlant {...fakeProps() } />);
|
||||
const wrapper = shallow(<GardenPlant {...fakeProps() } />);
|
||||
expect(wrapper.find("image").length).toEqual(1);
|
||||
expect(wrapper.find("image").props().opacity).toEqual(1);
|
||||
expect(wrapper.find("Circle").length).toEqual(1);
|
||||
|
@ -29,9 +29,9 @@ describe("<GardenPlant/>", () => {
|
|||
});
|
||||
|
||||
it("renders drag helpers", () => {
|
||||
let p = fakeProps();
|
||||
const p = fakeProps();
|
||||
p.dragging = true;
|
||||
let wrapper = shallow(<GardenPlant {...p } />);
|
||||
const wrapper = shallow(<GardenPlant {...p } />);
|
||||
expect(wrapper.find("#coordinates-tooltip").length).toEqual(1);
|
||||
expect(wrapper.find("#long-crosshair").length).toEqual(1);
|
||||
expect(wrapper.find("#short-crosshair").length).toEqual(1);
|
||||
|
@ -40,9 +40,9 @@ describe("<GardenPlant/>", () => {
|
|||
});
|
||||
|
||||
it("renders coordinates tooltip while dragging", () => {
|
||||
let p = fakeProps();
|
||||
const p = fakeProps();
|
||||
p.dragging = true;
|
||||
let wrapper = shallow(<GardenPlant {...p } />);
|
||||
const wrapper = shallow(<GardenPlant {...p } />);
|
||||
expect(wrapper.find("text").length).toEqual(1);
|
||||
expect(wrapper.find("text").text()).toEqual("100, 200");
|
||||
expect(wrapper.find("text").props().fontSize).toEqual("1.25rem");
|
||||
|
@ -50,10 +50,10 @@ describe("<GardenPlant/>", () => {
|
|||
});
|
||||
|
||||
it("renders coordinates tooltip while dragging: scaled", () => {
|
||||
let p = fakeProps();
|
||||
const p = fakeProps();
|
||||
p.dragging = true;
|
||||
p.zoomLvl = 0.9;
|
||||
let wrapper = shallow(<GardenPlant {...p } />);
|
||||
const wrapper = shallow(<GardenPlant {...p } />);
|
||||
expect(wrapper.find("text").length).toEqual(1);
|
||||
expect(wrapper.find("text").text()).toEqual("100, 200");
|
||||
expect(wrapper.find("text").props().fontSize).toEqual("3rem");
|
||||
|
@ -61,73 +61,73 @@ describe("<GardenPlant/>", () => {
|
|||
});
|
||||
|
||||
it("renders crosshair while dragging", () => {
|
||||
let p = fakeProps();
|
||||
const p = fakeProps();
|
||||
p.dragging = true;
|
||||
let wrapper = shallow(<GardenPlant {...p } />);
|
||||
let crosshair = wrapper.find("#short-crosshair");
|
||||
const wrapper = shallow(<GardenPlant {...p } />);
|
||||
const crosshair = wrapper.find("#short-crosshair");
|
||||
expect(crosshair.length).toEqual(1);
|
||||
let r1Props = crosshair.find("rect").at(0).props();
|
||||
const r1Props = crosshair.find("rect").at(0).props();
|
||||
expect(r1Props).toEqual({
|
||||
"height": 2, "width": 8, "x": 90, "y": 199, "style": { "fill": "#434343" }
|
||||
});
|
||||
let r2Props = crosshair.find("rect").at(1).props();
|
||||
const r2Props = crosshair.find("rect").at(1).props();
|
||||
expect(r2Props).toEqual({
|
||||
"height": 8, "width": 2, "x": 99, "y": 190, "style": { "fill": "#434343" }
|
||||
});
|
||||
let r3Props = crosshair.find("rect").at(2).props();
|
||||
const r3Props = crosshair.find("rect").at(2).props();
|
||||
expect(r3Props).toEqual({
|
||||
"height": 2, "width": 8, "x": 102, "y": 199, "style": { "fill": "#434343" }
|
||||
});
|
||||
let r4Props = crosshair.find("rect").at(3).props();
|
||||
const r4Props = crosshair.find("rect").at(3).props();
|
||||
expect(r4Props).toEqual({
|
||||
"height": 8, "width": 2, "x": 99, "y": 202, "style": { "fill": "#434343" }
|
||||
});
|
||||
});
|
||||
|
||||
it("renders crosshair while dragging: scaled", () => {
|
||||
let p = fakeProps();
|
||||
const p = fakeProps();
|
||||
p.dragging = true;
|
||||
p.zoomLvl = 0.9;
|
||||
let wrapper = shallow(<GardenPlant {...p } />);
|
||||
let crosshair = wrapper.find("#short-crosshair");
|
||||
const wrapper = shallow(<GardenPlant {...p } />);
|
||||
const crosshair = wrapper.find("#short-crosshair");
|
||||
expect(crosshair.length).toEqual(1);
|
||||
let r1Props = crosshair.find("rect").at(0).props();
|
||||
const r1Props = crosshair.find("rect").at(0).props();
|
||||
expect(r1Props).toEqual({
|
||||
"height": 4.8, "width": 19.2, "x": 76, "y": 197.6, "style": { "fill": "#434343" }
|
||||
});
|
||||
let r2Props = crosshair.find("rect").at(1).props();
|
||||
const r2Props = crosshair.find("rect").at(1).props();
|
||||
expect(r2Props).toEqual({
|
||||
"height": 19.2, "width": 4.8, "x": 97.6, "y": 176, "style": { "fill": "#434343" }
|
||||
});
|
||||
let r3Props = crosshair.find("rect").at(2).props();
|
||||
const r3Props = crosshair.find("rect").at(2).props();
|
||||
expect(r3Props).toEqual({
|
||||
"height": 4.8, "width": 19.2, "x": 104.8, "y": 197.6, "style": { "fill": "#434343" }
|
||||
});
|
||||
let r4Props = crosshair.find("rect").at(3).props();
|
||||
const r4Props = crosshair.find("rect").at(3).props();
|
||||
expect(r4Props).toEqual({
|
||||
"height": 19.2, "width": 4.8, "x": 97.6, "y": 204.8, "style": { "fill": "#434343" }
|
||||
});
|
||||
});
|
||||
|
||||
it("renders vertical alignment indicators", () => {
|
||||
let p = fakeProps();
|
||||
const p = fakeProps();
|
||||
p.dragging = false;
|
||||
p.plant.body.x = 100;
|
||||
p.plant.body.y = 100;
|
||||
p.activeDragXY = { x: 100, y: 0, z: 0 };
|
||||
let wrapper = shallow(<GardenPlant {...p } />);
|
||||
const wrapper = shallow(<GardenPlant {...p } />);
|
||||
expect(wrapper.find("#vert-alignment-indicator").length).toEqual(1);
|
||||
expect(wrapper.find("#horiz-alignment-indicator").length).toEqual(0);
|
||||
expect(wrapper.find("rect").length).toEqual(2);
|
||||
});
|
||||
|
||||
it("renders horizontal alignment indicators", () => {
|
||||
let p = fakeProps();
|
||||
const p = fakeProps();
|
||||
p.dragging = false;
|
||||
p.plant.body.x = 100;
|
||||
p.plant.body.y = 100;
|
||||
p.activeDragXY = { x: 0, y: 100, z: 0 };
|
||||
let wrapper = shallow(<GardenPlant {...p } />);
|
||||
const wrapper = shallow(<GardenPlant {...p } />);
|
||||
expect(wrapper.find("#vert-alignment-indicator").length).toEqual(0);
|
||||
expect(wrapper.find("#horiz-alignment-indicator").length).toEqual(1);
|
||||
expect(wrapper.find("rect").length).toEqual(2);
|
||||
|
|
|
@ -12,7 +12,7 @@ describe("Utils", () => {
|
|||
|
||||
it("translates garden coords to screen coords", () => {
|
||||
|
||||
let cornerCase = translateScreenToGarden({
|
||||
const cornerCase = translateScreenToGarden({
|
||||
quadrant: 2,
|
||||
pageX: 520,
|
||||
pageY: 212,
|
||||
|
@ -21,7 +21,7 @@ describe("Utils", () => {
|
|||
expect(cornerCase.x).toEqual(200);
|
||||
expect(cornerCase.y).toEqual(100);
|
||||
|
||||
let edgeCase = translateScreenToGarden({
|
||||
const edgeCase = translateScreenToGarden({
|
||||
quadrant: 2,
|
||||
pageX: 1132,
|
||||
pageY: 382,
|
||||
|
|
|
@ -10,8 +10,8 @@ interface CircleProps {
|
|||
}
|
||||
|
||||
export function Circle(props: CircleProps) {
|
||||
let { x, y, r, selected } = props;
|
||||
let cn = props.className;
|
||||
const { x, y, r, selected } = props;
|
||||
const cn = props.className;
|
||||
return <circle
|
||||
className={"is-chosen-" + !!selected + " " + (cn ? cn : "")}
|
||||
cx={x}
|
||||
|
|
|
@ -15,9 +15,9 @@ export class VirtualFarmBot extends
|
|||
React.Component<VFBProps, Partial<VFBState>> {
|
||||
|
||||
render() {
|
||||
let { x, y } = this.props.botPosition;
|
||||
let { quadrant } = this.props;
|
||||
let { qx, qy } = getXYFromQuadrant((x || 0), (y || 0), quadrant);
|
||||
const { x, y } = this.props.botPosition;
|
||||
const { quadrant } = this.props;
|
||||
const { qx, qy } = getXYFromQuadrant((x || 0), (y || 0), quadrant);
|
||||
return <g>
|
||||
<rect
|
||||
x={qx - 10}
|
||||
|
|
|
@ -31,7 +31,7 @@ export class GardenMap extends
|
|||
}
|
||||
|
||||
endDrag = () => {
|
||||
let p = this.getPlant();
|
||||
const p = this.getPlant();
|
||||
if (p) {
|
||||
this.props.dispatch(edit(p, { x: round(p.body.x), y: round(p.body.y) }));
|
||||
this.props.dispatch(save(p.uuid));
|
||||
|
@ -61,23 +61,23 @@ export class GardenMap extends
|
|||
|
||||
handleDrop = (e: React.DragEvent<HTMLElement>) => {
|
||||
e.preventDefault();
|
||||
let el = document.querySelector("#drop-area > svg");
|
||||
let map = document.querySelector(".farm-designer-map");
|
||||
let page = document.querySelector(".farm-designer");
|
||||
const el = document.querySelector("#drop-area > svg");
|
||||
const map = document.querySelector(".farm-designer-map");
|
||||
const page = document.querySelector(".farm-designer");
|
||||
if (el && map && page) {
|
||||
let zoomLvl = parseFloat(window.getComputedStyle(map).zoom || DRAG_ERROR);
|
||||
let { pageX, pageY } = e;
|
||||
const zoomLvl = parseFloat(window.getComputedStyle(map).zoom || DRAG_ERROR);
|
||||
const { pageX, pageY } = e;
|
||||
// let box = el.getBoundingClientRect();
|
||||
let crop = history.getCurrentLocation().pathname.split("/")[5];
|
||||
let OFEntry = this.findCrop(crop);
|
||||
let params: ScreenToGardenParams = {
|
||||
const crop = history.getCurrentLocation().pathname.split("/")[5];
|
||||
const OFEntry = this.findCrop(crop);
|
||||
const params: ScreenToGardenParams = {
|
||||
quadrant: this.props.designer.botOriginQuadrant,
|
||||
pageX: pageX + page.scrollLeft,
|
||||
pageY: pageY + map.scrollTop * zoomLvl,
|
||||
zoomLvl
|
||||
};
|
||||
let { x, y } = translateScreenToGarden(params);
|
||||
let p: TaggedPlantPointer = {
|
||||
const { x, y } = translateScreenToGarden(params);
|
||||
const p: TaggedPlantPointer = {
|
||||
kind: "points",
|
||||
uuid: "--never",
|
||||
specialStatus: undefined,
|
||||
|
@ -97,14 +97,14 @@ export class GardenMap extends
|
|||
}
|
||||
|
||||
drag = (e: React.MouseEvent<SVGElement>) => {
|
||||
let plant = this.getPlant();
|
||||
let map = document.querySelector(".farm-designer-map");
|
||||
let { botOriginQuadrant } = this.props.designer;
|
||||
const plant = this.getPlant();
|
||||
const map = document.querySelector(".farm-designer-map");
|
||||
const { botOriginQuadrant } = this.props.designer;
|
||||
if (this.isEditing && this.state.isDragging && plant && map) {
|
||||
let zoomLvl = parseFloat(window.getComputedStyle(map).zoom || DRAG_ERROR);
|
||||
let { qx, qy } = getXYFromQuadrant(e.pageX, e.pageY, botOriginQuadrant);
|
||||
let deltaX = Math.round((qx - (this.state.pageX || qx)) / zoomLvl);
|
||||
let deltaY = Math.round((qy - (this.state.pageY || qy)) / zoomLvl);
|
||||
const zoomLvl = parseFloat(window.getComputedStyle(map).zoom || DRAG_ERROR);
|
||||
const { qx, qy } = getXYFromQuadrant(e.pageX, e.pageY, botOriginQuadrant);
|
||||
const deltaX = Math.round((qx - (this.state.pageX || qx)) / zoomLvl);
|
||||
const deltaY = Math.round((qy - (this.state.pageY || qy)) / zoomLvl);
|
||||
this.setState({
|
||||
pageX: qx, pageY: qy,
|
||||
activeDragXY: { x: plant.body.x + deltaX, y: plant.body.y + deltaY, z: 0 }
|
||||
|
|
|
@ -5,7 +5,7 @@ import { GardenMapLegendProps } from "./interfaces";
|
|||
|
||||
export function GardenMapLegend(props: GardenMapLegendProps) {
|
||||
|
||||
let {
|
||||
const {
|
||||
zoom,
|
||||
toggle,
|
||||
updateBotOriginQuadrant,
|
||||
|
@ -18,9 +18,9 @@ export function GardenMapLegend(props: GardenMapLegendProps) {
|
|||
showFarmbot
|
||||
} = props;
|
||||
|
||||
let plusBtnClass = (zoomLvl && zoomLvl >= 1.8) ? "disabled" : "";
|
||||
let minusBtnClass = (zoomLvl && zoomLvl <= 0.4) ? "disabled" : "";
|
||||
let menuClass = legendMenuOpen ? "active" : "";
|
||||
const plusBtnClass = (zoomLvl && zoomLvl >= 1.8) ? "disabled" : "";
|
||||
const minusBtnClass = (zoomLvl && zoomLvl <= 0.4) ? "disabled" : "";
|
||||
const menuClass = legendMenuOpen ? "active" : "";
|
||||
|
||||
return (
|
||||
<div
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue