fix toast colors
parent
42430c569b
commit
7a7d24c17f
|
@ -5,5 +5,6 @@ jest.mock("../toast/toast", () => ({
|
|||
success: jest.fn(),
|
||||
info: jest.fn(),
|
||||
error: jest.fn(),
|
||||
warning: jest.fn()
|
||||
warning: jest.fn(),
|
||||
busy: jest.fn(),
|
||||
}));
|
||||
|
|
|
@ -40,7 +40,7 @@ import { talk } from "browser-speech";
|
|||
import { globalQueue } from "../../batch_queue";
|
||||
import { MessageType } from "../../../sequences/interfaces";
|
||||
import { FbjsEventName } from "farmbot/dist/constants";
|
||||
import { info, error, success, warning } from "../../../toast/toast";
|
||||
import { info, error, success, warning, fun, busy } from "../../../toast/toast";
|
||||
|
||||
const A_STRING = expect.any(String);
|
||||
describe("readStatus()", () => {
|
||||
|
@ -89,21 +89,32 @@ describe("showLogOnScreen", () => {
|
|||
function assertToastr(types: ALLOWED_MESSAGE_TYPES[], toastr: Function) {
|
||||
jest.resetAllMocks();
|
||||
types.map((x) => {
|
||||
const fun = fakeLog(x, ["toast"]);
|
||||
showLogOnScreen(fun);
|
||||
expect(toastr).toHaveBeenCalledWith(fun.message, TITLE());
|
||||
const log = fakeLog(x, ["toast"]);
|
||||
showLogOnScreen(log);
|
||||
expect(toastr).toHaveBeenCalledWith(log.message, TITLE());
|
||||
});
|
||||
}
|
||||
|
||||
it("routes `fun`, `info` and all others to toastr.info()", () => {
|
||||
it("routes `info` and all others to toastr.info()", () => {
|
||||
assertToastr([
|
||||
MessageType.fun,
|
||||
MessageType.info,
|
||||
("FOO" as ALLOWED_MESSAGE_TYPES)], info);
|
||||
});
|
||||
|
||||
it("routes `busy`, `warn` and `error` to toastr.error()", () => {
|
||||
assertToastr([MessageType.busy, MessageType.warn, MessageType.error], error);
|
||||
it("routes `error` to toastr.error()", () => {
|
||||
assertToastr([MessageType.error], error);
|
||||
});
|
||||
|
||||
it("routes `warn` to toastr.warning()", () => {
|
||||
assertToastr([MessageType.warn], warning);
|
||||
});
|
||||
|
||||
it("routes `busy` to toastr.busy()", () => {
|
||||
assertToastr([MessageType.busy], busy);
|
||||
});
|
||||
|
||||
it("routes `fun` to toastr.fun()", () => {
|
||||
assertToastr([MessageType.fun], fun);
|
||||
});
|
||||
|
||||
it("routes `success` to toastr.success()", () => {
|
||||
|
@ -174,8 +185,8 @@ describe("onOnline", () => {
|
|||
|
||||
describe("onReconnect", () => {
|
||||
onReconnect();
|
||||
expect(warning)
|
||||
.toHaveBeenCalledWith("Attempting to reconnect to the message broker", "Offline");
|
||||
expect(warning).toHaveBeenCalledWith(
|
||||
"Attempting to reconnect to the message broker", "Offline", "yellow");
|
||||
});
|
||||
|
||||
describe("changeLastClientConnected", () => {
|
||||
|
|
|
@ -4,7 +4,7 @@ import { Log } from "farmbot/dist/resources/api_resources";
|
|||
import { Farmbot, BotStateTree, TaggedResource } from "farmbot";
|
||||
import { FbjsEventName } from "farmbot/dist/constants";
|
||||
import { noop } from "lodash";
|
||||
import { success, error, info, warning } from "../toast/toast";
|
||||
import { success, error, info, warning, fun, busy } from "../toast/toast";
|
||||
import { HardwareState } from "../devices/interfaces";
|
||||
import { GetState, ReduxAction } from "../redux/interfaces";
|
||||
import { Content, Actions } from "../constants";
|
||||
|
@ -57,19 +57,24 @@ export function actOnChannelName(
|
|||
/** Take a log message (of type toast) and determines the correct kind of toast
|
||||
* to execute. */
|
||||
export function showLogOnScreen(log: Log) {
|
||||
switch (log.type) {
|
||||
case MessageType.success:
|
||||
return success(log.message, TITLE());
|
||||
case MessageType.warn:
|
||||
return warning(log.message, TITLE());
|
||||
case MessageType.busy:
|
||||
case MessageType.error:
|
||||
return error(log.message, TITLE());
|
||||
case MessageType.fun:
|
||||
case MessageType.info:
|
||||
default:
|
||||
return info(log.message, TITLE());
|
||||
}
|
||||
const toast = () => {
|
||||
switch (log.type) {
|
||||
case MessageType.success:
|
||||
return success;
|
||||
case MessageType.warn:
|
||||
return warning;
|
||||
case MessageType.error:
|
||||
return error;
|
||||
case MessageType.fun:
|
||||
return fun;
|
||||
case MessageType.busy:
|
||||
return busy;
|
||||
case MessageType.info:
|
||||
default:
|
||||
return info;
|
||||
}
|
||||
};
|
||||
toast()(log.message, TITLE());
|
||||
}
|
||||
|
||||
export function speakLogAloud(getState: GetState) {
|
||||
|
@ -164,7 +169,8 @@ export const onOnline =
|
|||
dispatchNetworkUp("user.mqtt", undefined, "MQTT.js is online");
|
||||
};
|
||||
export const onReconnect =
|
||||
() => warning(t("Attempting to reconnect to the message broker"), t("Offline"));
|
||||
() => warning(t("Attempting to reconnect to the message broker"),
|
||||
t("Offline"), "yellow");
|
||||
|
||||
export function onPublicBroadcast(payl: unknown) {
|
||||
console.log(FbjsEventName.publicBroadcast, payl);
|
||||
|
|
|
@ -352,7 +352,7 @@ describe("<FarmEventForm/>", () => {
|
|||
const i = instance(p);
|
||||
await i.commitViewModel(moment("2017-06-22T05:00:00.000Z"));
|
||||
expect(warning).toHaveBeenCalledWith(expect.stringContaining(
|
||||
"Nothing to run."), "Warning");
|
||||
"Nothing to run."));
|
||||
});
|
||||
|
||||
it("allows start time: edit with unsupported OS", () => {
|
||||
|
|
|
@ -337,8 +337,7 @@ export class EditFEForm extends React.Component<EditFEProps, State> {
|
|||
success(nextRunText);
|
||||
return true;
|
||||
} else {
|
||||
warning(t("All items scheduled before the start time. Nothing to run."),
|
||||
t("Warning"));
|
||||
warning(t("All items scheduled before the start time. Nothing to run."));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ const {
|
|||
info,
|
||||
fun,
|
||||
init,
|
||||
busy,
|
||||
}: typeof import("../toast") = jest.requireActual("../toast");
|
||||
|
||||
describe("toasts", () => {
|
||||
|
@ -21,7 +22,7 @@ describe("toasts", () => {
|
|||
warning("test suite msg 1");
|
||||
expect(createToastOnce).toHaveBeenCalledWith("test suite msg 1",
|
||||
"Warning",
|
||||
"yellow",
|
||||
"orange",
|
||||
console.warn);
|
||||
});
|
||||
|
||||
|
@ -45,6 +46,18 @@ describe("toasts", () => {
|
|||
.toHaveBeenCalledWith("test suite msg", "FYI", "blue");
|
||||
});
|
||||
|
||||
it("pops a busy() toast", () => {
|
||||
busy("test suite msg");
|
||||
expect(createToast)
|
||||
.toHaveBeenCalledWith("test suite msg", "Busy", "yellow");
|
||||
});
|
||||
|
||||
it("pops a busy() toast with different title and color", () => {
|
||||
busy("test suite msg", "new title", "purple");
|
||||
expect(createToast)
|
||||
.toHaveBeenCalledWith("test suite msg", "new title", "purple");
|
||||
});
|
||||
|
||||
it("pops a fun() toast", () => {
|
||||
fun("test suite msg");
|
||||
expect(createToast)
|
||||
|
|
|
@ -2,10 +2,10 @@ import { createToast, createToastOnce } from "./toast_internal_support";
|
|||
import { t } from "../i18next_wrapper";
|
||||
|
||||
/**
|
||||
* Yellow message with "Warning" as the default title.
|
||||
* Orange message with "Warning" as the default title.
|
||||
*/
|
||||
export const warning =
|
||||
(message: string, title = t("Warning"), color = "yellow") => {
|
||||
(message: string, title = t("Warning"), color = "orange") => {
|
||||
createToastOnce(message, title, color, console.warn);
|
||||
};
|
||||
|
||||
|
@ -24,14 +24,21 @@ export const success =
|
|||
createToast(message, title, color);
|
||||
|
||||
/**
|
||||
* Red message with "FYI" as the default title.
|
||||
* Blue message with "FYI" as the default title.
|
||||
*/
|
||||
export const info =
|
||||
(message: string, title = t("FYI"), color = "blue") =>
|
||||
createToast(message, title, color);
|
||||
|
||||
/**
|
||||
* Blue message with "Did you know?" as the default title.
|
||||
* Yellow message with "Busy" as the default title.
|
||||
*/
|
||||
export const busy =
|
||||
(message: string, title = t("Busy"), color = "yellow") =>
|
||||
createToast(message, title, color);
|
||||
|
||||
/**
|
||||
* Dark blue message with "Did you know?" as the default title.
|
||||
*/
|
||||
export const fun =
|
||||
(message: string, title = t("Did you know?"), color = "dark-blue") =>
|
||||
|
|
Loading…
Reference in New Issue