Skip to content

Commit

Permalink
Add test framework (using karma and jasmine, launched via grunt, fron…
Browse files Browse the repository at this point in the history
…tend via `npm test`) and a basic test.
  • Loading branch information
Tom Clift committed May 27, 2014
1 parent 84f0939 commit 6791a1e
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,4 @@ pip-log.txt
.DS_Store

bower_components/
node_modules/
26 changes: 26 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.exports = function(grunt) {
grunt.config.init({
karma: {
options: {
browsers: [ 'Chrome', 'Firefox', 'Safari', 'Opera', 'IE' ],
frameworks: [ 'jasmine' ],
reportSlowerThan: 500,
singleRun: true
},
unit: {
files: [
{ pattern: 'bower_components/jquery/dist/jquery.min.js' },
{ pattern: 'bower_components/jasmine-jquery/lib/jasmine-jquery.js' },
{ pattern: 'jquery.are-you-sure.js' },
{ pattern: 'spec/javascripts/*.js' },
{ pattern: 'spec/javascripts/fixtures/**/*.html', included: false }
]
}
}
});

grunt.registerTask('test', 'Run tests.', [ 'karma' ]);
grunt.registerTask('default', [ 'test' ]);

grunt.loadNpmTasks('grunt-karma');
};
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
Are You Sure? - A light "dirty forms" JQuery Plugin!
Are You Sure? - A light "dirty forms" JQuery Plugin
======
**Version:** 1.7


*Are-you-sure* (```jquery.are-you-sure.js```) is simple light-weight "dirty
form" JQuery Plugin for modern browsers. It helps prevent users from losing
unsaved HTML Form changes by promoting the user to save/submit.
Expand Down Expand Up @@ -181,7 +180,7 @@ For experimental Mobile Safari support, also include ```ays-beforeunload-shim.js
*Are-you-sure* may also be installed with [Bower](http://twitter.github.com/bower/):
``` bash
```bash
$ bower install jquery.are-you-sure
```
Expand Down Expand Up @@ -214,14 +213,19 @@ check with *Are-you-sure* before navigating away. To use, simply include
####Firefox
The custom message option may not work on Firefox ([Firefox bug 588292](https://bugzilla.mozilla.org/show_bug.cgi?id=588292)).
###Future / Developers
###Development
The aim is to keep *Are-you-sure* simple and light. If you think you have
a good idea which is aligned with this objective, please voice your thoughts
in the issues list.
*Pull Requests:* If possible, please submit your pull request based off the most
recent ```dev-*``` branch rather than master. This will make it easier to
merge your code into the next planned release.
####Pull Requests
If possible, please submit your pull request against the most recent ```dev-*``` branch rather than master. This will make it easier to merge your code into the next planned release.
####Running tests
```bash
$ npm install
$ npm test
```
###Release History
Expand Down Expand Up @@ -268,7 +272,7 @@ merge your code into the next planned release.
###Prerequisites
jQuery version 1.4.2 or higher. 1.10+ recommended.
jQuery version 1.4.2 or higher. 2.0+ or 1.10+ recommended.
###License
Expand All @@ -280,4 +284,3 @@ The same as JQuery...
Copyright (c) 2012-2014, Chris Dance - PaperCut Software http://www.papercut.com/
Dual licensed under the MIT or GPL Version 2 licenses.
http://jquery.org/license
3 changes: 3 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@
],
"dependencies": {
"jquery": ">=1.4.2"
},
"devDependencies": {
"jasmine-jquery": "~2.0.3"
}
}
46 changes: 46 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "jquery.AreYouSure",
"description": "A light-weight jQuery \"dirty forms\" Plugin - it monitors HTML forms and alerts users to unsaved changes if they attempt to close the browser or navigate away from the page. (Are you sure?)",
"homepage": "https://github.com/codedance/jquery.AreYouSure",
"author": "Chris Dance <[email protected]> (https://github.com/codedance)",
"contributors": [
"Tom Clift <[email protected]> (https://github.com/tclift)",
"Jon Egerton <[email protected]> (http://www.jonegerton.com/)",
"Scadoodles (https://github.com/Scadoodles)",
"Albin Sunnanbo (https://github.com/albinsunnanbo)",
"Marc Sutton <[email protected]> (http://www.codev.co.uk)"
],
"version": "1.7.0",
"license": "MIT/GPLv2",
"keywords": [ "dirty", "form", "onbeforeunload", "save", "check" ],
"main": "jquery.are-you-sure.js",
"engines": {
"node": ">=0.8.0"
},
"repository": {
"type": "git",
"url": "https://github.com/codedance/jquery.AreYouSure"
},
"bugs": {
"url": "https://github.com/codedance/jquery.AreYouSure/issues"
},
"dependencies": {
"jquery": ">=1.4.2"
},
"devDependencies": {
"bower": "^1.3.1",
"grunt": "^0.4.5",
"grunt-cli": "^0.1.13",
"grunt-karma": "^0.8.3",
"karma-chrome-launcher": "^0.1.4",
"karma-jasmine": "^0.2.2",
"karma-ie-launcher": "^0.1.5",
"karma-opera-launcher": "^0.1.0",
"karma-firefox-launcher": "^0.1.3",
"karma-safari-launcher": "^0.1.1"
},
"scripts": {
"postinstall": "$(npm bin)/bower install && npm prune && $(npm bin)/bower prune",
"test": "$(npm bin)/grunt test"
}
}
4 changes: 4 additions & 0 deletions spec/javascripts/fixtures/input-text.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<form>
<input type="text" name="a">
<input type="submit">
</form>
28 changes: 28 additions & 0 deletions spec/javascripts/jquery.are-you-sure_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

// Karma adds 'base/' to the default path
jasmine.getFixtures().fixturesPath = 'base/spec/javascripts/fixtures';

describe("A form's", function() {
var $form = undefined;

describe('text input', function() {
var $textInput = undefined;

beforeEach(function() {
loadFixtures('input-text.html');
$form = $('form');
$textInput = $('input[type=text]');
$form.areYouSure();
});

it('should cause dirtyness after its value changes', function(done) {
expect($form.hasClass('dirty')).toBe(false);
$textInput.val('new').change();
setTimeout(function() {
expect($form.hasClass('dirty')).toBe(true);
done();
}, 0);
});
});
});

0 comments on commit 6791a1e

Please sign in to comment.