offendersHelpersTest.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. describe('domPathToButton', function() {
  67. it('should transform html', function() {
  68. var result = offendersHelpers.domPathToButton('html');
  69. result.should.equal('<div class="eltButton htmlButton"><b>html</b></div>');
  70. });
  71. it('should transform body', function() {
  72. var result = offendersHelpers.domPathToButton('body');
  73. result.should.equal('<div class="eltButton bodyButton"><b>body</b></div>');
  74. });
  75. it('should transform head', function() {
  76. var result = offendersHelpers.domPathToButton('head');
  77. result.should.equal('<div class="eltButton headButton"><b>head</b></div>');
  78. });
  79. it('should transform a standard in-body element', function() {
  80. var result = offendersHelpers.domPathToButton('body > div#colorbox > div#cboxContent');
  81. result.should.equal('<div class="eltButton domButton opens">DOM element <b>div#cboxContent</b><div class="domTree"><div><span>body</span><div><span>div#colorbox</span><div><span>div#cboxContent</span></div></div></div></div></div>');
  82. });
  83. it('should transform a domFragment element', function() {
  84. var result = offendersHelpers.domPathToButton('DocumentFragment');
  85. result.should.equal('<div class="eltButton fragButton">Fragment</div>');
  86. });
  87. it('should transform a domFragment element', function() {
  88. var result = offendersHelpers.domPathToButton('DocumentFragment > div#colorbox > div#cboxContent');
  89. result.should.equal('<div class="eltButton fragEltButton opens">Fragment element <b>div#cboxContent</b><div class="domTree"><div><span>DocumentFragment</span><div><span>div#colorbox</span><div><span>div#cboxContent</span></div></div></div></div></div>');
  90. });
  91. it('should transform an not-attached element', function() {
  92. var result = offendersHelpers.domPathToButton('div#sizcache');
  93. result.should.equal('<div class="eltButton aloneButton">Created element <b>div#sizcache</b></div>');
  94. });
  95. it('should transform an not-attached element path', function() {
  96. var result = offendersHelpers.domPathToButton('div > div#sizcache');
  97. result.should.equal('<div class="eltButton aloneEltButton opens">Created element <b>div#sizcache</b><div class="domTree"><div><span>div</span><div><span>div#sizcache</span></div></div></div></div>');
  98. });
  99. });
  100. });