Skip to content

Commit

Permalink
use setting instead of hardware to show sensors
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielburnworth committed Jan 26, 2024
1 parent fb75c29 commit ef69bb7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
18 changes: 17 additions & 1 deletion frontend/farm_designer/__tests__/panel_header_test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { shallow, mount, ReactWrapper } from "enzyme";
import { DesignerNavTabs } from "../panel_header";
import { buildResourceIndex } from "../../__test_support__/resource_index_builder";
import {
fakeFarmwareInstallation,
fakeFarmwareInstallation, fakeWebAppConfig,
} from "../../__test_support__/fake_state/resources";

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down Expand Up @@ -64,6 +64,22 @@ describe("<DesignerNavTabs />", () => {
expectActive(wrapper, "zones");
});

it("shows sensors tab", () => {
const config = fakeWebAppConfig();
config.body.hide_sensors = false;
mockState.resources = buildResourceIndex([config]);
const wrapper = mount(<DesignerNavTabs />);
expect(wrapper.html()).toContain("sensors");
});

it("doesn't show sensors tab", () => {
const config = fakeWebAppConfig();
config.body.hide_sensors = true;
mockState.resources = buildResourceIndex([config]);
const wrapper = mount(<DesignerNavTabs />);
expect(wrapper.html()).not.toContain("sensors");
});

it("renders scroll indicator", () => {
Object.defineProperty(document, "getElementsByClassName", {
value: () => [{}, { scrollWidth: 100, scrollLeft: 0, clientWidth: 75 }],
Expand Down
9 changes: 1 addition & 8 deletions frontend/farm_designer/panel_header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ import { DevSettings } from "../settings/dev/dev_support";
import { getWebAppConfigValue } from "../config_storage/actions";
import { store } from "../redux/store";
import { BooleanSetting } from "../session_keys";
import {
getFwHardwareValue, hasSensors,
} from "../settings/firmware/firmware_hardware_support";
import { getFbosConfig } from "../resources/getters";
import { computeEditorUrlFromState } from "../nav/compute_editor_url_from_state";
import { compact } from "lodash";
import { selectAllFarmwareInstallations } from "../resources/selectors";
Expand Down Expand Up @@ -218,10 +214,7 @@ const displayScrollIndicator = () => {

export const showSensors = () => {
const getWebAppConfigVal = getWebAppConfigValue(store.getState);
const firmwareHardware = getFwHardwareValue(getFbosConfig(
store.getState().resources.index));
return !getWebAppConfigVal(BooleanSetting.hide_sensors)
&& hasSensors(firmwareHardware);
return !getWebAppConfigVal(BooleanSetting.hide_sensors);
};

export const showFarmware = () => {
Expand Down
23 changes: 13 additions & 10 deletions frontend/nav/__tests__/nav_links_test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ jest.mock("../../history", () => ({
getPathArray: jest.fn(() => mockPath.split("/")),
}));

let mockHasSensors = false;
jest.mock("../../settings/firmware/firmware_hardware_support", () => ({
hasSensors: () => mockHasSensors,
getFwHardwareValue: jest.fn(),
isExpress: jest.fn(),
}));

import { fakeState } from "../../__test_support__/fake_state";
const mockState = fakeState();
jest.mock("../../redux/store", () => ({ store: { getState: () => mockState } }));
Expand All @@ -21,7 +14,7 @@ import { NavLinks } from "../nav_links";
import { NavLinksProps } from "../interfaces";
import { buildResourceIndex } from "../../__test_support__/resource_index_builder";
import {
fakeFarmwareInstallation,
fakeFarmwareInstallation, fakeWebAppConfig,
} from "../../__test_support__/fake_state/resources";
import { fakeHelpState } from "../../__test_support__/fake_designer_state";

Expand Down Expand Up @@ -60,16 +53,26 @@ describe("<NavLinks />", () => {
mockPath = Path.mock(Path.plants());
const wrapper = shallow(<NavLinks {...fakeProps()} />);
expect(wrapper.find("Link").at(1).hasClass("active")).toBeTruthy();
expect(wrapper.html().toLowerCase()).not.toContain("sensors");
});

it("shows sensors link", () => {
mockHasSensors = true;
const config = fakeWebAppConfig();
config.body.hide_sensors = false;
mockState.resources = buildResourceIndex([config]);
const p = fakeProps();
const wrapper = shallow(<NavLinks {...p} />);
expect(wrapper.html().toLowerCase()).toContain("sensors");
});

it("doesn't show sensors link", () => {
const config = fakeWebAppConfig();
config.body.hide_sensors = true;
mockState.resources = buildResourceIndex([config]);
const p = fakeProps();
const wrapper = shallow(<NavLinks {...p} />);
expect(wrapper.html().toLowerCase()).not.toContain("sensors");
});

it("doesn't show farmware link", () => {
const farmware = fakeFarmwareInstallation();
farmware.body.package = "included";
Expand Down

0 comments on commit ef69bb7

Please sign in to comment.