Increase coverage of hotkey code
parent
761c6b0444
commit
c4ac2e1485
|
@ -0,0 +1,43 @@
|
|||
jest.mock("../history",
|
||||
() => ({ push: jest.fn() }));
|
||||
const mockSyncThunk = jest.fn();
|
||||
jest.mock("../devices/actions",
|
||||
() => ({ sync: () => mockSyncThunk }));
|
||||
|
||||
import { HotKeys } from "../hotkeys";
|
||||
import { betterCompact } from "../util";
|
||||
import { push } from "../history";
|
||||
import { sync } from "../devices/actions";
|
||||
|
||||
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");
|
||||
|
||||
comp.toggle = jest.fn(() => () => { });
|
||||
fns[6](e);
|
||||
expect(comp.toggle).toHaveBeenCalledWith("guideOpen");
|
||||
});
|
||||
});
|
|
@ -55,10 +55,10 @@ export class HotKeys extends React.Component<Props, Partial<State>> {
|
|||
</Overlay>;
|
||||
}
|
||||
|
||||
private toggle = (property: keyof State) => () =>
|
||||
toggle = (property: keyof State) => () =>
|
||||
this.setState({ [property]: !this.state[property] });
|
||||
|
||||
private hotkeys(dispatch: Function, slug: string) {
|
||||
hotkeys(dispatch: Function, slug: string) {
|
||||
const links = getLinks();
|
||||
const idx = findIndex(links, { slug });
|
||||
const right = "/app/" + (links[idx + 1] || links[0]).slug;
|
||||
|
|
Loading…
Reference in New Issue