platformutils.spec.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { getPlatformSpecialKey } from "../platformutils"
  2. describe("getPlatformSpecialKey", () => {
  3. let platformGetter
  4. beforeEach(() => {
  5. platformGetter = jest.spyOn(navigator, "platform", "get")
  6. })
  7. test("returns '⌘' for Apple platforms", () => {
  8. platformGetter.mockReturnValue("Mac")
  9. expect(getPlatformSpecialKey()).toMatch("⌘")
  10. platformGetter.mockReturnValue("iPhone")
  11. expect(getPlatformSpecialKey()).toMatch("⌘")
  12. platformGetter.mockReturnValue("iPad")
  13. expect(getPlatformSpecialKey()).toMatch("⌘")
  14. platformGetter.mockReturnValue("iPod")
  15. expect(getPlatformSpecialKey()).toMatch("⌘")
  16. })
  17. test("return 'Ctrl' for non-Apple platforms", () => {
  18. platformGetter.mockReturnValue("Android")
  19. expect(getPlatformSpecialKey()).toMatch("Ctrl")
  20. platformGetter.mockReturnValue("Windows")
  21. expect(getPlatformSpecialKey()).toMatch("Ctrl")
  22. platformGetter.mockReturnValue("Linux")
  23. expect(getPlatformSpecialKey()).toMatch("Ctrl")
  24. })
  25. test("returns 'Ctrl' for null/undefined platforms", () => {
  26. platformGetter.mockReturnValue(null)
  27. expect(getPlatformSpecialKey()).toMatch("Ctrl")
  28. platformGetter.mockReturnValue(undefined)
  29. expect(getPlatformSpecialKey()).toMatch("Ctrl")
  30. })
  31. })