String.spec.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import {
  2. equalsIgnoreCase,
  3. substitute,
  4. stripTags,
  5. } from 'handsontable/helpers/string';
  6. describe('String helper', () => {
  7. //
  8. // Handsontable.helper.equalsIgnoreCase
  9. //
  10. describe('equalsIgnoreCase', () => {
  11. it('should correct equals strings', () => {
  12. expect(equalsIgnoreCase()).toEqual(false);
  13. expect(equalsIgnoreCase('', '')).toEqual(true);
  14. expect(equalsIgnoreCase('True', 'TRUE', 'TrUe', true)).toEqual(true);
  15. expect(equalsIgnoreCase('FALSE', 'false')).toEqual(true);
  16. expect(equalsIgnoreCase('True', 'TRUE', false)).toEqual(false);
  17. expect(equalsIgnoreCase('fals e', false)).toEqual(false);
  18. });
  19. });
  20. //
  21. // Handsontable.helper.substitute
  22. //
  23. describe('substitute', () => {
  24. it('should properly substitute string to specified values', () => {
  25. var vars = {
  26. zero: 0,
  27. empty: '',
  28. undef: void 0,
  29. string1: 'foo;',
  30. string2: 'foo\nbar',
  31. };
  32. expect(substitute('', vars)).toBe('');
  33. expect(substitute('[zero]', vars)).toBe('0');
  34. expect(substitute('[zero][zero]', vars)).toBe('00');
  35. expect(substitute('[empty][zero][string1]', vars)).toBe('0foo;');
  36. expect(substitute('BAZ [string2] test', vars)).toBe('BAZ foo\nbar test');
  37. expect(substitute('1[undef]', vars)).toBe('1');
  38. });
  39. });
  40. //
  41. // Handsontable.helper.stripTags
  42. //
  43. describe('stripTags', () => {
  44. it('should strip any HTML tags from the string', () => {
  45. expect(stripTags('')).toBe('');
  46. expect(stripTags('<i>foo</i>')).toBe('foo');
  47. expect(stripTags('<script>alert()</script>')).toBe('alert()');
  48. expect(stripTags('<strong>Hello</strong> <span class="my">my</span> world<sup>2</sup>')).toBe('Hello my world2');
  49. expect(stripTags('This is my <a href="https://handsontable.com">link</a>')).toBe('This is my link');
  50. });
  51. });
  52. });