Skip to content

Commit

Permalink
remove firmware setting section
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielburnworth committed Jul 13, 2022
1 parent c15a98d commit e1c75f7
Show file tree
Hide file tree
Showing 18 changed files with 104 additions and 153 deletions.
5 changes: 1 addition & 4 deletions frontend/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1870,16 +1870,13 @@ export enum DeviceSetting {
osAutoUpdate = `auto update`,
farmbotOS = `Farmbot OS`,
bootSequence = `Boot Sequence`,

// Firmware
firmwareSection = `Firmware`,
firmware = `Firmware`,
firmwarePath = `Firmware path`,
restartFirmware = `Restart Firmware`,
flashFirmware = `Flash firmware`,

// Power and Reset
powerAndReset = `Power and Reset`,
restartFirmware = `Restart Firmware`,
restartFarmbot = `Restart Farmbot`,
shutdownFarmbot = `Shutdown Farmbot`,
softReset = `Soft Reset`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,42 @@ jest.mock("../boot_sequence_selector", () => ({
BootSequenceSelector: () => <div />
}));

const mockDevice = {
flashFirmware: jest.fn((_) => Promise.resolve()),
};
jest.mock("../../../device", () => ({ getDevice: () => mockDevice }));

import React from "react";
import { FarmBotSettings } from "../farmbot_os_settings";
import { shallow } from "enzyme";
import { mount, shallow } from "enzyme";
import { bot } from "../../../__test_support__/fake_state/bot";
import { FarmbotSettingsProps } from "../interfaces";
import { fakeTimeSettings } from "../../../__test_support__/fake_time_settings";
import { fakeDevice } from "../../../__test_support__/resource_index_builder";
import {
buildResourceIndex, fakeDevice,
} from "../../../__test_support__/resource_index_builder";
import { settingsPanelState } from "../../../__test_support__/panel_state";
import { clickButton } from "../../../__test_support__/helpers";
import { fakeFbosConfig } from "../../../__test_support__/fake_state/resources";
import { fakeState } from "../../../__test_support__/fake_state";
import { isFunction } from "lodash";

describe("<FarmBotSettings />", () => {
const fakeConfig = fakeFbosConfig();
const state = fakeState();
state.resources = buildResourceIndex([fakeConfig, fakeDevice()]);

const fakeProps = (): FarmbotSettingsProps => ({
device: fakeDevice(),
dispatch: jest.fn(),
dispatch: jest.fn(x => isFunction(x) && x(jest.fn(), () => state)),
bot,
alerts: [],
botOnline: true,
sourceFbosConfig: x =>
({ value: bot.hardware.configuration[x], consistent: true }),
timeSettings: fakeTimeSettings(),
settingsPanelState: settingsPanelState(),
showAdvanced: true,
});

it("displays boot sequence selector", () => {
Expand All @@ -30,4 +46,14 @@ describe("<FarmBotSettings />", () => {
const osSettings = shallow(<FarmBotSettings {...p} />);
expect(osSettings.find("BootSequenceSelector").length).toEqual(1);
});

it("flashes firmware", () => {
const p = fakeProps();
p.settingsPanelState.farmbot_settings = true;
p.sourceFbosConfig = () => ({ value: "arduino", consistent: true });
const wrapper = mount(<FarmBotSettings {...p} />);
expect(wrapper.text().toLowerCase()).toContain("flash");
clickButton(wrapper, 5, "flash");
expect(mockDevice.flashFirmware).toHaveBeenCalledWith("arduino");
});
});
12 changes: 12 additions & 0 deletions frontend/settings/fbos_settings/__tests__/power_and_reset_test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { fakeFbosConfig } from "../../../__test_support__/fake_state/resources";
import {
buildResourceIndex,
} from "../../../__test_support__/resource_index_builder";
import { clickButton } from "../../../__test_support__/helpers";

describe("<PowerAndReset/>", () => {
const fakeConfig = fakeFbosConfig();
Expand All @@ -21,6 +22,7 @@ describe("<PowerAndReset/>", () => {
settingsPanelState: settingsPanelState(),
dispatch: jest.fn(x => x(jest.fn(), () => state)),
botOnline: true,
showAdvanced: true,
});

it("renders in open state", () => {
Expand All @@ -41,4 +43,14 @@ describe("<PowerAndReset/>", () => {
expect(wrapper.text().toLowerCase())
.not.toContain("Soft Reset".toLowerCase());
});

it("restarts firmware", () => {
const p = fakeProps();
p.settingsPanelState.power_and_reset = true;
const wrapper = mount(<PowerAndReset {...p} />);
expect(wrapper.text().toLowerCase())
.toContain("Restart Firmware".toLowerCase());
clickButton(wrapper, 0, "restart");
expect(mockDevice.rebootFirmware).toHaveBeenCalled();
});
});
6 changes: 2 additions & 4 deletions frontend/settings/fbos_settings/boot_sequence_selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,12 @@ export class RawBootSequenceSelector
render() {
return <Highlight settingName={DeviceSetting.bootSequence}>
<Row>
<Col xs={12}>
<Col xs={5}>
<label>
{t("BOOT SEQUENCE")}
</label>
</Col>
</Row>
<Row>
<Col xs={12} className="no-pad">
<Col xs={7} className="no-pad">
<this.SelectionInput />
</Col>
</Row>
Expand Down
17 changes: 17 additions & 0 deletions frontend/settings/fbos_settings/farmbot_os_settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import { DeviceSetting } from "../../constants";
import { Collapse } from "@blueprintjs/core";
import { OrderNumberRow } from "./order_number_row";
import { GardenLocationRow } from "./garden_location_row";
import { BoardType } from "../firmware/board_type";
import { FirmwarePathRow } from "../firmware/firmware_path";
import { validFirmwareHardware } from "../firmware/firmware_hardware_support";

export enum ColWidth {
label = 3,
Expand All @@ -23,6 +26,8 @@ export const FarmBotSettings = (props: FarmbotSettingsProps) => {
const {
dispatch, device, timeSettings, sourceFbosConfig, botOnline,
} = props;
const { value } = props.sourceFbosConfig("firmware_hardware");
const firmwareHardware = validFirmwareHardware(value);
const commonProps = { dispatch, device };
return <Highlight className={"section"}
settingName={DeviceSetting.farmbotSettings}>
Expand All @@ -47,6 +52,18 @@ export const FarmBotSettings = (props: FarmbotSettingsProps) => {
botOnline={botOnline}
timeSettings={timeSettings} />
<BootSequenceSelector />
<BoardType
botOnline={botOnline}
bot={props.bot}
alerts={props.alerts}
dispatch={props.dispatch}
timeSettings={props.timeSettings}
firmwareHardware={firmwareHardware}
sourceFbosConfig={sourceFbosConfig} />
<FirmwarePathRow
dispatch={props.dispatch}
firmwarePath={"" + sourceFbosConfig("firmware_path").value}
showAdvanced={props.showAdvanced} />
</Collapse>
</Highlight>;
};
6 changes: 5 additions & 1 deletion frontend/settings/fbos_settings/fbos_button_row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ export interface FbosButtonRowProps {
description: string;
buttonText: string;
color: string;
advanced?: boolean;
showAdvanced?: boolean;
action: () => void;
}

export const FbosButtonRow = (props: FbosButtonRowProps) => {
return <Highlight settingName={props.label}>
return <Highlight settingName={props.label}
hidden={props.advanced && !props.showAdvanced}
className={props.advanced ? "advanced" : ""}>
<Row>
<Col xs={7}>
<label>
Expand Down
2 changes: 2 additions & 0 deletions frontend/settings/fbos_settings/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface FarmbotSettingsProps {
timeSettings: TimeSettings;
botOnline: boolean;
settingsPanelState: SettingsPanelState;
showAdvanced: boolean;
}

export interface NameRowProps {
Expand Down Expand Up @@ -57,6 +58,7 @@ export interface PowerAndResetProps {
settingsPanelState: SettingsPanelState;
dispatch: Function;
botOnline: boolean;
showAdvanced: boolean;
}

export interface FactoryResetRowsProps {
Expand Down
3 changes: 1 addition & 2 deletions frontend/settings/fbos_settings/ota_time_selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import moment from "moment";
import { t } from "../../i18next_wrapper";
import { FBSelect, Row, Col, DropDownItem, Help } from "../../ui";
import { edit, save } from "../../api/crud";
import { ColWidth } from "./farmbot_os_settings";
import { Content, DeviceSetting } from "../../constants";
import { Highlight } from "../maybe_highlight";
import { OtaTimeSelectorProps, OtaTimeSelectorRowProps } from "./interfaces";
Expand Down Expand Up @@ -75,7 +74,7 @@ export function OtaTimeSelectorRow(props: OtaTimeSelectorRowProps) {
</label>
<Help text={Content.OS_AUTO_UPDATE} />
</Col>
<Col xs={ColWidth.description}>
<Col xs={7}>
<OtaTimeSelector
sourceFbosConfig={props.sourceFbosConfig}
timeSettings={props.timeSettings}
Expand Down
11 changes: 10 additions & 1 deletion frontend/settings/fbos_settings/power_and_reset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { FactoryResetRows } from "./factory_reset_row";
import { PowerAndResetProps } from "./interfaces";
import { FbosButtonRow } from "./fbos_button_row";
import { Content, DeviceSetting } from "../../constants";
import { reboot, powerOff } from "../../devices/actions";
import { reboot, powerOff, restartFirmware } from "../../devices/actions";
import { t } from "../../i18next_wrapper";
import { Highlight } from "../maybe_highlight";

Expand All @@ -20,6 +20,15 @@ export function PowerAndReset(props: PowerAndResetProps) {
panel={"power_and_reset"}
dispatch={dispatch} />
<Collapse isOpen={!!power_and_reset}>
<FbosButtonRow
botOnline={botOnline}
label={DeviceSetting.restartFirmware}
description={Content.RESTART_FIRMWARE}
buttonText={t("RESTART")}
color={"yellow"}
advanced={true}
showAdvanced={props.showAdvanced}
action={() => { restartFirmware(); }} />
<FbosButtonRow
botOnline={botOnline}
label={DeviceSetting.restartFarmbot}
Expand Down
59 changes: 0 additions & 59 deletions frontend/settings/firmware/__tests__/firmware_test.tsx

This file was deleted.

12 changes: 5 additions & 7 deletions frontend/settings/firmware/board_type.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from "react";
import { Row, Col, DropDownItem, FBSelect } from "../../ui";
import { info } from "../../toast/toast";
import { ColWidth } from "../fbos_settings/farmbot_os_settings";
import { updateConfig } from "../../devices/actions";
import { BoardTypeProps } from "./interfaces";
import { t } from "../../i18next_wrapper";
Expand Down Expand Up @@ -50,12 +49,12 @@ export class BoardType extends React.Component<BoardTypeProps, {}> {
render() {
return <Highlight settingName={DeviceSetting.firmware}>
<Row>
<Col xs={ColWidth.label}>
<Col xs={2}>
<label>
{t("FIRMWARE")}
</label>
</Col>
<Col xs={ColWidth.button}>
<Col xs={1}>
<FirmwareHardwareStatus
botOnline={this.props.botOnline}
apiFirmwareValue={this.props.firmwareHardware}
Expand All @@ -64,14 +63,13 @@ export class BoardType extends React.Component<BoardTypeProps, {}> {
dispatch={this.props.dispatch}
timeSettings={this.props.timeSettings} />
</Col>
<Col xs={ColWidth.description}>
<Col xs={2}>
<FlashFirmwareBtn
short={true}
apiFirmwareValue={this.props.firmwareHardware}
botOnline={this.props.botOnline} />
</Col>
</Row>
<Row>
<Col xs={12} className="no-pad">
<Col xs={7} className="no-pad">
<this.FirmwareSelection />
</Col>
</Row>
Expand Down
49 changes: 0 additions & 49 deletions frontend/settings/firmware/firmware.tsx

This file was deleted.

Loading

0 comments on commit e1c75f7

Please sign in to comment.