diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/tests/mochitest/ajax/scriptaculous/test/unit/ajax_inplaceeditor_test.html | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | dom/tests/mochitest/ajax/scriptaculous/test/unit/ajax_inplaceeditor_test.html | 152 |
1 files changed, 152 insertions, 0 deletions
diff --git a/dom/tests/mochitest/ajax/scriptaculous/test/unit/ajax_inplaceeditor_test.html b/dom/tests/mochitest/ajax/scriptaculous/test/unit/ajax_inplaceeditor_test.html new file mode 100644 index 0000000000..4104d9959d --- /dev/null +++ b/dom/tests/mochitest/ajax/scriptaculous/test/unit/ajax_inplaceeditor_test.html @@ -0,0 +1,152 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + <title>script.aculo.us Unit test file</title> + <meta http-equiv="content-type" content="text/html; charset=utf-8" /> + <script src="../../lib/prototype.js" type="text/javascript"></script> + <script src="../../src/scriptaculous.js" type="text/javascript"></script> + <script src="../../src/unittest.js" type="text/javascript"></script> + <link rel="stylesheet" href="../test.css" type="text/css" /> +</head> +<body> +<h1>script.aculo.us Unit test file</h1> +<p> + Tests for Ajax.InPlaceEditor in controls.js +</p> + +<!-- Log output --> +<div id="testlog"> </div> + +<h1 id="tobeedited">To be edited</h1> +<a id="tobeeditedEditControl" href="#">edit</a> + +<div id="tobeeditedMultiLine">First line<br/>Second line<br/>Third line</div> + +<!-- Tests follow --> +<script type="text/javascript" language="javascript" charset="utf-8"> +// <![CDATA[ + + new Test.Unit.Runner({ + + setup: function() { with(this) { + inPlaceEditor = new Ajax.InPlaceEditor($('tobeedited'), '_ajax_inplaceeditor_result.html', { + externalControl: $('tobeeditedEditControl'), + ajaxOptions: {method: 'get'} //override so we can use a static for the result + }); + inPlaceEditorMultiLine = new Ajax.InPlaceEditor($('tobeeditedMultiLine'), '_ajax_inplaceeditor_result.html', { + ajaxOptions: {method: 'get'} //override so we can use a static for the result + }); + }}, + + teardown: function() { with(this) { + inPlaceEditor.dispose(); + }}, + + testDisposesProperly: function() { with(this) { + assertEqual("rgba(0, 0, 0, 0)", Element.getStyle('tobeedited','background-color')); + inPlaceEditor.dispose(); + assertEqual("rgba(0, 0, 0, 0)", Element.getStyle('tobeedited','background-color')); + assertVisible($('tobeedited')); + Event.simulateMouse('tobeedited','click'); + assertVisible($('tobeedited')); + }}, + + testUsesTextAreaWhenMoreThanOneRows: function() { with(this) { + inPlaceEditor.options.rows = 5; + inPlaceEditor.enterEditMode(); + assertEqual("TEXTAREA", document.forms[0].firstChild.tagName); + assertEqual("BR", document.forms[0].childNodes[1].tagName); + }}, + + testCanSpecifyAllTextsThroughOptions: function() { with(this) { + // swedish translation ;-) + inPlaceEditor.options.okText = "spara"; + inPlaceEditor.options.cancelText = "avbryt"; + inPlaceEditor.options.savingText = "Sparar..."; + inPlaceEditor.enterEditMode(); + assertEqual("spara", document.forms[0].lastChild.previousSibling.value); + assertEqual("avbryt", document.forms[0].lastChild.innerHTML); + inPlaceEditor.showSaving(); + assertEqual("Sparar...", $('tobeedited').innerHTML); + }}, + + testCanSpecifyFormIdThroughOptions: function() { with(this) { + inPlaceEditor.enterEditMode(); + // default form id + assertEqual("tobeedited-inplaceeditor", document.forms[0].id); + inPlaceEditor.leaveEditMode(); + inPlaceEditor.options.formId = "myFormId"; + inPlaceEditor.enterEditMode(); + assertEqual("myFormId", document.forms[0].id); + }}, + + testCantEditWhileSaving: function() { with(this) { + inPlaceEditor.onLoading(); + Event.simulateMouse('tobeedited','mouseover'); + assertEqual("rgba(0, 0, 0, 0)", Element.getStyle('tobeedited','background-color')); + Event.simulateMouse('tobeedited','click'); + assertVisible($('tobeedited')); + }}, + + testCallbackFunctionGetsCalled: function() { with(this) { + called = false; + inPlaceEditor.options.callback = function(form) { + called = true; + } + Event.simulateMouse('tobeedited','click'); + Event.simulateMouse(document.forms[0].childNodes[1],'click'); + assert(called, "callback was not called"); + }}, + + testCanUseExternalElementToGoIntoEditMode: function() { with(this) { + Event.simulateMouse('tobeeditedEditControl','click'); + assertNotNull(document.forms[0], "external control didn't work"); + // doesn't work if you click it again while in edit mode + Event.simulateMouse('tobeeditedEditControl','click'); + assertNull(document.forms[1], "external control created two forms"); + assertNotVisible($('tobeeditedEditControl')); + Event.simulateMouse(document.forms[0].childNodes[2],'click'); + assertVisible($('tobeeditedEditControl')); + }}, + + testHasLineBreaksDetectsHTMLLineBreaks: function() { with(this) { + assert(inPlaceEditorMultiLine.hasHTMLLineBreaks("Line 1<br/>Line 2")); + assert(inPlaceEditorMultiLine.hasHTMLLineBreaks("Line 1<br>Line 2")); + assert(inPlaceEditorMultiLine.hasHTMLLineBreaks("<p>Line 1</p>Line 2")); + assert(inPlaceEditorMultiLine.hasHTMLLineBreaks("Line 1<BR/>Line 2")); + assert(inPlaceEditorMultiLine.hasHTMLLineBreaks("Line 1<BR>Line 2")); + assert(inPlaceEditorMultiLine.hasHTMLLineBreaks("<P>Line 1</P>Line 2")); + assert(inPlaceEditorMultiLine.hasHTMLLineBreaks("<P>Line 1<P>Line 2")); + assert(!inPlaceEditorMultiLine.hasHTMLLineBreaks("One line")); + }}, + + testConvertsHTMLLineBreaksIntoNewLines: function() { with(this) { + assertEqual("Line 1\nLine 2", inPlaceEditorMultiLine.convertHTMLLineBreaks("Line 1<br/>Line 2")); + assertEqual("Line 1\nLine 2", inPlaceEditorMultiLine.convertHTMLLineBreaks("Line 1<br>Line 2")); + // <p> not supported (too hard) + //assertEqual("Line 1\nLine 2", inPlaceEditorMultiLine.convertHTMLLineBreaks("<p>Line 1</p>Line 2")); + assertEqual("Line 1\nLine 2", inPlaceEditorMultiLine.convertHTMLLineBreaks("Line 1<BR/>Line 2")); + assertEqual("Line 1\nLine 2", inPlaceEditorMultiLine.convertHTMLLineBreaks("Line 1<BR>Line 2")); + // <p> not supported (too hard) + //assertEqual("Line 1\nLine 2", inPlaceEditorMultiLine.convertHTMLLineBreaks("<P>Line 1</P>Line 2")); + // unclosed <P>s not supported yet + //assertEqual("Line 1\nLine 2", inPlaceEditorMultiLine.convertHTMLLineBreaks("<P>Line 1<P>Line 2")); + // <p> not supported (too hard) + //assertEqual("Line 1\nLine 2\nLine 3\nLine 4", inPlaceEditorMultiLine.convertHTMLLineBreaks("<P>Line 1</P>Line 2<br>Line 3<p>Line 4</P>")); + assertEqual("One line", inPlaceEditorMultiLine.convertHTMLLineBreaks("One line")); + }}, + + testConvertsParagraphsAndBRsIntoLineBreaks: function() { with(this) { + inPlaceEditorMultiLine.enterEditMode(); + assertEqual("TEXTAREA", document.forms[0].firstChild.tagName); + assertEqual("First line\nSecond line\nThird line", document.forms[0].firstChild.value) + // doesn't automatically determine size yet + //assertEqual(3, document.forms[0].firstChild.rows); + }} + + }); +// ]]> +</script> +</body> +</html> |