string.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. describe('StringService', function() {
  2. let $service;
  3. // Ignoring page reload request
  4. beforeAll(() => window.onbeforeunload = () => null);
  5. beforeEach(function() {
  6. module('3ema.services');
  7. // Inject the service
  8. inject(function(StringService) {
  9. $service = StringService;
  10. });
  11. });
  12. it('parse null string', () => {
  13. expect($service.getWord(null, 1)).toEqual('');
  14. });
  15. it('parse empty string', () => {
  16. expect($service.getWord('', 1)).toEqual('');
  17. });
  18. it('parse string (spaces)', () => {
  19. expect($service.getWord('When the man comes around.', 12)).toEqual('man');
  20. expect($service.getWord('When the man comes around.', 13)).toEqual('man');
  21. expect($service.getWord('When the man comes around.', 16)).toEqual('man');
  22. });
  23. it('parse string (newline)', () => {
  24. expect($service.getWord("When\nthe\nman\ncomes\naround.", 12)).toEqual('man');
  25. expect($service.getWord("When\nthe\nman\ncomes\naround.", 13)).toEqual('man');
  26. expect($service.getWord("When\nthe\nman\n\n\n\n\n\n\n\ncomes\naround.", 16)).toEqual('man');
  27. });
  28. it('parse string (newline/spaces)', () => {
  29. expect($service.getWord("When the\nman comes around.", 12)).toEqual('man');
  30. expect($service.getWord("When the\nman \ncomes around.", 13)).toEqual('man');
  31. expect($service.getWord("When the\nman \n \n \n \ncomes around.", 16)).toEqual('man');
  32. });
  33. it('parse string (special character)', () => {
  34. expect($service.getWord('When the :man: comes around.', 15)).toEqual(':man:');
  35. });
  36. it('parse string (with emoji (2 chars))', () => {
  37. expect($service.getWord('this 😄 is a :smile: face', 19)).toEqual(':smile:');
  38. });
  39. it('parse string (additional separators)', () => {
  40. expect($service.getWord('When the spider:man: comes around.', 20, [':'])).toEqual(':man:');
  41. });
  42. });