Primer commit del sistema avantika sin cambios
This commit is contained in:
1
javascript/scoluos/test/unit/_ajax_inplaceeditor_ipce_alt_text.html
Executable file
1
javascript/scoluos/test/unit/_ajax_inplaceeditor_ipce_alt_text.html
Executable file
@@ -0,0 +1 @@
|
||||
ntbe
|
||||
1
javascript/scoluos/test/unit/_ajax_inplaceeditor_result.html
Executable file
1
javascript/scoluos/test/unit/_ajax_inplaceeditor_result.html
Executable file
@@ -0,0 +1 @@
|
||||
Server received: To be edited
|
||||
1
javascript/scoluos/test/unit/_ajax_inplaceeditor_result2.html
Executable file
1
javascript/scoluos/test/unit/_ajax_inplaceeditor_result2.html
Executable file
@@ -0,0 +1 @@
|
||||
New to be edited - edited
|
||||
1
javascript/scoluos/test/unit/_ajax_inplaceeditor_tagged.html
Executable file
1
javascript/scoluos/test/unit/_ajax_inplaceeditor_tagged.html
Executable file
@@ -0,0 +1 @@
|
||||
<span>New to be edited - edited</span>
|
||||
1
javascript/scoluos/test/unit/_ajax_inplaceeditor_text.html
Executable file
1
javascript/scoluos/test/unit/_ajax_inplaceeditor_text.html
Executable file
@@ -0,0 +1 @@
|
||||
Text from server
|
||||
20
javascript/scoluos/test/unit/_ajax_updater_result.html
Executable file
20
javascript/scoluos/test/unit/_ajax_updater_result.html
Executable file
@@ -0,0 +1,20 @@
|
||||
Test text
|
||||
|
||||
<script type="text/javascript" language="javascript" charset="utf-8">
|
||||
// <![CDATA[
|
||||
alert('fragment1 hit!');
|
||||
// ]]>
|
||||
</script>
|
||||
|
||||
more test text
|
||||
|
||||
|
||||
<script>alert('fragment2 hit!')</script>
|
||||
|
||||
|
||||
even more test text
|
||||
|
||||
<script type="text/javascript">
|
||||
alert('fragment3 hit!');
|
||||
</script> some other test text
|
||||
|
||||
11
javascript/scoluos/test/unit/_autocomplete_result.html
Executable file
11
javascript/scoluos/test/unit/_autocomplete_result.html
Executable file
@@ -0,0 +1,11 @@
|
||||
<ul>
|
||||
<li>test1</li><li>test2</li>
|
||||
<li>test3</li>
|
||||
<li><b>BOLD</b></li>
|
||||
|
||||
<li><span class="informal">(GET ME NOT)</span>(GET <ME> INSTEAD)</li>
|
||||
|
||||
<li>Here we have <a href="_autocomplete_result.html">a link</a> which should work</li>
|
||||
|
||||
<li>Here we have some international ©∏Á®Äç†∑rß</li>
|
||||
</ul>
|
||||
1
javascript/scoluos/test/unit/_autocomplete_result_nobr.html
Executable file
1
javascript/scoluos/test/unit/_autocomplete_result_nobr.html
Executable file
@@ -0,0 +1 @@
|
||||
<ul><li>test1</li><li>test2</li><li>test3</li><li><b>BOLD</b></li><li><span class="informal">(GET ME NOT)</span>(GET <ME> INSTEAD)</li><li>Here we have <a href="_autocomplete_result.html">a link</a> which should work</li><li>Here we have some international ©∏Á®Äç†∑rß</li></ul>
|
||||
243
javascript/scoluos/test/unit/ajax_autocompleter_test.html
Executable file
243
javascript/scoluos/test/unit/ajax_autocompleter_test.html
Executable file
@@ -0,0 +1,243 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<!-- vim:expandtab=on
|
||||
-->
|
||||
<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" />
|
||||
<style>
|
||||
.selected { background-color: #888; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>script.aculo.us Unit test file</h1>
|
||||
<p>
|
||||
Tests for Ajax.Autocompleter in controls.js.
|
||||
</p>
|
||||
|
||||
<!-- Log output -->
|
||||
<div id="testlog"> </div>
|
||||
|
||||
<input id="ac_input" type="text" autocomplete="off" />
|
||||
<div id="ac_update" style="display:none;border:1px solid black;background-color:white;position:relative;"></div>
|
||||
|
||||
<input id="ac_input_br" type="text" autocomplete="off" />
|
||||
<div id="ac_update_br" style="display:none;border:1px solid black;background-color:white;position:relative;"></div>
|
||||
|
||||
<input id="ac2_input" type="text" autocomplete="off" />
|
||||
<div id="ac2_update" style="display:none;border:1px solid black;background-color:white;position:relative;"></div>
|
||||
|
||||
<input id="actoken_input" type="text" autocomplete="off" />
|
||||
<div id="actoken_update" style="display:none;border:1px solid black;background-color:white;position:relative;"></div>
|
||||
|
||||
<input id="dummy_element" type="text" autocomplete="off" />
|
||||
|
||||
<!-- Tests follow -->
|
||||
<script type="text/javascript" language="javascript" charset="utf-8">
|
||||
// <![CDATA[
|
||||
|
||||
|
||||
new Test.Unit.Runner({
|
||||
|
||||
// Integration test, tests the entire cycle
|
||||
testAjaxAutocompleter: function() { with(this) {
|
||||
var ac = new Ajax.Autocompleter('ac_input','ac_update','_autocomplete_result.html',
|
||||
{ method: 'get' }); //override so we can use a static for the result
|
||||
assertInstanceOf(Ajax.Autocompleter, ac);
|
||||
|
||||
// box not visible
|
||||
assertNotVisible('ac_update');
|
||||
|
||||
// focus, but box not visible
|
||||
Event.simulateMouse('ac_input', 'click');
|
||||
assertNotVisible('ac_update');
|
||||
|
||||
Event.simulateKeys('ac_input','abcdefg');
|
||||
assertEqual('abcdefg', $('ac_input').value);
|
||||
|
||||
// check box popping up on input
|
||||
wait(1000, function() { with(this) {
|
||||
assertVisible('ac_update');
|
||||
assertEqual('test1', $('ac_update').firstChild.firstChild.innerHTML);
|
||||
assertEqual('test2', $('ac_update').firstChild.firstChild.nextSibling.innerHTML);
|
||||
|
||||
// intl. characters return (UTF-8)
|
||||
assertEqual('Here we have some international ©∏Á®Äç†∑rß', $('ac_update').firstChild.lastChild.innerHTML);
|
||||
|
||||
// first entry should be selected
|
||||
assert(Element.hasClassName($('ac_update').firstChild.firstChild, 'selected'),'Selected item should have a className of: selected');
|
||||
|
||||
Event.simulateKey('ac_input','keypress',{keyCode:Event.KEY_DOWN});
|
||||
|
||||
// second entry should be selected
|
||||
assert(!Element.hasClassName($('ac_update').firstChild.firstChild),'Item shouldn\'t have a className of: selected');
|
||||
assert(Element.hasClassName($('ac_update').firstChild.firstChild.nextSibling, 'selected'),'Second entry should have a className of: selected');
|
||||
|
||||
// check selecting with <TAB>
|
||||
Event.simulateKey('ac_input','keypress',{keyCode:Event.KEY_TAB});
|
||||
assertEqual('test2',$('ac_input').value);
|
||||
|
||||
// check box going away
|
||||
wait(500, function() { with(this) {
|
||||
assertNotVisible('ac_update');
|
||||
|
||||
// check selecting with mouse click
|
||||
Event.simulateKeys('ac_input','3');
|
||||
assertEqual('test23', $('ac_input').value);
|
||||
wait(1000, function() { with(this) {
|
||||
assertVisible('ac_update');
|
||||
Event.simulateMouse($('ac_update').firstChild.childNodes[4],'click');
|
||||
|
||||
wait(1000, function() { with(this) {
|
||||
// tests if removal of 'informal' nodes and HTML escaping works
|
||||
assertEqual('(GET <ME> INSTEAD)',$('ac_input').value);
|
||||
assertNotVisible('ac_update');
|
||||
|
||||
// check cancelling with <ESC>
|
||||
Event.simulateKeys('ac_input','abcdefg');
|
||||
|
||||
wait(1000, function() { with(this) {
|
||||
assertVisible('ac_update');
|
||||
assertEqual('(GET <ME> INSTEAD)abcdefg', $('ac_input').value);
|
||||
|
||||
Event.simulateKey('ac_input','keypress',{keyCode:Event.KEY_DOWN});
|
||||
Event.simulateKey('ac_input','keypress',{keyCode:Event.KEY_ESC});
|
||||
|
||||
assertEqual('(GET <ME> INSTEAD)abcdefg', $('ac_input').value);
|
||||
}});
|
||||
}});
|
||||
}});
|
||||
}});
|
||||
}});
|
||||
}},
|
||||
|
||||
testAfterUpdateElement: function() { with(this) {
|
||||
var ac = new Ajax.Autocompleter('ac2_input','ac2_update','_autocomplete_result.html',
|
||||
{ method: 'get',
|
||||
afterUpdateElement: function(element,selectedElement) {
|
||||
element.value = 'afterupdate:' + selectedElement.tagName;
|
||||
}
|
||||
});
|
||||
assertInstanceOf(Ajax.Autocompleter, ac);
|
||||
|
||||
Event.simulateMouse('ac2_input', 'click');
|
||||
Event.simulateKeys('ac2_input','abcdefg');
|
||||
|
||||
wait(1000, function() { with(this) {
|
||||
assertVisible('ac2_update');
|
||||
Event.simulateKey('ac2_input','keypress',{keyCode:Event.KEY_TAB});
|
||||
|
||||
assertEqual('afterupdate:LI',$('ac2_input').value);
|
||||
}});
|
||||
}},
|
||||
|
||||
testTokenizing: function() { with(this) {
|
||||
var actoken = new Ajax.Autocompleter('actoken_input','ac_update','_autocomplete_result.html',
|
||||
{ tokens:',', method: 'get' });
|
||||
assertInstanceOf(Ajax.Autocompleter, actoken);
|
||||
|
||||
Event.simulateKeys('actoken_input','abc');
|
||||
|
||||
wait(1000, function() { with(this) {
|
||||
Event.simulateKey('actoken_input','keypress',{keyCode:Event.KEY_TAB});
|
||||
assertEqual('test1',$('actoken_input').value);
|
||||
Event.simulateKeys('actoken_input',',abc');
|
||||
wait(1000, function() { with(this) {
|
||||
Event.simulateKey('actoken_input','keypress',{keyCode:Event.KEY_DOWN});
|
||||
Event.simulateKey('actoken_input','keypress',{keyCode:Event.KEY_TAB});
|
||||
assertEqual('test1,test2',$('actoken_input').value);
|
||||
// Simulating KEY_LEFT's prior to a 'b' doesn't work! So slightly ugly here...
|
||||
$('actoken_input').value = 'test1b,test2';
|
||||
actoken.onObserverEvent();
|
||||
wait(1000, function() { with(this) {
|
||||
for (var index = 0; index < 2; ++index)
|
||||
Event.simulateKey('actoken_input', 'keypress', {keyCode: Event.KEY_DOWN});
|
||||
Event.simulateKey('actoken_input', 'keypress', {keyCode: Event.KEY_TAB});
|
||||
assertEqual('test3,test2', $('actoken_input').value);
|
||||
}});
|
||||
}});
|
||||
}});
|
||||
}},
|
||||
|
||||
// Same integration test, results has no linebreaks
|
||||
testAjaxAutocompleterNoLinebreaksInResult: function() { with(this) {
|
||||
var ac = new Ajax.Autocompleter('ac_input_br','ac_update_br','_autocomplete_result_nobr.html',
|
||||
{ method: 'get' }); //override so we can use a static for the result
|
||||
assertInstanceOf(Ajax.Autocompleter, ac);
|
||||
|
||||
// box not visible
|
||||
assertNotVisible('ac_update_br');
|
||||
|
||||
// focus, but box not visible
|
||||
Event.simulateMouse('ac_input_br', 'click');
|
||||
assertNotVisible('ac_update_br');
|
||||
|
||||
Event.simulateKeys('ac_input_br','abcdefg');
|
||||
assertEqual('abcdefg', $('ac_input_br').value);
|
||||
|
||||
// check box popping up on input
|
||||
wait(1000, function() { with(this) {
|
||||
assertVisible('ac_update_br');
|
||||
assertEqual('test1', $('ac_update_br').firstChild.firstChild.innerHTML);
|
||||
assertEqual('test2', $('ac_update_br').firstChild.firstChild.nextSibling.innerHTML);
|
||||
|
||||
// intl. characters return (UTF-8)
|
||||
assertEqual('Here we have some international ©∏Á®Äç†∑rß', $('ac_update_br').firstChild.lastChild.innerHTML);
|
||||
|
||||
// first entry should be selected
|
||||
assert(Element.hasClassName($('ac_update_br').firstChild.firstChild, 'selected'),'Selected item should have a className of: selected');
|
||||
|
||||
Event.simulateKey('ac_input_br','keypress',{keyCode:Event.KEY_DOWN});
|
||||
|
||||
// second entry should be selected
|
||||
assert(!Element.hasClassName($('ac_update_br').firstChild.firstChild),'Item shouldn\'t have a className of: selected');
|
||||
assert(Element.hasClassName($('ac_update_br').firstChild.firstChild.nextSibling, 'selected'),'Second entry should have a className of: selected');
|
||||
|
||||
// check selecting with <TAB>
|
||||
Event.simulateKey('ac_input_br','keypress',{keyCode:Event.KEY_TAB});
|
||||
assertEqual('test2',$('ac_input_br').value);
|
||||
|
||||
// check box going away
|
||||
wait(500, function() { with(this) {
|
||||
assertNotVisible('ac_update_br');
|
||||
|
||||
// check selecting with mouse click
|
||||
Event.simulateKeys('ac_input_br','3');
|
||||
assertEqual('test23', $('ac_input_br').value);
|
||||
wait(1000, function() { with(this) {
|
||||
assertVisible('ac_update_br');
|
||||
Event.simulateMouse($('ac_update_br').firstChild.childNodes[4],'click');
|
||||
|
||||
wait(1000, function() { with(this) {
|
||||
// tests if removal of 'informal' nodes and HTML escaping works
|
||||
assertEqual('(GET <ME> INSTEAD)',$('ac_input_br').value);
|
||||
assertNotVisible('ac_update_br');
|
||||
|
||||
// check cancelling with <ESC>
|
||||
Event.simulateKeys('ac_input_br','abcdefg');
|
||||
|
||||
wait(1000, function() { with(this) {
|
||||
assertVisible('ac_update_br');
|
||||
assertEqual('(GET <ME> INSTEAD)abcdefg', $('ac_input_br').value);
|
||||
|
||||
Event.simulateKey('ac_input_br','keypress',{keyCode:Event.KEY_DOWN});
|
||||
Event.simulateKey('ac_input_br','keypress',{keyCode:Event.KEY_ESC});
|
||||
|
||||
assertEqual('(GET <ME> INSTEAD)abcdefg', $('ac_input_br').value);
|
||||
}});
|
||||
}});
|
||||
}});
|
||||
}});
|
||||
}});
|
||||
}}
|
||||
|
||||
});
|
||||
// ]]>
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
895
javascript/scoluos/test/unit/ajax_inplaceeditor_test.html
Executable file
895
javascript/scoluos/test/unit/ajax_inplaceeditor_test.html
Executable file
@@ -0,0 +1,895 @@
|
||||
<!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 <code>Ajax.InPlaceEditor</code> and <code>Ajax.InPlaceCollectionEditor</code> in controls.js
|
||||
</p>
|
||||
|
||||
<!-- Log output -->
|
||||
<div id="testlog"> </div>
|
||||
|
||||
<h1 id="tobeedited">To be edited</h1>
|
||||
<a id="tobeeditedEditControl" href="#">edit</a>
|
||||
|
||||
<p id="newtbe">New to be edited</p>
|
||||
<p id="newtbe_external">External control for it</p>
|
||||
|
||||
<p id="contains_ampersand">Me & Myself</p>
|
||||
|
||||
<div id="tobeeditedMultiLine">First line<br/>
|
||||
Second line<br/>
|
||||
Third line</div>
|
||||
|
||||
<!-- Tests follow -->
|
||||
<script type="text/javascript" language="javascript" charset="utf-8">
|
||||
// <![CDATA[
|
||||
|
||||
var IPCE_COLLECTION = [
|
||||
['tbe', 'To be edited'],
|
||||
['ntbe', 'New to be edited'],
|
||||
['ntbe2', 'New to be edited 2'],
|
||||
['ntbe3', 'New to be edited 3']
|
||||
];
|
||||
|
||||
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();
|
||||
inPlaceEditorMultiLine.dispose();
|
||||
}},
|
||||
|
||||
// Original-version tests, still pass thx to backward compatibility
|
||||
|
||||
// Integration test, tests the entire cycle
|
||||
testInPlaceEditor: function() { with(this) {
|
||||
Event.simulateMouse('tobeedited','click');
|
||||
assertHidden($('tobeedited'));
|
||||
assertNotNull(document.forms[0]);
|
||||
assertEqual("cancel", document.forms[0].lastChild.innerHTML);
|
||||
assertVisible(document.forms[0]);
|
||||
|
||||
Event.simulateMouse(document.forms[0].lastChild,'click');
|
||||
assertNull(document.forms[0]);
|
||||
assertVisible($('tobeedited'));
|
||||
assertEqual("transparent", Element.getStyle('tobeedited','background-color'));
|
||||
Event.simulateMouse('tobeedited','mouseover');
|
||||
Event.simulateMouse('tobeedited','click');
|
||||
|
||||
assertEqual("INPUT", document.forms[0].firstChild.tagName);
|
||||
assertEqual("To be edited", document.forms[0].firstChild.value);
|
||||
assertEqual("INPUT", document.forms[0].childNodes[1].tagName);
|
||||
assertEqual("submit", document.forms[0].childNodes[1].type);
|
||||
assertEqual("To be edited", document.forms[0].firstChild.value);
|
||||
assert(Element.hasClassName(document.forms[0], 'inplaceeditor-form'),
|
||||
"form doesn't have proper class: " + document.forms[0].className);
|
||||
|
||||
Event.simulateMouse(document.forms[0].childNodes[1],'click');
|
||||
|
||||
assertVisible($('tobeedited'));
|
||||
assertEqual("Saving...", $('tobeedited').innerHTML);
|
||||
assertEqual("transparent", Element.getStyle('tobeedited','background-color'));
|
||||
assert(Element.hasClassName($('tobeedited'), 'inplaceeditor-saving'),
|
||||
"doesn't have saving class");
|
||||
|
||||
wait(1000, function() {
|
||||
assertEqual("Server received: To be edited", $('tobeedited').innerHTML);
|
||||
assertNull(document.forms[0]);
|
||||
assertVisible($('tobeedited'));
|
||||
assert(!Element.hasClassName($('tobeedited'), 'inplaceeditor-saving'));
|
||||
});
|
||||
}},
|
||||
|
||||
testHovering: function() { with(this) {
|
||||
Event.simulateMouse('tobeedited','mouseover');
|
||||
assertEqual("rgb(255, 255, 153)", Element.getStyle('tobeedited','background-color'));
|
||||
|
||||
Event.simulateMouse('tobeedited','mouseout');
|
||||
wait(1100, function() {
|
||||
assertEqual("transparent", Element.getStyle('tobeedited','background-color'),
|
||||
"should be transparent after mouse leaves element");
|
||||
|
||||
Event.simulateMouse('tobeedited','click');
|
||||
})
|
||||
}},
|
||||
|
||||
testLoadsTextFromServer: function() { with(this) {
|
||||
inPlaceEditor.options.loadTextURL = '_ajax_inplaceeditor_text.html';
|
||||
inPlaceEditor.enterEditMode();
|
||||
assertEqual('Loading...', inPlaceEditor._form.value.value);
|
||||
assert(inPlaceEditor._form.value.disabled);
|
||||
assert(Element.hasClassName(inPlaceEditor._form, 'inplaceeditor-loading'));
|
||||
wait(1000, function() {
|
||||
assertEqual('Text from server', inPlaceEditor._form.value.value);
|
||||
assert(!inPlaceEditor._form.value.disabled);
|
||||
});
|
||||
}},
|
||||
|
||||
testDisposesProperly: function() { with(this) {
|
||||
assertEqual("transparent", Element.getStyle('tobeedited','background-color'));
|
||||
inPlaceEditor.dispose();
|
||||
assertEqual("transparent", 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.prepareSubmission();
|
||||
Event.simulateMouse('tobeedited','mouseover');
|
||||
assertEqual("transparent", Element.getStyle('tobeedited','background-color'));
|
||||
Event.simulateMouse('tobeedited','click');
|
||||
assertVisible($('tobeedited'));
|
||||
}},
|
||||
|
||||
testCallbackFunctionGetsCalled: function() { with(this) {
|
||||
var 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'));
|
||||
}},
|
||||
|
||||
// Rewritten-version tests
|
||||
testControlOptions: function() {with(this) {
|
||||
// Default, then explicit default-equivalent, settings
|
||||
[{}, { okControl: 'button', cancelControl: 'link' }].each(function(opts) {
|
||||
var ipe = new Ajax.InPlaceEditor('newtbe', '', opts);
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
var submits = $('newtbe-inplaceeditor').getInputs('submit');
|
||||
assertEqual(1, submits.length, 'Not just one submit');
|
||||
assertEqual(Ajax.InPlaceEditor.DefaultOptions.okText, submits[0].value, 'Incorrect button label');
|
||||
assert(submits[0].hasClassName('editor_ok_button'), 'Missing class name on ok button');
|
||||
var links = $$('#newtbe-inplaceeditor a');
|
||||
assertEqual(1, links.length, 'Not just one link');
|
||||
assertEqual(Ajax.InPlaceEditor.DefaultOptions.cancelText, links[0].firstChild.nodeValue, 'Incorrect cancel link text');
|
||||
assert(links[0].href.endsWith('#'), 'Incorrect cancel link href');
|
||||
assert(links[0].hasClassName('editor_cancel_link'), 'Missing class name on cancel link');
|
||||
ipe.dispose();
|
||||
});
|
||||
// Reverse: ok link, cancel button
|
||||
var ipe = new Ajax.InPlaceEditor('newtbe', '', { okControl: 'link', cancelControl: 'button' });
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
var links = $$('#newtbe-inplaceeditor a');
|
||||
assertEqual(1, links.length, 'Not just one link');
|
||||
assertEqual(Ajax.InPlaceEditor.DefaultOptions.okText, links[0].firstChild.nodeValue, 'Incorrect ok link text');
|
||||
assert(links[0].href.endsWith('#'), 'Incorrect ok link href');
|
||||
assert(links[0].hasClassName('editor_ok_link'), 'Missing class name on ok link');
|
||||
var submits = $('newtbe-inplaceeditor').getInputs('submit');
|
||||
assertEqual(1, submits.length, 'Not just one submit');
|
||||
assertEqual(Ajax.InPlaceEditor.DefaultOptions.cancelText, submits[0].value, 'Incorrect button label');
|
||||
assert(submits[0].hasClassName('editor_cancel_button'), 'Missing class name on cancel button');
|
||||
ipe.dispose();
|
||||
// Full links
|
||||
ipe = new Ajax.InPlaceEditor('newtbe', '', { okControl: 'link' });
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
var links = $$('#newtbe-inplaceeditor a');
|
||||
assertEqual(2, links.length, 'There should be two links');
|
||||
assertEqual(Ajax.InPlaceEditor.DefaultOptions.okText, links[0].firstChild.nodeValue, 'Incorrect ok link text');
|
||||
assertEqual(Ajax.InPlaceEditor.DefaultOptions.cancelText, links[1].firstChild.nodeValue, 'Incorrect cancel link text');
|
||||
assert(links[0].href.endsWith('#'), 'Incorrect ok link href');
|
||||
assert(links[1].href.endsWith('#'), 'Incorrect cancel link href');
|
||||
assert(links[0].hasClassName('editor_ok_link'), 'Missing class name on ok link');
|
||||
assert(links[1].hasClassName('editor_cancel_link'), 'Missing class name on cancel link');
|
||||
var submits = $('newtbe-inplaceeditor').getInputs('submit');
|
||||
assertEqual(0, submits.length, 'There should be no submit');
|
||||
ipe.dispose();
|
||||
// Full buttons
|
||||
ipe = new Ajax.InPlaceEditor('newtbe', '', { cancelControl: 'button' });
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
var submits = $('newtbe-inplaceeditor').getInputs('submit');
|
||||
assertEqual(2, submits.length, 'There should be two submits');
|
||||
assertEqual(Ajax.InPlaceEditor.DefaultOptions.okText, submits[0].value, 'Incorrect ok button text');
|
||||
assertEqual(Ajax.InPlaceEditor.DefaultOptions.cancelText, submits[1].value, 'Incorrect cancel button text');
|
||||
assert(submits[0].hasClassName('editor_ok_button'), 'Missing class name on ok button');
|
||||
assert(submits[1].hasClassName('editor_cancel_button'), 'Missing class name on cancel button');
|
||||
var links = $$('#newtbe-inplaceeditor a');
|
||||
assertEqual(0, links.length, 'There should be no link');
|
||||
ipe.dispose();
|
||||
// No cancel
|
||||
ipe = new Ajax.InPlaceEditor('newtbe', '', { cancelControl: false });
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
var submits = $('newtbe-inplaceeditor').getInputs('submit');
|
||||
assertEqual(1, submits.length, 'Not just one submit');
|
||||
var links = $$('#newtbe-inplaceeditor a');
|
||||
assertEqual(0, links.length, 'There should be no link');
|
||||
ipe.dispose();
|
||||
// No OK
|
||||
ipe = new Ajax.InPlaceEditor('newtbe', '', { okControl: false });
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
var submits = $('newtbe-inplaceeditor').getInputs('submit');
|
||||
assertEqual(0, submits.length, 'There should be no submit');
|
||||
var links = $$('#newtbe-inplaceeditor a');
|
||||
assertEqual(1, links.length, 'Not just one link');
|
||||
ipe.dispose();
|
||||
// Nothing
|
||||
ipe = new Ajax.InPlaceEditor('newtbe', '', { okControl: false, cancelControl: false });
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
var submits = $('newtbe-inplaceeditor').getInputs('submit');
|
||||
assertEqual(0, submits.length, 'There should be no submit');
|
||||
var links = $$('#newtbe-inplaceeditor a');
|
||||
assertEqual(0, links.length, 'There should be no link');
|
||||
ipe.dispose();
|
||||
// Texts: default mode
|
||||
ipe = new Ajax.InPlaceEditor('newtbe', '', { okControl: false, cancelControl: false });
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
var submits = $('newtbe-inplaceeditor').getInputs('submit');
|
||||
assertEqual(0, submits.length, 'There should be no submit');
|
||||
var links = $$('#newtbe-inplaceeditor a');
|
||||
assertEqual(0, links.length, 'There should be no link');
|
||||
ipe.dispose();
|
||||
// Texts: before w/ controls
|
||||
ipe = new Ajax.InPlaceEditor('newtbe', '', { textBeforeControls: '[' });
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
var text = $('newtbe-inplaceeditor').childNodes[1];
|
||||
assertEqual(3, text.nodeType, 'Missing/misplaced initial text');
|
||||
assertEqual('[', text.nodeValue, 'Incorrect text');
|
||||
ipe.dispose();
|
||||
// Texts: after w/ controls
|
||||
ipe = new Ajax.InPlaceEditor('newtbe', '', { textAfterControls: ']' });
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
var text = $('newtbe-inplaceeditor').childNodes[3];
|
||||
assertEqual(3, text.nodeType, 'Missing/misplaced final text');
|
||||
assertEqual(']', text.nodeValue, 'Incorrect text');
|
||||
ipe.dispose();
|
||||
// Texts: between w/ controls
|
||||
ipe = new Ajax.InPlaceEditor('newtbe', '', { textBetweenControls: ' ' });
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
var text = $('newtbe-inplaceeditor').childNodes[2];
|
||||
assertEqual(3, text.nodeType, 'Missing/misplaced middle text');
|
||||
assertEqual(' ', text.nodeValue, 'Incorrect text');
|
||||
ipe.dispose();
|
||||
// Texts: before w/ no control
|
||||
ipe = new Ajax.InPlaceEditor('newtbe', '', { textBeforeControls: '[', okControl: false, cancelControl: false });
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
var nodes = $('newtbe-inplaceeditor').childNodes;
|
||||
assertEqual(1, nodes.length, 'Too many nodes in the form.');
|
||||
ipe.dispose();
|
||||
// Texts: after w/ no control
|
||||
ipe = new Ajax.InPlaceEditor('newtbe', '', { textAfterControls: ']', okControl: false, cancelControl: false });
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
var nodes = $('newtbe-inplaceeditor').childNodes;
|
||||
assertEqual(1, nodes.length, 'Too many nodes in the form.');
|
||||
ipe.dispose();
|
||||
// Texts: between w/ less than two controls
|
||||
ipe = new Ajax.InPlaceEditor('newtbe', '', { textBetweenControls: ' ', okControl: false });
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
var nodes = $('newtbe-inplaceeditor').childNodes;
|
||||
assertEqual(2, nodes.length, 'The form should have only two nodes (edit+cancel)');
|
||||
assertEnumEqual(['input', 'a'], $A(nodes).pluck('tagName').invoke('toLowerCase'), 'Incorrect nodes');
|
||||
ipe.dispose();
|
||||
}},
|
||||
|
||||
testExternalControlOnly: function() {with(this) {
|
||||
var ipe = new Ajax.InPlaceEditor('newtbe', '_ajax_inplaceeditor_result2.html', {
|
||||
externalControl: 'newtbe_external'
|
||||
});
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
assert(ipe._editing, 'Clicking on the element should turn editable.');
|
||||
ipe.leaveEditMode();
|
||||
Event.simulateMouse('newtbe_external', 'click');
|
||||
assert(ipe._editing, 'Clicking on the external control should turn editable.');
|
||||
ipe.dispose();
|
||||
ipe = new Ajax.InPlaceEditor('newtbe', '_ajax_inplaceeditor_result2.html', {
|
||||
externalControl: 'newtbe_external', externalControlOnly: true
|
||||
});
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
assert(!ipe._editing, 'Clicking on the element should not turn editable.');
|
||||
Event.simulateMouse('newtbe_external', 'click');
|
||||
assert(ipe._editing, 'Clicking on the external control should turn editable.');
|
||||
ipe.dispose();
|
||||
}},
|
||||
|
||||
testNewCallbacks: function() {with(this) {
|
||||
var called = [];
|
||||
var opts = {
|
||||
onEnterHover: function() { called.push('onEnterHover') },
|
||||
onEnterEditMode: function() { called.push('onEnterEditMode') },
|
||||
onLeaveEditMode: function() { called.push('onLeaveEditMode') },
|
||||
callback: function(form) {
|
||||
called.push('callback');
|
||||
return form.serialize();
|
||||
},
|
||||
onFailure: function() { called.push('onFailure') },
|
||||
onComplete: function() { called.push('onComplete') },
|
||||
onLeaveEditMode: function() { called.push('onLeaveEditMode') }
|
||||
}
|
||||
// Proper success
|
||||
$('newtbe').update('New to be edited');
|
||||
var ipe = new Ajax.InPlaceEditor('newtbe', '_ajax_inplaceeditor_result2.html', opts);
|
||||
Event.simulateMouse('newtbe', 'mouseover');
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
Event.simulateKey('newtbe', 'keydown', { keyCode: Event.KEY_RETURN });
|
||||
var postUpdateHTML;
|
||||
wait(1000, function() {
|
||||
assertEnumEqual(['onEnterHover', 'onEnterEditMode', 'callback', 'onLeaveEditMode', 'onComplete'],
|
||||
called.uniq(), 'Incorrect callback sequence');
|
||||
postUpdateHTML = $('newtbe').innerHTML.strip();
|
||||
assertEqual('New to be edited - edited', postUpdateHTML, 'Update trouble');
|
||||
ipe.dispose();
|
||||
// Failure
|
||||
called.clear();
|
||||
// Any ideas? Requesting file:// URLs on non-existent stuff doesn't trigger A.U's onFailure...
|
||||
});
|
||||
}},
|
||||
|
||||
testCallbackFunctionReturnTypes: function() { with(this) {
|
||||
var params = [];
|
||||
var responder = {
|
||||
onCreate: function(req) {
|
||||
params.push(req.options.parameters);
|
||||
}
|
||||
};
|
||||
Ajax.Responders.register(responder);
|
||||
var ipe = new Ajax.InPlaceEditor('newtbe', '_ajax_inplaceeditor_result2.html', {
|
||||
callback: function(form) {
|
||||
return 'foo=bar';
|
||||
}
|
||||
});
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
Event.simulateKey('newtbe', 'keydown', { keyCode: Event.KEY_RETURN });
|
||||
wait(200, function() {
|
||||
assert(params[0] && params[0].foo == 'bar');
|
||||
ipe.dispose();
|
||||
ipe = new Ajax.InPlaceEditor('newtbe', '_ajax_inplaceeditor_result2.html', {
|
||||
callback: function(form) {
|
||||
return { bar: '?', 'r&d': 42 };
|
||||
}
|
||||
});
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
Event.simulateKey('newtbe', 'keydown', { keyCode: Event.KEY_RETURN });
|
||||
wait(200, function() {
|
||||
assert(params[1] && params[1].bar == '?' && params[1]['r&d'] == 42);
|
||||
ipe.dispose();
|
||||
Ajax.Responders.unregister(responder);
|
||||
})
|
||||
});
|
||||
}},
|
||||
|
||||
testHtmlResponse: function() {with(this) {
|
||||
// Default (true) -> A.U w/ evalScripts: true
|
||||
$('newtbe').update('New to be edited');
|
||||
var ipe = new Ajax.InPlaceEditor('newtbe', '_ajax_inplaceeditor_result2.html');
|
||||
Event.simulateMouse('newtbe', 'mouseover');
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
Event.simulateKey('newtbe', 'keydown', { keyCode: Event.KEY_RETURN });
|
||||
var postUpdateHTML;
|
||||
wait(1000, function() {
|
||||
postUpdateHTML = $('newtbe').innerHTML.strip();
|
||||
assertEqual('New to be edited - edited', postUpdateHTML, 'Should have updated contents');
|
||||
ipe.dispose();
|
||||
// Explicit htmlResponse: true -> A.U w/ evalScripts: true
|
||||
$('newtbe').update('New to be edited');
|
||||
ipe = new Ajax.InPlaceEditor('newtbe', '_ajax_inplaceeditor_result2.html', { htmlResponse: true });
|
||||
Event.simulateMouse('newtbe', 'mouseover');
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
Event.simulateKey('newtbe', 'keydown', { keyCode: Event.KEY_RETURN });
|
||||
wait(1000, function() {
|
||||
postUpdateHTML = $('newtbe').innerHTML.strip();
|
||||
assertEqual('New to be edited - edited', postUpdateHTML, 'Should have updated contents');
|
||||
ipe.dispose();
|
||||
// Explicit htmlResponse: false -> A.R
|
||||
$('newtbe').update('New to be edited');
|
||||
ipe = new Ajax.InPlaceEditor('newtbe', '_ajax_inplaceeditor_result2.html', { htmlResponse: false });
|
||||
Event.simulateMouse('newtbe', 'mouseover');
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
Event.simulateKey('newtbe', 'keydown', { keyCode: Event.KEY_RETURN });
|
||||
wait(1000, function() {
|
||||
postUpdateHTML = $('newtbe').innerHTML.strip();
|
||||
assertEqual(ipe.options.savingText, postUpdateHTML, 'Should not have updated contents');
|
||||
ipe.dispose();
|
||||
});
|
||||
});
|
||||
});
|
||||
}},
|
||||
|
||||
testSingleOrMultipleRows: function() {with(this) {
|
||||
// Single-line value, rows <= 1 -> 1
|
||||
$('newtbe').update('New to be edited');
|
||||
var ipe = new Ajax.InPlaceEditor('newtbe',
|
||||
'_ajax_inplaceeditor_result2.html');
|
||||
Event.simulateMouse('newtbe', 'mouseover');
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
assertEqual('input', ipe._controls.editor.tagName.toLowerCase());
|
||||
ipe.dispose();
|
||||
// Single-line value, rows > 1 (2) -> 2
|
||||
var ipe = new Ajax.InPlaceEditor('newtbe',
|
||||
'_ajax_inplaceeditor_result2.html', { rows: 2 });
|
||||
Event.simulateMouse('newtbe', 'mouseover');
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
assertEqual('textarea', ipe._controls.editor.tagName.toLowerCase());
|
||||
assertEqual(2, ipe._controls.editor.rows);
|
||||
ipe.dispose();
|
||||
// Multiple-line value, rows <= 1, autoRows default (3) -> 3
|
||||
$('newtbe').update('Line 1\nLine 2\nLine 3');
|
||||
var ipe = new Ajax.InPlaceEditor('newtbe',
|
||||
'_ajax_inplaceeditor_result2.html');
|
||||
Event.simulateMouse('newtbe', 'mouseover');
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
assertEqual('textarea', ipe._controls.editor.tagName.toLowerCase());
|
||||
assertEqual(Ajax.InPlaceEditor.DefaultOptions.autoRows, ipe._controls.editor.rows);
|
||||
ipe.dispose();
|
||||
// Multiple-line value, rows <= 1, autoRows custom (5) -> 5
|
||||
var ipe = new Ajax.InPlaceEditor('newtbe',
|
||||
'_ajax_inplaceeditor_result2.html', { autoRows: 5 });
|
||||
Event.simulateMouse('newtbe', 'mouseover');
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
assertEqual('textarea', ipe._controls.editor.tagName.toLowerCase());
|
||||
assertEqual(5, ipe._controls.editor.rows);
|
||||
ipe.dispose();
|
||||
// Multiple-line value, rows > 1 (2), autoRows default (3) -> 2
|
||||
var ipe = new Ajax.InPlaceEditor('newtbe',
|
||||
'_ajax_inplaceeditor_result2.html', { rows: 2 });
|
||||
Event.simulateMouse('newtbe', 'mouseover');
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
assertEqual('textarea', ipe._controls.editor.tagName.toLowerCase());
|
||||
assertEqual(2, ipe._controls.editor.rows);
|
||||
ipe.dispose();
|
||||
// Multiple-line value, rows > 1 (2), autoRows custom (5) -> 2
|
||||
var ipe = new Ajax.InPlaceEditor('newtbe',
|
||||
'_ajax_inplaceeditor_result2.html', { rows: 2, autoRows: 5 });
|
||||
Event.simulateMouse('newtbe', 'mouseover');
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
assertEqual('textarea', ipe._controls.editor.tagName.toLowerCase());
|
||||
assertEqual(2, ipe._controls.editor.rows);
|
||||
ipe.dispose();
|
||||
}},
|
||||
|
||||
testFormCustomizationCallback: function() {with(this) {
|
||||
var ipe = new Ajax.InPlaceEditor('newtbe', '_ajax_inplaceeditor_result2.html', {
|
||||
onFormCustomization: function(ipe, form) {
|
||||
form.appendChild(new Element('input', { type: 'text', name: 'test', value: 'foobar' }));
|
||||
}
|
||||
});
|
||||
Event.simulateMouse('newtbe', 'mouseover');
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
assertEqual('foobar', Form.serialize(ipe._form, true).test, 'Custom field not present');
|
||||
ipe.dispose();
|
||||
}},
|
||||
|
||||
testPostCreationBehavior: function() {with(this) {
|
||||
var focused = false, activated = false;
|
||||
function override(name, fx) {
|
||||
arguments.callee.backups[name] = Field.Methods[name];
|
||||
Field.Methods[name] = fx;
|
||||
};
|
||||
override.backups = {};
|
||||
function restore() {
|
||||
$A(arguments).each(function(n) {
|
||||
Field.Methods[name] = override.backups[name];
|
||||
});
|
||||
Element.addMethods();
|
||||
};
|
||||
override('activate', function(elt) {
|
||||
override.backups['activate'](elt);
|
||||
activated = true;
|
||||
});
|
||||
override('focus', function(elt) { focused = true; });
|
||||
Element.addMethods();
|
||||
// fieldPostCreation default (activate)
|
||||
var ipe = new Ajax.InPlaceEditor('newtbe',
|
||||
'_ajax_inplaceeditor_result2.html');
|
||||
Event.simulateMouse('newtbe', 'mouseover');
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
assert(focused && activated, "Should be focused and activated (resp. " + focused + " and " + activated + ')');
|
||||
ipe.dispose();
|
||||
// fieldPostCreation == 'focus'
|
||||
focused = activated = false;
|
||||
ipe = new Ajax.InPlaceEditor('newtbe',
|
||||
'_ajax_inplaceeditor_result2.html', { fieldPostCreation: 'focus' });
|
||||
Event.simulateMouse('newtbe', 'mouseover');
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
assert(focused && !activated, "Should be focused, not activated (resp. " + focused + " and " + activated + ')');
|
||||
ipe.dispose();
|
||||
// fieldPostCreation == false
|
||||
focused = activated = false;
|
||||
ipe = new Ajax.InPlaceEditor('newtbe',
|
||||
'_ajax_inplaceeditor_result2.html', { fieldPostCreation: false });
|
||||
Event.simulateMouse('newtbe', 'mouseover');
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
assert(!focused && !activated, "Should be neither focused nor activated (resp. " + focused + " and " + activated + ')');
|
||||
ipe.dispose();
|
||||
// fieldPostCreation == non-false yet neither activate nor focus -> default
|
||||
focused = activated = false;
|
||||
ipe = new Ajax.InPlaceEditor('newtbe',
|
||||
'_ajax_inplaceeditor_result2.html', { fieldPostCreation: 'foobar' });
|
||||
Event.simulateMouse('newtbe', 'mouseover');
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
assert(focused && activated, "Should be focused and activated (resp. " + focused + " and " + activated + ')');
|
||||
ipe.dispose();
|
||||
restore('activate', 'focus');
|
||||
}},
|
||||
|
||||
testResponseTagStripping: function() {with(this) {
|
||||
// stripLoadedTextTags default (false)
|
||||
var ipe = new Ajax.InPlaceEditor('newtbe',
|
||||
'_ajax_inplaceeditor_result2.html',
|
||||
{ loadTextURL: '_ajax_inplaceeditor_tagged.html' });
|
||||
Event.simulateMouse('newtbe', 'mouseover');
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
wait(1000, function() {
|
||||
assertEqual('<span>New to be edited - edited</span>', ipe._controls.editor.value.strip());
|
||||
ipe.dispose();
|
||||
// stripLoadedTextTags == true
|
||||
ipe = new Ajax.InPlaceEditor('newtbe',
|
||||
'_ajax_inplaceeditor_result2.html',
|
||||
{ loadTextURL: '_ajax_inplaceeditor_tagged.html',
|
||||
stripLoadedTextTags: true });
|
||||
Event.simulateMouse('newtbe', 'mouseover');
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
wait(1000, function() {
|
||||
assertEqual('New to be edited - edited', ipe._controls.editor.value.strip());
|
||||
ipe.dispose();
|
||||
});
|
||||
});
|
||||
}},
|
||||
|
||||
testSubmitOnBlur: function() {with(this) {
|
||||
// submitOnBlur default (false)
|
||||
$('newtbe').update('To be edited');
|
||||
var ipe = new Ajax.InPlaceEditor('newtbe',
|
||||
'_ajax_inplaceeditor_result2.html');
|
||||
Event.simulateMouse('newtbe', 'mouseover');
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
ipe._controls.editor.blur();
|
||||
wait(1000, function() {
|
||||
assertEqual('To be edited', ipe._controls.editor ? ipe._controls.editor.value : '');
|
||||
ipe.dispose();
|
||||
// submitOnBlur == true
|
||||
ipe = new Ajax.InPlaceEditor('newtbe',
|
||||
'_ajax_inplaceeditor_result2.html', { submitOnBlur: true });
|
||||
Event.simulateMouse('newtbe', 'mouseover');
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
ipe._controls.editor.blur();
|
||||
wait(1200, function() {
|
||||
assertEqual('New to be edited - edited', $('newtbe').innerHTML.strip());
|
||||
ipe.dispose();
|
||||
});
|
||||
});
|
||||
}},
|
||||
|
||||
testEscReturnKeys: function() {with(this) {
|
||||
// No controls, Esc
|
||||
var ipe = new Ajax.InPlaceEditor('newtbe',
|
||||
'_ajax_inplaceeditor_result2.html', { okControl: false, cancelControl: false});
|
||||
Event.simulateMouse('newtbe', 'mouseover');
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
Event.simulateKey('newtbe', 'keydown', { keyCode: Event.KEY_ESC });
|
||||
assert(!ipe._editing, 'Esc should have disabled IPE');
|
||||
ipe.dispose();
|
||||
// Cancel control, Esc
|
||||
var ipe = new Ajax.InPlaceEditor('newtbe',
|
||||
'_ajax_inplaceeditor_result2.html', { okControl: false });
|
||||
Event.simulateMouse('newtbe', 'mouseover');
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
Event.simulateKey('newtbe', 'keydown', { keyCode: Event.KEY_ESC });
|
||||
assert(!ipe._editing, 'Esc should have disabled IPE');
|
||||
ipe.dispose();
|
||||
// OK control, Esc
|
||||
var ipe = new Ajax.InPlaceEditor('newtbe',
|
||||
'_ajax_inplaceeditor_result2.html', { cancelControl: false });
|
||||
Event.simulateMouse('newtbe', 'mouseover');
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
Event.simulateKey('newtbe', 'keydown', { keyCode: Event.KEY_ESC });
|
||||
assert(!ipe._editing, 'Esc should have disabled IPE');
|
||||
ipe.dispose();
|
||||
// Both controls, Esc
|
||||
ipe = new Ajax.InPlaceEditor('newtbe',
|
||||
'_ajax_inplaceeditor_result2.html');
|
||||
Event.simulateMouse('newtbe', 'mouseover');
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
Event.simulateKey('newtbe', 'keydown', { keyCode: Event.KEY_ESC });
|
||||
assert(!ipe._editing, 'Esc should have disabled IPE');
|
||||
ipe.dispose();
|
||||
// No controls, Return
|
||||
$('newtbe').update('New to be edited');
|
||||
ipe = new Ajax.InPlaceEditor('newtbe',
|
||||
'_ajax_inplaceeditor_result2.html', { okControl: false, cancelControl: false });
|
||||
Event.simulateMouse('newtbe', 'mouseover');
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
Event.simulateKey('newtbe', 'keydown', { keyCode: Event.KEY_RETURN });
|
||||
wait(1000, function() {
|
||||
assertEqual('New to be edited - edited', $('newtbe').innerHTML.strip());
|
||||
ipe.dispose();
|
||||
// Cancel control, Return
|
||||
$('newtbe').update('New to be edited');
|
||||
ipe = new Ajax.InPlaceEditor('newtbe',
|
||||
'_ajax_inplaceeditor_result2.html', { okControl: false });
|
||||
Event.simulateMouse('newtbe', 'mouseover');
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
Event.simulateKey('newtbe', 'keydown', { keyCode: Event.KEY_RETURN });
|
||||
wait(1000, function() {
|
||||
assertEqual('New to be edited - edited', $('newtbe').innerHTML.strip());
|
||||
ipe.dispose();
|
||||
// OK control, Return
|
||||
$('newtbe').update('New to be edited');
|
||||
ipe = new Ajax.InPlaceEditor('newtbe',
|
||||
'_ajax_inplaceeditor_result2.html', { cancelControl: false });
|
||||
Event.simulateMouse('newtbe', 'mouseover');
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
Event.simulateKey('newtbe', 'keydown', { keyCode: Event.KEY_RETURN });
|
||||
wait(1000, function() {
|
||||
assertEqual('New to be edited - edited', $('newtbe').innerHTML.strip());
|
||||
ipe.dispose();
|
||||
// Both controls, Return
|
||||
$('newtbe').update('New to be edited');
|
||||
ipe = new Ajax.InPlaceEditor('newtbe',
|
||||
'_ajax_inplaceeditor_result2.html');
|
||||
Event.simulateMouse('newtbe', 'mouseover');
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
Event.simulateKey('newtbe', 'keydown', { keyCode: Event.KEY_RETURN });
|
||||
wait(1000, function() {
|
||||
assertEqual('New to be edited - edited', $('newtbe').innerHTML.strip());
|
||||
ipe.dispose();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}},
|
||||
|
||||
testIPCEBasic: function() {with(this) {
|
||||
// Basic creation, population and choice.
|
||||
$('newtbe').update('ntbe');
|
||||
var fieldValue = '';
|
||||
var ipe = new Ajax.InPlaceCollectionEditor('newtbe',
|
||||
'_ajax_inplaceeditor_result2.html', { paramName: 'test',
|
||||
collection: IPCE_COLLECTION, callback: function(f, value) {
|
||||
fieldValue = value;
|
||||
}, onComplete: Prototype.emptyFunction
|
||||
});
|
||||
Event.simulateMouse('newtbe', 'mouseover');
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
var editor = ipe._controls.editor;
|
||||
assertEqual('test', editor.name);
|
||||
assertEqual('select', editor.tagName.toLowerCase());
|
||||
assertEqual(IPCE_COLLECTION.length, editor.options.length, 'Incorrect amount of options');
|
||||
for (var index = 0; index < IPCE_COLLECTION.length; ++index) {
|
||||
var ref = IPCE_COLLECTION[index];
|
||||
var item = editor.options[index];
|
||||
assertEqual(ref[0], item.value, 'Incorrect OPTION value');
|
||||
assertEqual(ref[1], item.text.strip(), 'Incorrect OPTION text');
|
||||
};
|
||||
assertEqual(1, editor.selectedIndex, 'Did not properly select item');
|
||||
editor.selectedIndex = 2;
|
||||
Event.simulateMouse(ipe._controls.ok, 'click');
|
||||
assertEqual('ntbe2', fieldValue);
|
||||
ipe.dispose();
|
||||
// Test the value option
|
||||
$('newtbe').update('ntbe');
|
||||
ipe = new Ajax.InPlaceCollectionEditor('newtbe',
|
||||
'_ajax_inplaceeditor_result2.html', { paramName: 'test',
|
||||
collection: IPCE_COLLECTION, onComplete: Prototype.emptyFunction,
|
||||
value: 'ntbe2'
|
||||
});
|
||||
Event.simulateMouse('newtbe', 'mouseover');
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
editor = ipe._controls.editor;
|
||||
assertEqual(2, editor.selectedIndex, 'Did not properly select item');
|
||||
ipe.dispose();
|
||||
}},
|
||||
|
||||
testIPCECollectionSyntaxes: function() {with(this) {
|
||||
// Array of two-item arrays (0 = value, 1 = text)
|
||||
$('newtbe').update('ntbe');
|
||||
var ipe = new Ajax.InPlaceCollectionEditor('newtbe',
|
||||
'_ajax_inplaceeditor_result2.html', { paramName: 'test',
|
||||
collection: IPCE_COLLECTION, onComplete: Prototype.emptyFunction
|
||||
});
|
||||
Event.simulateMouse('newtbe', 'mouseover');
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
var editor = ipe._controls.editor;
|
||||
assertEqual(1, editor.selectedIndex, 'Did not properly select item');
|
||||
// (further contents testing already done in Basic)
|
||||
ipe.dispose();
|
||||
// Array of one-item arrays
|
||||
ipe = new Ajax.InPlaceCollectionEditor('newtbe',
|
||||
'_ajax_inplaceeditor_result2.html', { paramName: 'test',
|
||||
collection: [['tbe'], ['ntbe'], ['ntbe2'], ['ntbe3']],
|
||||
onComplete: Prototype.emptyFunction
|
||||
});
|
||||
Event.simulateMouse('newtbe', 'mouseover');
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
var editor = ipe._controls.editor;
|
||||
assertEqual(1, editor.selectedIndex, 'Did not properly select item');
|
||||
assertEqual('ntbe', $F(editor).strip(), 'Did not properly define text');
|
||||
ipe.dispose();
|
||||
// Array of items
|
||||
ipe = new Ajax.InPlaceCollectionEditor('newtbe',
|
||||
'_ajax_inplaceeditor_result2.html', { paramName: 'test',
|
||||
collection: ['tbe', 'ntbe', 'ntbe2', 'ntbe3'],
|
||||
onComplete: Prototype.emptyFunction
|
||||
});
|
||||
Event.simulateMouse('newtbe', 'mouseover');
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
var editor = ipe._controls.editor;
|
||||
assertEqual(1, editor.selectedIndex, 'Did not properly select item');
|
||||
assertEqual('ntbe', $F(editor).strip(), 'Did not properly define text');
|
||||
ipe.dispose();
|
||||
}},
|
||||
|
||||
testIPCEAlternateTextOptions: function() {with(this) {
|
||||
// loadTextURL (check loading text, verify alternate text eventually)
|
||||
$('newtbe').update('New to be edited');
|
||||
var ipe = new Ajax.InPlaceCollectionEditor('newtbe',
|
||||
'_ajax_inplaceeditor_result2.html', { paramName: 'test',
|
||||
collection: IPCE_COLLECTION, loadTextURL: '_ajax_inplaceeditor_ipce_alt_text.html',
|
||||
onComplete: Prototype.emptyFunction
|
||||
});
|
||||
Event.simulateMouse('newtbe', 'mouseover');
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
var editor = ipe._controls.editor;
|
||||
var text = editor.options[editor.selectedIndex].text.strip();
|
||||
assertEqual(Ajax.InPlaceEditor.DefaultOptions.loadingText, text);
|
||||
wait(1200, function() {
|
||||
assertEqual(1, editor.selectedIndex, 'Did not properly select item based on alternate text.');
|
||||
ipe.dispose();
|
||||
});
|
||||
}},
|
||||
|
||||
testIPCEDynamicCollectionOptions: function() {with(this) {
|
||||
// loadCollectionURL, default loadingCollectionText
|
||||
$('newtbe').update('ntbe');
|
||||
var ipe = new Ajax.InPlaceCollectionEditor('newtbe',
|
||||
'_ajax_inplaceeditor_result2.html', { paramName: 'test',
|
||||
loadCollectionURL: '_ajax_inplaceeditor_ipce_collection.js',
|
||||
onComplete: Prototype.emptyFunction
|
||||
});
|
||||
Event.simulateMouse('newtbe', 'mouseover');
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
var editor = ipe._controls.editor;
|
||||
var text = editor.options[editor.selectedIndex].text.strip();
|
||||
assertEqual(Ajax.InPlaceCollectionEditor.DefaultOptions.loadingCollectionText, text);
|
||||
wait(1000, function() {
|
||||
assertEqual(5, ipe._collection.length);
|
||||
assertEqual(2, editor.selectedIndex, 'Did not properly select item');
|
||||
ipe.dispose();
|
||||
// loadCollectionURL, custom loadingCollectionText
|
||||
$('newtbe').update('bar');
|
||||
ipe = new Ajax.InPlaceCollectionEditor('newtbe',
|
||||
'_ajax_inplaceeditor_result2.html', { paramName: 'test',
|
||||
loadCollectionURL: '_ajax_inplaceeditor_ipce_collection.js',
|
||||
loadingCollectionText: 'There we go...',
|
||||
onComplete: Prototype.emptyFunction
|
||||
});
|
||||
Event.simulateMouse('newtbe', 'mouseover');
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
editor = ipe._controls.editor;
|
||||
text = editor.options[editor.selectedIndex].text.strip();
|
||||
assertEqual('There we go...', text);
|
||||
wait(1000, function() {
|
||||
assertEqual(1, editor.selectedIndex, 'Did not properly select item');
|
||||
ipe.dispose();
|
||||
});
|
||||
});
|
||||
}},
|
||||
|
||||
testIPCEATPlusDC: function() {with(this) {
|
||||
// loadCollectionURL, loadTextURL
|
||||
$('newtbe').update('Like I care');
|
||||
var ipe = new Ajax.InPlaceCollectionEditor('newtbe',
|
||||
'_ajax_inplaceeditor_result2.html', { paramName: 'test',
|
||||
loadCollectionURL: '_ajax_inplaceeditor_ipce_collection.js',
|
||||
loadingCollectionText: 'There we go...',
|
||||
loadTextURL: '_ajax_inplaceeditor_ipce_alt_text.html',
|
||||
loadingText: 'OK, so, the text...',
|
||||
onComplete: Prototype.emptyFunction
|
||||
});
|
||||
ipe._regularCFET = ipe.checkForExternalText;
|
||||
ipe.checkForExternalText = function() {
|
||||
assert(5, ipe._collection.length);
|
||||
ipe._regularCFET();
|
||||
var editor = ipe._controls.editor;
|
||||
var text = editor.options[editor.selectedIndex].text.strip();
|
||||
assertEqual('OK, so, the text...', text);
|
||||
};
|
||||
Event.simulateMouse('newtbe', 'mouseover');
|
||||
Event.simulateMouse('newtbe', 'click');
|
||||
var editor = ipe._controls.editor;
|
||||
var text = editor.options[editor.selectedIndex].text.strip();
|
||||
assertEqual('There we go...', text);
|
||||
wait(2000, function() {
|
||||
assertEqual(2, editor.selectedIndex, 'Did not properly select item');
|
||||
ipe.dispose();
|
||||
});
|
||||
}},
|
||||
|
||||
testDeprecationLayer: function() {with(this) {
|
||||
// FIXME: needs to be coded yet, doesn't it?
|
||||
var ipe = new Ajax.InPlaceCollectionEditor('newtbe',
|
||||
'_ajax_inplaceeditor_result2.html', { paramName: 'test',
|
||||
okButton: false, cancelLink: false
|
||||
});
|
||||
assertIdentical(false, ipe.options.okControl, 'OK control should be disabled');
|
||||
assertIdentical(false, ipe.options.cancelControl, 'Cancel control should be disabled');
|
||||
ipe.dispose();
|
||||
ipe = new Ajax.InPlaceCollectionEditor('newtbe',
|
||||
'_ajax_inplaceeditor_result2.html', { paramName: 'test',
|
||||
okLink: true, cancelButton: true
|
||||
});
|
||||
assertEqual('link', ipe.options.okControl, 'OK control should be a link');
|
||||
assertEqual('button', ipe.options.cancelControl, 'Cancel control should be a button');
|
||||
ipe.dispose();
|
||||
ipe = new Ajax.InPlaceCollectionEditor('newtbe',
|
||||
'_ajax_inplaceeditor_result2.html', { paramName: 'test',
|
||||
highlightcolor: '#ff0000', highlightendcolor: '#00ff00'
|
||||
});
|
||||
assertEqual('#ff0000', ipe.options.highlightColor, 'Highlight color was not migrated');
|
||||
assertEqual('#00ff00', ipe.options.highlightEndColor, 'Highlight end color was not migrated');
|
||||
ipe.dispose();
|
||||
}},
|
||||
|
||||
|
||||
testShouldShowAmpersandsProperly: function() {with(this) {
|
||||
var ipe = new Ajax.InPlaceEditor('contains_ampersand', '', {});
|
||||
Event.simulateMouse('contains_ampersand', 'click');
|
||||
assertEqual("Me & Myself", $$('form#contains_ampersand-inplaceeditor input.editor_field')[0].value);
|
||||
ipe.dispose();
|
||||
}}
|
||||
// FIXME: add AC w/o key conflicts?
|
||||
// FIXME: doc w/ full details on what's new, what's changed, etc. + deprecation layer info.
|
||||
});
|
||||
// ]]>
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
150
javascript/scoluos/test/unit/bdd_test.html
Executable file
150
javascript/scoluos/test/unit/bdd_test.html
Executable file
@@ -0,0 +1,150 @@
|
||||
<!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>
|
||||
|
||||
<!-- Log output -->
|
||||
<div id="testlog"> </div>
|
||||
|
||||
<div id="d">initial</div>
|
||||
|
||||
<!-- Tests follow -->
|
||||
<script type="text/javascript" language="javascript" charset="utf-8">
|
||||
// <![CDATA[
|
||||
var moo = 0;
|
||||
|
||||
var assertMethods = [];
|
||||
for(method in Test.Unit.Assertions.prototype) {
|
||||
if(/^assert/.test(method)) assertMethods.push(method);
|
||||
}
|
||||
|
||||
var testObj = {
|
||||
isNice: function(){
|
||||
return true;
|
||||
},
|
||||
isBroken: function(){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Test.context("BDD-style testing",{
|
||||
|
||||
setup: function() {
|
||||
$('d').update('setup!');
|
||||
moo++;
|
||||
},
|
||||
|
||||
teardown: function() {
|
||||
moo--;
|
||||
},
|
||||
|
||||
'should run setup before each specification': function(){
|
||||
assert($('d').innerHTML == 'setup!');
|
||||
assert(moo == 1);
|
||||
},
|
||||
|
||||
'should run teardown after each specification': function(){
|
||||
assert(moo == 1);
|
||||
},
|
||||
|
||||
'should provide extensions to tie in isSomething and respondsTo object methods': function(){
|
||||
Object.extend(testObj, Test.BDDMethods);
|
||||
|
||||
testObj.shouldBe('nice');
|
||||
testObj.shouldNotBe('broken');
|
||||
|
||||
testObj.shouldRespondTo('isNice');
|
||||
testObj.shouldRespondTo('isBroken');
|
||||
},
|
||||
|
||||
'should automatically add extensions to strings': function(){
|
||||
'a'.shouldEqual('a');
|
||||
'a'.shouldNotEqual('b');
|
||||
'a'.shouldNotBeNull();
|
||||
'a'.shouldBeA(String);
|
||||
|
||||
var aString = 'boo!';
|
||||
aString.shouldEqual('boo!');
|
||||
aString.shouldBeA(String);
|
||||
aString.shouldNotBeA(Number);
|
||||
},
|
||||
|
||||
'should automatically add extensions to numbers': function(){
|
||||
var n = 123;
|
||||
n.shouldEqual(123);
|
||||
n.shouldNotEqual(4);
|
||||
|
||||
n.shouldBeA(Number);
|
||||
n.shouldNotBeA(Test);
|
||||
},
|
||||
|
||||
'should automatically add extensions to arrays': function(){
|
||||
['a'].shouldNotBeA(String);
|
||||
[1,2,3].shouldBeAn(Array);
|
||||
[1,2,3].shouldEqualEnum([1,2,3]);
|
||||
},
|
||||
|
||||
'should automatically add extensions to booleans': function(){
|
||||
var theTruth = true;
|
||||
var lies = false;
|
||||
|
||||
theTruth.shouldNotBeA(String);
|
||||
lies.shouldBeA(Boolean);
|
||||
'false'.shouldNotBeA(Boolean);
|
||||
|
||||
theTruth.shouldEqual(true);
|
||||
lies.shouldNotEqual(true);
|
||||
},
|
||||
|
||||
'should support the eval() method': function(){
|
||||
eval('2*2').shouldEqual(4);
|
||||
},
|
||||
|
||||
'should support equality assertion': function(){
|
||||
assertEqual(1, 1);
|
||||
assertEqual('a', 'a');
|
||||
assertEqual(1, '1');
|
||||
|
||||
var x = 1;
|
||||
var y = 1;
|
||||
assertEqual(1, x)
|
||||
assertEqual(x, y);
|
||||
},
|
||||
|
||||
'should provide all assertions': function(){
|
||||
assertMethods.each(function(m){
|
||||
assert(typeof this[m] == 'function');
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
'should support deferred execution': function(){
|
||||
wait(10,function(){
|
||||
'a'.shouldEqual('a');
|
||||
});
|
||||
|
||||
wait(10,function(){
|
||||
'a'.shouldEqual('a');
|
||||
wait(10,function(){
|
||||
'a'.shouldEqual('a');
|
||||
wait(10,function(){
|
||||
'a'.shouldEqual('a');
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// ]]>
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
262
javascript/scoluos/test/unit/builder_test.html
Executable file
262
javascript/scoluos/test/unit/builder_test.html
Executable file
@@ -0,0 +1,262 @@
|
||||
<!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 builder.js
|
||||
</p>
|
||||
|
||||
<!-- Log output -->
|
||||
<div id="testlog"> </div>
|
||||
|
||||
<div id="result"></div>
|
||||
|
||||
<!-- Tests follow -->
|
||||
<script type="text/javascript" language="javascript" charset="utf-8">
|
||||
// <![CDATA[
|
||||
|
||||
// Serializes a node and it's contents to plain old HTML
|
||||
// IMPORTANT: style attributes can't be correctly serialized cross-browser wise,
|
||||
// so the contents of style attributes must match what IE thinks is correct
|
||||
function serializeNode(node){
|
||||
if(node.nodeType == 3) return node.nodeValue;
|
||||
node = $(node);
|
||||
var tag = node.tagName.toLowerCase();
|
||||
return '<' + ([tag].concat($A(node.attributes).map(function(attr){
|
||||
// Filter out stuff that we don't need
|
||||
if(attr.nodeName == '_extended' || attr.nodeName == '_counted' ||
|
||||
typeof attr.nodeValue == 'function' ||!Element.hasAttribute(node, attr.nodeName)) return;
|
||||
// remove trailing ; in style attributes on Firefox
|
||||
var value = node.readAttribute(attr.nodeName);
|
||||
if(attr.nodeName == 'style' && value.endsWith(';'))
|
||||
value = value.substr(0, value.length-1);
|
||||
return attr.nodeName + '="' + value + '"'
|
||||
}).compact().sort())).join(' ') + '>' + $A(node.childNodes).map(serializeNode).join('') +
|
||||
'</' + tag + '>';
|
||||
}
|
||||
|
||||
new Test.Unit.Runner({
|
||||
|
||||
setup: function() {
|
||||
$('result').innerHTML = '';
|
||||
},
|
||||
|
||||
testBuilderBasics: function() { with(this) {
|
||||
var element = Builder.node('div');
|
||||
assertEqual('DIV', element.nodeName);
|
||||
|
||||
var element = Builder.node('div',{id:'mydiv'})
|
||||
assertEqual('mydiv', element.id);
|
||||
|
||||
var element = Builder.node('div',{id:'mydiv',className:'one two'})
|
||||
assertEqual('mydiv', element.id);
|
||||
assertEqual('one two', element.className);
|
||||
|
||||
var element = Builder.node('span','text 123 <blah>');
|
||||
assertEqual('SPAN', element.nodeName);
|
||||
assertEqual('text 123 <blah>', element.innerHTML);
|
||||
|
||||
var element = Builder.node('span',123);
|
||||
assertEqual('SPAN', element.nodeName);
|
||||
assertEqual('123', element.innerHTML);
|
||||
|
||||
var element = Builder.node('span',['test']);
|
||||
assertEqual('SPAN', element.nodeName);
|
||||
assertEqual('test', element.innerHTML);
|
||||
|
||||
var element = Builder.node('span',['test',123]);
|
||||
assertEqual('SPAN', element.nodeName);
|
||||
assertEqual('test123', element.innerHTML);
|
||||
|
||||
var element = Builder.node('span',{},['test',123]);
|
||||
assertEqual('SPAN', element.nodeName);
|
||||
assertEqual('test123', element.innerHTML);
|
||||
|
||||
var element = Builder.node('span',{id:'myspan'},['test',123]);
|
||||
assertEqual('SPAN', element.nodeName);
|
||||
assertEqual('myspan', element.id);
|
||||
assertEqual('test123', element.innerHTML);
|
||||
|
||||
var element = Builder.node('div',[1,2,[3],[[[4],5],6],7,8,[[[[9]]],0]]);
|
||||
assertEqual('1234567890',element.innerHTML);
|
||||
|
||||
var element = Builder.node('div',[1,'2',['3'],[[[4],'5'],6],7,'8',[[[['9']]],0]]);
|
||||
assertEqual('1234567890',element.innerHTML);
|
||||
|
||||
var element = Builder.node('div',{id:'mydiv'},[1,2,[3],[[[4],5],6],7,8,[[[[9]]],0]]);
|
||||
assertEqual('1234567890',element.innerHTML);
|
||||
|
||||
var element = Builder.node('div',{id:'mydiv'},[1,'2',['3'],[[[4],'5'],6],7,'8',[[[['9']]],0]]);
|
||||
assertEqual('1234567890',element.innerHTML);
|
||||
assertEqual(10, element.childNodes.length);
|
||||
|
||||
var element = Builder.node('div', Builder.node('span'));
|
||||
assertEqual(1, element.childNodes.length);
|
||||
assertEqual('SPAN', element.childNodes[0].tagName);
|
||||
|
||||
var element = Builder.node('div', {id:'mydiv'}, Builder.node('span'));
|
||||
assertEqual(1, element.childNodes.length);
|
||||
assertEqual('mydiv', element.id);
|
||||
assertEqual('SPAN', element.childNodes[0].tagName);
|
||||
}},
|
||||
|
||||
testBuilderClassAndFor: function() { with(this) {
|
||||
var elt = Builder.node('div', { className: 'demoClass' });
|
||||
assertEqual('demoClass', elt.className);
|
||||
var elt = Builder.node('label', { htmlFor: 'mydiv' });
|
||||
assertEqual('mydiv', elt.htmlFor);
|
||||
}},
|
||||
|
||||
testBuilderExtendsElement: function() { with(this) {
|
||||
assertRespondsTo('hide', Builder.node('div'));
|
||||
}},
|
||||
|
||||
testBuilderAllXHTMLTags: function() { with(this) {
|
||||
var XHTML_TAGS = [
|
||||
'a','abbr','acronym','address','applet','area',
|
||||
'b','bdo','big','blockquote','br','button',
|
||||
'caption','cite','code','col','colgroup',
|
||||
'dd','del','dfn','div','dl','dt',
|
||||
'em',
|
||||
'fieldset','form',
|
||||
'h1','h2','h3','h4','h5','h6','hr',
|
||||
'i','iframe','img','input','ins',
|
||||
'kbd',
|
||||
'label','legend','li',
|
||||
'map',
|
||||
'object','ol','optgroup','option',
|
||||
'p','param','pre',
|
||||
'q',
|
||||
'samp','script','select','small','span','strong','style','sub','sup',
|
||||
'table','tbody','td','textarea','tfoot','th','thead','tr','tt',
|
||||
'ul','var']
|
||||
|
||||
XHTML_TAGS.each(function(tag) {
|
||||
try {
|
||||
var element = Builder.node(tag);
|
||||
assertNotNull(element, 'Tag "'+tag+'" expected, but was null.');
|
||||
assertEqual(tag.toUpperCase(), element.nodeName);
|
||||
|
||||
var element = Builder.node(tag,{id:'tag_'+tag+'_test_id'});
|
||||
assertEqual(tag.toUpperCase(), element.nodeName);
|
||||
assertEqual('tag_'+tag+'_test_id', element.id, 'Setting id attribute for "'+tag+'" failed!');
|
||||
} catch(e) {
|
||||
assert(false, 'Error while creating node of type '+tag+'. Note: Firefox bug in 1.0.X on option and optgroup, fixed in 1.5b1. Internet Explorer 6 doesn\'t support the ABBR tag and has no standard DOM implementation for tables.');
|
||||
}
|
||||
});
|
||||
}},
|
||||
|
||||
// special case, because requires workarounds on IE and Firefox < 1.5
|
||||
testBuilderOptionTag: function() { with(this) {
|
||||
assertEqual('', Builder.node('option').innerHTML);
|
||||
assertEqual('test', Builder.node('option','test').innerHTML);
|
||||
assertEqual('', Builder.node('option',{className:'test'}).innerHTML);
|
||||
assertEqual('test', Builder.node('option',{className:'test'},'test').innerHTML);
|
||||
assertEqual('test', Builder.node('option',{},'test').innerHTML);
|
||||
|
||||
var selectElement = Builder.node('select');
|
||||
var optionElement = Builder.node('option',{className:'test',id:'option_123'},123);
|
||||
selectElement.appendChild(optionElement);
|
||||
document.body.appendChild(selectElement);
|
||||
assertEqual('123', $('option_123').innerHTML);
|
||||
}},
|
||||
|
||||
testBuilderContatenation: function() { with(this) {
|
||||
var element = Builder.node('div', [Builder.node('span')]);
|
||||
assertEqual('DIV', element.nodeName);
|
||||
assertEqual(1, element.childNodes.length);
|
||||
assertEqual('SPAN', element.firstChild.nodeName);
|
||||
|
||||
var element = Builder.node('div', [Builder.node('span'),'text']);
|
||||
assertEqual(2, element.childNodes.length);
|
||||
assertEqual(0, element.firstChild.childNodes.length);
|
||||
assertEqual('DIV', element.nodeName);
|
||||
assertEqual('SPAN', element.firstChild.nodeName);
|
||||
assertEqual(3, element.firstChild.nextSibling.nodeType);
|
||||
|
||||
var element = Builder.node('div', [Builder.node('span',[Builder.node('strong','blah')]),'text']);
|
||||
assertEqual(2, element.childNodes.length);
|
||||
assertEqual(1, element.firstChild.childNodes.length);
|
||||
assertEqual('DIV', element.nodeName);
|
||||
assertEqual('SPAN', element.firstChild.nodeName);
|
||||
assertEqual('STRONG', element.firstChild.firstChild.nodeName);
|
||||
assertEqual('blah', element.firstChild.firstChild.innerHTML);
|
||||
assertEqual(3, element.firstChild.nextSibling.nodeType);
|
||||
}},
|
||||
|
||||
testBuilderComplexExample: function() { with(this) {
|
||||
var element = Builder.node('div',{id:'ghosttrain'},[
|
||||
Builder.node('div',{style:'font-weight: bold; font-size: 11px'},[
|
||||
Builder.node('h1','Ghost Train'),
|
||||
"testtext", 2, 3, 4,
|
||||
Builder.node('ul',[
|
||||
Builder.node('li',{onclick:'alert(\'test\')'},'click me')
|
||||
]),
|
||||
]),
|
||||
]);
|
||||
assertEqual('DIV', element.nodeName);
|
||||
|
||||
$('result').appendChild(element);
|
||||
|
||||
// browsers aren't sure about upper and lower case on elements
|
||||
assertEqual(
|
||||
'<div id="ghosttrain"><div style="font-weight: bold; font-size: 11px">' +
|
||||
'<h1>Ghost Train</h1>testtext234<ul><li onclick="alert(\'test\')">click me</li></ul></div></div>',
|
||||
serializeNode($('result').childNodes[0]));
|
||||
}},
|
||||
|
||||
testBuilderShortcuts: function() { with(this) {
|
||||
Builder.dump();
|
||||
|
||||
var element = DIV(SPAN());
|
||||
assertEqual('SPAN', element.childNodes[0].tagName);
|
||||
|
||||
var element = DIV({id:'test'},SPAN());
|
||||
assertEqual('SPAN', element.childNodes[0].tagName);
|
||||
|
||||
var element = DIV({id:'ghosttrain'},[
|
||||
DIV({style:'font-weight: bold; font-size: 11px'},[
|
||||
H1('Ghost Train'),
|
||||
"testtext", 2, 3, 4,
|
||||
UL([
|
||||
LI({onclick:'alert(\'test\')'},'click me')
|
||||
]),
|
||||
]),
|
||||
]);
|
||||
assertEqual('DIV', element.nodeName);
|
||||
|
||||
$('result').appendChild(element);
|
||||
|
||||
assertEqual(
|
||||
'<div id="ghosttrain"><div style="font-weight: bold; font-size: 11px">' +
|
||||
'<h1>Ghost Train</h1>testtext234<ul><li onclick="alert(\'test\')">click me</li></ul></div></div>',
|
||||
serializeNode($('result').childNodes[0]));
|
||||
}},
|
||||
|
||||
testBuilderBuild: function() { with(this) {
|
||||
['<span>this is <b>neat!</b></span>',' \n<span>this is <b>neat!</b></span>\n '].each(
|
||||
function(html){
|
||||
var node = Builder.build(html);
|
||||
assertEqual('<span>this is <b>neat!</b></span>', serializeNode(node));
|
||||
});
|
||||
}},
|
||||
|
||||
testBuilderAttributeEscaping: function() { with(this) {
|
||||
var element = Builder.node('div',{blah:"<foo'bar&baz\"bat>"});
|
||||
assertEqual("<foo'bar&baz\"bat>", $(element).readAttribute('blah'));
|
||||
}}
|
||||
|
||||
});
|
||||
// ]]>
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
131
javascript/scoluos/test/unit/dragdrop_test.html
Executable file
131
javascript/scoluos/test/unit/dragdrop_test.html
Executable file
@@ -0,0 +1,131 @@
|
||||
<!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" />
|
||||
<style type="text/css" media="screen">
|
||||
/* <![CDATA[ */
|
||||
#div_absolute_test { position: absolute }
|
||||
/* ]]> */
|
||||
</style>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<h1>script.aculo.us Unit test file</h1>
|
||||
<p>
|
||||
Test of drag & drop functions in dragdrop.js
|
||||
</p>
|
||||
|
||||
<!-- Log output -->
|
||||
<div id="testlog"> </div>
|
||||
|
||||
<p id="p_test">p_test</p>
|
||||
<p id="p_test2">p_test2</p>
|
||||
<p id="p_test3">p_test3</p>
|
||||
<img id="img_test" src="icon.png" alt="img_text"/>
|
||||
<div id="droppable_test">droppable_test</div>
|
||||
|
||||
<div id="div_test">div_test</div>
|
||||
<div id="div_absolute_test">div_absolute_test</div>
|
||||
<div id="div_absolute_inline_test" style="position:absolute">div_absolute_inline_test</div>
|
||||
|
||||
<div id="droppable_container">
|
||||
<div id="d1">droppable_test</div>
|
||||
<div id="d2">droppable_test</div>
|
||||
</div>
|
||||
|
||||
<div id="droppable_container_2">
|
||||
<div id="d3">droppable_test</div>
|
||||
</div>
|
||||
|
||||
<!-- Tests follow -->
|
||||
<script type="text/javascript" language="javascript" charset="utf-8">
|
||||
// <![CDATA[
|
||||
|
||||
new Test.Unit.Runner({
|
||||
|
||||
testDraggableBasics: function() { with(this) {
|
||||
var d = new Draggable('p_test');
|
||||
assertInstanceOf(Draggable, d);
|
||||
}},
|
||||
|
||||
testDraggableStartEffect: function() { with(this) {
|
||||
var d = new Draggable('p_test2');
|
||||
assert(d.options.starteffect, 'There should be a default start effect.');
|
||||
d = new Draggable('p_test3', { endeffect: Prototype.EmptyFunction });
|
||||
assert(undefined === d.options.startEffect, 'There should be no default start effect.');
|
||||
}},
|
||||
|
||||
testAutoPositioning: function() { with(this) {
|
||||
assertEqual('static', Element.getStyle('div_test','position'));
|
||||
new Draggable('div_test');
|
||||
new Draggable('div_absolute_test');
|
||||
new Draggable('div_absolute_inline_test');
|
||||
assertEqual('relative', Element.getStyle('div_test','position'));
|
||||
assertEqual('absolute', Element.getStyle('div_absolute_test','position'));
|
||||
assertEqual('absolute', Element.getStyle('div_absolute_inline_test','position'));
|
||||
}},
|
||||
|
||||
testDroppbalesBasics: function() { with(this) {
|
||||
assertEqual(0, Droppables.drops.length);
|
||||
assertEqual('static', Element.getStyle('droppable_test','position'));
|
||||
|
||||
Droppables.add('droppable_test');
|
||||
assertEqual(1, Droppables.drops.length);
|
||||
assertEqual('relative', Element.getStyle('droppable_test','position'));
|
||||
|
||||
Droppables.remove('droppable_test');
|
||||
assertEqual(0, Droppables.drops.length);
|
||||
|
||||
// accept option should take strings or array of strings
|
||||
Droppables.add('droppable_test',{accept:'document'});
|
||||
assertEqual(['document'].inspect(), Droppables.drops[0].accept.inspect());
|
||||
Droppables.remove('droppable_test');
|
||||
|
||||
Droppables.add('droppable_test',{accept:['document','image']});
|
||||
assertEqual(['document','image'].inspect(), Droppables.drops[0].accept.inspect());
|
||||
Droppables.remove('droppable_test');
|
||||
}},
|
||||
|
||||
testDroppableContainment: function() { with(this) {
|
||||
// Droppable containers should be cached
|
||||
Droppables.add('droppable_test', {
|
||||
containment:'droppable_container' });
|
||||
assertEqual(1, Droppables.drops[0]._containers.length);
|
||||
assertEqual($('droppable_container'), Droppables.drops[0]._containers[0]);
|
||||
assert(Droppables.isContained($('d1'), Droppables.drops[0]));
|
||||
assert(Droppables.isContained($('d2'), Droppables.drops[0]));
|
||||
assert(!Droppables.isContained($('d3'), Droppables.drops[0]));
|
||||
Droppables.remove('droppable_test');
|
||||
|
||||
Droppables.add('droppable_test', {
|
||||
containment:['droppable_container','droppable_container_2'] });
|
||||
assertEqual(2, Droppables.drops[0]._containers.length);
|
||||
assertEqual($('droppable_container'), Droppables.drops[0]._containers[0]);
|
||||
assertEqual($('droppable_container_2'), Droppables.drops[0]._containers[1]);
|
||||
assert(Droppables.isContained($('d1'), Droppables.drops[0]));
|
||||
assert(Droppables.isContained($('d2'), Droppables.drops[0]));
|
||||
assert(Droppables.isContained($('d3'), Droppables.drops[0]));
|
||||
Droppables.remove('droppable_test');
|
||||
}},
|
||||
|
||||
testDroppablesIsAffected: function() { with(this) {
|
||||
Droppables.add('droppable_test');
|
||||
|
||||
Position.prepare();
|
||||
assert(!Droppables.isAffected([-10, -10], null, Droppables.drops[0]));
|
||||
|
||||
var p = Position.page($('droppable_test'));
|
||||
assert(Droppables.isAffected(p, null, Droppables.drops[0]));
|
||||
}}
|
||||
|
||||
}, "testlog");
|
||||
// ]]>
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
547
javascript/scoluos/test/unit/effects_test.html
Executable file
547
javascript/scoluos/test/unit/effects_test.html
Executable file
@@ -0,0 +1,547 @@
|
||||
<!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" />
|
||||
<style type="text/css" media="screen">
|
||||
#rotfl {
|
||||
color: red;
|
||||
font-family: serif;
|
||||
font-style: italic;
|
||||
font-size: 40px;
|
||||
background: #fed;
|
||||
padding: 1em;
|
||||
width: 400px;
|
||||
}
|
||||
.final {
|
||||
color: #fff;
|
||||
font-style: italic;
|
||||
background: #000;
|
||||
opacity: 0.5;
|
||||
}
|
||||
body div.final {
|
||||
font-size: 20px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>script.aculo.us Unit test file</h1>
|
||||
<p>
|
||||
Tests for effects.js
|
||||
</p>
|
||||
|
||||
<!-- generated elements go in here -->
|
||||
<div id="sandbox"></div>
|
||||
|
||||
<!-- Log output -->
|
||||
<div id="testlog"> </div>
|
||||
|
||||
<div class="morphing blub" style="font-size:25px;color:#f00">Well</div>
|
||||
<div class="morphing">You know</div>
|
||||
<div id="blah" style="border:1px solid black;width:100px">Whoo-hoo!</div>
|
||||
|
||||
<div id="error_message">ERROR MESSAGE</div>
|
||||
<div id="error_message_2">SECOND ERROR MESSAGE</div>
|
||||
<div id="error_message_3" style="border:1px solid red; width:100px; color: #f00">THIRD ERROR MESSAGE</div>
|
||||
|
||||
<ul class="error-list" id="error_test_ul">
|
||||
<li>Lorem ipsum dolor sit amet, consectetur adipisicing elit,</li>
|
||||
<li>sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</li>
|
||||
<li>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris</li>
|
||||
<li>nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in</li>
|
||||
<li>reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</li>
|
||||
</ul>
|
||||
|
||||
<div id="rotfl">ROTFL</div>
|
||||
|
||||
<div id="tween">foo!</div>
|
||||
|
||||
<!-- Tests follow -->
|
||||
<script type="text/javascript" language="javascript" charset="utf-8">
|
||||
// <![CDATA[
|
||||
|
||||
var TAGS =
|
||||
['div','span','ol','ul','table','p','h1','h2','h3','h4','h5','h6'];
|
||||
|
||||
var COMBINED_EFFECTS =
|
||||
['Fade','Appear','BlindUp','BlindDown','Puff','SwitchOff','DropOut','Shake',
|
||||
'SlideUp','SlideDown','Pulsate','Squish','Fold','Grow','Shrink'];
|
||||
|
||||
var COMBINED_RJS_EFFECTS = $w('fade appear blind_up blind_down puff switch_off '+
|
||||
'drop_out shake slide_up slide_down pulsate squish fold grow shrink');
|
||||
|
||||
var tmp, tmp2;
|
||||
|
||||
new Test.Unit.Runner({
|
||||
|
||||
setup: function() { with (this) {
|
||||
$('sandbox').innerHTML = "";
|
||||
}},
|
||||
|
||||
teardown: function() { with(this) {
|
||||
// remove all queued effects
|
||||
Effect.Queue.each(function(e) { e.cancel() });
|
||||
}},
|
||||
|
||||
testExceptionOnNonExistingElement: function() { with(this) {
|
||||
assertRaise('ElementDoesNotExistError',
|
||||
function(){new Effect.Opacity('nothing-to-see-here')});
|
||||
assertRaise('ElementDoesNotExistError',
|
||||
function(){new Effect.Move('nothing-to-see-here')});
|
||||
assertRaise('ElementDoesNotExistError',
|
||||
function(){new Effect.Scale('nothing-to-see-here')});
|
||||
assertRaise('ElementDoesNotExistError',
|
||||
function(){new Effect.Highlight('nothing-to-see-here')});
|
||||
}},
|
||||
|
||||
testCallbacks: function() { with(this) {
|
||||
tmp = tmp2 = 0;
|
||||
var e1 = new Effect.Opacity('sandbox',{from:1.0,to:0.5,duration:0.5,
|
||||
beforeStart: function() { tmp++ },
|
||||
beforeStartInternal: function() { tmp++ },
|
||||
beforeSetup: function() { tmp++ },
|
||||
beforeSetupInternal: function() { tmp++ },
|
||||
afterSetup: function() { tmp++ },
|
||||
afterSetupInternal: function() { tmp++ },
|
||||
beforeUpdate: function() { tmp2++ },
|
||||
beforeUpdateInternal: function() { tmp2++ },
|
||||
beforeFinish: function() { tmp++ },
|
||||
beforeFinishInternal: function() { tmp++ },
|
||||
afterFinish: function() { tmp++ },
|
||||
afterFinishInternal: function() { tmp++ }
|
||||
});
|
||||
wait(1000, function() {
|
||||
assertEqual(10, tmp);
|
||||
assert(tmp2 > 0);
|
||||
});
|
||||
}},
|
||||
|
||||
testEvent: function() { with(this) {
|
||||
tmp = 0;
|
||||
new Effect.Event({ afterFinish:function(){ tmp++ }, position:'end'});
|
||||
wait(100, function() {
|
||||
assertEqual(1, tmp);
|
||||
});
|
||||
}},
|
||||
|
||||
testTransition: function() { with(this) {
|
||||
// false implies linear
|
||||
var e = new Effect.Opacity('sandbox',{transition:false,from:0.0,to:0.25,duration:0.5});
|
||||
assert(e.options.transition == Effect.Transitions.linear);
|
||||
|
||||
wait(1000, function() {
|
||||
assertEqual(0.25, $('sandbox').getStyle('opacity'));
|
||||
// default to sinoidal
|
||||
var e = new Effect.Opacity('sandbox',{from:0.0,to:0.25,duration:0.5});
|
||||
assert(e.options.transition == Effect.Transitions.sinoidal);
|
||||
wait(1000, function() {
|
||||
assertEqual(0.25, $('sandbox').getStyle('opacity'));
|
||||
|
||||
var transitions = [
|
||||
{ transition: Effect.Transitions.linear, expected: 1 },
|
||||
{ transition: Effect.Transitions.sinoidal, expected: 1 },
|
||||
{ transition: Effect.Transitions.reverse, expected: 0 },
|
||||
{ transition: Effect.Transitions.flicker, expected: 1 },
|
||||
{ transition: Effect.Transitions.wobble, expected: 1 },
|
||||
{ transition: Effect.Transitions.pulse, expected: 1 },
|
||||
{ transition: Effect.Transitions.none, expected: 0 }
|
||||
];
|
||||
|
||||
transitions.each(function(t){
|
||||
var e = new Effect.Opacity('sandbox',{sync:true, from:0, to: 1, transition:t.transition});
|
||||
assert(e.options.transition == t.transition);
|
||||
e.render(1.0);
|
||||
assertEqual(t.expected, e.position, t.transition);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
}},
|
||||
|
||||
testInspect: function() { with(this) {
|
||||
var e1 = new Effect.Opacity('sandbox',{from:1.0,to:0.5,duration:0.5});
|
||||
info( e1.inspect() );
|
||||
assertEqual(0, e1.inspect().indexOf('#<Effect:'));
|
||||
assert(e1.inspect().indexOf('idle')>0);
|
||||
wait(1000, function() {
|
||||
assert(e1.inspect().indexOf('finished')>0);
|
||||
});
|
||||
}},
|
||||
|
||||
testDefaultOptions: function() { with(this) {
|
||||
var oldDefaultOptions = Object.extend({},Effect.DefaultOptions);
|
||||
|
||||
assertEqual(1.0, Effect.DefaultOptions.duration);
|
||||
Effect.DefaultOptions.duration = 0.5;
|
||||
var e1 = new Effect.Opacity('sandbox');
|
||||
assertEqual(0.5, e1.options.duration);
|
||||
|
||||
wait(750, function() {
|
||||
assertEqual('finished', e1.state);
|
||||
Effect.DefaultOptions = oldDefaultOptions;
|
||||
});
|
||||
}},
|
||||
|
||||
testEffectsQueue: function() { with(this) {
|
||||
var e1 = new Effect.Highlight('sandbox');
|
||||
var e2 = new Effect.Appear('sandbox');
|
||||
|
||||
assertEqual(2, Effect.Queue.effects.length);
|
||||
|
||||
tmp = 0;
|
||||
Effect.Queue.each(function(e) { tmp++ });
|
||||
assertEqual(2, tmp);
|
||||
|
||||
// the internal interval timer should be active
|
||||
assertNotNull(Effect.Queue.interval);
|
||||
e1.cancel();
|
||||
e2.cancel();
|
||||
assertEqual(0, Effect.Queue.effects.length);
|
||||
|
||||
// should be inactive after all effects are removed from queue
|
||||
assertNull(Effect.Queue.interval);
|
||||
|
||||
// should be in e3,e1,e2 order
|
||||
var e1 = new Effect.Highlight('sandbox');
|
||||
var e2 = new Effect.Appear('sandbox',{queue:'end'});
|
||||
var e3 = new Effect.Fade('sandbox',{queue:'front'});
|
||||
assert(e2.startOn > e1.startOn);
|
||||
assert(e3.startOn < e1.startOn);
|
||||
assert(e3.startOn < e2.startOn);
|
||||
assertEqual(3, Effect.Queue.effects.length);
|
||||
|
||||
Effect.Queue.each(function(e) { e.cancel() });
|
||||
assertEqual(0, Effect.Queue.effects.length);
|
||||
}},
|
||||
|
||||
testScopedEffectsQueue: function() { with(this) {
|
||||
var e1 = new Effect.Highlight('sandbox', {queue: {scope:'myscope'} } );
|
||||
var e2 = new Effect.Appear('sandbox', {queue: {scope:'myscope'} } );
|
||||
var e3 = new Effect.Highlight('sandbox', {queue: {scope:'secondscope'} } );
|
||||
var e4 = new Effect.Appear('sandbox');
|
||||
|
||||
assertEqual(2, Effect.Queues.get('myscope').effects.length);
|
||||
assertEqual(1, Effect.Queues.get('secondscope').effects.length);
|
||||
assertEqual(1, Effect.Queues.get('global').effects.length);
|
||||
assertEqual(Effect.Queue.effects.length, Effect.Queues.get('global').effects.length);
|
||||
|
||||
var tmp = 0;
|
||||
Effect.Queues.get('myscope').effects.each(function(e) { tmp++ });
|
||||
assertEqual(2, tmp);
|
||||
|
||||
// the internal interval timer should be active
|
||||
assertNotNull(Effect.Queues.get('myscope').interval);
|
||||
assertNotNull(Effect.Queues.get('secondscope').interval);
|
||||
assertNotNull(Effect.Queues.get('global').interval);
|
||||
|
||||
e1.cancel(); e2.cancel(); e3.cancel(); e4.cancel();
|
||||
|
||||
assertEqual(0, Effect.Queues.get('myscope').effects.length);
|
||||
assertEqual(0, Effect.Queues.get('secondscope').effects.length);
|
||||
assertEqual(0, Effect.Queues.get('global').effects.length);
|
||||
|
||||
// should be inactive after all effects are removed from queues
|
||||
assertNull(Effect.Queues.get('myscope').interval);
|
||||
assertNull(Effect.Queues.get('secondscope').interval);
|
||||
assertNull(Effect.Queues.get('global').interval);
|
||||
|
||||
// should be in e3 and e4 together and then e1,e2 order
|
||||
var e1 = new Effect.Highlight('sandbox', {queue: {scope:'myscope'} } );
|
||||
var e2 = new Effect.Appear('sandbox', {queue: {position: 'end', scope:'myscope'} } );
|
||||
var e3 = new Effect.Fade('sandbox', {queue: {position: 'front', scope:'myscope'} } );
|
||||
var e4 = new Effect.Appear('sandbox');
|
||||
assert(e2.startOn > e1.startOn);
|
||||
assert(e3.startOn < e1.startOn);
|
||||
assert(e3.startOn < e2.startOn);
|
||||
assert(e3.startOn = e4.startOn);
|
||||
assertEqual(3, Effect.Queues.get('myscope').effects.length);
|
||||
|
||||
Effect.Queues.get('myscope').each(function(e) { e.cancel() });
|
||||
assertEqual(0, Effect.Queues.get('myscope').effects.length);
|
||||
|
||||
Effect.Queues.get('global').each(function(e) { e.cancel() });
|
||||
assertEqual(0, Effect.Queues.get('global').effects.length);
|
||||
|
||||
// should only allow the first two effects and ignore the third
|
||||
var e1 = new Effect.Highlight('sandbox', {queue: {scope:'myscope', limit: 2} } );
|
||||
var e2 = new Effect.Appear('sandbox', {queue: {position: 'end', scope:'myscope', limit: 2} } );
|
||||
var e3 = new Effect.Fade('sandbox', {queue: {position: 'front', scope:'myscope', limit: 2} } );
|
||||
|
||||
assertEqual(2, Effect.Queues.get('myscope').effects.length);
|
||||
}},
|
||||
|
||||
testEffectMultiple: function() { with(this) {
|
||||
$('sandbox').appendChild(Builder.node('div',{id:'test_1'}));
|
||||
$('sandbox').appendChild(Builder.node('div',{id:'test_2'},[Builder.node('div',{id:'test_2a'})]));
|
||||
$('sandbox').appendChild(Builder.node('div',{id:'test_3'}));
|
||||
|
||||
// only direct child elements
|
||||
Effect.multiple('sandbox',Effect.Fade);
|
||||
assertEqual(3, Effect.Queue.effects.length);
|
||||
|
||||
Effect.Queue.each(function(e) { e.cancel() });
|
||||
assertEqual(0, Effect.Queue.effects.length);
|
||||
|
||||
// call with array
|
||||
Effect.multiple(['test_1','test_3'],Effect.Puff);
|
||||
assertEqual(2, Effect.Queue.effects.length);
|
||||
}},
|
||||
|
||||
testEffectTagifyText: function() { with(this) {
|
||||
$('sandbox').innerHTML = "Blah<strong>bleb</strong> Blub";
|
||||
assertEqual(3, $('sandbox').childNodes.length);
|
||||
Effect.tagifyText('sandbox');
|
||||
assertEqual(10, $('sandbox').childNodes.length);
|
||||
|
||||
Effect.multiple('sandbox', Effect.Fade);
|
||||
assertEqual(10, Effect.Queue.effects.length);
|
||||
}},
|
||||
|
||||
testEffectParallel: function() { with(this) {
|
||||
assert( new Effect.Parallel() );
|
||||
assert( new Effect.Parallel([]) );
|
||||
assert( new Effect.Parallel([],{}) );
|
||||
assert( new Effect.Parallel([
|
||||
new Effect.Event({sync:true})
|
||||
],{ duration: 2}) );
|
||||
}},
|
||||
|
||||
testEffectTween: function() { with(this) {
|
||||
// basic initialization
|
||||
assert(new Effect.Tween(null,0,0,function(){}));
|
||||
assert(new Effect.Tween(null,0,0,{duration:0.1},function(){}));
|
||||
|
||||
// fun with objects
|
||||
var object = {
|
||||
blech: 2,
|
||||
foo: function(p){
|
||||
this.bar = p;
|
||||
}
|
||||
};
|
||||
assert(new Effect.Tween(object,0,1,{transition:Effect.Transitions.reverse},'blech'));
|
||||
assert(new Effect.Tween(object,0,1,'foo'));
|
||||
|
||||
// fun with elements
|
||||
assert(new Effect.Tween('tween',50,1,'update'));
|
||||
|
||||
wait(1500, function(){
|
||||
assertEqual(0, object.blech);
|
||||
assertEqual(1, object.bar);
|
||||
assertEqual('1', $('tween').innerHTML);
|
||||
});
|
||||
}},
|
||||
|
||||
// test if all combined effects correctly initialize themselves
|
||||
testCombinedEffectsInitialize: function() { with(this) {
|
||||
COMBINED_EFFECTS.each(function(fx,idx){
|
||||
info('Effect.'+fx);
|
||||
$('sandbox').innerHTML = "";
|
||||
$('sandbox').appendChild(
|
||||
Builder.node('div',{id:'test_element'},
|
||||
Builder.node('span','test'))); //some effects require a child element
|
||||
|
||||
// should work with new Effect.Blah syntax
|
||||
var effect = new Effect[fx]('test_element');
|
||||
assertEqual(0, effect.currentFrame);
|
||||
|
||||
// and without the 'new'
|
||||
var effect = Effect[fx]('test_element');
|
||||
assertEqual(0, effect.currentFrame);
|
||||
|
||||
// visualEffect
|
||||
assert($('test_element') == $('test_element').visualEffect(COMBINED_RJS_EFFECTS[idx]));
|
||||
|
||||
// direct element extension
|
||||
var method = COMBINED_EFFECTS[idx].charAt(0).toLowerCase() + COMBINED_EFFECTS[idx].substring(1)
|
||||
assert($('test_element') == $('test_element')[method]());
|
||||
|
||||
// options parsing (shake, squish and grow are special here)
|
||||
if(!['Shake','Squish','Grow'].include(fx)) {
|
||||
var effect = Effect[fx]('test_element',{duration:2.0});
|
||||
assertEqual(2.0, effect.options.duration, fx);
|
||||
}
|
||||
});
|
||||
}},
|
||||
|
||||
testSynchronizedEffects: function() { with(this) {
|
||||
var e1 = new Effect.Fade('sandbox',{sync:true});
|
||||
wait(250, function() {
|
||||
// effect should still be at frame 0
|
||||
assertEqual(0, e1.currentFrame);
|
||||
assertEqual('idle', e1.state);
|
||||
e1.render(0.01);
|
||||
|
||||
// no frame count for sync effects
|
||||
assertEqual(0, e1.currentFrame);
|
||||
assertEqual('running', e1.state);
|
||||
});
|
||||
}},
|
||||
|
||||
testEffectPosition: function() { with(this) {
|
||||
var testeffect = new Effect.Opacity('sandbox',{
|
||||
afterSetup: function(effect) { effect.frames = 0; },
|
||||
afterUpdate: function(effect) { effect.frames++; $('sandbox').update(effect.position); },
|
||||
duration: 0.5, from: 1.0, to: 0.5
|
||||
});
|
||||
assertNull(testeffect.position);
|
||||
assertEqual('idle', testeffect.state);
|
||||
wait(1000, function() {
|
||||
info('Rendered ' + testeffect.frames + ' frames in .5 seconds ' +
|
||||
'(~' + (testeffect.frames/0.5) + 'fps of a possible 60fps, ' +
|
||||
'note that this can exceed 60fps because of additional last frame rendering)');
|
||||
assertEqual('0.5', $('sandbox').innerHTML);
|
||||
assertEqual(0.5, testeffect.position);
|
||||
assertEqual('finished', testeffect.state);
|
||||
});
|
||||
}},
|
||||
|
||||
testRenderPerformance: function() { with(this) {
|
||||
info('The render() method is generated on a per-effect basis')
|
||||
var e = new Effect.Opacity('sandbox',{sync:true});
|
||||
benchmark(function(){
|
||||
e.render(0.5);
|
||||
},1000, 'Without events');
|
||||
var e = new Effect.Opacity('sandbox',{sync:true,afterUpdate:function(){return}});
|
||||
benchmark(function(){
|
||||
e.render(0.5);
|
||||
},1000, 'With afterUpdate event');
|
||||
}},
|
||||
|
||||
testElementMorph: function() { with(this) {
|
||||
$('error_test_ul').morph('font-size:40px', {duration: 0.5}).setStyle({marginRight:'17px'});
|
||||
$('error_message_2').morph({
|
||||
fontSize: '20px',
|
||||
color: '#f00',
|
||||
backgroundColor: '#ffffff'
|
||||
},
|
||||
{
|
||||
duration:0.5
|
||||
});
|
||||
$('error_message_3').morph('final', {duration:0.5});
|
||||
wait(1000,function(){
|
||||
assertEqual('17px', $('error_test_ul').getStyle('margin-right'));
|
||||
assertEqual('40px', $('error_test_ul').getStyle('font-size'));
|
||||
assertEqual('#ffffff', $('error_message_2').getStyle('background-color').parseColor());
|
||||
assertEqual('20px', $('error_message_2').getStyle('font-size'));
|
||||
assertEqual('italic', $('error_message_3').getStyle('font-style'));
|
||||
assertEqual('20px', $('error_message_3').getStyle('font-size'));
|
||||
assertEqual(.5, $('error_message_3').getStyle('opacity'));
|
||||
assertEqual('', $('error_message_3').style.fontSize);
|
||||
});
|
||||
}},
|
||||
|
||||
testElementMorphChaining: function() { with(this) {
|
||||
$('error_message').morph('font-size:17px').morph('opacity:0',{delay:2});
|
||||
wait(3100,function(){ // 2000ms delay + 1000ms default duration
|
||||
assertEqual(0, $('error_message').getStyle('opacity'));
|
||||
});
|
||||
}},
|
||||
|
||||
testTransformBySelector: function() { with(this) {
|
||||
new Effect.Transform([
|
||||
{ 'ul.error-list li': 'font-size:20px;text-indent:40pt' }
|
||||
],{ duration: 0.5 }).play();
|
||||
|
||||
wait(700,function(){
|
||||
var idx = 0;
|
||||
$A($('error_test_ul').cleanWhitespace().childNodes).each(function(node){
|
||||
assertEqual('20px', $(node).getStyle('font-size'));
|
||||
assertEqual('40pt', $(node).getStyle('text-indent'));
|
||||
idx++;
|
||||
});
|
||||
assertEqual(5, idx);
|
||||
});
|
||||
}},
|
||||
|
||||
testTransformUsesCSSClassPresets: function() { with(this) {
|
||||
assertEqual('40px', $('rotfl').getStyle('font-size'));
|
||||
|
||||
// Render the effect at half-way through, font-size should be
|
||||
// exactly half-way between original and target
|
||||
new Effect.Transform([
|
||||
{ 'rotfl': 'font-size:20px;text-indent:40pt;background-color:#888' }
|
||||
],{ sync:true }).play().render(0.5);
|
||||
|
||||
wait(1100,function(){
|
||||
// should be 30px = 40px + (20px-40px)/2
|
||||
assertEqual('30px', $('rotfl').getStyle('font-size'));
|
||||
});
|
||||
}},
|
||||
|
||||
testTransformMultiple: function() { with(this) {
|
||||
var transformation = new Effect.Transform([
|
||||
{ 'div.morphing': 'font-size:20px;padding-left:40em;opacity:0.5' },
|
||||
{ 'blah' :
|
||||
'width:480px;border-width:10px;border-right-width:20px;' +
|
||||
'margin:20px;margin-bottom:-20px;font-size:30px;' +
|
||||
'background:#954' }
|
||||
],{ duration: 0.5 });
|
||||
|
||||
var generatedEffect = transformation.play();
|
||||
|
||||
assertEqual(3, generatedEffect.effects.length);
|
||||
|
||||
wait(700, function(){
|
||||
// have a look at the generated color transforms for the 3rd found element
|
||||
// which is the "blah" div
|
||||
assertEqual('blah', generatedEffect.effects[2].element.id);
|
||||
assertEnumEqual([255,255,255],
|
||||
generatedEffect.effects[2].transforms.detect( function(transform){
|
||||
return (transform.style == 'backgroundColor')
|
||||
}).originalValue);
|
||||
assertEnumEqual([153,85,68],
|
||||
generatedEffect.effects[2].transforms.detect( function(transform){
|
||||
return (transform.style == 'backgroundColor')
|
||||
}).targetValue);
|
||||
|
||||
assertEqual('20px', $$('div.morphing').first().getStyle('font-size'));
|
||||
assertEqual('20px', $$('div.morphing').last().getStyle('font-size'));
|
||||
assertEqual('30px', $('blah').getStyle('font-size'));
|
||||
|
||||
// border-width/border-right-width should be set independently
|
||||
assertEqual('10px', $('blah').getStyle('border-top-width'));
|
||||
assertEqual('10px', $('blah').getStyle('border-bottom-width'));
|
||||
assertEqual('10px', $('blah').getStyle('border-left-width'));
|
||||
assertEqual('20px', $('blah').getStyle('border-right-width'));
|
||||
|
||||
// colors should assume transition from
|
||||
// #ffffff (white) if original was transparent
|
||||
// we now should have arrived at the given color
|
||||
assertEqual('#995544', $('blah').getStyle('background-color').parseColor());
|
||||
|
||||
// play again = should have same values
|
||||
transformation.play();
|
||||
wait(700, function(){
|
||||
assertEqual('20px', $$('div.morphing').first().getStyle('font-size'));
|
||||
assertEqual('20px', $$('div.morphing').last().getStyle('font-size'));
|
||||
assertEqual('30px', $('blah').getStyle('font-size'));
|
||||
|
||||
$('blah').setStyle({fontSize:'100px'});
|
||||
assertEqual('100px', $('blah').getStyle('font-size'));
|
||||
transformation.play();
|
||||
wait(700, function(){
|
||||
assertEqual('30px', $('blah').getStyle('font-size'));
|
||||
|
||||
new Effect.Transform([
|
||||
{ 'blah': 'color: #80d980; background: #208020' }
|
||||
],{ duration: 1.1 }).play();
|
||||
wait(1500, function(){
|
||||
assertEqual('#80d980', $('blah').getStyle('color').parseColor());
|
||||
assertEqual('#208020', $('blah').getStyle('background-color').parseColor());
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}}
|
||||
|
||||
});
|
||||
|
||||
// ]]>
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
116
javascript/scoluos/test/unit/element_test.html
Executable file
116
javascript/scoluos/test/unit/element_test.html
Executable file
@@ -0,0 +1,116 @@
|
||||
<!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" />
|
||||
<style type="text/css" media="screen">
|
||||
#style_test_1 { color:rgb(0, 0, 255); background-color: rgb(0, 0, 255); }
|
||||
blah { color:rgb(0, 255, 0); }
|
||||
#op2 { opacity:0.5;filter:alpha(opacity=50)progid:DXImageTransform.Microsoft.Blur(strength=10);}
|
||||
#allStyles_1 {font-size: 12px;}
|
||||
#allStyles_2 {opacity:0.5; filter:alpha(opacity=50);}
|
||||
#allStyles_3 {opacity:0.5;}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>script.aculo.us Unit test file</h1>
|
||||
<p>
|
||||
Tests for Element extensions in effects.js
|
||||
</p>
|
||||
|
||||
<!-- Log output -->
|
||||
<div id="testlog"> </div>
|
||||
|
||||
<!-- Test elements follow -->
|
||||
<div id="test_1" class="a bbbbbbbbbbbb cccccccccc dddd"> </div>
|
||||
|
||||
<div id="test_2" class="classA-foobar classB-foobar"> </div> <span> </span>
|
||||
|
||||
<div id="style_test_1" style="display:none;"></div>
|
||||
<div id="style_test_2" class="blah" style="font-size:11px;"></div>
|
||||
|
||||
<div id="style_test_3">blah</div>
|
||||
|
||||
<div id="test_whitespace"> <span> </span>
|
||||
|
||||
|
||||
|
||||
<div><div></div> </div><span> </span>
|
||||
</div>
|
||||
|
||||
<!-- Test Element opacity functions -->
|
||||
<img id="op1" alt="op2" src="icon.png" style="opacity:0.5;filter:alpha(opacity=50)" />
|
||||
<img id="op2" alt="op2" src="icon.png"/>
|
||||
<img id="op3" alt="op3" src="icon.png"/>
|
||||
<img id="op4-ie" alt="op3" src="icon.png" style="filter:alpha(opacity=30)" />
|
||||
|
||||
<!-- Test Element.childrenWithClassName -->
|
||||
<div id="Container" class="moo hoo">
|
||||
<span id="1" class="firstClass">First class</span>
|
||||
<span id="2" class="secondClass">Second class</span>
|
||||
<span id="3" class="firstClass secondClass">First and Second class</span>
|
||||
<span id="4" class="thirdClass">Third class <span id="5" class="firstClass">Nested First class</span></span>
|
||||
|
||||
<div id="collect">1<span class="ignore"><span class="someclass">2</span>3</span><ul><li class="ignore">4</li></ul></div>
|
||||
|
||||
</div>
|
||||
|
||||
<div id="perftest1"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></div>
|
||||
<div id="allStyles_1"></div>
|
||||
<div id="allStyles_2"></div>
|
||||
<div id="allStyles_3"></div>
|
||||
<!-- Tests follow -->
|
||||
<script type="text/javascript" language="javascript" charset="utf-8">
|
||||
// <![CDATA[
|
||||
|
||||
new Test.Unit.Runner({
|
||||
|
||||
testElementCollectTextNodes: function() { with(this) {
|
||||
assertEqual('1234', Element.collectTextNodes('collect'));
|
||||
assert(benchmark(function(){
|
||||
Element.collectTextNodes('collect')
|
||||
},50) < 1000);
|
||||
|
||||
benchmark(function(){
|
||||
Element.collectTextNodes('collect')
|
||||
},10,'Element.collectTextNodes');
|
||||
|
||||
assertEqual('1234', Element.collectTextNodesIgnoreClass('collect', 'somethingcompletelydifferent'));
|
||||
assertEqual('1', $('collect').collectTextNodesIgnoreClass('ignore'));
|
||||
benchmark(function(){
|
||||
Element.collectTextNodesIgnoreClass('collect','ignore')
|
||||
},10,'Element.collectTextNodesIgnoreClass');
|
||||
|
||||
assertEqual('134', Element.collectTextNodesIgnoreClass('collect', 'someclass'));
|
||||
}},
|
||||
|
||||
testVisualEffect: function() { with(this) {
|
||||
assert($('style_test_3') == $('style_test_3').visualEffect('fade'));
|
||||
wait(1500,function(){
|
||||
assert(!$('style_test_3').visible())
|
||||
});
|
||||
}},
|
||||
|
||||
testParseStylePerformance: function() { with(this) {
|
||||
benchmark(function(){
|
||||
"font:12px/15pt Verdana;opacity:0.4;border:4px dotted red".parseStyle();
|
||||
},100);
|
||||
}},
|
||||
|
||||
testGetStyles: function() { with(this) {
|
||||
assertEqual('12px', $('allStyles_1').getStyles().fontSize);
|
||||
assertEqual(1, parseFloat($('allStyles_1').getStyles().opacity));
|
||||
assertEqual(0.5, parseFloat($('allStyles_2').getStyles().opacity));
|
||||
assertEqual(0.5, parseFloat($('allStyles_3').getStyles().opacity));
|
||||
}}
|
||||
|
||||
}, "testlog");
|
||||
// ]]>
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
BIN
javascript/scoluos/test/unit/icon.png
Executable file
BIN
javascript/scoluos/test/unit/icon.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 281 B |
70
javascript/scoluos/test/unit/index.html
Executable file
70
javascript/scoluos/test/unit/index.html
Executable file
@@ -0,0 +1,70 @@
|
||||
<!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 class="navigation">
|
||||
|
||||
<h1>script.aculo.us<br/>Unit Tests</h1>
|
||||
|
||||
<p id="version"></p>
|
||||
|
||||
<script type="text/javascript" language="javascript" charset="utf-8">
|
||||
// <![CDATA[
|
||||
$('version').innerHTML = 'script.aculo.us version '+Scriptaculous.Version+'<br/>Prototype version ' + Prototype.Version;
|
||||
// ]]>
|
||||
</script>
|
||||
|
||||
<p><a href="http://wiki.script.aculo.us/scriptaculous/show/UnitTesting" target="test">Documentation</a></p>
|
||||
|
||||
<h2>scriptaculous.js</h2>
|
||||
<ul>
|
||||
<li><a href="loading_test.html" target="test">Dynamic loading test</a></li>
|
||||
</ul>
|
||||
|
||||
<h2>effects.js</h2>
|
||||
<ul>
|
||||
<li><a href="effects_test.html" target="test">Effects test</a></li>
|
||||
<li><a href="string_test.html" target="test">String test</a></li>
|
||||
<li><a href="element_test.html" target="test">Element extensions test</a></li>
|
||||
<li><a href="position_clone_test.html" target="test">Position.clone test</a></li>
|
||||
</ul>
|
||||
|
||||
<h2>dragdrop.js</h2>
|
||||
<ul>
|
||||
<li><a href="dragdrop_test.html" target="test">Drag & Drop test</a></li>
|
||||
<li><a href="sortable_test.html" target="test">Sortable test</a></li>
|
||||
</ul>
|
||||
|
||||
<h2>builder.js</h2>
|
||||
<ul>
|
||||
<li><a href="builder_test.html" target="test">Builder test</a></li>
|
||||
</ul>
|
||||
|
||||
<h2>controls.js</h2>
|
||||
<ul>
|
||||
<li><a href="ajax_autocompleter_test.html" target="test">Ajax.Autocompleter test</a></li>
|
||||
<li><a href="ajax_inplaceeditor_test.html" target="test">Ajax.InPlaceEditor test</a></li>
|
||||
<li>Note: unit tests work on Firefox only. The controls themselves are fully supported on IE6+, Firefox and Safari.</li>
|
||||
</ul>
|
||||
|
||||
<h2>slider.js</h2>
|
||||
<ul>
|
||||
<li><a href="slider_test.html" target="test">Control.Slider test</a></li>
|
||||
</ul>
|
||||
|
||||
|
||||
<h2>unittest.js</h2>
|
||||
<ul>
|
||||
<li><a href="unittest_test.html" target="test">Unittest test</a></li>
|
||||
<li><a href="bdd_test.html" target="test">BDD test</a></li>
|
||||
</ul>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
41
javascript/scoluos/test/unit/loading_test.html
Executable file
41
javascript/scoluos/test/unit/loading_test.html
Executable file
@@ -0,0 +1,41 @@
|
||||
<!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?load=effects,dragdrop" 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>
|
||||
Test dynamic loading in scriptaculous.js
|
||||
</p>
|
||||
|
||||
<!-- Log output -->
|
||||
<div id="testlog"> </div>
|
||||
|
||||
<!-- Tests follow -->
|
||||
<script type="text/javascript" language="javascript" charset="utf-8">
|
||||
// <![CDATA[
|
||||
|
||||
new Test.Unit.Runner({
|
||||
|
||||
testDynamicLoading: function() { with(this) {
|
||||
|
||||
// not loaded: controls
|
||||
assertNull(Ajax.Autocompleter || null);
|
||||
assertNull(Form.Element.DelayedObserver || null);
|
||||
|
||||
// we loading dragdrop
|
||||
assertNotNull(Draggable || null);
|
||||
}}
|
||||
|
||||
}, "testlog");
|
||||
// ]]>
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
312
javascript/scoluos/test/unit/position_clone_test.html
Executable file
312
javascript/scoluos/test/unit/position_clone_test.html
Executable file
@@ -0,0 +1,312 @@
|
||||
<!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 Postion.clone (to be moved to Prototype)
|
||||
</p>
|
||||
|
||||
<!-- Log output -->
|
||||
<div id="testlog"> </div>
|
||||
|
||||
<!-- Tests follow -->
|
||||
<script type="text/javascript" language="javascript" charset="utf-8">
|
||||
// <![CDATA[
|
||||
|
||||
function prepareTarget(contained, position1, position2) {
|
||||
var target;
|
||||
if($('target_div')) Element.remove('target_div');
|
||||
if($('container_div')) Element.remove('container_div');
|
||||
if(contained) {
|
||||
target = Builder.node('div',
|
||||
{id: 'container_div', style: 'position:' + position1},
|
||||
[Builder.node('div', {id: 'target_div', style: 'position: ' +position2})]);
|
||||
} else {
|
||||
target = Builder.node('div',
|
||||
{id: 'target_div', style: 'position:' + position1}, '456');
|
||||
}
|
||||
document.body.appendChild(target);
|
||||
Position.clone($('source_div'),$('target_div'));
|
||||
}
|
||||
|
||||
function prepareTargetHidden(contained, position1, position2) {
|
||||
var target;
|
||||
if($('target_div')) Element.remove('target_div');
|
||||
if($('container_div')) Element.remove('container_div');
|
||||
if(contained) {
|
||||
target = Builder.node('div',
|
||||
{id: 'container_div', style: 'position:' + position1},
|
||||
[Builder.node('div', {id: 'target_div', style: 'display:none; position: ' +position2})]);
|
||||
} else {
|
||||
target = Builder.node('div',
|
||||
{id: 'target_div', style: 'display:none; position:' + position1}, '456');
|
||||
}
|
||||
document.body.appendChild(target);
|
||||
Position.clone($('source_div'),$('target_div'));
|
||||
Element.show($('target_div'));
|
||||
}
|
||||
|
||||
new Test.Unit.Runner({
|
||||
|
||||
teardown: function() {
|
||||
Element.remove($('source_div'));
|
||||
},
|
||||
|
||||
testPositionCloneFromAbsolute: function() { with(this) {
|
||||
var source = Builder.node('div',
|
||||
{id: 'source_div', style: 'position:absolute; top:20px; left:120px; width:100px; height:50px;'}, '123');
|
||||
document.body.appendChild(source);
|
||||
var expected = Object.inspect([120, 20]);
|
||||
assertEqual(expected, Object.inspect(Position.page($('source_div'))));
|
||||
|
||||
prepareTarget(false, 'absolute');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to absolute BODY child");
|
||||
|
||||
prepareTarget(false, 'fixed');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to fixed BODY child");
|
||||
|
||||
prepareTarget(true, 'absolute', 'absolute');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to absolute child of absolute BODY child");
|
||||
|
||||
prepareTarget(true, 'absolute', 'fixed');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to fixed child of absolute BODY child");
|
||||
|
||||
prepareTarget(true, 'relative', 'absolute');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to absolute child of relative BODY child");
|
||||
|
||||
prepareTarget(true, 'relative', 'fixed');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to fixed child of relative BODY child");
|
||||
|
||||
prepareTarget(true, 'static', 'absolute');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to absolute child of static BODY child");
|
||||
|
||||
prepareTarget(true, 'static', 'fixed');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to fixed child of static BODY child");
|
||||
}},
|
||||
|
||||
testPositionCloneFromRelative: function() { with(this) {
|
||||
var source = Builder.node('div',
|
||||
{id: 'source_div', style: 'position:relative; top:20px; left:120px; width:100px; height:50px;'}, '123');
|
||||
document.body.appendChild(source);
|
||||
var expected = Object.inspect(Position.page($('source_div')));
|
||||
assertEqual(expected, Object.inspect(Position.page($('source_div'))));
|
||||
|
||||
prepareTarget(false, 'absolute');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to absolute BODY child");
|
||||
|
||||
prepareTarget(false, 'fixed');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to fixed BODY child");
|
||||
|
||||
prepareTarget(true, 'absolute', 'absolute');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to absolute child of absolute BODY child");
|
||||
|
||||
prepareTarget(true, 'absolute', 'fixed');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to fixed child of absolute BODY child");
|
||||
|
||||
prepareTarget(true, 'relative', 'absolute');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to absolute child of relative BODY child");
|
||||
|
||||
prepareTarget(true, 'relative', 'fixed');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to fixed child of relative BODY child");
|
||||
|
||||
prepareTarget(true, 'static', 'absolute');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to absolute child of static BODY child");
|
||||
|
||||
prepareTarget(true, 'static', 'fixed');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to fixed child of static BODY child");
|
||||
}},
|
||||
|
||||
testPositionCloneFromStatic: function() { with(this) {
|
||||
var source = Builder.node('div',
|
||||
{id: 'source_div', style: 'top:20px; left:120px; width:100px; height:50px;'}, '123');
|
||||
document.body.appendChild(source);
|
||||
var expected = Object.inspect(Position.page($('source_div')));
|
||||
assertEqual(expected, Object.inspect(Position.page($('source_div'))));
|
||||
|
||||
prepareTarget(false, 'absolute');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to absolute BODY child");
|
||||
|
||||
prepareTarget(false, 'fixed');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to fixed BODY child");
|
||||
|
||||
prepareTarget(true, 'absolute', 'absolute');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to absolute child of absolute BODY child");
|
||||
|
||||
prepareTarget(true, 'absolute', 'fixed');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to fixed child of absolute BODY child");
|
||||
|
||||
prepareTarget(true, 'relative', 'absolute');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to absolute child of relative BODY child");
|
||||
|
||||
prepareTarget(true, 'relative', 'fixed');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to fixed child of relative BODY child");
|
||||
|
||||
prepareTarget(true, 'static', 'absolute');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to absolute child of static BODY child");
|
||||
|
||||
prepareTarget(true, 'static', 'fixed');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to fixed child of static BODY child");
|
||||
}},
|
||||
|
||||
testPositionCloneFromAbsoluteWithHiddenTarget: function() { with(this) {
|
||||
var source = Builder.node('div',
|
||||
{id: 'source_div', style: 'position:absolute; top:20px; left:120px; width:100px; height:50px;'}, '123');
|
||||
document.body.appendChild(source);
|
||||
var expected = Object.inspect([120, 20]);
|
||||
assertEqual(expected, Object.inspect(Position.page($('source_div'))));
|
||||
|
||||
prepareTargetHidden(false, 'absolute');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to absolute BODY child");
|
||||
|
||||
prepareTargetHidden(false, 'fixed');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to fixed BODY child");
|
||||
|
||||
prepareTargetHidden(true, 'absolute', 'absolute');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to absolute child of absolute BODY child");
|
||||
|
||||
prepareTargetHidden(true, 'absolute', 'fixed');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to fixed child of absolute BODY child");
|
||||
|
||||
prepareTargetHidden(true, 'relative', 'absolute');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to absolute child of relative BODY child");
|
||||
|
||||
prepareTargetHidden(true, 'relative', 'fixed');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to fixed child of relative BODY child");
|
||||
|
||||
prepareTargetHidden(true, 'static', 'absolute');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to absolute child of static BODY child");
|
||||
|
||||
prepareTargetHidden(true, 'static', 'fixed');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to fixed child of static BODY child");
|
||||
}},
|
||||
|
||||
testPositionCloneFromRelativeWithHiddenTarget: function() { with(this) {
|
||||
var source = Builder.node('div',
|
||||
{id: 'source_div', style: 'position:relative; top:20px; left:120px; width:100px; height:50px;'}, '123');
|
||||
document.body.appendChild(source);
|
||||
var expected = Object.inspect(Position.page($('source_div')));
|
||||
assertEqual(expected, Object.inspect(Position.page($('source_div'))));
|
||||
|
||||
prepareTargetHidden(false, 'absolute');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to absolute BODY child");
|
||||
|
||||
prepareTargetHidden(false, 'fixed');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to fixed BODY child");
|
||||
|
||||
prepareTargetHidden(true, 'absolute', 'absolute');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to absolute child of absolute BODY child");
|
||||
|
||||
prepareTargetHidden(true, 'absolute', 'fixed');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to fixed child of absolute BODY child");
|
||||
|
||||
prepareTargetHidden(true, 'relative', 'absolute');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to absolute child of relative BODY child");
|
||||
|
||||
prepareTargetHidden(true, 'relative', 'fixed');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to fixed child of relative BODY child");
|
||||
|
||||
prepareTargetHidden(true, 'static', 'absolute');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to absolute child of static BODY child");
|
||||
|
||||
prepareTargetHidden(true, 'static', 'fixed');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to fixed child of static BODY child");
|
||||
}},
|
||||
|
||||
testPositionCloneFromStaticWithHiddenTarget: function() { with(this) {
|
||||
var source = Builder.node('div',
|
||||
{id: 'source_div', style: 'top:20px; left:120px; width:100px; height:50px;'}, '123');
|
||||
document.body.appendChild(source);
|
||||
var expected = Object.inspect(Position.page($('source_div')));
|
||||
assertEqual(expected, Object.inspect(Position.page($('source_div'))));
|
||||
|
||||
prepareTargetHidden(false, 'absolute');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to absolute BODY child");
|
||||
|
||||
prepareTargetHidden(false, 'fixed');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to fixed BODY child");
|
||||
|
||||
prepareTargetHidden(true, 'absolute', 'absolute');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to absolute child of absolute BODY child");
|
||||
|
||||
prepareTargetHidden(true, 'absolute', 'fixed');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to fixed child of absolute BODY child");
|
||||
|
||||
prepareTargetHidden(true, 'relative', 'absolute');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to absolute child of relative BODY child");
|
||||
|
||||
prepareTargetHidden(true, 'relative', 'fixed');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to fixed child of relative BODY child");
|
||||
|
||||
prepareTargetHidden(true, 'static', 'absolute');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to absolute child of static BODY child");
|
||||
|
||||
prepareTargetHidden(true, 'static', 'fixed');
|
||||
assertEqual(expected, Object.inspect(Position.page($('target_div'))),
|
||||
"Clone to fixed child of static BODY child");
|
||||
}}
|
||||
|
||||
});
|
||||
|
||||
// ]]>
|
||||
</script>
|
||||
|
||||
<!-- Test elements will be inserted after this -->
|
||||
|
||||
</body>
|
||||
</html>
|
||||
437
javascript/scoluos/test/unit/slider_test.html
Executable file
437
javascript/scoluos/test/unit/slider_test.html
Executable file
@@ -0,0 +1,437 @@
|
||||
<!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 slider.js
|
||||
</p>
|
||||
|
||||
<div id="track1" style="width:200px;background-color:#aaa;height:5px;">
|
||||
<div id="handle1" style="width:15px;height:25px;background-color:#f00;"> </div>
|
||||
</div>
|
||||
|
||||
<div id="track2-vertical" style="height:100px;background-color:#aaa;width:5px;">
|
||||
<div id="handle2-vertical" style="width:25px;height:10px;background-color:#f00;"> </div>
|
||||
</div>
|
||||
|
||||
<div id="track2-horizontal" style="height:5px;background-color:#aaa;width:100px;">
|
||||
<div id="handle2-horizontal" style="width:10px;height:25px;background-color:#f00;"> </div>
|
||||
</div>
|
||||
|
||||
<div id="track3" style="width:300px;background-color:#cfb;height:30px;">
|
||||
<span id="handle3-1">1</span>
|
||||
<span id="handle3-2">2</span>
|
||||
<span id="handle3-3">3</span>
|
||||
</div>
|
||||
|
||||
<div id="track4" style="width:300px;position:relative;background-color:#cbf;height:30px;">
|
||||
<span id="handle4-1" style="top:0;left:0;position:absolute;background-color:#f00;">1</span>
|
||||
<span id="handle4-2" style="top:0;left:0;position:absolute;background-color:#0f0;">2</span>
|
||||
<span id="handle4-3" style="top:0;left:0;position:absolute;background-color:#00f;">3</span>
|
||||
</div>
|
||||
|
||||
<div id="track5" style="width:300px;background-color:#cbf;height:30px;position:relative;z-index:0;">
|
||||
<div id="handle5-1" style="top:0;left:0;position:absolute;background-color:#f00;z-index:2">1</div>
|
||||
<div id="handle5-2" style="top:0;left:0;position:absolute;background-color:#0f0;z-index:2">2</div>
|
||||
<div id="handle5-3" style="top:0;left:0;position:absolute;background-color:#00f;z-index:2">3</div>
|
||||
|
||||
<div id="span5-1" style="top:0;left:0;position:absolute;background-color:#000;height:20px;z-index:1;"> </div>
|
||||
<div id="span5-2" style="top:0;left:0;position:absolute;background-color:#444;height:20px;z-index:1;"> </div>
|
||||
</div>
|
||||
|
||||
<div id="track6" style="width:20px;background-color:#cbf;height:100px;position:relative;z-index:0;">
|
||||
<div id="handle6-1" style="top:0;left:0;height:13px;position:absolute;background-color:#f00;z-index:2">1</div>
|
||||
<div id="handle6-2" style="top:0;left:0;height:13px;position:absolute;background-color:#0f0;z-index:2">2</div>
|
||||
<div id="handle6-3" style="top:0;left:0;height:13px;position:absolute;background-color:#00f;z-index:2">3</div>
|
||||
|
||||
<div id="span6-1" style="top:0;left:0;position:absolute;background-color:#000;width:20px;z-index:1;"> </div>
|
||||
<div id="span6-2" style="top:0;left:0;position:absolute;background-color:#444;width:20px;z-index:1;"> </div>
|
||||
</div>
|
||||
|
||||
<div id="track7" style="width:200px;background-color:#cbf;height:30px;position:relative;z-index:0;">
|
||||
<div id="handle7-1" style="top:0;left:0;position:absolute;background-color:#f88;z-index:2">1</div>
|
||||
<div id="handle7-2" style="top:0;left:0;position:absolute;background-color:#8f8;z-index:2">2</div>
|
||||
<div id="handle7-3" style="top:0;left:0;position:absolute;background-color:#88f;z-index:2">3</div>
|
||||
|
||||
<div id="span7-1" style="top:0;left:0;position:absolute;background-color:#000;height:20px;z-index:1;"> </div>
|
||||
<div id="span7-2" style="top:0;left:0;position:absolute;background-color:#444;height:20px;z-index:1;"> </div>
|
||||
|
||||
<div id="span7-start" style="top:0;left:0;position:absolute;background-color:#f00;height:20px;z-index:1;"> </div>
|
||||
<div id="span7-end" style="top:0;left:0;position:absolute;background-color:#00f;height:20px;z-index:1;"> </div>
|
||||
</div>
|
||||
|
||||
|
||||
<div id="debug"> </div>
|
||||
|
||||
<!-- Log output -->
|
||||
<div id="testlog"> </div>
|
||||
|
||||
<!-- Tests follow -->
|
||||
<script type="text/javascript" language="javascript" charset="utf-8">
|
||||
// <![CDATA[
|
||||
var globalValue;
|
||||
|
||||
new Test.Unit.Runner({
|
||||
|
||||
testSliderBasics: function() { with(this) {
|
||||
var slider = new Control.Slider('handle1', 'track1');
|
||||
assertInstanceOf(Control.Slider, slider);
|
||||
|
||||
assertEqual('horizontal', slider.axis);
|
||||
assertEqual(false, slider.disabled);
|
||||
assertEqual(0, slider.value);
|
||||
|
||||
slider.dispose();
|
||||
}},
|
||||
|
||||
testSliderValues: function() { with(this) {
|
||||
['horizontal', 'vertical'].each( function(axis) {
|
||||
var slider = new Control.Slider('handle2-'+axis, 'track2-'+axis, {values:[0.2,0.4,0.6,0.8,1],axis:axis});
|
||||
assertEqual(axis, slider.axis);
|
||||
assertEqual(0.2, slider.value);
|
||||
|
||||
slider.setValue(0.35);
|
||||
assertEqual(0.4, slider.value);
|
||||
|
||||
slider.setValueBy(0.1);
|
||||
assertEqual(0.6, slider.value);
|
||||
slider.setValueBy(-0.6);
|
||||
assertEqual(0.2, slider.value);
|
||||
|
||||
slider.setValue(1);
|
||||
assertEqual(1, slider.value);
|
||||
|
||||
slider.setValue(-2);
|
||||
assertEqual(0.2, slider.value);
|
||||
|
||||
slider.setValue(55555);
|
||||
assertEqual(1, slider.value);
|
||||
|
||||
// leave active to be able to play around with the sliders
|
||||
// slider.dispose();
|
||||
});
|
||||
assertEqual("90px", $('handle2-horizontal').style.left);
|
||||
assertEqual("90px", $('handle2-vertical').style.top);
|
||||
}},
|
||||
|
||||
testSliderInitialValues: function() { with(this) {
|
||||
var slider = new Control.Slider('handle1', 'track1',{sliderValue:0.5});
|
||||
assertEqual(0.5, slider.value);
|
||||
|
||||
var slider = new Control.Slider(['handle4-1','handle4-2','handle4-3'], 'track4', {
|
||||
sliderValue:[50,145,170],
|
||||
values:[50,150,160,170,180],
|
||||
range:$R(50,180)
|
||||
});
|
||||
assertEqual(50, slider.value);
|
||||
assertEqual(50, slider.values[0]);
|
||||
assertEqual(150, slider.values[1]);
|
||||
assertEqual(170, slider.values[2]);
|
||||
slider.dispose();
|
||||
|
||||
var slider = new Control.Slider(['handle4-1','handle4-2','handle4-3'], 'track4', {
|
||||
sliderValue:[50,145,170],
|
||||
values:[50,150,160,170,180]
|
||||
});
|
||||
assertEqual(50, slider.value);
|
||||
assertEqual(50, slider.values[0]);
|
||||
assertEqual(150, slider.values[1]);
|
||||
assertEqual(170, slider.values[2]);
|
||||
slider.dispose();
|
||||
|
||||
var slider = new Control.Slider(['handle4-1','handle4-2','handle4-3'], 'track4', {
|
||||
restricted:true,
|
||||
sliderValue:[50,145,170],
|
||||
values:[50,150,160,170,180]
|
||||
});
|
||||
assertEqual(50, slider.value);
|
||||
assertEqual(50, slider.values[0]);
|
||||
assertEqual(150, slider.values[1]);
|
||||
assertEqual(170, slider.values[2]);
|
||||
slider.dispose();
|
||||
}},
|
||||
|
||||
testSliderOnChange: function() { with(this) {
|
||||
var slider = new Control.Slider('handle1', 'track1', { onChange:function(v){ globalValue = v; } });
|
||||
slider.setValue(1);
|
||||
assert(1, globalValue);
|
||||
assert(1, slider.value);
|
||||
|
||||
slider.setDisabled();
|
||||
slider.setValue(0.5);
|
||||
assert(1, globalValue);
|
||||
assert(1, slider.value);
|
||||
|
||||
slider.setEnabled();
|
||||
slider.setValue(0.2);
|
||||
assert(0.2, globalValue);
|
||||
assert(0.2, slider.value);
|
||||
|
||||
// s.event should be null if setValue is called from script
|
||||
var slider = new Control.Slider(['handle3-1','handle3-2','handle3-3'], 'track3', {
|
||||
onChange:function(v, s){ if(!s.event) globalValue = v; } });
|
||||
|
||||
slider.setValue(0.5,1);
|
||||
assertEqual([0,0.5,0].inspect(), globalValue.inspect());
|
||||
assert(!slider.event);
|
||||
|
||||
slider.dispose();
|
||||
}},
|
||||
|
||||
testMultipleHandles: function() { with(this) {
|
||||
var slider = new Control.Slider(['handle3-1','handle3-2','handle3-3'], 'track3', {range:$R(0,300)});
|
||||
assertInstanceOf(Control.Slider, slider);
|
||||
|
||||
slider.setValue(20, 0);
|
||||
slider.setValue(50, 1);
|
||||
slider.setValue(70, 2);
|
||||
assertEqual(20, slider.values[0]);
|
||||
assertEqual(50, slider.values[1]);
|
||||
assertEqual(70, slider.values[2]);
|
||||
assertEqual("20px", slider.handles[0].style.left);
|
||||
assertEqual("49px", slider.handles[1].style.left);
|
||||
assertEqual("68px", slider.handles[2].style.left);
|
||||
|
||||
// should change last manipulated handled by -10,
|
||||
// so check for handle with idx 2
|
||||
slider.setValueBy(-10);
|
||||
assertEqual(60, slider.values[2]);
|
||||
|
||||
slider.setValueBy(10, 0);
|
||||
assertEqual(20, slider.values[0]);
|
||||
slider.setValueBy(10, 1);
|
||||
assertEqual(60, slider.values[1]);
|
||||
slider.setValueBy(20, slider.activeHandleIdx);
|
||||
assertEqual(80, slider.values[1]);
|
||||
}},
|
||||
|
||||
testMultipleHandlesValues: function() { with(this) {
|
||||
var slider = new Control.Slider(['handle4-1','handle4-2','handle4-3'], 'track4', {values:[50,150,160,170,180],range:$R(50,180)});
|
||||
assertInstanceOf(Control.Slider, slider);
|
||||
|
||||
slider.setValue(20, 0);
|
||||
slider.setValue(150, 2);
|
||||
slider.setValue(179, 1);
|
||||
|
||||
assertEqual(50, slider.values[0]);
|
||||
assertEqual(150, slider.values[2]);
|
||||
assertEqual(180, slider.values[1]);
|
||||
|
||||
assertEqual("0px", slider.handles[0].style.left);
|
||||
assertEqual("225px", slider.handles[2].style.left);
|
||||
assertEqual("293px", slider.handles[1].style.left);
|
||||
|
||||
assertEqual($R(50,150).inspect(), slider.getRange().inspect());
|
||||
assertEqual(30, slider.getRange(1).end-slider.getRange(1).start);
|
||||
}},
|
||||
|
||||
testMultipleHandlesSpans: function() { with(this) {
|
||||
var slider = new Control.Slider(['handle5-1','handle5-2','handle5-3'], 'track5',
|
||||
{spans:['span5-1','span5-2'],range:$R(0,300)});
|
||||
assertInstanceOf(Control.Slider, slider);
|
||||
|
||||
slider.setValue(20, 0);
|
||||
slider.setValue(100, 1);
|
||||
slider.setValue(150, 2);
|
||||
|
||||
assertEqual("20px", $('span5-1').style.left);
|
||||
assertEqual("78px", $('span5-1').style.width);
|
||||
assertEqual("98px", $('span5-2').style.left);
|
||||
assertEqual("49px", $('span5-2').style.width);
|
||||
|
||||
slider.setValue(30, 0);
|
||||
slider.setValue(110, 1);
|
||||
slider.setValue(90, 2);
|
||||
|
||||
assertEqual("29px", $('span5-1').style.left);
|
||||
assertEqual("59px", $('span5-1').style.width);
|
||||
assertEqual("88px", $('span5-2').style.left);
|
||||
assertEqual("20px", $('span5-2').style.width);
|
||||
|
||||
slider.dispose();
|
||||
}},
|
||||
|
||||
testMultipleHandlesSpansStartEnd: function() { with(this) {
|
||||
var slider = new Control.Slider(['handle7-1','handle7-2','handle7-3'], 'track7',
|
||||
{ spans:['span7-1','span7-2'],
|
||||
startSpan:'span7-start',
|
||||
endSpan:'span7-end',
|
||||
range:$R(0,200) });
|
||||
assertInstanceOf(Control.Slider, slider);
|
||||
|
||||
slider.setValue(20, 0);
|
||||
slider.setValue(100, 1);
|
||||
slider.setValue(150, 2);
|
||||
assertEqual("0px", $('span7-start').style.left);
|
||||
assertEqual("19px", $('span7-start').style.width);
|
||||
assertEqual("145px", $('span7-end').style.left);
|
||||
assertEqual("48px", $('span7-end').style.width);
|
||||
|
||||
slider.dispose();
|
||||
}},
|
||||
|
||||
testSingleHandleSpansStartEnd: function() { with(this) {
|
||||
var slider = new Control.Slider('handle7-1', 'track7',
|
||||
{ spans:['span7-1','span7-2'],
|
||||
startSpan:'span7-start',
|
||||
endSpan:'span7-end',
|
||||
range:$R(0,200) });
|
||||
assertInstanceOf(Control.Slider, slider);
|
||||
|
||||
slider.setValue(20, 0);
|
||||
assertEqual("0px", $('span7-start').style.left);
|
||||
assertEqual("19px", $('span7-start').style.width);
|
||||
assertEqual("19px", $('span7-end').style.left);
|
||||
assertEqual("174px", $('span7-end').style.width);
|
||||
|
||||
slider.dispose();
|
||||
}},
|
||||
|
||||
testMultipleHandlesStyles: function() { with(this) {
|
||||
var slider = new Control.Slider(['handle7-1','handle7-2','handle7-3'], 'track7',
|
||||
{ spans:['span7-1','span7-2'],
|
||||
startSpan:'span7-start',
|
||||
endSpan:'span7-end',
|
||||
range:$R(0,200) });
|
||||
assertInstanceOf(Control.Slider, slider);
|
||||
assert(Element.hasClassName('handle7-1','selected'));
|
||||
assert(!Element.hasClassName('handle7-2','selected'));
|
||||
assert(!Element.hasClassName('handle7-3','selected'));
|
||||
|
||||
slider.setValue(20, 0);
|
||||
assert(Element.hasClassName('handle7-1','selected'));
|
||||
assert(!Element.hasClassName('handle7-2','selected'));
|
||||
assert(!Element.hasClassName('handle7-3','selected'));
|
||||
|
||||
slider.setValue(100, 1);
|
||||
assert(!Element.hasClassName('handle7-1','selected'));
|
||||
assert(Element.hasClassName('handle7-2','selected'));
|
||||
assert(!Element.hasClassName('handle7-3','selected'));
|
||||
|
||||
slider.setValue(150, 2);
|
||||
assert(!Element.hasClassName('handle7-1','selected'));
|
||||
assert(!Element.hasClassName('handle7-2','selected'));
|
||||
assert(Element.hasClassName('handle7-3','selected'));
|
||||
|
||||
slider.dispose();
|
||||
}},
|
||||
|
||||
testMultipleHandlesSpansRestricted: function() { with(this) {
|
||||
var slider = new Control.Slider(['handle5-1','handle5-2','handle5-3'], 'track5',
|
||||
{restricted:true,spans:['span5-1','span5-2'],range:$R(0,300)});
|
||||
assertInstanceOf(Control.Slider, slider);
|
||||
|
||||
slider.setValue(20, 0);
|
||||
slider.setValue(100, 1);
|
||||
slider.setValue(150, 2);
|
||||
assertEqual(0, slider.values[0]);
|
||||
assertEqual(0, slider.values[1]);
|
||||
assertEqual(150, slider.values[2]);
|
||||
|
||||
slider.setValue(150, 2);
|
||||
slider.setValue(100, 1);
|
||||
slider.setValue(20, 0);
|
||||
assertEqual(20, slider.values[0]);
|
||||
assertEqual(100, slider.values[1]);
|
||||
assertEqual(150, slider.values[2]);
|
||||
assertEqual("20px", $('span5-1').style.left);
|
||||
assertEqual("78px", $('span5-1').style.width);
|
||||
assertEqual("98px", $('span5-2').style.left);
|
||||
assertEqual("49px", $('span5-2').style.width);
|
||||
|
||||
slider.setValue(30, 0);
|
||||
slider.setValue(110, 1);
|
||||
slider.setValue(90, 2);
|
||||
assertEqual(30, slider.values[0]);
|
||||
assertEqual(110, slider.values[1]);
|
||||
assertEqual(110, slider.values[2], '???');
|
||||
|
||||
assertEqual("29px", $('span5-1').style.left);
|
||||
assertEqual("78px", $('span5-1').style.width);
|
||||
assertEqual("107px", $('span5-2').style.left);
|
||||
assertEqual("0px", $('span5-2').style.width);
|
||||
|
||||
slider.dispose();
|
||||
}},
|
||||
|
||||
testMultipleHandlesSpansVertical: function() { with(this) {
|
||||
var slider = new Control.Slider(['handle6-1','handle6-2','handle6-3'], 'track6', {axis:'vertical',spans:['span6-1','span6-2'],range:$R(0,100)});
|
||||
assertInstanceOf(Control.Slider, slider);
|
||||
|
||||
slider.setValue(20, 0);
|
||||
slider.setValue(80, 1);
|
||||
slider.setValue(90, 2);
|
||||
|
||||
assertEqual("17px", $('span6-1').style.top);
|
||||
assertEqual("52px", $('span6-1').style.height);
|
||||
assertEqual("70px", $('span6-2').style.top);
|
||||
assertEqual("9px", $('span6-2').style.height);
|
||||
|
||||
slider.setValue(30, 0);
|
||||
slider.setValue(20, 1);
|
||||
slider.setValue(95, 2);
|
||||
|
||||
assertEqual("17px", $('span6-1').style.top);
|
||||
assertEqual("9px", $('span6-1').style.height);
|
||||
assertEqual("26px", $('span6-2').style.top);
|
||||
assertEqual("57px", $('span6-2').style.height);
|
||||
}},
|
||||
|
||||
testRange: function() { with(this) {
|
||||
var slider = new Control.Slider('handle1','track1');
|
||||
assertEqual(0, slider.value);
|
||||
slider.setValue(1);
|
||||
assertEqual("185px", $('handle1').style.left);
|
||||
slider.dispose();
|
||||
|
||||
var slider = new Control.Slider('handle1','track1',{range:$R(10,20)});
|
||||
assertEqual(10, slider.value);
|
||||
assertEqual("0px", $('handle1').style.left);
|
||||
slider.setValue(15);
|
||||
assertEqual("93px", $('handle1').style.left);
|
||||
slider.setValue(20);
|
||||
assertEqual("185px", $('handle1').style.left);
|
||||
slider.dispose();
|
||||
}},
|
||||
|
||||
// test for #3732
|
||||
testRangeValues: function() { with(this) {
|
||||
// test for non-zero starting range
|
||||
var slider = new Control.Slider('handle1','track1',{
|
||||
range:$R(1,3), values:[1,2,3]
|
||||
});
|
||||
assertEqual(1, slider.value);
|
||||
assertEqual("0px", $('handle1').style.left);
|
||||
slider.setValue(2);
|
||||
assertEqual("93px", $('handle1').style.left);
|
||||
slider.setValue(3);
|
||||
assertEqual("185px", $('handle1').style.left);
|
||||
slider.dispose();
|
||||
|
||||
// test zero-starting range
|
||||
var slider = new Control.Slider('handle1','track1',{
|
||||
range:$R(0,2), values:[0,1,2]
|
||||
});
|
||||
assertEqual(0, slider.value);
|
||||
assertEqual("0px", $('handle1').style.left);
|
||||
slider.setValue(1);
|
||||
assertEqual("93px", $('handle1').style.left);
|
||||
slider.setValue(2);
|
||||
assertEqual("185px", $('handle1').style.left);
|
||||
slider.dispose();
|
||||
}}
|
||||
|
||||
}, "testlog");
|
||||
// ]]>
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
205
javascript/scoluos/test/unit/sortable_test.html
Executable file
205
javascript/scoluos/test/unit/sortable_test.html
Executable file
@@ -0,0 +1,205 @@
|
||||
<!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>
|
||||
Test of sortable functions in dragdrop.js
|
||||
</p>
|
||||
|
||||
<!-- Log output -->
|
||||
<div id="testlog"> </div>
|
||||
|
||||
|
||||
<ul id="sortable1">
|
||||
<li id="item_1" class="a">item 1</li>
|
||||
<li id="item_2" class="c b">item 1<ul><li id="item_99">!!!</li></ul></li>
|
||||
<li id="item_3" class="b">item 1</li>
|
||||
<li id="item_xy" class="x y">item 1</li>
|
||||
<!-- a comment -->
|
||||
</ul>
|
||||
|
||||
<div id="sortable2">
|
||||
<div id="item_4">item 4</div> <div id="item_5">item 5</div>
|
||||
<img src="icon.png" alt="img"/>
|
||||
<!-- a comment -->
|
||||
</div>
|
||||
|
||||
<div id="sortable3">
|
||||
|
||||
</div>
|
||||
|
||||
<!--
|
||||
By default, _ is the only valid seperator
|
||||
for the DOM ids. Complex element ids as in
|
||||
the form of "some_element_id_1" should also
|
||||
be parsed correctly (only the last part should
|
||||
be serialized)
|
||||
-->
|
||||
<ul id="sortable_complex">
|
||||
<li id="a_b_item_1" class="a">item 1</li>
|
||||
<li id="ab_item_2" class="c b">item 1
|
||||
<ul>
|
||||
<li id="item_99">!!!</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li id="a-b-item_3z_33" class="b">item 1</li>
|
||||
<li id="a-item-xy" class="x y">item 1</li>
|
||||
<!-- a comment -->
|
||||
</ul>
|
||||
|
||||
|
||||
<ul id="sortable_specialcreate">
|
||||
<li id="y1item">item 1</li>
|
||||
<li id="y2item">item 1<ul><li id="yyyy9928282hjhd">!!!</li></ul></li>
|
||||
</ul>
|
||||
|
||||
<ul id="sortable_specialformat">
|
||||
<li id="x1item">item 1</li>
|
||||
<li id="x2item">item 1<ul><li id="xxxxx88888item">!!!</li></ul></li>
|
||||
</ul>
|
||||
|
||||
<!-- Tests follow -->
|
||||
<script type="text/javascript" language="javascript" charset="utf-8">
|
||||
// <![CDATA[
|
||||
|
||||
new Test.Unit.Runner({
|
||||
|
||||
setup: function() { with(this) {
|
||||
Sortable.create('sortable1',{only:['a','b']});
|
||||
Sortable.create('sortable2',{tag:'div'});
|
||||
Sortable.create('sortable3');
|
||||
Sortable.create('sortable_specialcreate',{ format:/(\d+)/ });
|
||||
Sortable.create('sortable_specialformat');
|
||||
Sortable.create('sortable_complex');
|
||||
}},
|
||||
|
||||
teardown: function() { with(this) {
|
||||
Sortable.destroy('sortable1');
|
||||
Sortable.destroy('sortable2');
|
||||
Sortable.destroy('sortable3');
|
||||
Sortable.destroy('sortable_specialformat');
|
||||
Sortable.destroy('sortable_specialcreate');
|
||||
Sortable.destroy('sortable_complex');
|
||||
}},
|
||||
|
||||
testSortableSerializeSequenceBasics: function() { with(this) {
|
||||
assertEqual('sortable1[]=1&sortable1[]=2&sortable1[]=3', Sortable.serialize('sortable1'));
|
||||
|
||||
// test empty sortable
|
||||
assertEqual('', Sortable.serialize('sortable3'));
|
||||
assertEnumEqual([], Sortable.sequence('sortable3'));
|
||||
|
||||
Element.remove('item_4');
|
||||
assertEqual('sortable2[]=5', Sortable.serialize('sortable2'));
|
||||
assertEnumEqual(['5'], Sortable.sequence('sortable2'));
|
||||
}},
|
||||
|
||||
testSortableSerializeFormat: function() { with(this) {
|
||||
// should correctly serialize from option given to Sortable.create()
|
||||
assertEqual('sortable_specialcreate[]=1&sortable_specialcreate[]=2',
|
||||
Sortable.serialize('sortable_specialcreate'));
|
||||
|
||||
benchmark(function(){
|
||||
Sortable.serialize('sortable_specialcreate')
|
||||
},1,'Sortable.serialize');
|
||||
|
||||
// test special format given explicitly
|
||||
assertEqual('sortable_specialformat[]=1&sortable_specialformat[]=2',
|
||||
Sortable.serialize('sortable_specialformat', {format:/(\d+)/}));
|
||||
|
||||
// return full id
|
||||
assertEqual('sortable_specialformat[]=x1item&sortable_specialformat[]=x2item',
|
||||
Sortable.serialize('sortable_specialformat', {format:/(.*)/}));
|
||||
|
||||
// test default format given explicitly
|
||||
assertEqual('sortable1[]=1&sortable1[]=2&sortable1[]=3',
|
||||
Sortable.serialize('sortable1',{format:/^[^_]*_(.*)$/}));
|
||||
|
||||
// Ensure default options.format handles longer, more complex list
|
||||
// item IDs
|
||||
assertEqual('sortable_complex[]=1&sortable_complex[]=2&sortable_complex[]=33&sortable_complex[]=',
|
||||
Sortable.serialize('sortable_complex'));
|
||||
}},
|
||||
|
||||
testSortableSerializeRule: function() { with(this) {
|
||||
var ids = ['x','x-y','test_test','x_y_z','x_y-x_z'];
|
||||
ids.each(function(id){
|
||||
assertEqual('1',
|
||||
(id+'_1').match(Sortable.SERIALIZE_RULE)[1]);
|
||||
});
|
||||
|
||||
assertNull('x'.match(Sortable.SERIALIZE_RULE));
|
||||
}},
|
||||
|
||||
testSortableSerializeName: function() { with(this) {
|
||||
assertEqual('dumdidu[]=1&dumdidu[]=2',
|
||||
Sortable.serialize('sortable_specialcreate',{name:'dumdidu'}));
|
||||
}},
|
||||
|
||||
testSortableSequenceFormat: function() { with(this) {
|
||||
// shauld correctly serialize from option given to Sortable.create()
|
||||
assertEnumEqual(['1','2'],
|
||||
Sortable.sequence('sortable_specialcreate'));
|
||||
|
||||
// test special format given explicitly
|
||||
assertEnumEqual(['1','2'],
|
||||
Sortable.sequence('sortable_specialformat', {format:/(\d+)/}));
|
||||
|
||||
// return full id
|
||||
assertEnumEqual(['x1item','x2item'],
|
||||
Sortable.sequence('sortable_specialformat', {format:/(.*)/}));
|
||||
|
||||
// test default format given explicitly
|
||||
assertEnumEqual(['1','2','3'],
|
||||
Sortable.sequence('sortable1',{format:/^[^_]*_(.*)$/}));
|
||||
}},
|
||||
|
||||
testSortableFindElements: function() { with(this) {
|
||||
assertEqual(3, Sortable.findElements($('sortable1'),{tag:'li',only:['a','b']}).length);
|
||||
benchmark(function(){
|
||||
Sortable.findElements($('sortable1'),{tag:'li',only:['a','b']})
|
||||
},1,'Sortable.findElements/1');
|
||||
|
||||
assertEqual(1, Sortable.findElements($('sortable1'),{tag:'li',only:['x']}).length);
|
||||
assertEqual(1, Sortable.findElements($('sortable1'),{tag:'li',only:'a'}).length);
|
||||
assertEqual(2, Sortable.findElements($('sortable1'),{tag:'li',only:'b'}).length);
|
||||
assertEqual(4, Sortable.findElements($('sortable1'),{tag:'li',only:['a','b','x']}).length);
|
||||
}},
|
||||
|
||||
testSortableSetSequence: function() { with(this) {
|
||||
// make sure assigning current sequence is a no-op
|
||||
var o = Sortable.sequence('sortable1');
|
||||
Sortable.setSequence('sortable1', ['1','2','3']);
|
||||
assertEnumEqual(o, Sortable.sequence('sortable1'));
|
||||
|
||||
// check new sequence
|
||||
Sortable.setSequence('sortable1', ['3','2','1']);
|
||||
assertEnumEqual(['3','2','1'], Sortable.sequence('sortable1'));
|
||||
|
||||
// non-default format
|
||||
Sortable.setSequence('sortable_specialformat', ['2','1'], { format:/(\d+)/ });
|
||||
assertEnumEqual(['2','1'], Sortable.sequence('sortable_specialformat'));
|
||||
|
||||
// invalid sequence ids should be ignored
|
||||
Sortable.setSequence('sortable1', ['x', '1', 'y', '2', '3', 'z']);
|
||||
assertEnumEqual(['1', '2', '3'], Sortable.sequence('sortable1'));
|
||||
|
||||
// elements omitted in new sequence should be cropped
|
||||
Sortable.setSequence('sortable1', ['1', '3']);
|
||||
assertEnumEqual(['1', '3'], Sortable.sequence('sortable1'));
|
||||
}}
|
||||
|
||||
}, "testlog");
|
||||
// ]]>
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
71
javascript/scoluos/test/unit/string_test.html
Executable file
71
javascript/scoluos/test/unit/string_test.html
Executable file
@@ -0,0 +1,71 @@
|
||||
<!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 String.prototype extensions in effects.js
|
||||
</p>
|
||||
|
||||
<!-- Log output -->
|
||||
<div id="testlog"> </div>
|
||||
|
||||
<!-- Tests follow -->
|
||||
<script type="text/javascript" language="javascript" charset="utf-8">
|
||||
// <![CDATA[
|
||||
|
||||
new Test.Unit.Runner({
|
||||
|
||||
testStringParseColor: function() { with(this) {
|
||||
assertEqual('#000000', "#000000".parseColor());
|
||||
assertEqual('#000000', "rgb(0,0,0)".parseColor());
|
||||
assertEqual('#000000', "rgb(0, 0, 0)".parseColor());
|
||||
assertEqual('#000000', "#000".parseColor());
|
||||
|
||||
assertEqual('#1', "#1".parseColor());
|
||||
assertEqual('#12', "#12".parseColor());
|
||||
assertEqual('#112233', "#123".parseColor());
|
||||
assertEqual('#1234', "#1234".parseColor());
|
||||
assertEqual('#12345', "#12345".parseColor());
|
||||
assertEqual('#123456', "#123456".parseColor());
|
||||
|
||||
assertEqual('#abcdef', "#aBcDeF".parseColor());
|
||||
assertEqual('#aabbcc', "#aBc".parseColor());
|
||||
|
||||
assertEqual('white', "white".parseColor());
|
||||
assertEqual('#123456', "#123456".parseColor('#000000')); // default to #000000 if not parseable
|
||||
assertEqual('#000000', "white".parseColor('#000000')); // default to #000000 if not parseable
|
||||
|
||||
assertEqual('#ffffff', "rgb(255,255,255)".parseColor());
|
||||
assertEqual('#ff0000', "rgb(255,0,0)".parseColor());
|
||||
assertEqual('#00ff00', "rgb(0,255,0)".parseColor());
|
||||
assertEqual('#0000ff', "rgb(0,0,255)".parseColor());
|
||||
}},
|
||||
|
||||
testStringParseStyle: function() { with(this) {
|
||||
var expected = "#<Hash:{'fontSize': '11px'}>";
|
||||
var expectedMultiple = "#<Hash:{'fontSize': '11px', 'width': '780px'}>";
|
||||
|
||||
assertInspect(expected, "font-size:11px".parseStyle());
|
||||
assertInspect(expected, "font-SIZE: 11px".parseStyle());
|
||||
assertInspect(expected, "font-size:11px ".parseStyle());
|
||||
assertInspect(expected, " Font-size: 11px ".parseStyle());
|
||||
|
||||
assertInspect(expectedMultiple, " font-size: 11px;width:780px".parseStyle());
|
||||
|
||||
}}
|
||||
|
||||
});
|
||||
|
||||
// ]]>
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
154
javascript/scoluos/test/unit/unittest_test.html
Executable file
154
javascript/scoluos/test/unit/unittest_test.html
Executable file
@@ -0,0 +1,154 @@
|
||||
<!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" />
|
||||
<style type="text/css" media="screen">
|
||||
/* <![CDATA[ */
|
||||
#testcss1 { font-size:11px; color: #f00; }
|
||||
#testcss2 { font-size:12px; color: #0f0; display: none; }
|
||||
/* ]]> */
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>script.aculo.us Unit test file</h1>
|
||||
<p>
|
||||
This is a preliminary version mostly for testing the unittest library.
|
||||
</p>
|
||||
|
||||
<!-- Log output -->
|
||||
<div id="testlog"> </div>
|
||||
|
||||
<!-- Test elements follow -->
|
||||
<div id="test_1" class="a bbbbbbbbbbbb cccccccccc dddd"> </div>
|
||||
|
||||
<div id="test_2"> <span> </span>
|
||||
|
||||
|
||||
|
||||
<div><div></div> </div><span> </span>
|
||||
</div>
|
||||
|
||||
<ul id="tlist"><li id="tlist_1">x1</li><li id="tlist_2">x2</li></ul>
|
||||
<ul id="tlist2"><li class="a" id="tlist2_1">x1</li><li id="tlist2_2">x2</li></ul>
|
||||
|
||||
<div id="testmoveby" style="background-color:#333;width:100px;">XXXX</div>
|
||||
|
||||
<div id="testcss1">testcss1<span id="testcss1_span" style="display:none;">blah</span></div><div id="testcss2">testcss1</div>
|
||||
|
||||
<!-- Tests follow -->
|
||||
<script type="text/javascript" language="javascript" charset="utf-8">
|
||||
// <![CDATA[
|
||||
|
||||
var testObj = {
|
||||
isNice: function(){
|
||||
return true;
|
||||
},
|
||||
isBroken: function(){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
new Test.Unit.Runner({
|
||||
|
||||
testAssertEqual: function() { with(this) {
|
||||
assertEqual(0, 0);
|
||||
assertEqual(0, 0, "test");
|
||||
|
||||
assertEqual(0,'0');
|
||||
assertEqual(65.0, 65);
|
||||
|
||||
assertEqual("a", "a");
|
||||
assertEqual("a", "a", "test");
|
||||
|
||||
assertNotEqual(0, 1);
|
||||
assertNotEqual("a","b");
|
||||
assertNotEqual({},{});
|
||||
assertNotEqual([],[]);
|
||||
assertNotEqual([],{});
|
||||
}},
|
||||
|
||||
testAssertRespondsTo: function() { with(this) {
|
||||
assertRespondsTo('isNice', testObj);
|
||||
assertRespondsTo('isBroken', testObj);
|
||||
}},
|
||||
|
||||
testAssertIndentical: function() { with(this) {
|
||||
assertIdentical(0, 0);
|
||||
assertIdentical(0, 0, "test");
|
||||
assertIdentical(1, 1);
|
||||
assertIdentical('a', 'a');
|
||||
assertIdentical('a', 'a', "test");
|
||||
assertIdentical('', '');
|
||||
assertIdentical(undefined, undefined);
|
||||
assertIdentical(null, null);
|
||||
assertIdentical(true, true);
|
||||
assertIdentical(false, false);
|
||||
|
||||
var obj = {a:'b'};
|
||||
assertIdentical(obj, obj);
|
||||
|
||||
assertNotIdentical({1:2,3:4},{1:2,3:4});
|
||||
|
||||
assertIdentical(1, 1.0); // both are typeof == 'number'
|
||||
|
||||
assertNotIdentical(1, '1');
|
||||
assertNotIdentical(1, '1.0');
|
||||
}},
|
||||
|
||||
testAssertMatch: function() { with(this) {
|
||||
assertMatch(/knowmad.jpg$/, 'http://script.aculo.us/images/knowmad.jpg');
|
||||
assertMatch(/Fuc/, 'Thomas Fuchs');
|
||||
assertMatch(/^\$(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?$/, '$19.95');
|
||||
assertMatch(/(\d{3}\) ?)|(\d{3}[- \.])?\d{3}[- \.]\d{4}(\s(x\d+)?){0,1}$/, '704-343-9330');
|
||||
assertMatch(/^(?:(?:(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(\/|-|\.)(?:0?2\1(?:29)))|(?:(?:(?:1[6-9]|[2-9]\d)?\d{2})(\/|-|\.)(?:(?:(?:0?[13578]|1[02])\2(?:31))|(?:(?:0?[1,3-9]|1[0-2])\2(29|30))|(?:(?:0?[1-9])|(?:1[0-2]))\2(?:0?[1-9]|1\d|2[0-8]))))$/, '2001-06-16');
|
||||
assertMatch(/^((0?[123456789])|(1[012]))\s*:\s*([012345]\d)(\s*:\s*([012345]\d))?\s*[ap]m\s*-\s*((0?[123456789])|(1[012]))\s*:\s*([012345]\d)(\s*:\s*([012345]\d))?\s*[ap]m$/i, '2:00PM-2:15PM');
|
||||
|
||||
}},
|
||||
|
||||
testAssertInstanceOf: function() { with(this) {
|
||||
assertInstanceOf(Effect.Opacity, new Effect.Opacity('testcss1',{sync:true}));
|
||||
assertNotInstanceOf(String, new Effect.Opacity('testcss1',{sync:true}));
|
||||
|
||||
// note: fails with firefox 1.0.X (bug, fixed in Deer Park)
|
||||
assertNotInstanceOf(Effect.Parallel, new Effect.Opacity('testcss1',{sync:true}), "(note: fails with firefox 1.0.X, fixed in Deer Park)");
|
||||
}},
|
||||
|
||||
testAssertReturns: function() { with(this) {
|
||||
|
||||
assertReturnsTrue('isNice',testObj);
|
||||
assertReturnsFalse('isBroken',testObj);
|
||||
|
||||
assertReturnsTrue('nice',testObj);
|
||||
assertReturnsFalse('broken',testObj);
|
||||
|
||||
}},
|
||||
|
||||
testAssertVisible: function() { with(this) {
|
||||
assertVisible('testcss1');
|
||||
assertNotVisible('testcss1_span');
|
||||
assertNotVisible('testcss2', "Due to a Safari bug, this test fails in Safari.");
|
||||
|
||||
Element.hide('testcss1');
|
||||
assertNotVisible('testcss1');
|
||||
assertNotVisible('testcss1_span');
|
||||
Element.show('testcss1');
|
||||
assertVisible('testcss1');
|
||||
assertNotVisible('testcss1_span');
|
||||
|
||||
Element.show('testcss1_span');
|
||||
assertVisible('testcss1_span');
|
||||
Element.hide('testcss1');
|
||||
assertNotVisible('testcss1_span'); // hidden by parent
|
||||
}}
|
||||
|
||||
}, "testlog");
|
||||
// ]]>
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user