Farmbot-Web-App/frontend/__tests__/hotkeys_test.tsx

45 lines
1.4 KiB
TypeScript
Raw Normal View History

2019-11-22 12:57:22 -07:00
jest.mock("../history", () => ({ push: jest.fn() }));
2019-09-03 13:55:56 -06:00
const mockSyncThunk = jest.fn();
2019-11-22 12:57:22 -07:00
jest.mock("../devices/actions", () => ({ sync: () => mockSyncThunk }));
jest.mock("../farm_designer/map/actions", () => ({ unselectPlant: jest.fn() }));
2019-09-03 13:55:56 -06:00
import { HotKeys } from "../hotkeys";
import { betterCompact } from "../util";
import { push } from "../history";
import { sync } from "../devices/actions";
2019-11-22 12:57:22 -07:00
import { unselectPlant } from "../farm_designer/map/actions";
2019-09-03 13:55:56 -06:00
describe("hotkeys", () => {
it("has key bindings", () => {
const dispatch = jest.fn();
const e = {} as KeyboardEvent;
const comp = new HotKeys({ dispatch });
const hmm = comp.hotkeys(dispatch, "whatever");
const fns = betterCompact(hmm.map(item => item.onKeyDown));
expect(fns.length).toBe(7);
fns[0](e);
expect(dispatch).toHaveBeenCalledWith(sync());
fns[1](e);
expect(push).toHaveBeenCalledWith("/app/designer");
fns[2](e);
expect(push).toHaveBeenCalledWith("/app/messages");
fns[3](e);
expect(push).toHaveBeenCalledWith("/app/designer/plants/crop_search");
fns[4](e);
expect(push).toHaveBeenCalledWith("/app/designer/events/add");
fns[5](e);
expect(push).toHaveBeenCalledWith("/app/designer/plants");
2019-10-13 10:41:29 -06:00
expect(dispatch).toHaveBeenCalledWith(unselectPlant(dispatch));
2019-09-03 13:55:56 -06:00
comp.toggle = jest.fn(() => () => { });
fns[6](e);
expect(comp.toggle).toHaveBeenCalledWith("guideOpen");
});
});