Add test for doToggle()

This commit is contained in:
Rick Carlino 2018-01-22 14:17:29 -06:00
parent cf0638d248
commit 3e7d1ca1b9
5 changed files with 22 additions and 11 deletions

View file

@ -0,0 +1,6 @@
describe("doToggle()", () => {
it("calls toggleWebAppBool, but isolated from its parent", () => {
const dispatch = jest.fn();
const toggler = doToggle(dispatch);
});
});

View file

@ -147,11 +147,11 @@ describe("<FarmwarePanel/>: farmware list", () => {
});
it("toggles first party farmware display", () => {
fail();
});
it("displays description", () => {
fail();
jest.resetAllMocks();
const p = fakeProps();
const panel = shallow(<FarmwarePanel {...p } />);
panel.find(FarmwareConfigMenu).simulate("toggle", {});
expect(p.onToggle).toHaveBeenCalled();
});
it("all 1st party farmwares are installed", () => {
@ -181,7 +181,7 @@ describe("<FarmwareConfigMenu />", () => {
function fakeProps(): FarmwareConfigMenuProps {
return {
show: true,
toggle: jest.fn(),
onToggle: jest.fn(),
firstPartyFwsInstalled: false
};
}
@ -214,7 +214,7 @@ describe("<FarmwareConfigMenu />", () => {
expect(button.hasClass("green")).toBeTruthy();
expect(button.hasClass("fb-toggle-button")).toBeTruthy();
button.simulate("click");
expect(p.toggle).toHaveBeenCalled();
expect(p.onToggle).toHaveBeenCalled();
});
it("1st party farmware display is disabled", () => {

View file

@ -37,7 +37,7 @@ export function FarmwareConfigMenu(props: FarmwareConfigMenuProps) {
</label>
<button
className={"fb-button fb-toggle-button " + listBtnColor}
onClick={props.toggle} />
onClick={props.onToggle} />
</fieldset>
</div>;
}
@ -143,7 +143,7 @@ export class FarmwarePanel extends React.Component<FWProps, Partial<FWState>> {
<i className="fa fa-gear" />
<FarmwareConfigMenu
show={this.props.showFirstParty}
toggle={() => this.props.onToggle("show_first_party_farmware")}
onToggle={() => this.props.onToggle("show_first_party_farmware")}
firstPartyFwsInstalled={
this.firstPartyFarmwaresPresent(this.state.firstPartyList)} />
</Popover>

View file

@ -11,6 +11,11 @@ import { envGet } from "./weed_detector/remote_env/selectors";
import { FarmwareForms } from "./farmware_forms";
import { catchErrors } from "../util";
import { toggleWebAppBool } from "../config_storage/actions";
import { BooleanConfigKey } from "../config_storage/web_app_configs";
export const doToggle =
(dispatch: Function) =>
(key: BooleanConfigKey) => dispatch(toggleWebAppBool(key));
@connect(mapStateToProps)
export class FarmwarePage extends React.Component<FarmwareProps, {}> {
@ -29,7 +34,7 @@ export class FarmwarePage extends React.Component<FarmwareProps, {}> {
<Col xs={12} sm={5}>
<FarmwarePanel
showFirstParty={!!this.props.webAppConfig.show_first_party_farmware}
onToggle={(key) => this.props.dispatch(toggleWebAppBool(key))}
onToggle={doToggle(this.props.dispatch)}
syncStatus={this.props.syncStatus}
botToMqttStatus={this.props.botToMqttStatus}
farmwares={this.props.farmwares} />

View file

@ -24,6 +24,6 @@ export type FarmwareManifestEntry = Record<"name" | "manifest", string>;
export interface FarmwareConfigMenuProps {
show: boolean | undefined;
toggle(): void;
onToggle(): void;
firstPartyFwsInstalled: boolean;
}