Skip to content

Commit 15186bd

Browse files
author
Rafael J. Staib
committed
Add first tests and some other stuff
- Tests added - Using as of now getValidEnumMethod
1 parent 0d2ecfe commit 15186bd

File tree

4 files changed

+62
-9
lines changed

4 files changed

+62
-9
lines changed

Gruntfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,6 @@ module.exports = function (grunt)
129129
grunt.loadNpmTasks('grunt-contrib-compress');
130130
grunt.loadNpmTasks('grunt-contrib-clean');
131131

132-
grunt.registerTask('default', ['clean', 'jshint'/*, 'qunit'*/]);
132+
grunt.registerTask('default', ['clean', 'jshint', 'qunit']);
133133
grunt.registerTask('release', ['default', 'yuidoc', 'concat', 'uglify', 'compress']);
134134
};

jquery.steps.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@
575575
loadAsyncContent(wizard);
576576

577577
var stepContents = $(".content > .body", wizard);
578-
switch (options.transitionEffect)
578+
switch (getValidEnumValue($.fn.steps.transitionEffect, options.transitionEffect))
579579
{
580580
case $.fn.steps.transitionEffect.fade:
581581
state.transitionShowElement = stepContents.eq(index);
@@ -755,7 +755,7 @@
755755
if (!options.enableContentCache || !state.currentStep.contentLoaded)
756756
{
757757
var currentStepContent;
758-
switch (state.currentStep.contentMode)
758+
switch (getValidEnumValue($.fn.steps.contentMode, state.currentStep.contentMode))
759759
{
760760
case $.fn.steps.contentMode.iframe:
761761
currentStepContent = $(".content > .body", wizard).eq(state.currentIndex);
@@ -902,8 +902,9 @@
902902
var options = wizard.data("options");
903903
var $header = $(".content > .title:eq(" + index + ")", wizard);
904904
var $content = $header.next(".body");
905-
var mode = (isNaN($content.data("mode")) || Number($content.data("mode")) > 2) ?
906-
$.fn.steps.contentMode.html : Number($content.data("mode"));
905+
var mode = ($content.data("mode") == null) ? $.fn.steps.contentMode.html :
906+
getValidEnumValue($.fn.steps.contentMode, (/^\s*$/.test($content.data("mode")) || isNaN($content.data("mode"))) ?
907+
$content.data("mode") : Number($content.data("mode")));
907908
var contentUrl = (mode === $.fn.steps.contentMode.html || $content.data("url") === undefined) ?
908909
"" : $content.data("url");
909910
var contentLoaded = (mode !== $.fn.steps.contentMode.html && $content.data("loaded") === "1");

test/index.html

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,50 @@
22
<html>
33
<head>
44
<meta charset="utf-8">
5-
<title>QUnit Example</title>
6-
<link rel="stylesheet" href="qunit/qunit.css">
5+
<title>jQuery Steps Test Suite</title>
6+
<link rel="stylesheet" href="qunit/qunit-1.11.0.css">
77
</head>
88
<body>
99
<div id="qunit"></div>
10-
<div id="qunit-fixture"></div>
11-
<script src="qunit/qunit.js"></script>
10+
<div id="qunit-fixture">
11+
<div id="contentModeWithEmptyStringArgument">
12+
<h1>contentModeWithEmptyStringArgument</h1>
13+
<div data-mode="">
14+
<p>contentModeWithEmptyStringArgument</p>
15+
</div>
16+
</div>
17+
18+
<div id="contentModeWithWrongNumberArgument">
19+
<h1>contentModeWithWrongNumberArgument</h1>
20+
<div data-mode="3">
21+
<p>contentModeWithWrongNumberArgument</p>
22+
</div>
23+
</div>
24+
25+
<div id="contentModeWithWrongStringArgument">
26+
<h1>contentModeWithWrongStringArgument</h1>
27+
<div data-mode="none">
28+
<p>contentModeWithWrongStringArgument</p>
29+
</div>
30+
</div>
31+
32+
<div id="contentModeWithNumberArgument">
33+
<h1>contentModeWithNumberArgument</h1>
34+
<div data-mode="0">
35+
<p>contentModeWithNumberArgument</p>
36+
</div>
37+
</div>
38+
39+
<div id="contentModeWithStringArgument">
40+
<h1>contentModeWithStringArgument</h1>
41+
<div data-mode="html">
42+
<p>contentModeWithStringArgument</p>
43+
</div>
44+
</div>
45+
</div>
46+
<script src="qunit/qunit-1.11.0.js"></script>
1247
<script src="tests.js"></script>
48+
<script src="../lib/jquery-1.9.1.min.js"></script>
49+
<script src="../jquery.steps.js"></script>
1350
</body>
1451
</html>

test/tests.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module("general");
2+
3+
test("contentMode", 5, function ()
4+
{
5+
/*jshint -W024 */
6+
throws(function() { $("#contentModeWithEmptyStringArgument").steps(); }, /The enum key/, "Empty string argument");
7+
throws(function() { $("#contentModeWithWrongNumberArgument").steps(); }, /Invalid enum value/, "Invalid number argument");
8+
throws(function() { $("#contentModeWithWrongStringArgument").steps(); }, /The enum key/, "Invalid string argument");
9+
10+
var contentModeWithNumberArgument = $("#contentModeWithNumberArgument").steps();
11+
equal(contentModeWithNumberArgument.steps("getCurrentStep").contentMode, 0, "Valid number argument");
12+
13+
var contentModeWithStringArgument = $("#contentModeWithStringArgument").steps();
14+
equal(contentModeWithStringArgument.steps("getCurrentStep").contentMode, 0, "Valid string argument");
15+
});

0 commit comments

Comments
 (0)