tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ajax_inplaceeditor_test.html (6843B)


      1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      2        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
      4 <head>
      5  <title>script.aculo.us Unit test file</title>
      6  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
      7  <script src="../../lib/prototype.js" type="text/javascript"></script>
      8  <script src="../../src/scriptaculous.js" type="text/javascript"></script>
      9  <script src="../../src/unittest.js" type="text/javascript"></script>
     10  <link rel="stylesheet" href="../test.css" type="text/css" />
     11 </head>
     12 <body>
     13 <h1>script.aculo.us Unit test file</h1>
     14 <p>
     15  Tests for Ajax.InPlaceEditor in controls.js
     16 </p>
     17 
     18 <!-- Log output -->
     19 <div id="testlog"> </div>
     20 
     21 <h1 id="tobeedited">To be edited</h1>
     22 <a id="tobeeditedEditControl" href="#">edit</a>
     23 
     24 <div id="tobeeditedMultiLine">First line<br/>Second line<br/>Third line</div>
     25 
     26 <!-- Tests follow -->
     27 <script type="text/javascript" language="javascript" charset="utf-8">
     28 // <![CDATA[
     29 
     30  new Test.Unit.Runner({
     31 
     32    setup: function() { with(this) {
     33      inPlaceEditor = new Ajax.InPlaceEditor($('tobeedited'), '_ajax_inplaceeditor_result.html', {
     34        externalControl: $('tobeeditedEditControl'),
     35        ajaxOptions: {method: 'get'} //override so we can use a static for the result
     36      });
     37      inPlaceEditorMultiLine = new Ajax.InPlaceEditor($('tobeeditedMultiLine'), '_ajax_inplaceeditor_result.html', {
     38        ajaxOptions: {method: 'get'} //override so we can use a static for the result
     39      });
     40    }},
     41 
     42    teardown: function() { with(this) {
     43      inPlaceEditor.dispose();
     44    }},
     45 
     46    testDisposesProperly: function() { with(this) {
     47      assertEqual("rgba(0, 0, 0, 0)", Element.getStyle('tobeedited','background-color'));
     48      inPlaceEditor.dispose();
     49      assertEqual("rgba(0, 0, 0, 0)", Element.getStyle('tobeedited','background-color'));
     50      assertVisible($('tobeedited'));
     51      Event.simulateMouse('tobeedited','click');
     52      assertVisible($('tobeedited'));
     53    }},
     54 
     55    testUsesTextAreaWhenMoreThanOneRows: function() { with(this) {
     56      inPlaceEditor.options.rows = 5;
     57      inPlaceEditor.enterEditMode();
     58      assertEqual("TEXTAREA", document.forms[0].firstChild.tagName);
     59      assertEqual("BR", document.forms[0].childNodes[1].tagName);
     60    }},
     61 
     62    testCanSpecifyAllTextsThroughOptions: function() { with(this) {
     63       // swedish translation ;-)
     64      inPlaceEditor.options.okText = "spara";
     65      inPlaceEditor.options.cancelText = "avbryt";
     66      inPlaceEditor.options.savingText = "Sparar...";
     67      inPlaceEditor.enterEditMode();
     68      assertEqual("spara", document.forms[0].lastChild.previousSibling.value);
     69      assertEqual("avbryt", document.forms[0].lastChild.innerHTML);
     70      inPlaceEditor.showSaving();
     71      assertEqual("Sparar...", $('tobeedited').innerHTML);
     72    }},
     73 
     74    testCanSpecifyFormIdThroughOptions: function() { with(this) {
     75      inPlaceEditor.enterEditMode();
     76      // default form id
     77      assertEqual("tobeedited-inplaceeditor", document.forms[0].id);
     78      inPlaceEditor.leaveEditMode();
     79      inPlaceEditor.options.formId = "myFormId";
     80      inPlaceEditor.enterEditMode();
     81      assertEqual("myFormId", document.forms[0].id);
     82    }},
     83 
     84    testCantEditWhileSaving: function() { with(this) {
     85      inPlaceEditor.onLoading();
     86      Event.simulateMouse('tobeedited','mouseover');
     87      assertEqual("rgba(0, 0, 0, 0)", Element.getStyle('tobeedited','background-color'));
     88      Event.simulateMouse('tobeedited','click');
     89      assertVisible($('tobeedited'));
     90    }},
     91 
     92    testCallbackFunctionGetsCalled: function() { with(this) {
     93      called = false;
     94      inPlaceEditor.options.callback = function(form) {
     95        called = true;
     96      }
     97      Event.simulateMouse('tobeedited','click');
     98      Event.simulateMouse(document.forms[0].childNodes[1],'click');
     99      assert(called, "callback was not called");
    100    }},
    101 
    102    testCanUseExternalElementToGoIntoEditMode: function() { with(this) {
    103      Event.simulateMouse('tobeeditedEditControl','click');
    104      assertNotNull(document.forms[0], "external control didn't work");
    105      // doesn't work if you click it again while in edit mode
    106      Event.simulateMouse('tobeeditedEditControl','click');
    107      assertNull(document.forms[1], "external control created two forms");
    108      assertNotVisible($('tobeeditedEditControl'));
    109      Event.simulateMouse(document.forms[0].childNodes[2],'click');
    110      assertVisible($('tobeeditedEditControl'));
    111    }},
    112 
    113    testHasLineBreaksDetectsHTMLLineBreaks: function() { with(this) {
    114      assert(inPlaceEditorMultiLine.hasHTMLLineBreaks("Line 1<br/>Line 2"));
    115      assert(inPlaceEditorMultiLine.hasHTMLLineBreaks("Line 1<br>Line 2"));
    116      assert(inPlaceEditorMultiLine.hasHTMLLineBreaks("<p>Line 1</p>Line 2"));
    117      assert(inPlaceEditorMultiLine.hasHTMLLineBreaks("Line 1<BR/>Line 2"));
    118      assert(inPlaceEditorMultiLine.hasHTMLLineBreaks("Line 1<BR>Line 2"));
    119      assert(inPlaceEditorMultiLine.hasHTMLLineBreaks("<P>Line 1</P>Line 2"));
    120      assert(inPlaceEditorMultiLine.hasHTMLLineBreaks("<P>Line 1<P>Line 2"));
    121      assert(!inPlaceEditorMultiLine.hasHTMLLineBreaks("One line"));
    122    }},
    123 
    124    testConvertsHTMLLineBreaksIntoNewLines: function() { with(this) {
    125      assertEqual("Line 1\nLine 2", inPlaceEditorMultiLine.convertHTMLLineBreaks("Line 1<br/>Line 2"));
    126      assertEqual("Line 1\nLine 2", inPlaceEditorMultiLine.convertHTMLLineBreaks("Line 1<br>Line 2"));
    127      // <p> not supported (too hard)
    128      //assertEqual("Line 1\nLine 2", inPlaceEditorMultiLine.convertHTMLLineBreaks("<p>Line 1</p>Line 2"));
    129      assertEqual("Line 1\nLine 2", inPlaceEditorMultiLine.convertHTMLLineBreaks("Line 1<BR/>Line 2"));
    130      assertEqual("Line 1\nLine 2", inPlaceEditorMultiLine.convertHTMLLineBreaks("Line 1<BR>Line 2"));
    131      // <p> not supported (too hard)
    132      //assertEqual("Line 1\nLine 2", inPlaceEditorMultiLine.convertHTMLLineBreaks("<P>Line 1</P>Line 2"));
    133      // unclosed <P>s not supported yet
    134      //assertEqual("Line 1\nLine 2", inPlaceEditorMultiLine.convertHTMLLineBreaks("<P>Line 1<P>Line 2"));
    135      // <p> not supported (too hard)
    136      //assertEqual("Line 1\nLine 2\nLine 3\nLine 4", inPlaceEditorMultiLine.convertHTMLLineBreaks("<P>Line 1</P>Line 2<br>Line 3<p>Line 4</P>"));
    137      assertEqual("One line", inPlaceEditorMultiLine.convertHTMLLineBreaks("One line"));
    138    }},
    139 
    140    testConvertsParagraphsAndBRsIntoLineBreaks: function() { with(this) {
    141      inPlaceEditorMultiLine.enterEditMode();
    142      assertEqual("TEXTAREA", document.forms[0].firstChild.tagName);
    143      assertEqual("First line\nSecond line\nThird line", document.forms[0].firstChild.value)
    144      // doesn't automatically determine size yet
    145      //assertEqual(3, document.forms[0].firstChild.rows);
    146    }}
    147 
    148  });
    149 // ]]>
    150 </script>
    151 </body>
    152 </html>