Unicode.spec.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import {
  2. isKey,
  3. isCtrlMetaKey,
  4. } from 'handsontable/helpers/unicode';
  5. describe('Unicode helper', () => {
  6. //
  7. // Handsontable.helper.isKey
  8. //
  9. describe('isKey', () => {
  10. it('should be defined', () => {
  11. expect(isKey).toBeDefined();
  12. });
  13. it('should return true when base code is defined individually', () => {
  14. expect(isKey(39, 'ARROW_RIGHT')).toBe(true);
  15. expect(isKey('39', 'ARROW_RIGHT')).toBe(false);
  16. expect(isKey(30, 'ARROW_RIGHT')).toBe(false);
  17. });
  18. it('should return true when base code is defined many times', () => {
  19. expect(isKey(39, 'ARROW_RIGHT|ARROW_UP|ARROW_DOWN')).toBe(true);
  20. expect(isKey(38, 'ARROW_RIGHT|ARROW_UP|ARROW_DOWN')).toBe(true);
  21. expect(isKey(40, 'ARROW_RIGHT|ARROW_UP|ARROW_DOWN')).toBe(true);
  22. expect(isKey(37, 'ARROW_RIGHT|ARROW_UP|ARROW_BOTTOM')).toBe(false);
  23. expect(isKey('39', 'ARROW_RIGHT|ARROW_UP|ARROW_BOTTOM')).toBe(false);
  24. expect(isKey(116, 'ARROW_RIGHT|ARROW_UP|ARROW_BOTTOM')).toBe(false);
  25. });
  26. });
  27. //
  28. // Handsontable.helper.isCtrlMetaKey
  29. //
  30. describe('isCtrlMetaKey', () => {
  31. it('should return `true` when CTRL/CMD key is pressed', () => {
  32. expect(isCtrlMetaKey(17)).toBe(true);
  33. expect(isCtrlMetaKey(91)).toBe(true);
  34. expect(isCtrlMetaKey(93)).toBe(true);
  35. expect(isCtrlMetaKey(224)).toBe(true);
  36. expect(isCtrlMetaKey()).toBe(false);
  37. expect(isCtrlMetaKey(223)).toBe(false);
  38. expect(isCtrlMetaKey(1)).toBe(false);
  39. expect(isCtrlMetaKey(16)).toBe(false);
  40. });
  41. });
  42. });