update onBroadcast
parent
b38e77694a
commit
9a5e7d8179
|
@ -14,7 +14,7 @@ jest.mock("../../../device", () => { return { getDevice: () => mockBot }; });
|
|||
jest.mock("../../ping_mqtt", () => { return { startPinging: jest.fn() }; });
|
||||
|
||||
import { getDevice } from "../../../device";
|
||||
import { attachEventListeners } from "../../connect_device";
|
||||
import { attachEventListeners, BROADCAST_CHANNEL } from "../../connect_device";
|
||||
import { startPinging } from "../../ping_mqtt";
|
||||
|
||||
describe("attachEventListeners", () => {
|
||||
|
@ -30,6 +30,7 @@ describe("attachEventListeners", () => {
|
|||
"online",
|
||||
"sent",
|
||||
"status_v8",
|
||||
BROADCAST_CHANNEL,
|
||||
].map(e => expect(dev.on).toHaveBeenCalledWith(e, expect.any(Function)));
|
||||
[
|
||||
"message",
|
||||
|
|
|
@ -27,7 +27,6 @@ import {
|
|||
onMalformed,
|
||||
speakLogAloud,
|
||||
onPublicBroadcast,
|
||||
BROADCAST_CHANNEL,
|
||||
} from "../../connect_device";
|
||||
import { onLogs } from "../../log_handlers";
|
||||
import { Actions, Content } from "../../../constants";
|
||||
|
@ -225,7 +224,7 @@ describe("onPublicBroadcast", () => {
|
|||
it("triggers when appropriate", () => {
|
||||
location.assign = jest.fn();
|
||||
window.confirm = jest.fn(() => true);
|
||||
onPublicBroadcast(BROADCAST_CHANNEL, {});
|
||||
onPublicBroadcast({});
|
||||
expect(window.confirm).toHaveBeenCalledWith(Content.FORCE_REFRESH_CONFIRM);
|
||||
expect(location.assign).toHaveBeenCalled();
|
||||
});
|
||||
|
@ -233,14 +232,8 @@ describe("onPublicBroadcast", () => {
|
|||
it("allows cancellation of refresh", () => {
|
||||
window.confirm = jest.fn(() => false);
|
||||
window.alert = jest.fn();
|
||||
onPublicBroadcast(BROADCAST_CHANNEL, {});
|
||||
onPublicBroadcast({});
|
||||
expect(window.alert).toHaveBeenCalledWith(Content.FORCE_REFRESH_CANCEL_WARNING);
|
||||
expect(location.assign).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("does not trigger under usual circumstances", () => {
|
||||
window.confirm = jest.fn(() => false);
|
||||
onPublicBroadcast("NOT" + BROADCAST_CHANNEL, {});
|
||||
expect(window.confirm).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -165,13 +165,12 @@ export const onReconnect =
|
|||
|
||||
export const BROADCAST_CHANNEL = "public_broadcast";
|
||||
|
||||
export function onPublicBroadcast(chan: string, _payl: unknown) {
|
||||
if (chan === BROADCAST_CHANNEL) {
|
||||
if (confirm(t(Content.FORCE_REFRESH_CONFIRM))) {
|
||||
location.assign(window.location.origin || "/");
|
||||
} else {
|
||||
alert(t(Content.FORCE_REFRESH_CANCEL_WARNING));
|
||||
}
|
||||
export function onPublicBroadcast(payl: unknown) {
|
||||
console.log(BROADCAST_CHANNEL, payl);
|
||||
if (confirm(t(Content.FORCE_REFRESH_CONFIRM))) {
|
||||
location.assign(window.location.origin || "/");
|
||||
} else {
|
||||
alert(t(Content.FORCE_REFRESH_CANCEL_WARNING));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -188,9 +187,9 @@ export const attachEventListeners =
|
|||
bot.on("legacy_status", onLegacyStatus(dispatch, getState));
|
||||
bot.on("status_v8", onStatus(dispatch, getState));
|
||||
bot.on("malformed", onMalformed);
|
||||
bot.client.on("message", autoSync(dispatch, getState));
|
||||
bot.client.subscribe(BROADCAST_CHANNEL);
|
||||
bot.client.on("message", onPublicBroadcast);
|
||||
bot.on(BROADCAST_CHANNEL, onPublicBroadcast);
|
||||
bot.client.on("message", autoSync(dispatch, getState));
|
||||
bot.client.on("reconnect", onReconnect);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue