Skip to content

Commit

Permalink
first steps to a better build: new gruntfile and jshint working+passing
Browse files Browse the repository at this point in the history
  • Loading branch information
stevegreatrex committed Oct 3, 2013
1 parent 11e9477 commit aad9642
Show file tree
Hide file tree
Showing 12 changed files with 3,859 additions and 3,709 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@
*.iws
target
*.ncrunchsolution
node_modules
*.webinfo
18 changes: 18 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"curly": true,
"eqeqeq": true,
"immed": true,
"latedef": true,
"newcap": true,
"noarg": true,
"sub": true,
"undef": true,
"boss": true,
"eqnull": true,
"browser": true,
"smarttabs": true,
"globals": {
"jQuery": false,
"ko": true
}
}
7,249 changes: 3,674 additions & 3,575 deletions Lib/knockout-latest.debug.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Scripts/_references.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

30 changes: 3 additions & 27 deletions Src/knockout.validation.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,4 @@
/*
===============================================================================
Author: Eric M. Barnard - @ericmbarnard
License: MIT (http://opensource.org/licenses/mit-license.php)
Description: Validation Library for KnockoutJS
===============================================================================
*/

/*jshint
sub:true,
curly: true,eqeqeq: true,
immed: true,
latedef: true,
newcap: true,
noarg: true,
sub: true,
undef: true,
boss: true,
eqnull: true,
browser: true
*/

/*globals
jQuery: false,
require: false,
exports: false,
define: false,
Expand Down Expand Up @@ -950,14 +926,14 @@
//manually set error state
observable.setError = function (error) {
observable.error(error);
observable.__valid__(false);
observable.__valid__(false);
};

//manually clear error state
observable.clearError = function () {
observable.error(null);
observable.error(null);
observable.__valid__(true);
}
};

//subscribe to changes in the observable
var h_change = observable.subscribe(function () {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion Tests/test-runner.htm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<link href="Qunit/qunit.css" rel="stylesheet" type="text/css" />
<script src="Qunit/qunit.js" type="text/javascript"></script>
<!--We only include jQuery for testing purposes (testing UI changes)-->
<script src="jquery-1.7.1.js" type="text/javascript"></script>
<script src="Qunit/jquery-1.7.1.js" type="text/javascript"></script>
<script src="../Lib/knockout-latest.debug.js" type="text/javascript"></script>
<script src="../Src/knockout.validation.js" type="text/javascript"></script>

Expand Down
38 changes: 23 additions & 15 deletions Tests/validation-tests.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
/// <reference path="Qunit/qunit.js" />
/// <reference path="../Lib/knockout-latest.debug.js" />
/// <reference path="../Src/knockout.validation.js" />
/*global
module:false,
equal:false,
notEqual:false,
strictEqual:false,
test:false,
ok:false,
asyncTest:false,
start: false,
stop: false
*/

//#region Required Validation

Expand Down Expand Up @@ -82,7 +90,7 @@ test('Object is Valid and isValid returns True', function () {
});

