Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
View
3  .gitmodules
@@ -4,3 +4,6 @@
[submodule "ext/yuicompressor"]
path = ext/yuicompressor
url = https://github.com/yui/yuicompressor.git
+[submodule "ext/qunit"]
+ path = ext/qunit
+ url = git://github.com/jquery/qunit.git
1  ext/qunit
@@ -0,0 +1 @@
+Subproject commit 171ad8f042007e795766893a701d9315bdedeef1
View
8 grunt.js
@@ -49,9 +49,9 @@ module.exports = function(grunt) {
dest: "dist/index.css"
}
},
- //qunit: {
- // files: ['test/**/*.html']
- //},
+ qunit: {
+ files: ['test/**/*.html']
+ },
lint: {
files: ['grunt.js', 'src/**/*.js', 'test/**/*.js']
},
@@ -84,7 +84,7 @@ module.exports = function(grunt) {
});
// Default task.
- grunt.registerTask('default', 'lint csslint');
+ grunt.registerTask('default', 'lint csslint qunit');
grunt.registerTask('dist', 'default haml less concat min cssmin copy');
View
28 test/jquery.placeholder.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>jQuery Placeholder Plugin Test Suite</title>
+ <!-- Load local jQuery, removing access to $ (use jQuery, not $). -->
+ <script src='http://code.jquery.com/jquery-1.7.2.js' type='text/javascript'></script>
+ <script>jQuery.noConflict()</script>
+ <!-- Load local QUnit (grunt requires v1.0.0 or newer). -->
+ <link rel="stylesheet" href="../ext/qunit/qunit/qunit.css" media="screen">
+ <script src="../ext/qunit/qunit/qunit.js"></script>
+ <!-- Load local lib and tests. -->
+ <script src="../src/jquery.placeholder.js"></script>
+ <script src="jquery.placeholder_test.js"></script>
+</head>
+<body>
+ <h1 id="qunit-header">jQuery Placeholder Plugin Test Suite</h1>
+ <h2 id="qunit-banner"></h2>
+ <div id="qunit-testrunner-toolbar"></div>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
+ <div id="qunit-fixture">
+ <input id="placeholder-text-foo" type="text" placeholder="foo" / >
+ <input id="placeholder-password-foo" type="password" placeholder="foo" / >
+ <input id="no-placeholder" type="text" / >
+ </div>
+</body>
+</html>
View
109 test/jquery.placeholder_test.js
@@ -0,0 +1,109 @@
+/*global QUnit:false, module:false, test:false, asyncTest:false, expect:false*/
+/*global start:false, stop:false ok:false, equal:false, notEqual:false, deepEqual:false*/
+/*global notDeepEqual:false, strictEqual:false, notStrictEqual:false, raises:false*/
+(function($) {
+
+ module('jQuery#placeholder', {
+ setup: function() {
+ // find the test elements
+ this.elems = $('#qunit-fixture');
+ this["placeholder-text-foo"] = this.elems.find("#placeholder-text-foo").first();
+ this["placeholder-password-foo"] = this.elems.find("#placeholder-password-foo").first();
+ this["no-placeholder"] = this.elems.find("#no-placeholder").first();
+ }
+ });
+
+ test('is chainable', 1, function() {
+ strictEqual(this.elems.placeholder(), this.elems, 'should be chaninable');
+ });
+
+ test("test default", 10, function() {
+ var el = this["placeholder-text-foo"].placeholder({
+ overrideSupport: true
+ });
+
+ // should set the value to the placeholder
+ strictEqual(el.attr('value'), 'foo');
+ strictEqual(el.attr('autocomplete'), 'off');
+
+ // should have the default class
+ ok(el.hasClass('placeholder'));
+ ok(! el.hasClass('placeholderFocus'));
+
+ // test on focus
+ el.focus();
+
+ strictEqual(el.attr('value'), '');
+ ok(! el.hasClass('placeholder'));
+ ok(el.hasClass('placeholderFocus'));
+
+ // and unfocus (blur) again
+ el.blur();
+
+ strictEqual(el.attr('value'), 'foo');
+ ok(el.hasClass('placeholder'));
+ ok(! el.hasClass('placeholderFocus'));
+ });
+
+ test("test set classes", 4, function() {
+ // class names
+ var activeClass = 'myactiveclass';
+ var focusClass = 'myfocusclass';
+
+ // run placeholder
+ var el = this["placeholder-text-foo"].placeholder({
+ overrideSupport: true,
+ activeClass: activeClass,
+ focusClass: focusClass
+ });
+
+ // should have the default class
+ ok(el.hasClass(activeClass));
+ ok(! el.hasClass(focusClass));
+
+ // test on focus
+ el.focus();
+
+ ok(! el.hasClass(activeClass));
+ ok(el.hasClass(focusClass));
+ });
+
+ test("test no placeholder", 2, function() {
+ var el = this["no-placeholder"].placeholder({
+ overrideSupport: true
+ });
+
+ // should not set value
+ ok(! el.attr('value'));
+
+ // should not set class
+ ok(! el.hasClass('placeholder'));
+ });
+
+ test("test password placeholder", 2, function() {
+ var el = this["placeholder-password-foo"].placeholder({
+ overrideSupport: true
+ });
+
+ // should not set value
+ ok(! el.attr('value'));
+
+ // should not set class
+ ok(! el.hasClass('placeholder'));
+ });
+
+ test("test preventRefreshIssues false", 1, function() {
+ var el = this["placeholder-text-foo"].placeholder({
+ overrideSupport: true,
+ preventRefreshIssues: false
+ });
+
+ // should not set autocomplete
+ ok(! el.attr('autocomplete'));
+ });
+
+ test("test submit form", 1, function() {
+ ok("TODO: test submiting a form, ensuring that the default placeholder is not sent through");
+ });
+
+}(jQuery));

No commit comments for this range

Something went wrong with that request. Please try again.