From e1c75f7ee585cd090e69d143919bd4afc30f99ee Mon Sep 17 00:00:00 2001 From: gabrielburnworth Date: Wed, 13 Jul 2022 08:54:04 -0700 Subject: [PATCH] remove firmware setting section --- frontend/constants.ts | 5 +- .../__tests__/farmbot_os_settings_test.tsx | 32 +++++++++- .../__tests__/power_and_reset_test.tsx | 12 ++++ .../fbos_settings/boot_sequence_selector.tsx | 6 +- .../fbos_settings/farmbot_os_settings.tsx | 17 ++++++ .../fbos_settings/fbos_button_row.tsx | 6 +- frontend/settings/fbos_settings/interfaces.ts | 2 + .../fbos_settings/ota_time_selector.tsx | 3 +- .../fbos_settings/power_and_reset.tsx | 11 +++- .../firmware/__tests__/firmware_test.tsx | 59 ------------------- frontend/settings/firmware/board_type.tsx | 12 ++-- frontend/settings/firmware/firmware.tsx | 49 --------------- .../firmware/firmware_hardware_status.tsx | 3 +- frontend/settings/firmware/firmware_path.tsx | 8 +-- .../__tests__/parameter_management_test.tsx | 1 + .../parameter_management.tsx | 16 +++-- frontend/settings/index.tsx | 8 +-- frontend/settings/maybe_highlight.tsx | 7 +-- 18 files changed, 104 insertions(+), 153 deletions(-) delete mode 100644 frontend/settings/firmware/__tests__/firmware_test.tsx delete mode 100644 frontend/settings/firmware/firmware.tsx 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