Add onLog test back

pull/1446/head
Rick Carlino 2019-09-17 19:56:18 -05:00
parent 6edbfa33c0
commit f2439292e8
2 changed files with 19 additions and 1 deletions

View File

@ -38,6 +38,9 @@ import { talk } from "browser-speech";
import { MessageType } from "../../../sequences/interfaces";
import { FbjsEventName } from "farmbot/dist/constants";
import { info, error, success, warning, fun, busy } from "../../../toast/toast";
import { onLogs } from "../../log_handlers";
import { fakeState } from "../../../__test_support__/fake_state";
import { globalQueue } from "../../batch_queue";
const ANY_NUMBER = expect.any(Number);
@ -237,6 +240,18 @@ describe("onPublicBroadcast", () => {
expect(console.log).toHaveBeenCalledWith(
FbjsEventName.publicBroadcast, expect.any(Object));
describe("onLogs", () => {
it("Calls `networkUp` when good logs come in", () => {
const dispatch = jest.fn();
const fn = onLogs(dispatch, fakeState);
const log = fakeLog(MessageType.error, []);
log.message = "bot xyz is offline";
const taggedLog = fn(log);
globalQueue.maybeWork();
expect(taggedLog && taggedLog.kind).toEqual("Log");
});
});
it("triggers when appropriate", () => {
location.assign = jest.fn();
window.confirm = jest.fn(() => true);

View File

@ -15,6 +15,9 @@ export const onLogs =
actOnChannelName(msg, "toast", showLogOnScreen);
actOnChannelName(msg, "espeak", speakLogAloud(getState));
const log = initLog(msg).payload;
log.kind == "Log" && globalQueue.push(log);
if (log.kind == "Log") {
globalQueue.push(log);
return log;
}
}
};