summaryrefslogtreecommitdiff
path: root/source/bower_components/jquery-placeholder/tests
diff options
context:
space:
mode:
authorLars Henrik Mai <lars.mai@kontinui.de>2014-09-21 12:25:47 +0200
committerLars Henrik Mai <lars.mai@kontinui.de>2014-09-21 12:25:47 +0200
commit7cc7910df63d19e7ebc67bb1156437f0559712d7 (patch)
tree66f972354559fe05b7a97efccd08fc363c91cf4d /source/bower_components/jquery-placeholder/tests
parent450a01136a510adc4c96ff12e05e00a2ce550c8f (diff)
add foundation via bower
Diffstat (limited to 'source/bower_components/jquery-placeholder/tests')
-rw-r--r--source/bower_components/jquery-placeholder/tests/index.html32
-rw-r--r--source/bower_components/jquery-placeholder/tests/tests.js134
2 files changed, 166 insertions, 0 deletions
diff --git a/source/bower_components/jquery-placeholder/tests/index.html b/source/bower_components/jquery-placeholder/tests/index.html
new file mode 100644
index 0000000..160e3e8
--- /dev/null
+++ b/source/bower_components/jquery-placeholder/tests/index.html
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>jquery-placeholder test suite</title>
+ <link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.12.0.css">
+ <style>
+ .placeholder { color: #aaa; }
+ #input-type-password { border: 5px solid lime; }
+ </style>
+ </head>
+ <body>
+ <div id="qunit"></div>
+ <div id="fixtures">
+ <!-- I explicitly want these to be visible in the page, for easier debugging. -->
+ <form>
+ <p><label><code>type=search</code> <input id="input-type-search" type="search" name="search" placeholder="Search this site..."></label></p>
+ <p><label><code>type=text</code> <input id="input-type-text" type="text" name="name" placeholder="e.g. John Doe"></label></p>
+ <p><label><code>type=email</code> <input id="input-type-email" type="email" name="email" placeholder="e.g. address@example.ext"></label></p>
+ <p><label><code>type=url</code> <input id="input-type-url" type="url" name="url" placeholder="e.g. http://mathiasbynens.be/"></label></p>
+ <p><label><code>type=tel</code> <input id="input-type-tel" type="tel" name="tel" placeholder="e.g. +32 472 77 69 88"></label></p>
+ <p><label for="input-type-password"><code>type=password</code> </label><input id="input-type-password" type="password" name="password" placeholder="e.g. hunter2"></p>
+ <p><label><code>textarea</code> <textarea id="textarea" name="message" placeholder="Your message goes here"></textarea></label></p>
+ <p><input type="submit" value="type=submit"></p>
+ </form>
+ </div>
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
+ <script src="http://code.jquery.com/qunit/qunit-1.12.0.js"></script>
+ <script src="../jquery.placeholder.js"></script>
+ <script src="tests.js"></script>
+ </body>
+</html>
diff --git a/source/bower_components/jquery-placeholder/tests/tests.js b/source/bower_components/jquery-placeholder/tests/tests.js
new file mode 100644
index 0000000..f721564
--- /dev/null
+++ b/source/bower_components/jquery-placeholder/tests/tests.js
@@ -0,0 +1,134 @@
+(function($) {
+
+ module('jQuery#placeholder');
+
+ test('caches results of feature tests', function() {
+ strictEqual(typeof $.fn.placeholder.input, 'boolean', '$.fn.placeholder.input');
+ strictEqual(typeof $.fn.placeholder.textarea, 'boolean', '$.fn.placeholder.textarea');
+ });
+
+ if ($.fn.placeholder.input && $.fn.placeholder.textarea) {
+ return;
+ }
+
+ var testElement = function($el) {
+
+ var el = $el[0];
+ var placeholder = el.getAttribute('placeholder');
+
+ strictEqual($el.placeholder(), $el, 'should be chainable');
+
+ strictEqual(el.value, placeholder, 'should set `placeholder` text as `value`');
+ strictEqual($el.prop('value'), '', 'propHooks works properly');
+ strictEqual($el.val(), '', 'valHooks works properly');
+ ok($el.hasClass('placeholder'), 'should have `placeholder` class');
+
+ // test on focus
+ $el.focus();
+ strictEqual(el.value, '', '`value` should be the empty string on focus');
+ strictEqual($el.prop('value'), '', 'propHooks works properly');
+ strictEqual($el.val(), '', 'valHooks works properly');
+ ok(!$el.hasClass('placeholder'), 'should not have `placeholder` class on focus');
+
+ // and unfocus (blur) again
+ $el.blur();
+
+ strictEqual(el.value, placeholder, 'should set `placeholder` text as `value`');
+ strictEqual($el.prop('value'), '', 'propHooks works properly');
+ strictEqual($el.val(), '', 'valHooks works properly');
+ ok($el.hasClass('placeholder'), 'should have `placeholder` class');
+
+ // change the value
+ $el.val('lorem ipsum');
+ strictEqual($el.prop('value'), 'lorem ipsum', '`$el.val(string)` should change the `value` property');
+ strictEqual(el.value, 'lorem ipsum', '`$el.val(string)` should change the `value` attribute');
+ ok(!$el.hasClass('placeholder'), '`$el.val(string)` should remove `placeholder` class');
+
+ // and clear it again
+ $el.val('');
+ strictEqual($el.prop('value'), '', '`$el.val("")` should change the `value` property');
+ strictEqual(el.value, placeholder, '`$el.val("")` should change the `value` attribute');
+ ok($el.hasClass('placeholder'), '`$el.val("")` should re-enable `placeholder` class');
+
+ // make sure the placeholder property works as expected.
+ strictEqual($el.prop('placeholder'), placeholder, '$el.prop(`placeholder`) should return the placeholder value');
+ $el.prop('placeholder', 'new placeholder');
+ strictEqual($el.prop('placeholder'), 'new placeholder', '$el.prop(`placeholder`, <string>) should set the placeholder value');
+ strictEqual($el.value, 'new placeholder', '$el.prop(`placeholder`, <string>) should update the displayed placeholder value');
+ $el.prop('placeholder', placeholder);
+ };
+
+ test('emulates placeholder for <input type=text>', function() {
+ testElement( $('#input-type-text') );
+ });
+
+ test('emulates placeholder for <input type=search>', function() {
+ testElement( $('#input-type-search') );
+ });
+
+ test('emulates placeholder for <input type=email>', function() {
+ testElement( $('#input-type-email') );
+ });
+
+ test('emulates placeholder for <input type=url>', function() {
+ testElement( $('#input-type-url') );
+ });
+
+ test('emulates placeholder for <input type=tel>', function() {
+ testElement( $('#input-type-tel') );
+ });
+
+ test('emulates placeholder for <input type=tel>', function() {
+ testElement( $('#input-type-tel') );
+ });
+
+ test('emulates placeholder for <input type=password>', function() {
+ var selector = '#input-type-password';
+
+ var $el = $(selector);
+ var el = $el[0];
+
+ var placeholder = el.getAttribute('placeholder');
+
+ strictEqual($el.placeholder(), $el, 'should be chainable');
+
+ // Re-select the element, as it gets replaced by another one in some browsers
+ $el = $(selector);
+ el = $el[0];
+
+ strictEqual(el.value, placeholder, 'should set `placeholder` text as `value`');
+ strictEqual($el.prop('value'), '', 'propHooks works properly');
+ strictEqual($el.val(), '', 'valHooks works properly');
+ ok($el.hasClass('placeholder'), 'should have `placeholder` class');
+
+ // test on focus
+ $el.focus();
+
+ // Re-select the element, as it gets replaced by another one in some browsers
+ $el = $(selector);
+ el = $el[0];
+
+ strictEqual(el.value, '', '`value` should be the empty string on focus');
+ strictEqual($el.prop('value'), '', 'propHooks works properly');
+ strictEqual($el.val(), '', 'valHooks works properly');
+ ok(!$el.hasClass('placeholder'), 'should not have `placeholder` class on focus');
+
+ // and unfocus (blur) again
+ $el.blur();
+
+ // Re-select the element, as it gets replaced by another one in some browsers
+ $el = $(selector);
+ el = $el[0];
+
+ strictEqual(el.value, placeholder, 'should set `placeholder` text as `value`');
+ strictEqual($el.prop('value'), '', 'propHooks works properly');
+ strictEqual($el.val(), '', 'valHooks works properly');
+ ok($el.hasClass('placeholder'), 'should have `placeholder` class');
+
+ });
+
+ test('emulates placeholder for <textarea></textarea>', function() {
+ testElement( $('#textarea') );
+ });
+
+}(jQuery));