offendersHelpersTest.js 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. var should = require('chai').should();
  2. var offendersHelpers = require('../../lib/offendersHelpers');
  3. describe('offendersHelpers', function() {
  4. describe('domPathToArray', function() {
  5. it('should transform a path to an array', function() {
  6. var result = offendersHelpers.domPathToArray('body > section#page > div.alternate-color > ul.retroGuide > li[0] > div.retro-chaine.france2');
  7. result.should.deep.equal(['body', 'section#page', 'div.alternate-color', 'ul.retroGuide', 'li[0]', 'div.retro-chaine.france2']);
  8. });
  9. it('should work even if a space is missing', function() {
  10. var result = offendersHelpers.domPathToArray('body > section#page> div.alternate-color > ul.retroGuide >li[0] > div.retro-chaine.france2');
  11. result.should.deep.equal(['body', 'section#page', 'div.alternate-color', 'ul.retroGuide', 'li[0]', 'div.retro-chaine.france2']);
  12. });
  13. });
  14. describe('listOfDomArraysToTree', function() {
  15. it('should transform a list of arrays into a tree', function() {
  16. var result = offendersHelpers.listOfDomArraysToTree([
  17. ['body', 'section#page', 'div.alternate-color', 'ul.retroGuide', 'li[0]', 'div.retro-chaine.france2'],
  18. ['body', 'section#page', 'div.alternate-color', 'ul.retroGuide', 'li[0]', 'div.retro-chaine.france2'],
  19. ['body', 'section#page', 'div.alternate-color', 'ul.retroGuide', 'li[1]', 'div.retro-chaine.france2']
  20. ]);
  21. result.should.deep.equal({
  22. 'body': {
  23. 'section#page': {
  24. 'div.alternate-color': {
  25. 'ul.retroGuide': {
  26. 'li[0]': {
  27. 'div.retro-chaine.france2': 2
  28. },
  29. 'li[1]': {
  30. 'div.retro-chaine.france2': 1
  31. }
  32. }
  33. }
  34. }
  35. }
  36. });
  37. });
  38. });
  39. describe('domTreeToHTML', function() {
  40. it('should transform a dom tree into HTML with the awaited format', function() {
  41. var result = offendersHelpers.domTreeToHTML({
  42. 'body': {
  43. 'ul.retroGuide': {
  44. 'li[0]': {
  45. 'div.retro-chaine.france2': 2
  46. },
  47. 'li[1]': {
  48. 'div.retro-chaine.france2': 1
  49. }
  50. }
  51. }
  52. });
  53. result.should.equal('<div class="domTree"><div><span>body</span><div><span>ul.retroGuide</span><div><span>li[0]</span><div><span>div.retro-chaine.france2 <span>(x2)</span></span></div></div><div><span>li[1]</span><div><span>div.retro-chaine.france2</span></div></div></div></div></div>');
  54. });
  55. });
  56. describe('listOfDomPathsToHTML', function() {
  57. it('should transform a list of path strings into HTML', function() {
  58. var result = offendersHelpers.listOfDomPathsToHTML([
  59. 'body > ul.retroGuide > li[0] > div.retro-chaine.france2',
  60. 'body > ul.retroGuide > li[1] > div.retro-chaine.france2',
  61. 'body > ul.retroGuide > li[0] > div.retro-chaine.france2',
  62. ]);
  63. result.should.equal('<div class="domTree"><div><span>body</span><div><span>ul.retroGuide</span><div><span>li[0]</span><div><span>div.retro-chaine.france2 <span>(x2)</span></span></div></div><div><span>li[1]</span><div><span>div.retro-chaine.france2</span></div></div></div></div></div>');
  64. });
  65. });
  66. });