test('Object is Valid and isValid returns True (with min: 0)', function () {
testObj = ko.observable('')
var testObj = ko.observable('')
.extend({ min: 0 });

testObj("0");
Expand Down Expand Up @@ -822,7 +830,7 @@ test('Issue #78 - Falsy Params', function () {
//#endregion

//#region Manual Validation
module("Manual Validation")
module("Manual Validation");
test("setError sets isValid and error message", function () {
var testObj = ko.observable();
testObj.extend({ validatable: true });
Expand All @@ -845,7 +853,7 @@ test("clearError clears manually-specified error", function () {
testObj.setError("oh no!");

//fail the validation
ok(!testObj.isValid())
ok(!testObj.isValid());

//clear the validation
testObj.clearError();
Expand Down Expand Up @@ -957,7 +965,7 @@ test('Error Grouping works', function () {

var errors = ko.validation.group(vm);

equals(errors().length, 2, 'Grouping correctly finds 2 invalid properties');
equal(errors().length, 2, 'Grouping correctly finds 2 invalid properties');
});

test('Nested Grouping works - Observable', function () {
Expand All @@ -975,7 +983,7 @@ test('Nested Grouping works - Observable', function () {

var errors = ko.validation.group(vm, { deep: true, observable: true });

equals(errors().length, 3, 'Grouping correctly finds 3 invalid properties');
equal(errors().length, 3, 'Grouping correctly finds 3 invalid properties');
});

test('Nested Grouping works - Not Observable', function () {
Expand All @@ -993,7 +1001,7 @@ test('Nested Grouping works - Not Observable', function () {

var errors = ko.validation.group(vm, { deep: true, observable: false });

equals(errors().length, 3, 'Grouping correctly finds 3 invalid properties');
equal(errors().length, 3, 'Grouping correctly finds 3 invalid properties');
});

test('Issue #31 - Recursively Show All Messages', function () {
Expand Down Expand Up @@ -1022,7 +1030,7 @@ test('Issue #31 - Recursively Show All Messages', function () {
ok(vm.two.one.isModified(), "Level 2 is modified");
ok(vm.three.two.one.isModified(), "Level 3 is modified");

equals(errors().length, 3, 'Grouping correctly finds 3 invalid properties');
equal(errors().length, 3, 'Grouping correctly finds 3 invalid properties');
});

test('Issue #31 - Recursively Show All Messages - using computed', function () {
Expand Down Expand Up @@ -1051,7 +1059,7 @@ test('Issue #31 - Recursively Show All Messages - using computed', function () {
ok(vm.two.one.isModified(), "Level 2 is modified");
ok(vm.three.two.one.isModified(), "Level 3 is modified");

equals(errors().length, 3, 'Grouping correctly finds 3 invalid properties');
equal(errors().length, 3, 'Grouping correctly finds 3 invalid properties');
});

test('Issue #37 - Toggle ShowAllMessages', function () {
Expand Down Expand Up @@ -1080,7 +1088,7 @@ test('Issue #37 - Toggle ShowAllMessages', function () {
ok(vm.two.one.isModified(), "Level 2 is modified");
ok(vm.three.two.one.isModified(), "Level 3 is modified");

equals(errors().length, 3, 'Grouping correctly finds 3 invalid properties');
equal(errors().length, 3, 'Grouping correctly finds 3 invalid properties');

// now shut them off
errors.showAllMessages(false);
Expand All @@ -1105,7 +1113,7 @@ test('Grouping options does not overwrite global configuration options', functio

var errors = ko.validation.group(vm);

equals(errors().length, 1, 'Grouping finds one invalid object because deep option was not specified.');
equal(errors().length, 1, 'Grouping finds one invalid object because deep option was not specified.');
});

test("Issue #235 - formatMessage should unwrap observable parameters", function () {
Expand Down Expand Up @@ -1153,10 +1161,10 @@ test('Changing the value of observable used in onlyIf condition triggers validat
required: { onlyIf: person.isMarried }
});
person.isMarried(false);
ok(person.spouseName.isValid(), 'Unmarried person is valid without spouse name')
ok(person.spouseName.isValid(), 'Unmarried person is valid without spouse name');

person.isMarried(true);
equal(person.spouseName.isValid(), false, 'Married person is not valid without spouse name')
equal(person.spouseName.isValid(), false, 'Married person is not valid without spouse name');
});
//#endregion

Expand Down
72 changes: 40 additions & 32 deletions Tests/validation-ui-tests.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
/// <reference path="jquery-1.7.1.js" />
/// <reference path="../Lib/knockout-latest.debug.js" />
/// <reference path="../Src/knockout.validation.js" />
/// <reference path="Qunit/qunit.js" />
/*global
module:false,
equal:false,
notEqual:false,
strictEqual:false,
test:false,
ok:false,
asyncTest:false,
start: false,
stop: false,
$: false
*/

module('UI Tests', {
setup: function () {
Expand Down Expand Up @@ -121,7 +129,7 @@ test('Showing Errors As Titles Works', function () {
var isValid = vm.firstName.isValid();

ok(!isValid, 'First Name is NOT Valid');
console.log($testInput)

var msg = $testInput.attr('title');

equal(msg, 'This field is required.', msg);
Expand Down Expand Up @@ -157,44 +165,44 @@ test('Original titles are restored', function () {
$testInput.val("a"); //set it
$testInput.change(); //trigger change event

var msg = $testInput.attr('title');
msg = $testInput.attr('title');
equal(msg, 'my-orig-title', msg);

});

test("Original titles are restored to blank", function () {
addTestHtml('<input id="myTestInput" data-bind="value: firstName" type="text" />');
addTestHtml('<input id="myTestInput" data-bind="value: firstName" type="text" />');

var vm = {
firstName: ko.observable('').extend({ required: true })
};
var vm = {
firstName: ko.observable('').extend({ required: true })
};

// make sure the options are ok.
ko.validation.init({
errorsAsTitleOnModified: true,
decorateElement: true
}, true);
// make sure the options are ok.
ko.validation.init({
errorsAsTitleOnModified: true,
decorateElement: true
}, true);

applyTestBindings(vm);
applyTestBindings(vm);

var $testInput = $('#myTestInput');
var $testInput = $('#myTestInput');

$testInput.val("a"); //set it
$testInput.change(); //trigger change event
$testInput.val("a"); //set it
$testInput.change(); //trigger change event

$testInput.val(""); //set it
$testInput.change(); //trigger change event
$testInput.val(""); //set it
$testInput.change(); //trigger change event

ok(!vm.firstName.isValid(), 'First Name is NOT Valid');
ok(!vm.firstName.isValid(), 'First Name is NOT Valid');

//now make the name valid
vm.firstName("valid name");
ok(vm.firstName.isValid(), "Should now be valid");
//now make the name valid
vm.firstName("valid name");
ok(vm.firstName.isValid(), "Should now be valid");

//and check that the title was reset to blank
var updatedTitle = $testInput.attr("title")
ok(!updatedTitle, "Title should have been reset to blank");
})
//and check that the title was reset to blank
var updatedTitle = $testInput.attr("title");
ok(!updatedTitle, "Title should have been reset to blank");
});

test('Original titles are restored with multiple validators, too', function () {

Expand Down Expand Up @@ -226,13 +234,13 @@ test('Original titles are restored with multiple validators, too', function () {
$testInput.val("a"); //set it
$testInput.change(); //trigger change event

var msg = $testInput.attr('title');
msg = $testInput.attr('title');
equal(msg, 'Please enter at least 2 characters.', msg);

$testInput.val("aa"); //set it
$testInput.change(); //trigger change event

var msg = $testInput.attr('title');
msg = $testInput.attr('title');
equal(msg, 'my-orig-title', msg);

});
Expand Down Expand Up @@ -265,7 +273,7 @@ test('Showing Errors As Titles is disabled sucessfully', function () {
var isValid = vm.firstName.isValid();

ok(!isValid, 'First Name is NOT Valid');
console.log($testInput)

var msg = $testInput.attr('title');

notEqual(msg, 'This field is required.', msg);
Expand Down
59 changes: 0 additions & 59 deletions grunt.js

This file was deleted.

Loading

0 comments on commit aad9642

Please sign in to comment.