đź‘Ź Remove old react-redux hacks

pull/1451/head
Rick Carlino 2019-09-19 14:09:00 -05:00
parent e5bfa4997c
commit 9297f3ae95
74 changed files with 177 additions and 217 deletions

View File

@ -1,4 +1,4 @@
jest.mock("react-redux", () => ({ connect: jest.fn() })); jest.mock("react-redux", () => ({ connect: jest.fn(() => (x: {}) => x) }));
let mockPath = ""; let mockPath = "";
jest.mock("../history", () => ({ jest.mock("../history", () => ({

View File

@ -1,4 +1,4 @@
jest.mock("react-redux", () => ({ connect: jest.fn() })); jest.mock("react-redux", () => ({ connect: jest.fn(() => (x: {}) => x) }));
jest.mock("../labs/labs_features", () => ({ LabsFeatures: () => <div /> })); jest.mock("../labs/labs_features", () => ({ LabsFeatures: () => <div /> }));
import * as React from "react"; import * as React from "react";

View File

@ -27,8 +27,7 @@ interface State {
warnThem: boolean; warnThem: boolean;
} }
@connect(mapStateToProps) export class RawAccount extends React.Component<Props, State> {
export class Account extends React.Component<Props, State> {
state: State = { warnThem: false }; state: State = { warnThem: false };
/** WHAT WE NEED: The ability to tell users to check their email if they try /** WHAT WE NEED: The ability to tell users to check their email if they try
@ -113,3 +112,5 @@ export class Account extends React.Component<Props, State> {
</Page>; </Page>;
} }
} }
export const Account = connect(mapStateToProps)(RawAccount);

View File

@ -97,8 +97,7 @@ const MUST_LOAD: ResourceName[] = [
"Tool" // Sequence editor needs this for rendering. "Tool" // Sequence editor needs this for rendering.
]; ];
@connect(mapStateToProps) export class RawApp extends React.Component<AppProps, {}> {
export class App extends React.Component<AppProps, {}> {
private get isLoaded() { private get isLoaded() {
return (MUST_LOAD.length === return (MUST_LOAD.length ===
intersection(this.props.loaded, MUST_LOAD).length); intersection(this.props.loaded, MUST_LOAD).length);
@ -152,3 +151,5 @@ export class App extends React.Component<AppProps, {}> {
</div>; </div>;
} }
} }
export const App = connect(mapStateToProps)(RawApp);

View File

@ -10,7 +10,7 @@ import { DeepPartial } from "redux";
import { AuthState } from "../../../auth/interfaces"; import { AuthState } from "../../../auth/interfaces";
import { fakeState } from "../../../__test_support__/fake_state"; import { fakeState } from "../../../__test_support__/fake_state";
describe("connectDevice()", async () => { describe("connectDevice()", () => {
it("connects a FarmBot to the network", async () => { it("connects a FarmBot to the network", async () => {
const auth: DeepPartial<AuthState> = { token: {} }; const auth: DeepPartial<AuthState> = { token: {} };
const dispatch = jest.fn(); const dispatch = jest.fn();

View File

@ -41,7 +41,7 @@ export function sendOutboundPing(bot: Farmbot) {
if (!x.done) { if (!x.done) {
x.done = true; x.done = true;
pingNO(id, now()); pingNO(id, now());
reject(); reject(new Error("sendOutboundPing failed: " + id));
} }
}; };
@ -51,9 +51,12 @@ export function sendOutboundPing(bot: Farmbot) {
}); });
} }
const beep = (bot: Farmbot) => sendOutboundPing(bot)
.then(() => { }, () => { }); // Silence errors;
export function startPinging(bot: Farmbot) { export function startPinging(bot: Farmbot) {
sendOutboundPing(bot); beep(bot);
setInterval(() => sendOutboundPing(bot), PING_INTERVAL); setInterval(() => beep(bot), PING_INTERVAL);
} }
export function pingAPI() { export function pingAPI() {

View File

@ -1,4 +1,4 @@
jest.mock("react-redux", () => ({ connect: jest.fn() })); jest.mock("react-redux", () => ({ connect: jest.fn(() => (x: {}) => x) }));
import * as React from "react"; import * as React from "react";
import { mount } from "enzyme"; import { mount } from "enzyme";

View File

@ -12,8 +12,7 @@ import { SensorReadings } from "./sensor_readings/sensor_readings";
import { isBotOnline } from "../devices/must_be_online"; import { isBotOnline } from "../devices/must_be_online";
/** Controls page. */ /** Controls page. */
@connect(mapStateToProps) export class RawControls extends React.Component<Props, {}> {
export class Controls extends React.Component<Props, {}> {
get arduinoBusy() { get arduinoBusy() {
return !!this.props.bot.hardware.informational_settings.busy; return !!this.props.bot.hardware.informational_settings.busy;
} }
@ -92,3 +91,5 @@ export class Controls extends React.Component<Props, {}> {
</Page>; </Page>;
} }
} }
export const Controls = connect(mapStateToProps)(RawControls);

View File

@ -1,4 +1,4 @@
jest.mock("react-redux", () => ({ connect: jest.fn() })); jest.mock("react-redux", () => ({ connect: jest.fn(() => (x: {}) => x) }));
import * as React from "react"; import * as React from "react";
import { shallow, render } from "enzyme"; import { shallow, render } from "enzyme";

View File

@ -1,3 +1,5 @@
jest.mock("react-redux", () => ({ connect: jest.fn(() => (x: {}) => x) }));
let mockReleaseNoteData = {}; let mockReleaseNoteData = {};
jest.mock("axios", () => ({ jest.mock("axios", () => ({
get: jest.fn(() => Promise.resolve(mockReleaseNoteData)) get: jest.fn(() => Promise.resolve(mockReleaseNoteData))

View File

@ -106,7 +106,7 @@ export class FarmbotOsSettings
</label> </label>
</Col> </Col>
<Col xs={9}> <Col xs={9}>
<BootSequenceSelector {...({} as BootSequenceSelector["props"])} /> <BootSequenceSelector />
</Col> </Col>
</Row> </Row>
<Row> <Row>

View File

@ -11,7 +11,7 @@ interface Props {
dispatch: Function; dispatch: Function;
} }
function mapStateToProps(p: Everything) { function mapStateToProps(p: Everything): Props {
const { index } = p.resources; const { index } = p.resources;
const fbosConfig = getFbosConfig(index); const fbosConfig = getFbosConfig(index);
if (fbosConfig) { if (fbosConfig) {
@ -25,10 +25,11 @@ function mapStateToProps(p: Everything) {
} }
} }
@connect(mapStateToProps) export class DisconnectedBootSequenceSelector extends React.Component<Props, {}> {
export class BootSequenceSelector extends React.Component<Props, {}> {
render() { render() {
return <div> Ey... </div>; return <div> Ey... </div>;
} }
} }
export const BootSequenceSelector =
connect(mapStateToProps)(DisconnectedBootSequenceSelector);

View File

@ -10,8 +10,7 @@ import { selectAllDiagnosticDumps } from "../resources/selectors";
import { getStatus } from "../connectivity/reducer_support"; import { getStatus } from "../connectivity/reducer_support";
import { isFwHardwareValue } from "./components/firmware_hardware_support"; import { isFwHardwareValue } from "./components/firmware_hardware_support";
@connect(mapStateToProps) export class RawDevices extends React.Component<Props, {}> {
export class Devices extends React.Component<Props, {}> {
render() { render() {
if (this.props.auth) { if (this.props.auth) {
const { botToMqtt } = this.props; const { botToMqtt } = this.props;
@ -61,3 +60,5 @@ export class Devices extends React.Component<Props, {}> {
} }
} }
} }
export const Devices = connect(mapStateToProps)(RawDevices);

View File

@ -1,4 +1,4 @@
jest.mock("react-redux", () => ({ connect: jest.fn() })); jest.mock("react-redux", () => ({ connect: jest.fn(() => (x: {}) => x) }));
let mockPath = "/app/designer/plants"; let mockPath = "/app/designer/plants";
jest.mock("../../history", () => ({ jest.mock("../../history", () => ({
@ -12,7 +12,7 @@ jest.mock("../../api/crud", () => ({
})); }));
import * as React from "react"; import * as React from "react";
import { FarmDesigner } from "../index"; import { RawFarmDesigner } from "../index";
import { mount } from "enzyme"; import { mount } from "enzyme";
import { Props } from "../interfaces"; import { Props } from "../interfaces";
import { GardenMapLegendProps } from "../map/interfaces"; import { GardenMapLegendProps } from "../map/interfaces";
@ -27,7 +27,7 @@ import { fakeState } from "../../__test_support__/fake_state";
import { edit } from "../../api/crud"; import { edit } from "../../api/crud";
import { BooleanSetting } from "../../session_keys"; import { BooleanSetting } from "../../session_keys";
describe("<FarmDesigner/>", () => { describe("<RawFarmDesigner/>", () => {
function fakeProps(): Props { function fakeProps(): Props {
return { return {
@ -63,7 +63,7 @@ describe("<FarmDesigner/>", () => {
} }
it("loads default map settings", () => { it("loads default map settings", () => {
const wrapper = mount(<FarmDesigner {...fakeProps()} />); const wrapper = mount(<RawFarmDesigner {...fakeProps()} />);
const legendProps = const legendProps =
wrapper.find("GardenMapLegend").props() as GardenMapLegendProps; wrapper.find("GardenMapLegend").props() as GardenMapLegendProps;
expect(legendProps.legendMenuOpen).toBeFalsy(); expect(legendProps.legendMenuOpen).toBeFalsy();
@ -86,7 +86,7 @@ describe("<FarmDesigner/>", () => {
image1.body.created_at = "2001-01-03T00:00:00.000Z"; image1.body.created_at = "2001-01-03T00:00:00.000Z";
image2.body.created_at = "2001-01-01T00:00:00.000Z"; image2.body.created_at = "2001-01-01T00:00:00.000Z";
p.latestImages = [image1, image2]; p.latestImages = [image1, image2];
const wrapper = mount(<FarmDesigner {...p} />); const wrapper = mount(<RawFarmDesigner {...p} />);
const legendProps = const legendProps =
wrapper.find("GardenMapLegend").props() as GardenMapLegendProps; wrapper.find("GardenMapLegend").props() as GardenMapLegendProps;
expect(legendProps.imageAgeInfo) expect(legendProps.imageAgeInfo)
@ -95,7 +95,7 @@ describe("<FarmDesigner/>", () => {
it("renders nav titles", () => { it("renders nav titles", () => {
mockPath = "/app/designer/plants"; mockPath = "/app/designer/plants";
const wrapper = mount(<FarmDesigner {...fakeProps()} />); const wrapper = mount(<RawFarmDesigner {...fakeProps()} />);
["Map", "Plants", "Events"].map(string => ["Map", "Plants", "Events"].map(string =>
expect(wrapper.text()).toContain(string)); expect(wrapper.text()).toContain(string));
expect(wrapper.find(".panel-nav").first().hasClass("hidden")).toBeTruthy(); expect(wrapper.find(".panel-nav").first().hasClass("hidden")).toBeTruthy();
@ -105,7 +105,7 @@ describe("<FarmDesigner/>", () => {
it("hides panel", () => { it("hides panel", () => {
mockPath = "/app/designer"; mockPath = "/app/designer";
const wrapper = mount(<FarmDesigner {...fakeProps()} />); const wrapper = mount(<RawFarmDesigner {...fakeProps()} />);
["Map", "Plants", "Events"].map(string => ["Map", "Plants", "Events"].map(string =>
expect(wrapper.text()).toContain(string)); expect(wrapper.text()).toContain(string));
expect(wrapper.find(".panel-nav").first().hasClass("hidden")).toBeFalsy(); expect(wrapper.find(".panel-nav").first().hasClass("hidden")).toBeFalsy();
@ -116,7 +116,7 @@ describe("<FarmDesigner/>", () => {
it("renders saved garden indicator", () => { it("renders saved garden indicator", () => {
const p = fakeProps(); const p = fakeProps();
p.designer.openedSavedGarden = "SavedGardenUuid"; p.designer.openedSavedGarden = "SavedGardenUuid";
const wrapper = mount(<FarmDesigner {...p} />); const wrapper = mount(<RawFarmDesigner {...p} />);
expect(wrapper.text().toLowerCase()).toContain("viewing saved garden"); expect(wrapper.text().toLowerCase()).toContain("viewing saved garden");
}); });
@ -126,7 +126,7 @@ describe("<FarmDesigner/>", () => {
const dispatch = jest.fn(); const dispatch = jest.fn();
state.resources = buildResourceIndex([fakeWebAppConfig()]); state.resources = buildResourceIndex([fakeWebAppConfig()]);
p.dispatch = jest.fn(x => x(dispatch, () => state)); p.dispatch = jest.fn(x => x(dispatch, () => state));
const wrapper = mount<FarmDesigner>(<FarmDesigner {...p} />); const wrapper = mount<RawFarmDesigner>(<RawFarmDesigner {...p} />);
wrapper.instance().toggle(BooleanSetting.show_plants)(); wrapper.instance().toggle(BooleanSetting.show_plants)();
expect(edit).toHaveBeenCalledWith(expect.any(Object), { bot_origin_quadrant: 2 }); expect(edit).toHaveBeenCalledWith(expect.any(Object), { bot_origin_quadrant: 2 });
}); });

View File

@ -1,4 +1,4 @@
jest.mock("react-redux", () => ({ connect: jest.fn() })); jest.mock("react-redux", () => ({ connect: jest.fn(() => (x: {}) => x) }));
const mockDevice = { moveAbsolute: jest.fn(() => Promise.resolve()) }; const mockDevice = { moveAbsolute: jest.fn(() => Promise.resolve()) };
jest.mock("../../device", () => ({ getDevice: () => mockDevice })); jest.mock("../../device", () => ({ getDevice: () => mockDevice }));

View File

@ -1,4 +1,4 @@
jest.mock("react-redux", () => ({ connect: jest.fn() })); jest.mock("react-redux", () => ({ connect: jest.fn(() => (x: {}) => x) }));
jest.mock("../../config_storage/actions", () => ({ jest.mock("../../config_storage/actions", () => ({
getWebAppConfigValue: jest.fn(x => { x(); return jest.fn(() => true); }), getWebAppConfigValue: jest.fn(x => { x(); return jest.fn(() => true); }),
@ -8,7 +8,7 @@ jest.mock("../../config_storage/actions", () => ({
import * as React from "react"; import * as React from "react";
import { mount, ReactWrapper } from "enzyme"; import { mount, ReactWrapper } from "enzyme";
import { import {
DesignerSettings, DesignerSettingsProps, mapStateToProps RawDesignerSettings, DesignerSettingsProps, mapStateToProps
} from "../settings"; } from "../settings";
import { fakeState } from "../../__test_support__/fake_state"; import { fakeState } from "../../__test_support__/fake_state";
import { BooleanSetting, NumericSetting } from "../../session_keys"; import { BooleanSetting, NumericSetting } from "../../session_keys";
@ -22,14 +22,14 @@ const getSetting =
return setting; return setting;
}; };
describe("<DesignerSettings />", () => { describe("<RawDesignerSettings />", () => {
const fakeProps = (): DesignerSettingsProps => ({ const fakeProps = (): DesignerSettingsProps => ({
dispatch: jest.fn(), dispatch: jest.fn(),
getConfigValue: jest.fn(), getConfigValue: jest.fn(),
}); });
it("renders settings", () => { it("renders settings", () => {
const wrapper = mount(<DesignerSettings {...fakeProps()} />); const wrapper = mount(<RawDesignerSettings {...fakeProps()} />);
expect(wrapper.text()).toContain("size"); expect(wrapper.text()).toContain("size");
const settings = wrapper.find(".designer-setting"); const settings = wrapper.find(".designer-setting");
expect(settings.length).toEqual(7); expect(settings.length).toEqual(7);
@ -38,13 +38,13 @@ describe("<DesignerSettings />", () => {
it("renders defaultOn setting", () => { it("renders defaultOn setting", () => {
const p = fakeProps(); const p = fakeProps();
p.getConfigValue = () => undefined; p.getConfigValue = () => undefined;
const wrapper = mount(<DesignerSettings {...p} />); const wrapper = mount(<RawDesignerSettings {...p} />);
const confirmDeletion = getSetting(wrapper, 6, "confirm plant"); const confirmDeletion = getSetting(wrapper, 6, "confirm plant");
expect(confirmDeletion.find("button").text()).toEqual("on"); expect(confirmDeletion.find("button").text()).toEqual("on");
}); });
it("toggles setting", () => { it("toggles setting", () => {
const wrapper = mount(<DesignerSettings {...fakeProps()} />); const wrapper = mount(<RawDesignerSettings {...fakeProps()} />);
const trailSetting = getSetting(wrapper, 1, "trail"); const trailSetting = getSetting(wrapper, 1, "trail");
trailSetting.find("button").simulate("click"); trailSetting.find("button").simulate("click");
expect(setWebAppConfigValue) expect(setWebAppConfigValue)
@ -54,7 +54,7 @@ describe("<DesignerSettings />", () => {
it("changes origin", () => { it("changes origin", () => {
const p = fakeProps(); const p = fakeProps();
p.getConfigValue = () => 2; p.getConfigValue = () => 2;
const wrapper = mount(<DesignerSettings {...p} />); const wrapper = mount(<RawDesignerSettings {...p} />);
const originSetting = getSetting(wrapper, 5, "origin"); const originSetting = getSetting(wrapper, 5, "origin");
originSetting.find("div").last().simulate("click"); originSetting.find("div").last().simulate("click");
expect(setWebAppConfigValue).toHaveBeenCalledWith( expect(setWebAppConfigValue).toHaveBeenCalledWith(

View File

@ -1,4 +1,4 @@
jest.mock("react-redux", () => ({ connect: jest.fn() })); jest.mock("react-redux", () => ({ connect: jest.fn(() => (x: {}) => x) }));
jest.mock("../../../history", () => ({ history: { push: jest.fn() } })); jest.mock("../../../history", () => ({ history: { push: jest.fn() } }));

View File

@ -1,5 +1,5 @@
jest.mock("react-redux", () => ({ jest.mock("react-redux", () => ({
connect: jest.fn() connect: jest.fn(() => (x: {}) => x)
})); }));
jest.mock("../../../history", () => ({ jest.mock("../../../history", () => ({

View File

@ -22,8 +22,7 @@ interface State {
uuid: string; uuid: string;
} }
@connect(mapStateToPropsAddEdit) export class RawAddFarmEvent
export class AddFarmEvent
extends React.Component<AddEditFarmEventProps, Partial<State>> { extends React.Component<AddEditFarmEventProps, Partial<State>> {
constructor(props: AddEditFarmEventProps) { constructor(props: AddEditFarmEventProps) {
@ -122,3 +121,5 @@ export class AddFarmEvent
} }
} }
} }
export const AddFarmEvent = connect(mapStateToPropsAddEdit)(RawAddFarmEvent);

View File

@ -7,8 +7,7 @@ import { TaggedFarmEvent } from "farmbot";
import { EditFEForm } from "./edit_fe_form"; import { EditFEForm } from "./edit_fe_form";
import { t } from "../../i18next_wrapper"; import { t } from "../../i18next_wrapper";
@connect(mapStateToPropsAddEdit) export class RawEditFarmEvent extends React.Component<AddEditFarmEventProps, {}> {
export class EditFarmEvent extends React.Component<AddEditFarmEventProps, {}> {
redirect() { redirect() {
history.push("/app/designer/events"); history.push("/app/designer/events");
return <div>{t("Loading")}...</div>; return <div>{t("Loading")}...</div>;
@ -34,3 +33,5 @@ export class EditFarmEvent extends React.Component<AddEditFarmEventProps, {}> {
return fe ? this.renderForm(fe) : this.redirect(); return fe ? this.renderForm(fe) : this.redirect();
} }
} }
export const EditFarmEvent = connect(mapStateToPropsAddEdit)(RawEditFarmEvent);

View File

@ -45,8 +45,7 @@ export const getGridSize =
export const gridOffset: AxisNumberProperty = { x: 50, y: 50 }; export const gridOffset: AxisNumberProperty = { x: 50, y: 50 };
@connect(mapStateToProps) export class RawFarmDesigner extends React.Component<Props, Partial<State>> {
export class FarmDesigner extends React.Component<Props, Partial<State>> {
initializeSetting = initializeSetting =
(name: keyof State, defaultValue: boolean): boolean => { (name: keyof State, defaultValue: boolean): boolean => {
@ -201,3 +200,5 @@ export class FarmDesigner extends React.Component<Props, Partial<State>> {
</div>; </div>;
} }
} }
export const FarmDesigner = connect(mapStateToProps)(RawFarmDesigner);

View File

@ -99,8 +99,7 @@ export class MoveToForm extends React.Component<MoveToFormProps, MoveToFormState
} }
} }
@connect(mapStateToProps) export class RawMoveTo extends React.Component<MoveToProps, {}> {
export class MoveTo extends React.Component<MoveToProps, {}> {
componentDidMount() { componentDidMount() {
unselectPlant(this.props.dispatch)(); unselectPlant(this.props.dispatch)();
@ -153,3 +152,5 @@ export const chooseLocation = (props: {
}); });
} }
}; };
export const MoveTo = connect(mapStateToProps)(RawMoveTo);

View File

@ -1,4 +1,4 @@
jest.mock("react-redux", () => ({ connect: jest.fn() })); jest.mock("react-redux", () => ({ connect: jest.fn(() => (x: {}) => x) }));
let mockPath = ""; let mockPath = "";
jest.mock("../../../history", () => ({ jest.mock("../../../history", () => ({

View File

@ -1,5 +1,5 @@
jest.mock("react-redux", () => ({ jest.mock("react-redux", () => ({
connect: jest.fn() connect: jest.fn(() => (x: {}) => x)
})); }));
jest.mock("../../../api/crud", () => ({ jest.mock("../../../api/crud", () => ({
@ -13,7 +13,7 @@ jest.mock("../../../farmware/weed_detector/actions", () => ({
import * as React from "react"; import * as React from "react";
import { mount, shallow } from "enzyme"; import { mount, shallow } from "enzyme";
import { import {
CreatePoints, RawCreatePoints as CreatePoints,
CreatePointsProps, CreatePointsProps,
mapStateToProps mapStateToProps
} from "../create_points"; } from "../create_points";

View File

@ -1,5 +1,5 @@
jest.mock("react-redux", () => ({ jest.mock("react-redux", () => ({
connect: jest.fn() connect: jest.fn(() => (x: {}) => x)
})); }));
jest.mock("lodash", () => ({ jest.mock("lodash", () => ({

View File

@ -1,4 +1,4 @@
jest.mock("react-redux", () => ({ connect: jest.fn() })); jest.mock("react-redux", () => ({ connect: jest.fn(() => (x: {}) => x) }));
let mockPath = ""; let mockPath = "";
jest.mock("../../../history", () => ({ jest.mock("../../../history", () => ({

View File

@ -1,4 +1,4 @@
jest.mock("react-redux", () => ({ connect: jest.fn() })); jest.mock("react-redux", () => ({ connect: jest.fn(() => (x: {}) => x) }));
let mockPath = "/app/designer/plants/1"; let mockPath = "/app/designer/plants/1";
jest.mock("../../../history", () => ({ jest.mock("../../../history", () => ({
@ -13,7 +13,7 @@ jest.mock("../../../api/crud", () => ({
})); }));
import * as React from "react"; import * as React from "react";
import { PlantInfo } from "../plant_info"; import { RawPlantInfo as PlantInfo } from "../plant_info";
import { mount } from "enzyme"; import { mount } from "enzyme";
import { fakePlant } from "../../../__test_support__/fake_state/resources"; import { fakePlant } from "../../../__test_support__/fake_state/resources";
import { EditPlantInfoProps } from "../../interfaces"; import { EditPlantInfoProps } from "../../interfaces";

View File

@ -1,7 +1,7 @@
jest.mock("react-redux", () => ({ connect: jest.fn() })); jest.mock("react-redux", () => ({ connect: jest.fn(() => (x: {}) => x) }));
import * as React from "react"; import * as React from "react";
import { Plants, PlantInventoryProps } from "../plant_inventory"; import { RawPlants, PlantInventoryProps } from "../plant_inventory";
import { mount, shallow } from "enzyme"; import { mount, shallow } from "enzyme";
import { fakePlant } from "../../../__test_support__/fake_state/resources"; import { fakePlant } from "../../../__test_support__/fake_state/resources";
@ -13,7 +13,7 @@ describe("<PlantInventory />", () => {
}); });
it("renders", () => { it("renders", () => {
const wrapper = mount(<Plants {...fakeProps()} />); const wrapper = mount(<RawPlants {...fakeProps()} />);
["Map", ["Map",
"Plants", "Plants",
"Events", "Events",
@ -25,13 +25,13 @@ describe("<PlantInventory />", () => {
}); });
it("has link to crops", () => { it("has link to crops", () => {
const wrapper = mount(<Plants {...fakeProps()} />); const wrapper = mount(<RawPlants {...fakeProps()} />);
expect(wrapper.html()).toContain("fa-plus"); expect(wrapper.html()).toContain("fa-plus");
expect(wrapper.html()).toContain("/app/designer/plants/crop_search"); expect(wrapper.html()).toContain("/app/designer/plants/crop_search");
}); });
it("updates search term", () => { it("updates search term", () => {
const wrapper = shallow<Plants>(<Plants {...fakeProps()} />); const wrapper = shallow<RawPlants>(<RawPlants {...fakeProps()} />);
expect(wrapper.state().searchTerm).toEqual(""); expect(wrapper.state().searchTerm).toEqual("");
wrapper.find("input").first().simulate("change", wrapper.find("input").first().simulate("change",
{ currentTarget: { value: "mint" } }); { currentTarget: { value: "mint" } });

View File

@ -1,4 +1,4 @@
jest.mock("react-redux", () => ({ connect: jest.fn() })); jest.mock("react-redux", () => ({ connect: jest.fn(() => (x: {}) => x) }));
let mockPath = "/app/designer/points/1"; let mockPath = "/app/designer/points/1";
jest.mock("../../../history", () => ({ jest.mock("../../../history", () => ({

View File

@ -1,4 +1,4 @@
jest.mock("react-redux", () => ({ connect: jest.fn() })); jest.mock("react-redux", () => ({ connect: jest.fn(() => (x: {}) => x) }));
jest.mock("../../../history", () => ({ jest.mock("../../../history", () => ({
push: jest.fn(), push: jest.fn(),
@ -7,7 +7,7 @@ jest.mock("../../../history", () => ({
import * as React from "react"; import * as React from "react";
import { mount, shallow } from "enzyme"; import { mount, shallow } from "enzyme";
import { Points, PointsProps } from "../point_inventory"; import { RawPoints, PointsProps } from "../point_inventory";
import { fakePoint } from "../../../__test_support__/fake_state/resources"; import { fakePoint } from "../../../__test_support__/fake_state/resources";
import { push } from "../../../history"; import { push } from "../../../history";
import { fakeState } from "../../../__test_support__/fake_state"; import { fakeState } from "../../../__test_support__/fake_state";
@ -16,21 +16,21 @@ import {
} from "../../../__test_support__/resource_index_builder"; } from "../../../__test_support__/resource_index_builder";
import { mapStateToProps } from "../point_inventory"; import { mapStateToProps } from "../point_inventory";
describe("<Points />", () => { describe("<RawPoints> />", () => {
const fakeProps = (): PointsProps => ({ const fakeProps = (): PointsProps => ({
points: [], points: [],
dispatch: jest.fn(), dispatch: jest.fn(),
}); });
it("renders no points", () => { it("renders no points", () => {
const wrapper = mount(<Points {...fakeProps()} />); const wrapper = mount(<RawPoints {...fakeProps()} />);
expect(wrapper.text()).toContain("No points yet."); expect(wrapper.text()).toContain("No points yet.");
}); });
it("renders points", () => { it("renders points", () => {
const p = fakeProps(); const p = fakeProps();
p.points = [fakePoint()]; p.points = [fakePoint()];
const wrapper = mount(<Points {...p} />); const wrapper = mount(<RawPoints {...p} />);
expect(wrapper.text()).toContain("Point 1"); expect(wrapper.text()).toContain("Point 1");
}); });
@ -38,7 +38,7 @@ describe("<Points />", () => {
const p = fakeProps(); const p = fakeProps();
p.points = [fakePoint()]; p.points = [fakePoint()];
p.points[0].body.id = 1; p.points[0].body.id = 1;
const wrapper = mount(<Points {...p} />); const wrapper = mount(<RawPoints {...p} />);
wrapper.find(".point-search-item").first().simulate("click"); wrapper.find(".point-search-item").first().simulate("click");
expect(push).toHaveBeenCalledWith("/app/designer/points/1"); expect(push).toHaveBeenCalledWith("/app/designer/points/1");
}); });
@ -48,7 +48,7 @@ describe("<Points />", () => {
p.points = [fakePoint(), fakePoint()]; p.points = [fakePoint(), fakePoint()];
p.points[0].body.name = "point 0"; p.points[0].body.name = "point 0";
p.points[1].body.name = "point 1"; p.points[1].body.name = "point 1";
const wrapper = shallow<Points>(<Points {...p} />); const wrapper = shallow<RawPoints>(<RawPoints {...p} />);
wrapper.find("input").first().simulate("change", wrapper.find("input").first().simulate("change",
{ currentTarget: { value: "0" } }); { currentTarget: { value: "0" } });
expect(wrapper.state().searchTerm).toEqual("0"); expect(wrapper.state().searchTerm).toEqual("0");
@ -59,7 +59,7 @@ describe("<Points />", () => {
p.points = [fakePoint(), fakePoint()]; p.points = [fakePoint(), fakePoint()];
p.points[0].body.name = "point 0"; p.points[0].body.name = "point 0";
p.points[1].body.name = "point 1"; p.points[1].body.name = "point 1";
const wrapper = mount(<Points {...p} />); const wrapper = mount(<RawPoints {...p} />);
wrapper.setState({ searchTerm: "0" }); wrapper.setState({ searchTerm: "0" });
expect(wrapper.text()).not.toContain("point 1"); expect(wrapper.text()).not.toContain("point 1");
}); });

View File

@ -1,4 +1,4 @@
jest.mock("react-redux", () => ({ connect: jest.fn() })); jest.mock("react-redux", () => ({ connect: jest.fn(() => (x: {}) => x) }));
let mockPath = ""; let mockPath = "";
jest.mock("../../../history", () => ({ jest.mock("../../../history", () => ({

View File

@ -42,8 +42,7 @@ export interface AddPlantProps {
openfarmSearch: OpenfarmSearch; openfarmSearch: OpenfarmSearch;
} }
@connect(mapStateToProps) export class RawAddPlant extends React.Component<AddPlantProps, {}> {
export class AddPlant extends React.Component<AddPlantProps, {}> {
componentDidMount() { componentDidMount() {
this.props.dispatch(searchForCurrentCrop(this.props.openfarmSearch)); this.props.dispatch(searchForCurrentCrop(this.props.openfarmSearch));
@ -72,3 +71,5 @@ export class AddPlant extends React.Component<AddPlantProps, {}> {
</DesignerPanel>; </DesignerPanel>;
} }
} }
export const AddPlant = connect(mapStateToProps)(RawAddPlant);

View File

@ -50,8 +50,7 @@ const DEFAULTS: CurrentPointPayl = {
color: "red" color: "red"
}; };
@connect(mapStateToProps) export class RawCreatePoints
export class CreatePoints
extends React.Component<CreatePointsProps, Partial<CreatePointsState>> { extends React.Component<CreatePointsProps, Partial<CreatePointsState>> {
constructor(props: CreatePointsProps) { constructor(props: CreatePointsProps) {
super(props); super(props);
@ -250,3 +249,5 @@ export class CreatePoints
</DesignerPanel>; </DesignerPanel>;
} }
} }
export const CreatePoints = connect(mapStateToProps)(RawCreatePoints);

View File

@ -28,8 +28,7 @@ export function mapStateToProps(props: Everything): CropCatalogProps {
}; };
} }
@connect(mapStateToProps) export class RawCropCatalog extends React.Component<CropCatalogProps, {}> {
export class CropCatalog extends React.Component<CropCatalogProps, {}> {
debouncedOFSearch = debounce((searchTerm: string) => { debouncedOFSearch = debounce((searchTerm: string) => {
this.props.openfarmSearch(searchTerm)(this.props.dispatch); this.props.openfarmSearch(searchTerm)(this.props.dispatch);
@ -99,3 +98,5 @@ export class CropCatalog extends React.Component<CropCatalogProps, {}> {
</DesignerPanel>; </DesignerPanel>;
} }
} }
export const CropCatalog = connect(mapStateToProps)(RawCropCatalog);

View File

@ -219,8 +219,7 @@ export const searchForCurrentCrop = (openfarmSearch: OpenfarmSearch) =>
unselectPlant(dispatch)(); unselectPlant(dispatch)();
}; };
@connect(mapStateToProps) export class RawCropInfo extends React.Component<CropInfoProps, {}> {
export class CropInfo extends React.Component<CropInfoProps, {}> {
componentDidMount() { componentDidMount() {
this.props.dispatch(searchForCurrentCrop(this.props.openfarmSearch)); this.props.dispatch(searchForCurrentCrop(this.props.openfarmSearch));
@ -270,3 +269,5 @@ export class CropInfo extends React.Component<CropInfoProps, {}> {
</DesignerPanel>; </DesignerPanel>;
} }
} }
export const CropInfo = connect(mapStateToProps)(RawCropInfo);

View File

@ -12,8 +12,7 @@ import { history, getPathArray } from "../../history";
import { destroy, edit, save } from "../../api/crud"; import { destroy, edit, save } from "../../api/crud";
import { BooleanSetting } from "../../session_keys"; import { BooleanSetting } from "../../session_keys";
@connect(mapStateToProps) export class RawPlantInfo extends React.Component<EditPlantInfoProps, {}> {
export class PlantInfo extends React.Component<EditPlantInfoProps, {}> {
get templates() { return isString(this.props.openedSavedGarden); } get templates() { return isString(this.props.openedSavedGarden); }
get stringyID() { return getPathArray()[this.templates ? 5 : 4] || ""; } get stringyID() { return getPathArray()[this.templates ? 5 : 4] || ""; }
get plant() { return this.props.findPlant(this.stringyID); } get plant() { return this.props.findPlant(this.stringyID); }
@ -64,3 +63,5 @@ export class PlantInfo extends React.Component<EditPlantInfoProps, {}> {
return plant_info ? this.default(plant_info) : this.fallback(); return plant_info ? this.default(plant_info) : this.fallback();
} }
} }
export const PlantInfo = connect(mapStateToProps)(RawPlantInfo);

View File

@ -34,8 +34,7 @@ function mapStateToProps(props: Everything): PlantInventoryProps {
}; };
} }
@connect(mapStateToProps) export class RawPlants extends React.Component<PlantInventoryProps, State> {
export class Plants extends React.Component<PlantInventoryProps, State> {
state: State = { searchTerm: "" }; state: State = { searchTerm: "" };
@ -72,3 +71,5 @@ export class Plants extends React.Component<PlantInventoryProps, State> {
</DesignerPanel>; </DesignerPanel>;
} }
} }
export const Plants = connect(mapStateToProps)(RawPlants);

View File

@ -24,8 +24,7 @@ export const mapStateToProps = (props: Everything): EditPointProps => ({
findPoint: id => maybeFindPointById(props.resources.index, id), findPoint: id => maybeFindPointById(props.resources.index, id),
}); });
@connect(mapStateToProps) export class RawEditPoint extends React.Component<EditPointProps, {}> {
export class EditPoint extends React.Component<EditPointProps, {}> {
get stringyID() { return getPathArray()[4] || ""; } get stringyID() { return getPathArray()[4] || ""; }
get point() { get point() {
if (this.stringyID) { if (this.stringyID) {
@ -84,3 +83,5 @@ export class EditPoint extends React.Component<EditPointProps, {}> {
return this.point ? this.default(this.point) : this.fallback(); return this.point ? this.default(this.point) : this.fallback();
} }
} }
export const EditPoint = connect(mapStateToProps)(RawEditPoint);

View File

@ -31,9 +31,7 @@ export function mapStateToProps(props: Everything): PointsProps {
}; };
} }
@connect(mapStateToProps) export class RawPoints extends React.Component<PointsProps, PointsState> {
export class Points extends React.Component<PointsProps, PointsState> {
state: PointsState = { searchTerm: "" }; state: PointsState = { searchTerm: "" };
update = ({ currentTarget }: React.SyntheticEvent<HTMLInputElement>) => { update = ({ currentTarget }: React.SyntheticEvent<HTMLInputElement>) => {
@ -71,3 +69,5 @@ export class Points extends React.Component<PointsProps, PointsState> {
</DesignerPanel>; </DesignerPanel>;
} }
} }
export const Points = connect(mapStateToProps)(RawPoints);

View File

@ -29,10 +29,7 @@ export interface SelectPlantsProps {
selected: string[]; selected: string[];
} }
@connect(mapStateToProps) export class RawSelectPlants extends React.Component<SelectPlantsProps, {}> {
export class SelectPlants
extends React.Component<SelectPlantsProps, {}> {
componentDidMount() { componentDidMount() {
const { dispatch, selected } = this.props; const { dispatch, selected } = this.props;
if (selected && selected.length == 1) { if (selected && selected.length == 1) {
@ -116,3 +113,5 @@ export class SelectPlants
</DesignerPanel>; </DesignerPanel>;
} }
} }
export const SelectPlants = connect(mapStateToProps)(RawSelectPlants);

View File

@ -45,7 +45,7 @@ describe("<GroupDetail />", () => {
mockId = -23; mockId = -23;
const store = fakeStore(); const store = fakeStore();
const el = mount(<Provider store={store}> const el = mount(<Provider store={store}>
<GroupDetail {...({} as GroupDetail["props"])} /> <GroupDetail />
</Provider>); </Provider>);
const result = el.find(GroupDetailActive); const result = el.find(GroupDetailActive);
expect(result.length).toEqual(0); expect(result.length).toEqual(0);
@ -56,7 +56,7 @@ describe("<GroupDetail />", () => {
mockId = GOOD_ID; mockId = GOOD_ID;
const store = fakeStore(); const store = fakeStore();
const el = mount(<Provider store={store}> const el = mount(<Provider store={store}>
<GroupDetail {...({} as GroupDetail["props"])} /> <GroupDetail />
</Provider>); </Provider>);
const result = el.find(GroupDetailActive); const result = el.find(GroupDetailActive);
expect(result.length).toEqual(1); expect(result.length).toEqual(1);

View File

@ -1,4 +1,4 @@
jest.mock("react-redux", () => ({ connect: jest.fn() })); jest.mock("react-redux", () => ({ connect: jest.fn(() => (x: {}) => x) }));
jest.mock("../../../history", () => ({ jest.mock("../../../history", () => ({
getPathArray: jest.fn(() => ["L", "O", "L"]), getPathArray: jest.fn(() => ["L", "O", "L"]),
@ -7,7 +7,7 @@ jest.mock("../../../history", () => ({
import React from "react"; import React from "react";
import { mount, shallow } from "enzyme"; import { mount, shallow } from "enzyme";
import { GroupListPanel, GroupListPanelProps, mapStateToProps } from "../group_list_panel"; import { RawGroupListPanel as GroupListPanel, GroupListPanelProps, mapStateToProps } from "../group_list_panel";
import { fakePointGroup } from "../../../__test_support__/fake_state/resources"; import { fakePointGroup } from "../../../__test_support__/fake_state/resources";
import { history } from "../../../history"; import { history } from "../../../history";
import { fakeState } from "../../../__test_support__/fake_state"; import { fakeState } from "../../../__test_support__/fake_state";

View File

@ -53,8 +53,7 @@ function mapStateToProps(props: Everything): GroupDetailProps {
return { plants, group, dispatch: props.dispatch }; return { plants, group, dispatch: props.dispatch };
} }
@connect(mapStateToProps) export class RawGroupDetail extends React.Component<GroupDetailProps, {}> {
export class GroupDetail extends React.Component<GroupDetailProps, {}> {
render() { render() {
const { group } = this.props; const { group } = this.props;
@ -66,3 +65,4 @@ export class GroupDetail extends React.Component<GroupDetailProps, {}> {
} }
} }
} }
export const GroupDetail = connect(mapStateToProps)(RawGroupDetail);

View File

@ -28,8 +28,7 @@ export function mapStateToProps(props: Everything): GroupListPanelProps {
return { groups, dispatch: props.dispatch }; return { groups, dispatch: props.dispatch };
} }
@connect(mapStateToProps) export class RawGroupListPanel extends React.Component<GroupListPanelProps, State> {
export class GroupListPanel extends React.Component<GroupListPanelProps, State> {
state: State = { searchTerm: "" }; state: State = { searchTerm: "" };
@ -72,3 +71,5 @@ export class GroupListPanel extends React.Component<GroupListPanelProps, State>
</DesignerPanel>; </DesignerPanel>;
} }
} }
export const GroupListPanel = connect(mapStateToProps)(RawGroupListPanel);

View File

@ -1,4 +1,4 @@
jest.mock("react-redux", () => ({ connect: jest.fn() })); jest.mock("react-redux", () => ({ connect: jest.fn(() => (x: {}) => x) }));
jest.mock("../actions", () => ({ jest.mock("../actions", () => ({
snapshotGarden: jest.fn(), snapshotGarden: jest.fn(),

View File

@ -28,8 +28,7 @@ export const mapStateToProps = (props: Everything): SavedGardensProps => ({
openedSavedGarden: props.resources.consumers.farm_designer.openedSavedGarden, openedSavedGarden: props.resources.consumers.farm_designer.openedSavedGarden,
}); });
@connect(mapStateToProps) export class RawSavedGardens extends React.Component<SavedGardensProps, {}> {
export class SavedGardens extends React.Component<SavedGardensProps, {}> {
componentDidMount() { componentDidMount() {
unselectPlant(this.props.dispatch)(); unselectPlant(this.props.dispatch)();
@ -104,3 +103,5 @@ export const SavedGardenHUD = (props: { dispatch: Function }) =>
{t("Exit")} {t("Exit")}
</button> </button>
</div>; </div>;
export const SavedGardens = connect(mapStateToProps)(RawSavedGardens);

View File

@ -26,8 +26,7 @@ export interface DesignerSettingsProps {
getConfigValue: GetWebAppConfigValue; getConfigValue: GetWebAppConfigValue;
} }
@connect(mapStateToProps) export class RawDesignerSettings
export class DesignerSettings
extends React.Component<DesignerSettingsProps, {}> { extends React.Component<DesignerSettingsProps, {}> {
render() { render() {
@ -142,3 +141,5 @@ const OriginSelector = (props: DesignerSettingsProps) => {
</div> </div>
</div>; </div>;
}; };
export const DesignerSettings = connect(mapStateToProps)(RawDesignerSettings);

View File

@ -1,10 +1,10 @@
jest.mock("react-redux", () => ({ connect: jest.fn() })); jest.mock("react-redux", () => ({ connect: jest.fn(() => (x: {}) => x) }));
jest.mock("../../../api/crud", () => ({ initSave: jest.fn() })); jest.mock("../../../api/crud", () => ({ initSave: jest.fn() }));
import * as React from "react"; import * as React from "react";
import { mount, shallow } from "enzyme"; import { mount, shallow } from "enzyme";
import { AddTool, AddToolProps, mapStateToProps } from "../add_tool"; import { RawAddTool as AddTool, AddToolProps, mapStateToProps } from "../add_tool";
import { fakeState } from "../../../__test_support__/fake_state"; import { fakeState } from "../../../__test_support__/fake_state";
import { SaveBtn } from "../../../ui"; import { SaveBtn } from "../../../ui";
import { initSave } from "../../../api/crud"; import { initSave } from "../../../api/crud";

View File

@ -1,4 +1,4 @@
jest.mock("react-redux", () => ({ connect: jest.fn() })); jest.mock("react-redux", () => ({ connect: jest.fn(() => (x: {}) => x) }));
jest.mock("../../../api/crud", () => ({ edit: jest.fn() })); jest.mock("../../../api/crud", () => ({ edit: jest.fn() }));
@ -9,7 +9,7 @@ jest.mock("../../../history", () => ({
import * as React from "react"; import * as React from "react";
import { mount, shallow } from "enzyme"; import { mount, shallow } from "enzyme";
import { EditTool, EditToolProps, mapStateToProps } from "../edit_tool"; import { RawEditTool as EditTool, EditToolProps, mapStateToProps } from "../edit_tool";
import { fakeTool } from "../../../__test_support__/fake_state/resources"; import { fakeTool } from "../../../__test_support__/fake_state/resources";
import { fakeState } from "../../../__test_support__/fake_state"; import { fakeState } from "../../../__test_support__/fake_state";
import { import {

View File

@ -1,4 +1,4 @@
jest.mock("react-redux", () => ({ connect: jest.fn() })); jest.mock("react-redux", () => ({ connect: jest.fn(() => (x: {}) => x) }));
jest.mock("../../../history", () => ({ jest.mock("../../../history", () => ({
history: { push: jest.fn() }, history: { push: jest.fn() },
@ -7,7 +7,7 @@ jest.mock("../../../history", () => ({
import * as React from "react"; import * as React from "react";
import { mount, shallow } from "enzyme"; import { mount, shallow } from "enzyme";
import { Tools, ToolsProps, mapStateToProps } from "../index"; import { RawTools as Tools, ToolsProps, mapStateToProps } from "../index";
import { import {
fakeTool, fakeToolSlot fakeTool, fakeToolSlot
} from "../../../__test_support__/fake_state/resources"; } from "../../../__test_support__/fake_state/resources";

View File

@ -21,8 +21,7 @@ export const mapStateToProps = (props: Everything): AddToolProps => ({
dispatch: props.dispatch, dispatch: props.dispatch,
}); });
@connect(mapStateToProps) export class RawAddTool extends React.Component<AddToolProps, AddToolState> {
export class AddTool extends React.Component<AddToolProps, AddToolState> {
state: AddToolState = { toolName: "" }; state: AddToolState = { toolName: "" };
render() { render() {
return <DesignerPanel panelName={"tool"} panelColor={"gray"}> return <DesignerPanel panelName={"tool"} panelColor={"gray"}>
@ -43,3 +42,5 @@ export class AddTool extends React.Component<AddToolProps, AddToolState> {
</DesignerPanel>; </DesignerPanel>;
} }
} }
export const AddTool = connect(mapStateToProps)(RawAddTool);

View File

@ -27,8 +27,7 @@ export const mapStateToProps = (props: Everything): EditToolProps => ({
dispatch: props.dispatch, dispatch: props.dispatch,
}); });
@connect(mapStateToProps) export class RawEditTool extends React.Component<EditToolProps, EditToolState> {
export class EditTool extends React.Component<EditToolProps, EditToolState> {
state: EditToolState = { toolName: this.tool ? this.tool.body.name || "" : "" }; state: EditToolState = { toolName: this.tool ? this.tool.body.name || "" : "" };
get stringyID() { return getPathArray()[4] || ""; } get stringyID() { return getPathArray()[4] || ""; }
@ -65,3 +64,5 @@ export class EditTool extends React.Component<EditToolProps, EditToolState> {
return this.tool ? this.default(this.tool) : this.fallback(); return this.tool ? this.default(this.tool) : this.fallback();
} }
} }
export const EditTool = connect(mapStateToProps)(RawEditTool);

View File

@ -34,8 +34,7 @@ export const mapStateToProps = (props: Everything): ToolsProps => ({
dispatch: props.dispatch, dispatch: props.dispatch,
}); });
@connect(mapStateToProps) export class RawTools extends React.Component<ToolsProps, ToolsState> {
export class Tools extends React.Component<ToolsProps, ToolsState> {
state: ToolsState = { searchTerm: "" }; state: ToolsState = { searchTerm: "" };
update = ({ currentTarget }: React.SyntheticEvent<HTMLInputElement>) => { update = ({ currentTarget }: React.SyntheticEvent<HTMLInputElement>) => {
@ -125,3 +124,5 @@ const ToolInventoryItem = (props: ToolInventoryItemProps) =>
</p> </p>
</Col> </Col>
</Row>; </Row>;
export const Tools = connect(mapStateToProps)(RawTools);

View File

@ -1,4 +1,4 @@
jest.mock("react-redux", () => ({ connect: jest.fn() })); jest.mock("react-redux", () => ({ connect: jest.fn(() => (x: {}) => x) }));
const mockDevice = { execScript: jest.fn(() => Promise.resolve({})) }; const mockDevice = { execScript: jest.fn(() => Promise.resolve({})) };
jest.mock("../../device", () => ({ getDevice: () => mockDevice })); jest.mock("../../device", () => ({ getDevice: () => mockDevice }));

View File

@ -115,8 +115,7 @@ export const BasicFarmwarePage = ({ farmwareName, farmware, botOnline }:
</p> </p>
</div>; </div>;
@connect(mapStateToProps) export class RawFarmwarePage extends React.Component<FarmwareProps, {}> {
export class FarmwarePage extends React.Component<FarmwareProps, {}> {
get current() { return this.props.currentFarmware; } get current() { return this.props.currentFarmware; }
get botOnline() { get botOnline() {
@ -264,3 +263,5 @@ export class FarmwarePage extends React.Component<FarmwareProps, {}> {
</Page>; </Page>;
} }
} }
export const FarmwarePage = connect(mapStateToProps)(RawFarmwarePage);

View File

@ -8,16 +8,13 @@ jest.mock("../../../device", () => ({
return mockDevice; return mockDevice;
} }
})); }));
jest.mock("react-redux", () => ({ connect: jest.fn(() => (x: {}) => x) }));
jest.mock("react-redux", () => ({
connect: jest.fn()
}));
jest.mock("../../images/actions", () => ({ selectImage: jest.fn() })); jest.mock("../../images/actions", () => ({ selectImage: jest.fn() }));
import * as React from "react"; import * as React from "react";
import { mount, shallow } from "enzyme"; import { mount, shallow } from "enzyme";
import { WeedDetector, namespace } from "../index"; import { RawWeedDetector as WeedDetector, namespace } from "../index";
import { FarmwareProps } from "../../../devices/interfaces"; import { FarmwareProps } from "../../../devices/interfaces";
import { API } from "../../../api"; import { API } from "../../../api";
import { selectImage } from "../../images/actions"; import { selectImage } from "../../images/actions";

View File

@ -23,8 +23,7 @@ export const namespace = (prefix: string) => (key: string): WDENVKey => {
} }
}; };
@connect(mapStateToProps) export class RawWeedDetector
export class WeedDetector
extends React.Component<FarmwareProps, Partial<DetectorState>> { extends React.Component<FarmwareProps, Partial<DetectorState>> {
constructor(props: FarmwareProps) { constructor(props: FarmwareProps) {
@ -103,3 +102,5 @@ export class WeedDetector
</div>; </div>;
} }
} }
export const WeedDetector = connect(mapStateToProps)(RawWeedDetector);

View File

@ -1,4 +1,4 @@
jest.mock("react-redux", () => ({ connect: jest.fn() })); jest.mock("react-redux", () => ({ connect: jest.fn(() => (x: {}) => x) }));
import * as React from "react"; import * as React from "react";
import { mount } from "enzyme"; import { mount } from "enzyme";

View File

@ -11,8 +11,7 @@ export function mapStateToProps(props: Everything): { dispatch: Function } {
return { dispatch }; return { dispatch };
} }
@connect(mapStateToProps) export class RawHelp extends React.Component<{ dispatch: Function }, {}> {
export class Help extends React.Component<{ dispatch: Function }, {}> {
componentDidMount() { componentDidMount() {
this.props.dispatch({ type: Actions.START_TOUR, payload: undefined }); this.props.dispatch({ type: Actions.START_TOUR, payload: undefined });
@ -27,3 +26,5 @@ export class Help extends React.Component<{ dispatch: Function }, {}> {
</Page>; </Page>;
} }
} }
export const Help = connect(mapStateToProps)(RawHelp);

View File

@ -1,10 +1,10 @@
jest.mock("react-redux", () => ({ connect: jest.fn() })); jest.mock("react-redux", () => ({ connect: jest.fn(() => (x: {}) => x) }));
const mockStorj: Dictionary<number | boolean> = {}; const mockStorj: Dictionary<number | boolean> = {};
import * as React from "react"; import * as React from "react";
import { mount } from "enzyme"; import { mount } from "enzyme";
import { Logs } from "../index"; import { RawLogs as Logs } from "../index";
import { ToolTips } from "../../constants"; import { ToolTips } from "../../constants";
import { TaggedLog, Dictionary } from "farmbot"; import { TaggedLog, Dictionary } from "farmbot";
import { NumericSetting } from "../../session_keys"; import { NumericSetting } from "../../session_keys";

View File

@ -25,8 +25,7 @@ export const formatLogTime =
.utcOffset(timeSettings.utcOffset) .utcOffset(timeSettings.utcOffset)
.format(`MMM D, ${timeFormatString(timeSettings)}`); .format(`MMM D, ${timeFormatString(timeSettings)}`);
@connect(mapStateToProps) export class RawLogs extends React.Component<LogsProps, Partial<LogsState>> {
export class Logs extends React.Component<LogsProps, Partial<LogsState>> {
/** Initialize log type verbosity level to the configured or default value. */ /** Initialize log type verbosity level to the configured or default value. */
initialize = (name: NumberConfigKey, defaultValue: number): number => { initialize = (name: NumberConfigKey, defaultValue: number): number => {
@ -131,3 +130,5 @@ export class Logs extends React.Component<LogsProps, Partial<LogsState>> {
</Page>; </Page>;
} }
} }
export const Logs = connect(mapStateToProps)(RawLogs);

View File

@ -1,4 +1,4 @@
jest.mock("react-redux", () => ({ connect: jest.fn() })); jest.mock("react-redux", () => ({ connect: jest.fn(() => (x: {}) => x) }));
import * as React from "react"; import * as React from "react";
import { mount } from "enzyme"; import { mount } from "enzyme";

View File

@ -7,8 +7,7 @@ import { mapStateToProps } from "./state_to_props";
import { MessagesProps } from "./interfaces"; import { MessagesProps } from "./interfaces";
import { Link } from "../link"; import { Link } from "../link";
@connect(mapStateToProps) export class RawMessages extends React.Component<MessagesProps, {}> {
export class Messages extends React.Component<MessagesProps, {}> {
render() { render() {
return <Page className="messages-page"> return <Page className="messages-page">
<Row> <Row>
@ -35,3 +34,5 @@ export class Messages extends React.Component<MessagesProps, {}> {
</Page>; </Page>;
} }
} }
export const Messages = connect(mapStateToProps)(RawMessages);

View File

@ -1,4 +1,4 @@
jest.mock("react-redux", () => ({ connect: jest.fn() })); jest.mock("react-redux", () => ({ connect: jest.fn(() => (x: {}) => x) }));
jest.mock("../../history", () => ({ jest.mock("../../history", () => ({
push: () => jest.fn(), push: () => jest.fn(),

View File

@ -27,8 +27,7 @@ export const RegimenBackButton = (props: RegimenBackButtonProps) => {
title={schedulerOpen ? t("back to regimen") : t("back to regimens")} />; title={schedulerOpen ? t("back to regimen") : t("back to regimens")} />;
}; };
@connect(mapStateToProps) export class RawRegimens extends React.Component<Props, {}> {
export class Regimens extends React.Component<Props, {}> {
UNSAFE_componentWillMount() { UNSAFE_componentWillMount() {
if (!this.props.current) { setActiveRegimenByName(); } if (!this.props.current) { setActiveRegimenByName(); }
} }
@ -87,3 +86,4 @@ export class Regimens extends React.Component<Props, {}> {
</Page>; </Page>;
} }
} }
export const Regimens = connect(mapStateToProps)(RawRegimens);

View File

@ -28,7 +28,6 @@ import { ReduxAction } from "../redux/interfaces";
import { ActionHandler } from "../redux/generate_reducer"; import { ActionHandler } from "../redux/generate_reducer";
import { get } from "lodash"; import { get } from "lodash";
import { Actions } from "../constants"; import { Actions } from "../constants";
import { getFbosConfig } from "./getters";
export function findByUuid(index: ResourceIndex, uuid: string): TaggedResource { export function findByUuid(index: ResourceIndex, uuid: string): TaggedResource {
const x = index.references[uuid]; const x = index.references[uuid];

View File

@ -51,7 +51,7 @@ export class RootComponent extends React.Component<RootComponentProps, RootCompo
try { try {
return <ErrorBoundary> return <ErrorBoundary>
<Provider store={_store}> <Provider store={_store}>
<App {...{} as App["props"]}> <App>
<Route {...props} /> <Route {...props} />
</App> </App>
</Provider> </Provider>

View File

@ -1,4 +1,4 @@
jest.mock("react-redux", () => ({ connect: jest.fn() })); jest.mock("react-redux", () => ({ connect: jest.fn(() => (x: {}) => x) }));
jest.mock("../../history", () => ({ jest.mock("../../history", () => ({
push: jest.fn(), push: jest.fn(),

View File

@ -1,4 +1,4 @@
jest.mock("react-redux", () => ({ connect: jest.fn() })); jest.mock("react-redux", () => ({ connect: jest.fn(() => (x: {}) => x) }));
import { mapStateToProps } from "../state_to_props"; import { mapStateToProps } from "../state_to_props";
import { fakeState } from "../../__test_support__/fake_state"; import { fakeState } from "../../__test_support__/fake_state";

View File

@ -29,8 +29,7 @@ export const SequenceBackButton = (props: SequenceBackButtonProps) => {
title={insertingStep ? t("back to sequence") : t("back to sequences")} />; title={insertingStep ? t("back to sequence") : t("back to sequences")} />;
}; };
@connect(mapStateToProps) export class RawSequences extends React.Component<Props, {}> {
export class Sequences extends React.Component<Props, {}> {
UNSAFE_componentWillMount() { UNSAFE_componentWillMount() {
if (!this.props.sequence) { setActiveSequenceByName(); } if (!this.props.sequence) { setActiveSequenceByName(); }
} }
@ -90,3 +89,5 @@ export class Sequences extends React.Component<Props, {}> {
</Page>; </Page>;
} }
} }
export const Sequences = connect(mapStateToProps)(RawSequences);

View File

@ -1,6 +1,4 @@
jest.mock("react-redux", () => ({ jest.mock("react-redux", () => ({ connect: jest.fn(() => (x: {}) => x) }));
connect: jest.fn()
}));
import * as React from "react"; import * as React from "react";
import { mount, shallow } from "enzyme"; import { mount, shallow } from "enzyme";

View File

@ -5,8 +5,7 @@ import { Col, Row, Page } from "../ui";
import { ToolBayList, ToolBayForm, ToolList, ToolForm } from "./components"; import { ToolBayList, ToolBayForm, ToolList, ToolForm } from "./components";
import { mapStateToProps } from "./state_to_props"; import { mapStateToProps } from "./state_to_props";
@connect(mapStateToProps) export class RawTools extends React.Component<Props, Partial<ToolsState>> {
export class Tools extends React.Component<Props, Partial<ToolsState>> {
state: ToolsState = { editingBays: false, editingTools: false }; state: ToolsState = { editingBays: false, editingTools: false };
toggle = (name: keyof ToolsState) => toggle = (name: keyof ToolsState) =>
@ -48,3 +47,5 @@ export class Tools extends React.Component<Props, Partial<ToolsState>> {
</Page>; </Page>;
} }
} }
export const Tools = connect(mapStateToProps)(RawTools);

2
typings/index.d.ts vendored
View File

@ -1,5 +1,3 @@
/// <reference path="react-redux.d.ts" />
/** This contains all of the global ENV vars passed from server => client. /** This contains all of the global ENV vars passed from server => client.
* Previously was `process.env.XYZ`. */ * Previously was `process.env.XYZ`. */
declare var globalConfig: { [k: string]: string }; declare var globalConfig: { [k: string]: string };

View File

@ -1,65 +0,0 @@
// Type definitions for react-redux 2.1.2
// Project: https://github.com/rackt/react-redux
// Definitions by: Qubo <https://github.com/tkqubo>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare module "react-redux" {
import { Component } from 'react';
import { Store, Dispatch, Action, AnyAction, ActionCreator } from 'redux';
export class ElementClass extends Component<any, any> { }
export interface ClassDecorator {
<T extends (typeof ElementClass)>(component: T): T
}
/**
* Connects a React component to a Redux store.
* @param mapStateToProps
* @param mapDispatchToProps
* @param mergeProps
* @param options
*/
export function connect(mapStateToProps?: MapStateToProps,
mapDispatchToProps?: MapDispatchToPropsFunction | MapDispatchToPropsObject,
mergeProps?: MergeProps,
options?: Options): ClassDecorator;
interface MapStateToProps {
(state: any, ownProps?: any): any;
}
interface MapDispatchToPropsFunction {
(dispatch: Dispatch<any>, ownProps?: any): any;
}
interface MapDispatchToPropsObject {
[name: string]: ActionCreator<any>;
}
interface MergeProps {
(stateProps: any, dispatchProps: any, ownProps: any): any;
}
interface Options {
/**
* If true, implements shouldComponentUpdate and shallowly compares the result of mergeProps,
* preventing unnecessary updates, assuming that the component is a “pure” component
* and does not rely on any input or state other than its props and the selected Redux store’s state.
* Defaults to true.
* @default true
*/
pure: boolean;
}
export interface ProviderProps<A extends Action = AnyAction> {
/**
* The single Redux store in your application.
*/
store: Store<any, A>;
}
/**
* Makes the Redux store available to the connect() calls in the component hierarchy below.
*/
export class Provider<A extends Action = AnyAction> extends Component<ProviderProps<A>> { }
}