-
Notifications
You must be signed in to change notification settings - Fork 3
/
jquery_caret_test.html
73 lines (61 loc) · 2.99 KB
/
jquery_caret_test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!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>JavaScript unit test file</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script src="lib/jsunittest.js" type="text/javascript"></script>
<script src="lib/jquery.js" type="text/javascript"></script>
<!-- TODO: REPLACE "example_library_to_test" throughout file with name of file to test -->
<script src="jquery.caret.js" type="text/javascript"></script>
<link rel="stylesheet" href="lib/unittest.css" type="text/css" />
</head>
<body>
<div id="content">
<div id="header">
<h1>JavaScript unit test file</h1>
<p>
This file tests <strong>jquery.caret.js</strong>.
</p>
</div>
<!-- Log output (one per Runner, via {testLog: "testlog"} option)-->
<div id="testlog"></div>
<!-- Put sample/test html here -->
<div id="sample">
</div>
</div>
<script type="text/javascript">
// <![CDATA[
new Test.Unit.Runner({
setup: function(){
if ($('#test_input').length == 0){
$('<textarea/>').attr('id', 'test_input').appendTo(document.body).focus().css({'position': 'absolute', 'top': '-1000px'});
}
},
testGetAndSetCaretPosition: function(){ with(this) {
assertEqual(5, $('#test_input').val('emergency broadcast system').setCaretPosition(5).getCaretPosition());
assertEqual(5, $('#test_input').val('emergency broadcast system').setCaretPosition(5, 8).getCaretPosition());
}},
testInsertAtCaret: function() { with(this) {
assertEqual('hello', $('#test_input').val('').setCaretPosition(0).insertAtCaret('hello').val());
assertEqual('hello', $('#test_input').val('helo').setCaretPosition(2).insertAtCaret('l').val());
assertEqual('why hello', $('#test_input').val('hello').setCaretPosition(0).insertAtCaret('why ').val());
}},
testChaining: function() { with(this) {
assertEqual('this is a test of the emergency broadcast system',
$('#test_input').val('this of the emergency broadcast system').setCaretPosition(5).insertAtCaret('is a test ').setCaretPosition(10, 14).val());
}},
testGetSelectedText: function() { with(this){
assertEqual('test', $('#test_input').val('this is a test of that').setCaretPosition(10, 14).getSelectedText());
}},
testTextareaInsertAtCaret: function() { with(this){
$('<textarea/>').attr('id', 'test_textarea').appendTo(document.body).focus().css({'position': 'absolute', 'top': '-10100px'})
assertEqual('this is a test', $('#test_textarea').val('').setCaretPosition(0).insertAtCaret('this is a test').val());
assertEqual('this is a test', $('#test_textarea').val('is a test').setCaretPosition(0).insertAtCaret('this ').val());
assertEqual('this is a test', $('#test_textarea').val('this test').setCaretPosition(5).insertAtCaret('is a').val());
}}
});
// ]]>
</script>
</body>
</html>