helpers.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. describe('Helpers', function () {
  2. let stringService;
  3. // Ignoring page reload request
  4. beforeAll(() => window.onbeforeunload = () => null);
  5. beforeEach(function () {
  6. // Load 3ema.services
  7. module('3ema.services');
  8. // Inject the $filter function
  9. inject(function(StringService) {
  10. stringService = StringService;
  11. });
  12. });
  13. describe('byteChunkSplit', function() {
  14. this.testPatterns = (cases, size, offset) => {
  15. for (let testcase of cases) {
  16. const input = testcase[0];
  17. const expected = testcase[1];
  18. expect(stringService.byteChunk(input, size, offset)).toEqual(expected);
  19. }
  20. };
  21. it('short chunks', () => {
  22. this.testPatterns([
  23. ['abc',
  24. ['abc',]],
  25. ['abcdefghijklmn',
  26. ['abcdef', 'ghijkl', 'mn',]],
  27. // four byte emoji
  28. ['😅😅',
  29. ['😅', '😅']]
  30. ], 6, null);
  31. });
  32. it('chunks with offset', () => {
  33. this.testPatterns([
  34. ['The quick white 🐼. He jumped over the lazy 🐶.',
  35. ['The', 'quick', 'white', '🐼.', 'He', 'jumped', 'over', 'the', 'lazy', '🐶.',]],
  36. ], 6, 10);
  37. this.testPatterns([
  38. ['The quick white 🐼. He jumped over the lazy 🐶.',
  39. ['The quick white 🐼', '. He jumped over the', 'lazy 🐶.',]],
  40. ], 20, 10);
  41. });
  42. });
  43. });