Skip to content

Commit

Permalink
minor missed step indicator updates
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielburnworth committed Jun 4, 2020
1 parent e9b9e81 commit e413fc6
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
20 changes: 16 additions & 4 deletions frontend/controls/__tests__/axis_display_group_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ jest.mock("../../account/dev/dev_support", () => ({
import { mount } from "enzyme";
import { AxisDisplayGroup } from "../axis_display_group";
import { AxisDisplayGroupProps } from "../interfaces";
import { MissedStepIndicator } from "../move/missed_step_indicator";

describe("<AxisDisplayGroup />", () => {
const fakeProps = (): AxisDisplayGroupProps => ({
Expand Down Expand Up @@ -44,7 +45,7 @@ describe("<AxisDisplayGroup />", () => {

it("renders missed step indicator", () => {
const p = fakeProps();
p.missedSteps = { x: 1, y: 2, z: 3 };
p.missedSteps = { x: 0, y: 2, z: 3 };
const wrapper = mount(AxisDisplayGroup(p));
expect(wrapper.find(".missed-step-indicator").length).toEqual(3);
});
Expand All @@ -63,6 +64,18 @@ describe("<AxisDisplayGroup />", () => {
expect(wrapper.find(".missed-step-indicator").length).toEqual(0);
});

it("renders missed step indicator when idle", () => {
const p = fakeProps();
p.missedSteps = { x: 1, y: 2, z: 3 };
p.axisStates = { x: "idle", y: undefined, z: "stop" };
const wrapper = mount(AxisDisplayGroup(p));
const indicators = wrapper.find(MissedStepIndicator);
expect(indicators.length).toEqual(3);
expect(indicators.first().props().missedSteps).toEqual(0);
expect(indicators.at(1).props().missedSteps).toEqual(2);
expect(indicators.last().props().missedSteps).toEqual(3);
});

it("renders axis state", () => {
mockDev = true;
const p = fakeProps();
Expand All @@ -72,11 +85,10 @@ describe("<AxisDisplayGroup />", () => {
expect(wrapper.text()).toContain("idle");
});

it("renders axis state", () => {
it("doesn't render axis state", () => {
mockDev = false;
const p = fakeProps();
p.busy = true;
p.axisStates = { x: "idle", y: "idle", z: "idle" };
p.axisStates = { x: undefined, y: undefined, z: undefined };
const wrapper = mount(AxisDisplayGroup(p));
expect(wrapper.text()).not.toContain("idle");
});
Expand Down
9 changes: 5 additions & 4 deletions frontend/controls/axis_display_group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import { t } from "../i18next_wrapper";
import { MissedStepIndicator } from "./move/missed_step_indicator";
import { DevSettings } from "../account/dev/dev_support";

const Axis = ({ axis, val, missedSteps, axisState, busy, index }: AxisProps) =>
const Axis = ({ axis, val, missedSteps, axisState, index }: AxisProps) =>
<Col xs={3} className={"index-" + index}>
{isNumber(missedSteps) && missedSteps > 0 &&
<MissedStepIndicator missedSteps={missedSteps} axis={axis} />}
{isNumber(missedSteps) && missedSteps >= 0 &&
<MissedStepIndicator
missedSteps={axisState == "idle" ? 0 : missedSteps}
axis={axis} />}
<input disabled name={axis} value={isNumber(val) ? val : "---"} />
{!isUndefined(axisState) && DevSettings.futureFeaturesEnabled() &&
busy &&
<p>{t(axisState)}</p>}
</Col>;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from "react";
import { mount } from "enzyme";
import {
MissedStepIndicator, MissedStepIndicatorProps,
MissedStepIndicator, MissedStepIndicatorProps, MISSED_STEP_HISTORY_LENGTH,
} from "../missed_step_indicator";
import { range } from "lodash";

Expand Down Expand Up @@ -60,7 +60,8 @@ describe("<MissedStepIndicator />", () => {
const wrapper = mount<MissedStepIndicator>(<MissedStepIndicator {...p} />);
wrapper.setState({ history: range(30) });
wrapper.instance().componentDidUpdate();
expect(wrapper.state().history).toEqual(range(6, 30).concat([10]));
const start = 30 - MISSED_STEP_HISTORY_LENGTH + 1;
expect(wrapper.state().history).toEqual(range(start, 30).concat([10]));
});

it.each<[
Expand Down
4 changes: 2 additions & 2 deletions frontend/controls/move/missed_step_indicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Popover, Position } from "@blueprintjs/core";
import { t } from "../../i18next_wrapper";
import { Xyz } from "farmbot";

const HISTORY_LENGTH = 25;
export const MISSED_STEP_HISTORY_LENGTH = 10;

enum StorageKey {
x = "missed_step_history_x",
Expand Down Expand Up @@ -36,7 +36,7 @@ export class MissedStepIndicator
this.props.missedSteps != last(this.state.history)) {
const newHistory = [...this.state.history];
newHistory.push(this.props.missedSteps);
this.setState({ history: newHistory.slice(-HISTORY_LENGTH) });
this.setState({ history: newHistory.slice(-MISSED_STEP_HISTORY_LENGTH) });
}
}

Expand Down
3 changes: 3 additions & 0 deletions frontend/css/farm_designer/farm_designer_panels.scss
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,9 @@
}
.map-size-inputs {
.row {
margin: 0;
padding: 0;
margin-top: 1rem;
margin-bottom: 1rem;
}
label {
Expand Down

0 comments on commit e413fc6

Please sign in to comment.