Text coverage bump

pull/578/head
Rick Carlino 2017-12-14 17:39:52 -06:00
parent 4ba23be474
commit 5ee1f0159e
4 changed files with 41 additions and 8 deletions

View File

@ -31,7 +31,8 @@ import {
changeLastClientConnected,
onSent,
onOnline,
onMalformed
onMalformed,
onLogs
} from "../../connect_device";
import { Actions, Content } from "../../../constants";
import { Log } from "../../../interfaces";
@ -182,3 +183,13 @@ describe("onMalformed()", () => {
.toHaveBeenCalledWith(Content.MALFORMED_MESSAGE_REC_UPGRADE);
});
});
describe("onLogs", () => {
it("Calls `networkUp` when good logs come in", () => {
const fn = onLogs(jest.fn());
const log = fakeLog("error", []);
log.message = "bot xyz is offline";
fn(log);
expect(dispatchNetworkDown).toHaveBeenCalledWith("bot.mqtt");
});
});

View File

@ -111,7 +111,7 @@ type Client = { connected?: boolean };
export const onSent = (client: Client) => () => !!client.connected ?
dispatchNetworkUp("user.mqtt") : dispatchNetworkDown("user.mqtt");
const onLogs = (dispatch: Function) => (msg: Log) => {
export const onLogs = (dispatch: Function) => (msg: Log) => {
bothUp();
if (isLog(msg)) {
ifToastWorthy(msg, showLogOnScreen);
@ -138,10 +138,10 @@ export function onMalformed() {
export const onOnline = () => dispatchNetworkUp("user.mqtt");
const onReconnect = () => success("Reconnected to the message broker");
const attachEventListeners =
(bot: Farmbot, dispatch: Function, getState: GetState) => {
bot.client.on("reconnect", throttle(onReconnect, 1000));
bot.client.on("reconnect",
throttle(() => success("Reconnected to the message broker"), 1000));
bot.on("online", onOnline);
bot.on("offline", onOffline);
bot.on("sent", onSent(bot.client));

View File

@ -1,7 +1,8 @@
import * as React from "react";
import { EncoderType, EncoderTypeProps } from "../encoder_type";
import { EncoderType, EncoderTypeProps, LOOKUP, findByType, isEncoderValue } from "../encoder_type";
import { shallow } from "enzyme";
import { FBSelect } from "../../../../ui/new_fb_select";
import { Encoder } from "farmbot";
describe("<EncoderType/>", () => {
it("renders default content", () => {
@ -18,3 +19,24 @@ describe("<EncoderType/>", () => {
// EncoderType
});
});
describe("findByType", () => {
it("handles undefined", () => {
expect(findByType(undefined)).toBe(LOOKUP.DEFAULT);
});
it("Handles known values like Encoder.differential", () => {
expect(findByType(Encoder.differential)).toBe(LOOKUP[Encoder.differential]);
});
it("Handles bad values like NaN", () => {
expect(findByType(-99)).toBe(LOOKUP.DEFAULT);
});
});
describe("isEncoderValue", () => {
it("determines typefulness", () => {
expect(isEncoderValue(-9)).toBeFalsy();
expect(isEncoderValue(Encoder.quadrature)).toBeTruthy();
});
});

View File

@ -9,7 +9,7 @@ export interface EncoderTypeProps {
onChange(key: McuParamName, value: Encoder): void;
}
const LOOKUP: { [name: string]: DropDownItem } = {
export const LOOKUP: { [name: string]: DropDownItem } = {
[Encoder.differential]: { label: "Differential", value: Encoder.differential },
[Encoder.quadrature]: { label: "Single-Ended", value: Encoder.quadrature },
DEFAULT: { label: "---", value: Encoder.unknown }
@ -24,9 +24,9 @@ const KEYS: McuParamName[] = [
];
// tslint:disable-next-line:no-any
function isEncoderValue(x: any): x is Encoder { return !!Encoder[x]; }
export function isEncoderValue(x: any): x is Encoder { return !!Encoder[x]; }
function findByType(input: number | string | undefined) {
export function findByType(input: number | string | undefined) {
return LOOKUP[input || "DEFAULT"] || LOOKUP.DEFAULT;
}