-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest.html
More file actions
79 lines (66 loc) · 2.94 KB
/
test.html
File metadata and controls
79 lines (66 loc) · 2.94 KB
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
74
75
76
77
78
79
<!DOCTYPE html>
<head>
<title>JavaScript unit test file</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js" type="text/javascript"></script>
<script src="http://code.jquery.com/qunit/qunit-1.11.0.js" type="text/javascript"></script>
<script src="jquery.placeholderpatch.js" type="text/javascript"></script>
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.11.0.css" type="text/css" media="screen" />
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture">
<form action="#" id="form">
<input type="text" id="input1" placeholder="Foo" />
<input type="text" id="input2" value="Foo" placeholder="Bar" />
<input type="text" id="input3" placeholder="Foo" />
<input type="password" id="input4" placeholder="Foo" />
</form>
</div>
<script type="text/javascript">
//<![CDATA[
(function ($) {
var form, input1, input2, input3, input4;
module('Core', {
setup: function () {
input1 = $('#input1').placeholder();
input2 = $('#input2').placeholder();
input3 = $('#input3').placeholder({placeholderClass: 'customPlaceholderClass'});
input4 = $('#input4');
form = $('#form').submit(function (e) { e.preventDefault(); return false; });
}
});
test('Empty input should take value from placeholder attribute', function () {
ok(input1.val() === 'Foo', 'Value is taken from placeholder attribute');
});
test('Input with a value and placeholder attribute should retain its value', function () {
ok(input2.val() === 'Foo', 'Value is taken from value attribute');
});
test('Empty input should initially have placeholder class', function () {
ok(input1.hasClass('placeholder'), 'Input has default placeholder class');
ok(input3.hasClass('customPlaceholderClass'), 'Input has custom placeholder class');
});
test('Input should clear on focus', function () {
input1.focus();
ok(input1.val() === '', 'Input cleared on focus');
});
test('Input should not have placeholder class on focus', function () {
input1.focus();
ok(!input1.hasClass('placeholder'), 'Input does not have default placeholder class on focus');
input3.focus();
ok(!input3.hasClass('customPlaceholderClass'), 'Input does not have custom placeholder class on focus');
});
test('Input should be cleared on submit if default value', function () {
form.submit();
ok(input1.val() === '', 'Default value cleared');
});
test('Should not be applied to password inputs', function () {
ok(input4.val() === '', 'Placeholder text empty');
input4.focus();
ok(input4.val() === '', 'Placeholder text empty after focus');
});
})(jQuery);
//]]>
</script>
</body>
</html>