Permalink
Browse files

cut tests folder to root folder, implement init,start,reset methods i…

…n jQuery.progressBar plugin
  • Loading branch information...
1 parent 2872f3c commit 1662696fb191bca3d8fca4261f3e6cd7b265ef24 @acazsouza committed Apr 23, 2012
View
@@ -5,14 +5,33 @@
'done': null
};
+ var decreaseBar = function (barElement) {
+ $(barElement).stop();
+
+ var barElementWidth = $(barElement).width();
+ $(barElement).animate({ width: 0 }, settings.velocity, function () {
+ if (0 >= $(barElement).width() && $.isFunction(settings.done)) {
+ settings.done();
+ }
+ });
+ }
+
var methods = {
init: function (options) {
settings = $.extend(settings, options);
- return this.each(function(){
- alert($.isFunction(settings.done));
- if ($.isFunction(settings.done))
- settings.done();
+ return this.each(function () {
+
+ });
+ },
+ start: function () {
+ return this.each(function () {
+ decreaseBar(this);
+ });
+ },
+ reset: function () {
+ return this.each(function () {
+ $(this).width($(this).parent().width());
});
}
};
@@ -1,47 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
- <meta charset="utf-8">
- <title>jQuery.ProgressBar Tests</title>
-
- <link href="../../libs/jquery-qunit-v1.5.0-7-g4f51c3f/qunit/qunit.css" rel="stylesheet" />
-
- <script type="text/javascript" src="../../libs/jquery-1.7.2/jquery-1.7.2.js"></script>
- <script type="text/javascript" src="../../libs/jquery-qunit-v1.5.0-7-g4f51c3f/qunit/qunit.js"></script>
-
- <script type="text/javascript" src="../jquery.progressbar.js"></script>
-
- <script type="text/javascript">
- $(function () {
- test("$('#SomeDiv').progressBar() should return a jQuery Object", function () {
- var progressaBar = $('#SomeDiv').progressBar();
- equal(null != progressaBar.jquery, true);
- });
-
- test("Done() event should trigger when barProgress finish", function () {
- var wasCalled = false;
-
- $('#SomeDiv').progressBar({
- done: function () {
- wasCalled = true;
- alert('teste');
- }
- });
-
- equal(wasCalled, true);
- });
-
- test("$('#SomeDiv').progressBar() should trigger an function when done.", function () {
- });
- });
- </script>
-</head>
-<body>
- <h1 id="qunit-header">jQuery.ProgressBar Tests</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">test markup, will be hidden</div>
-</body>
-</html>
@@ -4,12 +4,12 @@
<meta charset="utf-8">
<title>Twinoo Tests</title>
- <link href="../../libs/jquery-qunit-v1.5.0-7-g4f51c3f/qunit/qunit.css" rel="stylesheet" />
+ <link href="../libs/jquery-qunit-v1.5.0-7-g4f51c3f/qunit/qunit.css" rel="stylesheet" />
- <script type="text/javascript" src="../../libs/jquery-1.7.2/jquery-1.7.2.js"></script>
- <script type="text/javascript" src="../../libs/jquery-qunit-v1.5.0-7-g4f51c3f/qunit/qunit.js"></script>
+ <script type="text/javascript" src="../libs/jquery-1.7.2/jquery-1.7.2.js"></script>
+ <script type="text/javascript" src="../libs/jquery-qunit-v1.5.0-7-g4f51c3f/qunit/qunit.js"></script>
- <script type="text/javascript" src="../twinoo.js"></script>
+ <script type="text/javascript" src="../src/twinoo.js"></script>
<script type="text/javascript">
$(function () {
@@ -0,0 +1,83 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>jQuery.ProgressBar Tests</title>
+
+ <link href="../libs/jquery-qunit-v1.5.0-7-g4f51c3f/qunit/qunit.css" rel="stylesheet" />
+
+ <script type="text/javascript" src="../libs/jquery-1.7.2/jquery-1.7.2.js"></script>
+ <script type="text/javascript" src="../libs/jquery-qunit-v1.5.0-7-g4f51c3f/qunit/qunit.js"></script>
+
+ <script type="text/javascript" src="../src/jquery.progressbar.js"></script>
+
+ <style type="text/css">
+ .barProgress { width:100%; height:20px; border:solid 1px #000; position:relative }
+
+ .barProgress .bar { width:100%; height:20px; position:absolute; right:0; background-color:red }
+ </style>
+
+ <script type="text/javascript">
+ $(function () {
+
+ module("$.progressBar() Tests", {
+ setup: function () {
+ var HTMLStub = '<div id="div-id" class="barProgress"><div class="bar"></div><div>';
+ $(HTMLStub).appendTo('body');
+ },
+ teardown: function () {
+ $('#div-id').remove();
+ }
+ });
+
+ test("$('#div-id').progressBar() should return a jQuery Object", function () {
+ var myProgressBar = $('#div-id').progressBar();
+ equal(null != myProgressBar.jquery, true);
+ });
+
+ asyncTest("done() event should trigger when barProgress finish", function () {
+ var wasCalled = false;
+
+ var myProgressBar = $('#div-id').progressBar({
+ done: function () {
+ wasCalled = true;
+ }
+ });
+
+ myProgressBar.progressBar('start');
+
+ setTimeout(function () {
+ start();
+ equal(wasCalled, true);
+ }, 100);
+ });
+
+ asyncTest("start() method should decrease the width of .bar div to 0", function () {
+ var myProgressBar = $('#div-id').progressBar();
+ myProgressBar.progressBar('start');
+
+ setTimeout(function () {
+ start();
+ equal(0 == myProgressBar.find('.bar').width(), true);
+ }, 100);
+ });
+
+ test("reset() method should increase the width of .bar div to 100", function () {
+ var myProgressBar = $('#div-id').progressBar();
+ myProgressBar.progressBar('start');
+ myProgressBar.progressBar('reset');
+
+ equal($('.barProgress').width() == myProgressBar.find('.bar').width(), true);
+ });
+ });
+ </script>
+</head>
+<body>
+ <h1 id="qunit-header">jQuery.ProgressBar Tests</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">test markup, will be hidden</div>
+</body>
+</html>

0 comments on commit 1662696

Please sign in to comment.