Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tests for severity #1

Merged
merged 5 commits into from
Nov 3, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "Renamed 'severity' in 'validatable' to 'errorSeverity'"
This reverts commit 466c0b3.
  • Loading branch information
Hekku2 committed Nov 3, 2016
commit a7fa4e51fb1ada9a2aabe3c63a9e9866069d6fb4
8 changes: 4 additions & 4 deletions dist/knockout.validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ kv.configuration = configuration;
// }
// )};
//
if (params && (params.message || params.onlyIf || params.severity)) { //if it has a message, condition, or severity object, then its an object literal to use
if (params && !ko.isObservable(params) && (params.message || params.onlyIf || params.severity)) { //if it has a message, condition, or severity object, then its an object literal to use
return kv.addRule(observable, {
rule: ruleName,
message: params.message,
Expand Down Expand Up @@ -1207,8 +1207,8 @@ ko.extenders['validatable'] = function (observable, options) {
throttleEvaluation : options.throttle || config.throttle
};

observable.error = ko.observable(null); // holds the error message, we only need one since we stop processing validators when one is invalid and has a severity of 1
observable.errorSeverity = ko.observable(1);
observable.error = ko.observable(null); // holds the error message, we only need one since we stop processing validators when one is invalid and has and has a severity of 1
observable.severity = ko.observable(1);

// observable.rules:
// ObservableArray of Rule Contexts, where a Rule Context is simply the name of a rule and the params to supply to it
Expand All @@ -1233,7 +1233,7 @@ ko.extenders['validatable'] = function (observable, options) {
var previousIsValid = observable.__valid__.peek();

observable.error(error);
observable.errorSeverity(severity);
observable.severity(severity);
observable.__valid__(false);

if (previousError !== error && !previousIsValid) {
Expand Down
2 changes: 1 addition & 1 deletion src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@
// }
// )};
//
if (params && (params.message || params.onlyIf || params.severity)) { //if it has a message, condition, or severity object, then its an object literal to use
if (params && !ko.isObservable(params) && (params.message || params.onlyIf || params.severity)) { //if it has a message, condition, or severity object, then its an object literal to use
return ko.validation.addRule(observable, {
rule: ruleName,
message: params.message,
Expand Down
6 changes: 3 additions & 3 deletions src/extenders.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ ko.extenders['validatable'] = function (observable, options) {
throttleEvaluation : options.throttle || config.throttle
};

observable.error = ko.observable(null); // holds the error message, we only need one since we stop processing validators when one is invalid and has a severity of 1
observable.errorSeverity = ko.observable(1);
observable.error = ko.observable(null); // holds the error message, we only need one since we stop processing validators when one is invalid and has and has a severity of 1
observable.severity = ko.observable(1);

// observable.rules:
// ObservableArray of Rule Contexts, where a Rule Context is simply the name of a rule and the params to supply to it
Expand All @@ -68,7 +68,7 @@ ko.extenders['validatable'] = function (observable, options) {
var previousIsValid = observable.__valid__.peek();

observable.error(error);
observable.errorSeverity(severity);
observable.severity(severity);
observable.__valid__(false);

if (previousError !== error && !previousIsValid) {
Expand Down
10 changes: 5 additions & 5 deletions test/validation-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ QUnit.test('message parameter receives params and observable when async', functi

//#region Severity tests

QUnit.module('Error Severity tests');
QUnit.module('Severity tests');

QUnit.test('isValid returns false for warning severity', function(assert) {
var testObj = ko.observable('something').extend({
Expand All @@ -446,7 +446,7 @@ QUnit.test('isValid returns false for warning severity', function(assert) {
});
testObj('');
assert.equal(testObj.isValid(), false);
assert.equal(testObj.errorSeverity(), 2, 'Severity should equal severity defined in required-validation');
assert.equal(testObj.severity(), 2, 'Severity should equal severity defined in required-validation');
});

QUnit.test('default severity is 1', function(assert) {
Expand All @@ -455,7 +455,7 @@ QUnit.test('default severity is 1', function(assert) {
});
testObj('');
assert.equal(testObj.isValid(), false);
assert.equal(testObj.errorSeverity(), 1, 'Severity should be 1 when not defined');
assert.equal(testObj.severity(), 1, 'Severity should be 1 when not defined');
});

QUnit.test('Lowest invalid rule severity is returned', function(assert) {
Expand All @@ -474,7 +474,7 @@ QUnit.test('Lowest invalid rule severity is returned', function(assert) {
});
testObj('test');
assert.equal(testObj.isValid(), false);
assert.equal(testObj.errorSeverity(), 2, 'Lowest broken rule severity should be 2');
assert.equal(testObj.severity(), 2, 'Lowest broken rule severity should be 2');
});

QUnit.test('Lowest invalid rule severity for default severity is returned', function(assert) {
Expand All @@ -486,6 +486,6 @@ QUnit.test('Lowest invalid rule severity for default severity is returned', func
});
testObj('');
assert.equal(testObj.isValid(), false);
assert.equal(testObj.errorSeverity(), 1, 'Default severity for broken rule should be 1');
assert.equal(testObj.severity(), 1, 'Default severity for broken rule should be 1');
});
//#endregion