-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
27 additions
and
9 deletions.
There are no files selected for viewing
36 changes: 27 additions & 9 deletions
36
starsky/starsky/clientapp/src/shared/global-shortcuts/global-shortcuts.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,42 @@ | ||
import React from "react"; | ||
import * as useHotKeysParent from "../../hooks/use-keyboard/use-hotkeys"; | ||
import * as useLocation from "../../hooks/use-location/use-location"; | ||
import { UrlQuery } from "../url-query"; | ||
import { GlobalShortcuts } from "./global-shortcuts"; | ||
|
||
describe("GlobalShortcuts", () => { | ||
it("should call useHotKeys with the correct arguments", () => { | ||
it("command + shift + k", () => { | ||
const locationObject = { | ||
location: window.location, | ||
navigate: jest.fn() | ||
}; | ||
|
||
jest.spyOn(useLocation, "default").mockImplementationOnce(() => locationObject); | ||
jest.spyOn(React, "useEffect").mockImplementationOnce((cb) => { | ||
cb(); | ||
}); | ||
|
||
GlobalShortcuts(); | ||
const event = new KeyboardEvent("keydown", { | ||
bubbles: true, | ||
cancelable: true, | ||
key: "k", | ||
metaKey: true, | ||
shiftKey: true | ||
}); | ||
|
||
jest.spyOn(useHotKeysParent, "default").mockImplementationOnce((_, callback) => { | ||
if (callback) { | ||
callback(event); | ||
} | ||
}); | ||
|
||
expect(useHotKeysParent).toHaveBeenCalledWith( | ||
{ key: "k", shiftKey: true, ctrlKeyOrMetaKey: true }, | ||
expect.any(Function), | ||
[] | ||
); | ||
const useLocationSpy = jest | ||
.spyOn(useLocation, "default") | ||
.mockImplementationOnce(() => locationObject); | ||
|
||
GlobalShortcuts(); | ||
|
||
expect(locationObject.navigate).toHaveBeenCalledWith(expect.any(String)); | ||
expect(useLocationSpy).toHaveBeenCalled(); | ||
expect(locationObject.navigate).toHaveBeenCalled(); | ||
expect(locationObject.navigate).toHaveBeenCalledWith(new UrlQuery().UrlPreferencesPage()); | ||
}); | ||
}); |