Changeset 1178


Ignore:
Timestamp:
04/09/09 18:46:46 (11 years ago)
Author:
douglas
Message:

Working testrunner with a few test cases

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/Ticket1226/paraHandlerBest.js

    r1176 r1178  
    858858* Test suite for this, because it's really tough to get right. 
    859859*/ 
    860 EnterParagraphs.RunTests = function(xinha) 
     860EnterParagraphs.RunTests = function(xinha, debug) 
    861861{ 
    862   function test(before, cursorBefore, after, cursorAfter) { 
    863     xinha.setHTML(before); 
     862  function test(message, before, cursorBefore, after, cursorAfter) { 
     863    console.group('Test: ', message, null, before); 
     864    if (before !== null) { 
     865      xinha.setHTML(before); 
     866    } 
    864867    // Do something 
    865868    var cAnchor, cOffset; 
    866869 
    867870    var mockEvent = { 
    868       preventDefault: function() {console.log("Preventing default.");}, 
    869       stopPropagation: function() {console.log("Stopping propagation.");}, 
     871      preventDefault: function() {if (debug) console.log("Preventing default.");}, 
     872      stopPropagation: function() {if (debug) console.log("Stopping propagation.");}, 
    870873    } 
    871874    function setCursor(commands) { 
     
    876879        if ('id' == command[0]) { 
    877880            cAnchor = xinha._doc.getElementById(command[1]); 
     881        } else if ('tag' == command[0]) { 
     882            cAnchor = xinha._doc.getElementsByTagName(command[1])[0]; 
    878883        } else if ('child' == command[0]) { 
    879884            cAnchor = cAnchor.childNodes[command[1]]; 
     
    887892          } 
    888893        } else if ('offset' == command[0]) { 
    889           cOffset = command[1]; 
     894          if (command[1] == 'length') { 
     895            if (TEXT_NODE == cAnchor.nodeType) { 
     896              cOffset = cAnchor.nodeValue.length; 
     897            } else { 
     898              cOffset = cAnchor.childNodes.length; 
     899            } 
     900          } else if (command[1] < 0) { 
     901            if (TEXT_NODE == cAnchor.nodeType) { 
     902              cOffset = cAnchor.nodeValue.length + command[1]; 
     903            } else { 
     904              cOffset = cAnchor.childNodes.length + command[1]; 
     905            } 
     906          } else { 
     907            cOffset = command[1]; 
     908          } 
    890909        } 
    891910      } 
     
    902921    selection.addRange(range); 
    903922 
    904     return; 
    905923    // Breakline 
    906924    xinha.plugins['EnterParagraphs'].instance.breakLine(mockEvent, xinha._doc); 
     
    917935    result = xinha.getInnerHTML(); 
    918936    if (result == after) { 
    919       console.info('Was', before, 'Got', after) 
     937      console.info('Success!') 
    920938    } else { 
    921       console.error('Was', before, 'Expected', after, 'Got', result) 
    922     } 
     939      console.error('Was', null, before, null, 'Expected', null, after, null, 'Got', null, result, null) 
     940    } 
     941    console.groupEnd(); 
    923942  } 
    924943  contentBackup = xinha.getInnerHTML(); 
    925944  console.group('Running tests:'); 
    926   test('<h1 id="before">hi</h1>', [['id', 'before'], ['child', 0], ['offset', 2]], '<h1 id="before">hi</h1><h1></h1>', [['id', 'before'], ['next', 1], ['offset', 2]]); 
     945  /* 
     946     The initial content on browser load seems to be: 
     947     <body><br />\n</body> 
     948     That's a break tag and a whitespace text node containing a newline character. 
     949    */ 
     950  test('Initial Xinha Content', 
     951       null, [], 
     952       '<p>&nbsp;</p><p><br>&nbsp;</p>\n', [['child', 1]]);  // Mozilla kicks off a trailing newline.  Do I care about this? 
     953  test('Initial Xinha Content: Recreated', 
     954       '<br>\n', [], 
     955       '<p>&nbsp;</p><p><br>&nbsp;</p>\n', [['child', 1]]);  // Mozilla kicks off a trailing newline.  Do I care about this? 
     956  test('Empty Body', 
     957       '', [], 
     958       '<p>&nbsp;</p><p></p>', [['child', 1], ['offset', 0]]); 
     959  test('Text node in body', 
     960       'Hi', [], 
     961       '<p>&nbsp;</p><p>Hi</p>', [['child', 1], ['offset', 0]]); 
     962  test('Split h1', 
     963       '<h1 id="before">hi</h1>', [['id', 'before'], ['child', 0], ['offset', 2]], 
     964       '<h1 id="before">hi</h1><h1></h1>', [['id', 'before'], ['next', 1], ['offset', 2]]); 
    927965  console.groupEnd(); 
    928   return; 
    929966  xinha.setHTML(contentBackup); 
    930967  // EnterParagraphs.RunTests(xinha_editors['myTextArea']) 
     
    14761513    else 
    14771514    { 
    1478       var newCursor = splitTree(embedNode, treeRoot, cursorOffset, doc); 
     1515      var parentOffset = this.indexInParent(treeRoot); 
     1516      if (null === parentOffset) 
     1517      { 
     1518        // We can't do anything with this cursor, so return. 
     1519        return; 
     1520      } 
     1521      var newCursor = splitTree(embedNode, treeRoot.parentNode, parentOffset, doc); 
    14791522    } 
    14801523  } 
Note: See TracChangeset for help on using the changeset viewer.