diff --git a/frontend/constants.ts b/frontend/constants.ts index 44c97ab0d1..747697abba 100644 --- a/frontend/constants.ts +++ b/frontend/constants.ts @@ -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`, diff --git a/frontend/settings/fbos_settings/__tests__/farmbot_os_settings_test.tsx b/frontend/settings/fbos_settings/__tests__/farmbot_os_settings_test.tsx index 16da81f110..52d7cebadc 100644 --- a/frontend/settings/fbos_settings/__tests__/farmbot_os_settings_test.tsx +++ b/frontend/settings/fbos_settings/__tests__/farmbot_os_settings_test.tsx @@ -2,19 +2,34 @@ jest.mock("../boot_sequence_selector", () => ({ BootSequenceSelector: () =>
})); +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("", () => { + 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, @@ -22,6 +37,7 @@ describe("", () => { ({ value: bot.hardware.configuration[x], consistent: true }), timeSettings: fakeTimeSettings(), settingsPanelState: settingsPanelState(), + showAdvanced: true, }); it("displays boot sequence selector", () => { @@ -30,4 +46,14 @@ describe("", () => { const osSettings = shallow(); 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(); + expect(wrapper.text().toLowerCase()).toContain("flash"); + clickButton(wrapper, 5, "flash"); + expect(mockDevice.flashFirmware).toHaveBeenCalledWith("arduino"); + }); }); diff --git a/frontend/settings/fbos_settings/__tests__/power_and_reset_test.tsx b/frontend/settings/fbos_settings/__tests__/power_and_reset_test.tsx index 57f98a1823..9440c32d5d 100644 --- a/frontend/settings/fbos_settings/__tests__/power_and_reset_test.tsx +++ b/frontend/settings/fbos_settings/__tests__/power_and_reset_test.tsx @@ -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("", () => { const fakeConfig = fakeFbosConfig(); @@ -21,6 +22,7 @@ describe("", () => { settingsPanelState: settingsPanelState(), dispatch: jest.fn(x => x(jest.fn(), () => state)), botOnline: true, + showAdvanced: true, }); it("renders in open state", () => { @@ -41,4 +43,14 @@ describe("", () => { expect(wrapper.text().toLowerCase()) .not.toContain("Soft Reset".toLowerCase()); }); + + it("restarts firmware", () => { + const p = fakeProps(); + p.settingsPanelState.power_and_reset = true; + const wrapper = mount(); + expect(wrapper.text().toLowerCase()) + .toContain("Restart Firmware".toLowerCase()); + clickButton(wrapper, 0, "restart"); + expect(mockDevice.rebootFirmware).toHaveBeenCalled(); + }); }); diff --git a/frontend/settings/fbos_settings/boot_sequence_selector.tsx b/frontend/settings/fbos_settings/boot_sequence_selector.tsx index 4ff2723a6c..7c9af7284b 100644 --- a/frontend/settings/fbos_settings/boot_sequence_selector.tsx +++ b/frontend/settings/fbos_settings/boot_sequence_selector.tsx @@ -72,14 +72,12 @@ export class RawBootSequenceSelector render() { return - + - - - + diff --git a/frontend/settings/fbos_settings/farmbot_os_settings.tsx b/frontend/settings/fbos_settings/farmbot_os_settings.tsx index 2907e89bd1..55520424d9 100644 --- a/frontend/settings/fbos_settings/farmbot_os_settings.tsx +++ b/frontend/settings/fbos_settings/farmbot_os_settings.tsx @@ -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, @@ -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 @@ -47,6 +52,18 @@ export const FarmBotSettings = (props: FarmbotSettingsProps) => { botOnline={botOnline} timeSettings={timeSettings} /> + + ; }; diff --git a/frontend/settings/fbos_settings/fbos_button_row.tsx b/frontend/settings/fbos_settings/fbos_button_row.tsx index 61dfd1c5dd..8c1d016e51 100644 --- a/frontend/settings/fbos_settings/fbos_button_row.tsx +++ b/frontend/settings/fbos_settings/fbos_button_row.tsx @@ -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 + return