Skip to content

Commit

Permalink
model and version updates part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielburnworth committed Feb 18, 2020
1 parent 3106865 commit a04ec59
Show file tree
Hide file tree
Showing 87 changed files with 1,480 additions and 700 deletions.
13 changes: 6 additions & 7 deletions frontend/__tests__/attach_app_to_dom_test.ts
@@ -1,10 +1,9 @@
jest.mock("../util", () => {
return {
attachToRoot: jest.fn(),
// Incidental mock. Can be removed if errors go away.
trim: jest.fn(x => x)
};
});
jest.mock("../util", () => ({
attachToRoot: jest.fn(),
// Incidental mock. Can be removed if errors go away.
trim: jest.fn(x => x),
urlFriendly: jest.fn(),
}));

jest.mock("../redux/store", () => {
return { store: { dispatch: jest.fn() } };
Expand Down
10 changes: 5 additions & 5 deletions frontend/__tests__/external_urls_test.ts
Expand Up @@ -6,9 +6,9 @@ import { ExternalUrl } from "../external_urls";
describe("ExternalUrl", () => {
it("returns urls", () => {
expect(ExternalUrl.featureMinVersions)
.toEqual("https://raw.githubusercontent.com/FarmBot/farmbot_os/FEATURE_MIN_VERSIONS.json");
.toEqual("https://raw.githubusercontent.com/FarmBot/farmbot_os/staging/FEATURE_MIN_VERSIONS.json");
expect(ExternalUrl.osReleaseNotes)
.toEqual("https://raw.githubusercontent.com/FarmBot/farmbot_os/RELEASE_NOTES.md");
.toEqual("https://raw.githubusercontent.com/FarmBot/farmbot_os/staging/RELEASE_NOTES.md");
expect(ExternalUrl.latestRelease)
.toEqual("https://api.github.com/repos/FarmBot/farmbot_os/releases/latest");
expect(ExternalUrl.webAppRepo)
Expand All @@ -18,16 +18,16 @@ describe("ExternalUrl", () => {
expect(ExternalUrl.softwareDocs)
.toEqual("https://software.farm.bot/docs");
expect(ExternalUrl.softwareForum)
.toEqual("http://forum.farmbot.org/c/software");
.toEqual("https://forum.farmbot.org/c/software");
expect(ExternalUrl.OpenFarm.cropApi)
.toEqual("https://openfarm.cc/api/v1/crops/");
expect(ExternalUrl.OpenFarm.cropBrowse)
.toEqual("https://openfarm.cc/crops/");
expect(ExternalUrl.OpenFarm.newCrop)
.toEqual("https://openfarm.cc/en/crops/new");
expect(ExternalUrl.Videos.desktop)
expect(ExternalUrl.Video.desktop)
.toEqual("https://cdn.shopify.com/s/files/1/2040/0289/files/Farm_Designer_Loop.mp4?9552037556691879018");
expect(ExternalUrl.Videos.mobile)
expect(ExternalUrl.Video.mobile)
.toEqual("https://cdn.shopify.com/s/files/1/2040/0289/files/Controls.png?9668345515035078097");
});
});
107 changes: 101 additions & 6 deletions frontend/constants.ts
Expand Up @@ -702,9 +702,9 @@ export namespace Content {
trim(`FarmBot sent a malformed message. You may need to upgrade
FarmBot OS. Please upgrade FarmBot OS and log back in.`);

export const OLD_FBOS_REC_UPGRADE = trim(`Your version of FarmBot OS is
outdated and will soon no longer be supported. Please update your device as
soon as possible.`);
export const OLD_FBOS_REC_UPGRADE =
trim(`Your version of FarmBot OS is outdated and will soon no longer
be supported. Please update your device as soon as possible.`);

export const EXPERIMENTAL_WARNING =
trim(`Warning! This is an EXPERIMENTAL feature. This feature may be
Expand Down Expand Up @@ -812,7 +812,10 @@ export namespace Content {
trim(`add this crop on OpenFarm?`);

export const NO_TOOLS =
trim(`Press "+" to add a new tool.`);
trim(`Press "+" to add a new tool or seed container.`);

export const NO_SEED_CONTAINERS =
trim(`Press "+" to add a seed container.`);

export const MOUNTED_TOOL =
trim(`The tool currently mounted to the UTM can be set here or by using
Expand Down Expand Up @@ -887,12 +890,23 @@ export namespace TourContent {
selecting one, and dragging it into the garden.`);

export const ADD_TOOLS =
trim(`Press edit and then the + button to add tools and seed containers.`);
trim(`Press the + button to add tools and seed containers.`);

export const ADD_SEED_CONTAINERS =
trim(`Press the + button to add seed containers.`);

export const ADD_TOOLS_AND_SLOTS =
trim(`Press the + button to add tools and seed containers. Then create
tool slots for them to by pressing the tool slot + button.`);

export const ADD_SEED_CONTAINERS_AND_SLOTS =
trim(`Press the + button to add seed containers. Then create
slots for them to by pressing the seed container slot + button.`);

export const ADD_TOOLS_SLOTS =
trim(`Add the newly created tools and seed containers to the
corresponding tool slots on FarmBot:
press edit and then + to create a tool slot.`);
press the + button to create a tool slot.`);

export const ADD_PERIPHERALS =
trim(`Press edit and then the + button to add peripherals.`);
Expand Down Expand Up @@ -930,6 +944,87 @@ export namespace TourContent {
trim(`Toggle various settings to customize your web app experience.`);
}

export enum DeviceSetting {
// Homing and calibration
homingAndCalibration = `Homing and Calibration`,
homing = `Homing`,
calibration = `Calibration`,
setZeroPosition = `Set Zero Position`,
findHomeOnBoot = `Find Home on Boot`,
stopAtHome = `Stop at Home`,
stopAtMax = `Stop at Max`,
negativeCoordinatesOnly = `Negative Coordinates Only`,
axisLength = `Axis Length (mm)`,

// Motors
motors = `Motors`,
maxSpeed = `Max Speed (mm/s)`,
homingSpeed = `Homing Speed (mm/s)`,
minimumSpeed = `Minimum Speed (mm/s)`,
accelerateFor = `Accelerate for (mm)`,
stepsPerMm = `Steps per MM`,
microstepsPerStep = `Microsteps per step`,
alwaysPowerMotors = `Always Power Motors`,
invertMotors = `Invert Motors`,
motorCurrent = `Motor Current`,
enable2ndXMotor = `Enable 2nd X Motor`,
invert2ndXMotor = `Invert 2nd X Motor`,

// Encoders / Stall Detection
encoders = `Encoders`,
stallDetection = `Stall Detection`,
enableEncoders = `Enable Encoders`,
enableStallDetection = `Enable Stall Detection`,
stallSensitivity = `Stall Sensitivity`,
useEncodersForPositioning = `Use Encoders for Positioning`,
invertEncoders = `Invert Encoders`,
maxMissedSteps = `Max Missed Steps`,
missedStepDecay = `Missed Step Decay`,
encoderScaling = `Encoder Scaling`,

// Endstops
endstops = `Endstops`,
enableEndstops = `Enable Endstops`,
swapEndstops = `Swap Endstops`,
invertEndstops = `Invert Endstops`,

// Error handling
errorHandling = `Error Handling`,
timeoutAfter = `Timeout after (seconds)`,
maxRetries = `Max Retries`,
estopOnMovementError = `E-Stop on Movement Error`,

// Pin Guard
pinGuard = `Pin Guard`,

// Danger Zone
dangerZone = `dangerZone`,
resetHardwareParams = `Reset hardware parameter defaults`,

// Pin Bindings
pinBindings = `Pin Bindings`,

// FarmBot OS
name = `name`,
timezone = `timezone`,
camera = `camera`,
firmware = `firmware`,
farmbotOSAutoUpdate = `Farmbot OS Auto Update`,
farmbotOS = `Farmbot OS`,
autoSync = `Auto Sync`,
bootSequence = `Boot Sequence`,

// Power and Reset
powerAndReset = `Power and Reset`,
restartFarmbot = `Restart Farmbot`,
shutdownFarmbot = `Shutdown Farmbot`,
restartFirmware = `Restart Firmware`,
factoryReset = `Factory Reset`,
autoFactoryReset = `Automatic Factory Reset`,
connectionAttemptPeriod = `Connection Attempt Period`,
changeOwnership = `Change Ownership`,
}

export namespace DiagnosticMessages {
export const OK = trim(`All systems nominal.`);

Expand Down
2 changes: 2 additions & 0 deletions frontend/controls/controls.tsx
Expand Up @@ -38,6 +38,7 @@ export class RawControls extends React.Component<Props, {}> {
getWebAppConfigVal={this.props.getWebAppConfigVal} />

peripherals = () => <Peripherals
firmwareHardware={this.props.firmwareHardware}
bot={this.props.bot}
peripherals={this.props.peripherals}
dispatch={this.props.dispatch}
Expand All @@ -50,6 +51,7 @@ export class RawControls extends React.Component<Props, {}> {
sensors = () => this.hideSensors
? <div id="hidden-sensors-widget" />
: <Sensors
firmwareHardware={this.props.firmwareHardware}
bot={this.props.bot}
sensors={this.props.sensors}
dispatch={this.props.dispatch}
Expand Down
18 changes: 13 additions & 5 deletions frontend/controls/peripherals/__tests__/index_test.tsx
Expand Up @@ -5,7 +5,7 @@ import { bot } from "../../../__test_support__/fake_state/bot";
import { PeripheralsProps } from "../../../devices/interfaces";
import { fakePeripheral } from "../../../__test_support__/fake_state/resources";
import { clickButton } from "../../../__test_support__/helpers";
import { SpecialStatus } from "farmbot";
import { SpecialStatus, FirmwareHardware } from "farmbot";
import { error } from "../../../toast/toast";

describe("<Peripherals />", () => {
Expand All @@ -14,7 +14,8 @@ describe("<Peripherals />", () => {
bot,
peripherals: [fakePeripheral()],
dispatch: jest.fn(),
disabled: false
disabled: false,
firmwareHardware: undefined,
};
}

Expand Down Expand Up @@ -73,11 +74,18 @@ describe("<Peripherals />", () => {
expect(p.dispatch).toHaveBeenCalled();
});

it("adds farmduino peripherals", () => {
it.each<[FirmwareHardware, number]>([
["arduino", 2],
["farmduino", 5],
["farmduino_k14", 5],
["farmduino_k15", 5],
["express_k10", 3],
])("adds peripherals: %s", (firmware, expectedAdds) => {
const p = fakeProps();
p.firmwareHardware = firmware;
const wrapper = mount(<Peripherals {...p} />);
wrapper.setState({ isEditing: true });
clickButton(wrapper, 3, "farmduino");
expect(p.dispatch).toHaveBeenCalledTimes(5);
clickButton(wrapper, 3, "stock");
expect(p.dispatch).toHaveBeenCalledTimes(expectedAdds);
});
});
38 changes: 29 additions & 9 deletions frontend/controls/peripherals/index.tsx
Expand Up @@ -56,12 +56,31 @@ export class Peripherals
this.props.dispatch(init("Peripheral", { pin, label }));
};

farmduinoPeripherals = () => {
this.newPeripheral(7, t("Lighting"));
this.newPeripheral(8, t("Water"));
this.newPeripheral(9, t("Vacuum"));
this.newPeripheral(10, t("Peripheral ") + "4");
this.newPeripheral(12, t("Peripheral ") + "5");
get stockPeripherals() {
switch (this.props.firmwareHardware) {
case "arduino":
return [
{ pin: 8, label: t("Water") },
{ pin: 9, label: t("Vacuum") },
];
case "farmduino":
case "farmduino_k14":
case "farmduino_k15":
default:
return [
{ pin: 7, label: t("Lighting") },
{ pin: 8, label: t("Water") },
{ pin: 9, label: t("Vacuum") },
{ pin: 10, label: t("Peripheral ") + "4" },
{ pin: 12, label: t("Peripheral ") + "5" },
];
case "express_k10":
return [
{ pin: 7, label: t("Lighting") },
{ pin: 8, label: t("Water") },
{ pin: 9, label: t("Vacuum") },
];
}
}

render() {
Expand Down Expand Up @@ -92,10 +111,11 @@ export class Peripherals
hidden={!isEditing}
className="fb-button green"
type="button"
onClick={this.farmduinoPeripherals}>
onClick={() => this.stockPeripherals.map(p =>
this.newPeripheral(p.pin, p.label))}>
<i className="fa fa-plus" style={{ marginRight: "0.5rem" }} />
Farmduino
</button>
{t("Stock")}
</button>
</WidgetHeader>
<WidgetBody>
{this.showPins()}
Expand Down
11 changes: 10 additions & 1 deletion frontend/controls/sensors/__tests__/index_test.tsx
Expand Up @@ -18,7 +18,8 @@ describe("<Sensors />", () => {
bot,
sensors: [fakeSensor1, fakeSensor2],
dispatch: jest.fn(),
disabled: false
disabled: false,
firmwareHardware: undefined,
};
}

Expand Down Expand Up @@ -68,8 +69,16 @@ describe("<Sensors />", () => {
it("adds stock sensors", () => {
const p = fakeProps();
const wrapper = mount(<Sensors {...p} />);
expect(wrapper.text().toLowerCase()).toContain("stock sensors");
wrapper.setState({ isEditing: true });
clickButton(wrapper, 3, "stock sensors");
expect(p.dispatch).toHaveBeenCalledTimes(2);
});

it("doesn't display + stock button", () => {
const p = fakeProps();
p.firmwareHardware = "express_k10";
const wrapper = mount(<Sensors {...p} />);
expect(wrapper.text().toLowerCase()).not.toContain("stock sensors");
});
});
7 changes: 7 additions & 0 deletions frontend/controls/sensors/__tests__/sensor_list_test.tsx
Expand Up @@ -100,4 +100,11 @@ describe("<SensorList/>", function () {
readSensorBtn.last().simulate("click");
expect(mockDevice.readPin).not.toHaveBeenCalled();
});

it("renders analog reading", () => {
const p = fakeProps();
p.pins[50] && (p.pins[50].value = 600);
const wrapper = mount(<SensorList {...p} />);
expect(wrapper.html()).toContain("margin-left: -3.5rem");
});
});
18 changes: 10 additions & 8 deletions frontend/controls/sensors/index.tsx
Expand Up @@ -10,6 +10,7 @@ import { saveAll, init } from "../../api/crud";
import { ToolTips } from "../../constants";
import { uniq } from "lodash";
import { t } from "../../i18next_wrapper";
import { isExpressBoard } from "../../devices/components/firmware_hardware_support";

export class Sensors extends React.Component<SensorsProps, SensorState> {
constructor(props: SensorsProps) {
Expand Down Expand Up @@ -79,14 +80,15 @@ export class Sensors extends React.Component<SensorsProps, SensorState> {
onClick={() => this.newSensor()}>
<i className="fa fa-plus" />
</button>
<button
hidden={!isEditing}
className="fb-button green"
type="button"
onClick={this.stockSensors}>
<i className="fa fa-plus" style={{ marginRight: "0.5rem" }} />
{t("Stock sensors")}
</button>
{!isExpressBoard(this.props.firmwareHardware) &&
<button
hidden={!isEditing}
className="fb-button green"
type="button"
onClick={this.stockSensors}>
<i className="fa fa-plus" style={{ marginRight: "0.5rem" }} />
{t("Stock sensors")}
</button>}
</WidgetHeader>
<WidgetBody>
{this.showPins()}
Expand Down
1 change: 1 addition & 0 deletions frontend/css/_blueprint_overrides.scss
@@ -1,5 +1,6 @@
// Padding for the popups.
.bp3-popover-content {
z-index: 999;
padding: 1rem;
}

Expand Down
20 changes: 20 additions & 0 deletions frontend/css/global.scss
Expand Up @@ -1629,3 +1629,23 @@ textarea:focus {
}
}
}

.section {
display: block !important;
}

.highlight,
.unhighlight {
display: flex;
}

.highlight {
background-color: $light_yellow;
box-shadow: 0px 0px 7px 4px $light_yellow;
}

.unhighlight {
transition: background-color 10s linear, box-shadow 10s linear;
background-color: transparent;
box-shadow: none;
}

0 comments on commit a04ec59

Please sign in to comment.