Fix JS codestyle

This commit is contained in:
Romain Neutron
2013-11-12 12:49:23 +01:00
parent 51fb364d13
commit 9fa95db23c
78 changed files with 5184 additions and 6309 deletions

View File

@@ -15,24 +15,7 @@ define([
'apps/admin/fields/views/modal',
'apps/admin/fields/views/save',
'apps/admin/fields/views/dcField'
], function(
chai,
fixtures,
$,
App,
FieldModel,
FieldCollection,
DcFieldCollection,
VocabularyCollection,
SingleItemView,
ListItemView,
AlertView,
EditView,
FieldErrorView,
ModalView,
SaveView,
DcFieldView
) {
], function (chai, fixtures, $, App, FieldModel, FieldCollection, DcFieldCollection, VocabularyCollection, SingleItemView, ListItemView, AlertView, EditView, FieldErrorView, ModalView, SaveView, DcFieldView) {
var expect = chai.expect;
var assert = chai.assert;
var should = chai.should();
@@ -44,36 +27,36 @@ define([
App.initialize();
describe("Admin field", function() {
describe("Initialization", function() {
it("should create a global variable", function() {
describe("Admin field", function () {
describe("Initialization", function () {
it("should create a global variable", function () {
should.exist(AdminFieldApp);
});
});
describe("Collections", function() {
describe("DcField Collection", function() {
beforeEach(function() {
describe("Collections", function () {
describe("DcField Collection", function () {
beforeEach(function () {
this.collection = new DcFieldCollection([]);
});
it("should set collection url according to provided 'sbas-id'", function() {
it("should set collection url according to provided 'sbas-id'", function () {
this.collection.url().should.equal("/admin/fields/dc-fields");
});
});
describe("Vocabulary Collection", function() {
beforeEach(function() {
describe("Vocabulary Collection", function () {
beforeEach(function () {
this.collection = new VocabularyCollection([]);
});
it("should set collection url according to provided 'sbas-id'", function() {
it("should set collection url according to provided 'sbas-id'", function () {
this.collection.url().should.equal("/admin/fields/vocabularies");
});
});
describe("Field Collection", function() {
beforeEach(function() {
describe("Field Collection", function () {
beforeEach(function () {
this.collection = new FieldCollection([
{"id": 1, "sbas-id": sbasId, "name": "Categorie", "tag": "XMP:Categorie"},
{"id": 2, "sbas-id": sbasId, "name": "Object", "tag": "XMP:Object"}
@@ -82,24 +65,24 @@ define([
});
});
describe("Initialization", function() {
it("should throw an exception if 'sbas_id' is missing", function() {
expect(function() {
describe("Initialization", function () {
it("should throw an exception if 'sbas_id' is missing", function () {
expect(function () {
new FieldCollection([]);
}).to.throw("You must set a sbas id");
});
it("should set collection url according to provided 'sbas-id'", function() {
this.collection.url().should.equal("/admin/fields/"+sbasId+"/fields");
it("should set collection url according to provided 'sbas-id'", function () {
this.collection.url().should.equal("/admin/fields/" + sbasId + "/fields");
});
});
describe("Methods", function() {
it("should retrieve categorie item if searching terms begins with 'cat'", function() {
describe("Methods", function () {
it("should retrieve categorie item if searching terms begins with 'cat'", function () {
this.collection.search('Cat')._wrapped.length.should.equal(1);
});
it("should retrieve previous and next index for given model", function() {
it("should retrieve previous and next index for given model", function () {
expect(this.collection.previousIndex(this.collection.first())).to.be.null;
this.collection.nextIndex(this.collection.first()).should.equal(1);
this.collection.previousIndex(this.collection.last()).should.equal(0);
@@ -109,29 +92,29 @@ define([
});
});
describe("Views", function() {
describe("Single Item Views", function() {
beforeEach(function() {
describe("Views", function () {
describe("Single Item Views", function () {
beforeEach(function () {
this.field = new FieldModel({"sbas-id": sbasId, "name": "Categorie", "tag": "XMP:Categorie"});
this.view = new SingleItemView({model: this.field});
});
it("render() should return the view object", function() {
it("render() should return the view object", function () {
this.view.render().should.equal(this.view);
});
it("should render as a LI element", function() {
it("should render as a LI element", function () {
this.view.render().el.nodeName.should.equal("LI");
});
it("should render as a LI element with proper properties", function() {
it("should render as a LI element with proper properties", function () {
this.view.render().$el.find('.field-name').html().should.equal("Categorie");
this.view.render().$el.find('.field-tag').html().should.equal("XMP:Categorie");
});
});
describe("List Item Views", function() {
beforeEach(function() {
describe("List Item Views", function () {
beforeEach(function () {
this.collection = new FieldCollection([
{"sbas-id": sbasId, "name": "Categorie", "tag": "XMP:Categorie"},
{"sbas-id": sbasId, "name": "Object", "tag": "XMP:Object"}
@@ -145,45 +128,47 @@ define([
});
});
it("render() should return the view object", function() {
it("render() should return the view object", function () {
this.view.render().should.equal(this.view);
});
it("should render as a DIV block", function() {
it("should render as a DIV block", function () {
this.view.render().el.nodeName.should.equal("DIV");
});
it("should include list items for all models in collection", function() {
it("should include list items for all models in collection", function () {
this.view.render();
this.view.$el.find("li").should.have.length(2);
});
});
describe("Alert Views", function() {
beforeEach(function() {
describe("Alert Views", function () {
beforeEach(function () {
this.view = new AlertView({alert: "info", message: "Hello world!"});
});
it("render() should return the view object", function() {
it("render() should return the view object", function () {
this.view.render().should.equal(this.view);
});
it("should render as a DIV element", function() {
it("should render as a DIV element", function () {
this.view.render().el.nodeName.should.equal("DIV");
});
});
describe("DcField Views", function() {
beforeEach(function() {
this.collection = new DcFieldCollection([{
"label": "Contributor",
"definition": "An entity responsible for making contributions to the resource.",
"URI": "http://dublincore.org/documents/dces/#contributor"
}, {
"label": "Coverage",
"definition": "The spatial or temporal topic of the resource, the spatial applicability of the resource,\n or the jurisdiction under which the resource\n is relevant.",
"URI": "http://dublincore.org/documents/dces/#coverage"
}
describe("DcField Views", function () {
beforeEach(function () {
this.collection = new DcFieldCollection([
{
"label": "Contributor",
"definition": "An entity responsible for making contributions to the resource.",
"URI": "http://dublincore.org/documents/dces/#contributor"
},
{
"label": "Coverage",
"definition": "The spatial or temporal topic of the resource, the spatial applicability of the resource,\n or the jurisdiction under which the resource\n is relevant.",
"URI": "http://dublincore.org/documents/dces/#coverage"
}
]);
var model = new FieldModel({"id": 1, "sbas-id": sbasId, "name": "Categorie", "tag": "XMP:Categorie"});
@@ -194,17 +179,17 @@ define([
});
});
it("render() should return the view object", function() {
it("render() should return the view object", function () {
this.view.render().should.equal(this.view);
});
it("should render as a DIV element", function() {
it("should render as a DIV element", function () {
this.view.render().el.nodeName.should.equal("DIV");
});
});
describe("Edit Views", function() {
beforeEach(function() {
describe("Edit Views", function () {
beforeEach(function () {
var model = new FieldModel({"id": 1, "sbas-id": sbasId, "name": "Categorie", "tag": "XMP:Categorie"});
this.view = new EditView({"model": model});
@@ -227,24 +212,24 @@ define([
AdminFieldApp.fieldListView.render();
});
it("render() should return the view object", function() {
it("render() should return the view object", function () {
this.view.render().should.equal(this.view);
});
it("should render as a DIV element", function() {
it("should render as a DIV element", function () {
this.view.render().el.nodeName.should.equal("DIV");
});
it("should not render an error message if provided tag is empty", function() {
var view = this.view.render();
it("should not render an error message if provided tag is empty", function () {
var view = this.view.render();
view.$('input#tag').val("").blur();
assert.isFalse(view.$('input#tag').closest(".control-group").hasClass("error"));
});
it("should uncheck vocabulary restricted if provided vocabulary is empty", function() {
var view = this.view.render();
it("should uncheck vocabulary restricted if provided vocabulary is empty", function () {
var view = this.view.render();
view.$('input#vocabulary-restricted').attr("checked", true);
view.$('input#vocabulary-type option').first().attr("selected", true);
@@ -253,22 +238,22 @@ define([
});
});
describe("FieldError Views", function() {
beforeEach(function() {
describe("FieldError Views", function () {
beforeEach(function () {
this.view = new FieldErrorView();
});
it("render() should return the view object", function() {
it("render() should return the view object", function () {
this.view.render().should.equal(this.view);
});
it("should render as a DIV element", function() {
it("should render as a DIV element", function () {
this.view.render().el.nodeName.should.equal("DIV");
});
});
describe("Modal Views", function() {
beforeEach(function() {
describe("Modal Views", function () {
beforeEach(function () {
var model = new FieldModel({"id": 1, "sbas-id": sbasId, "name": "Categorie", "tag": "XMP:Categorie"});
this.view = new ModalView({
@@ -277,34 +262,34 @@ define([
});
});
it("render() should return the view object", function() {
it("render() should return the view object", function () {
this.view.render().should.equal(this.view);
this.view.remove();
});
it("should render as a DIV element", function() {
it("should render as a DIV element", function () {
this.view.render().el.nodeName.should.equal("DIV");
this.view.remove();
});
});
describe("Save Views", function() {
beforeEach(function() {
describe("Save Views", function () {
beforeEach(function () {
this.view = new SaveView();
});
it("render() should return the view object", function() {
it("render() should return the view object", function () {
this.view.render().should.equal(this.view);
});
it("should render as a DIV element", function() {
it("should render as a DIV element", function () {
this.view.render().el.nodeName.should.equal("DIV");
});
});
});
describe("Edge cases", function() {
beforeEach(function() {
describe("Edge cases", function () {
beforeEach(function () {
AdminFieldApp.fieldsCollection.reset();
AdminFieldApp.fieldsCollection.add({"sbas-id": sbasId, "name": "Categorie", "tag": "XMP:Categorie"});
AdminFieldApp.dcFieldsCollection.add({
@@ -324,7 +309,7 @@ define([
AdminFieldApp.fieldListView.render();
});
it("should update collection when model change", function() {
it("should update collection when model change", function () {
AdminFieldApp.fieldListView.itemViews[0].clickAction();
AdminFieldApp.fieldEditView.model.set({
"name": "new name"
@@ -332,15 +317,17 @@ define([
assert.equal(AdminFieldApp.fieldListView.itemViews[0].model.get('name'), "new name", 'model is updated');
});
it("should update edit view when clicking on single element", function() {
it("should update edit view when clicking on single element", function () {
AdminFieldApp.fieldListView.itemViews[0].clickAction();
should.exist(AdminFieldApp.fieldEditView);
assert.equal(AdminFieldApp.fieldEditView.model, AdminFieldApp.fieldListView.collection.first(), 'model is updated');
});
it("should reorder collection on drop action", function() {
var ui = {item: {index: function() {return 2;}}};
AdminFieldApp.fieldListView.itemViews[0].dropAction({},ui);
it("should reorder collection on drop action", function () {
var ui = {item: {index: function () {
return 2;
}}};
AdminFieldApp.fieldListView.itemViews[0].dropAction({}, ui);
assert.equal(AdminFieldApp.fieldListView.collection.last().get('sorter'), 3, 'model is updated');
});
});

View File

@@ -5,14 +5,7 @@ define([
'common/forms/views/form',
'common/forms/views/input',
'common/forms/views/error'
], function(
chai,
fixtures,
$,
FormView,
InputView,
ErrorView
) {
], function (chai, fixtures, $, FormView, InputView, ErrorView) {
var expect = chai.expect;
var assert = chai.assert;
var should = chai.should();
@@ -20,10 +13,12 @@ define([
fixtures.path = 'fixtures';
$("body").append(fixtures.read('home/login/form', 'home/login/templates'));
describe("Login Home", function() {
describe("Form View", function() {
it("should initialize validator with proper rules", function() {
var rules = [{name: "hello",rules: "simple_rules"}];
describe("Login Home", function () {
describe("Form View", function () {
it("should initialize validator with proper rules", function () {
var rules = [
{name: "hello", rules: "simple_rules"}
];
var form = new FormView({
el: $('form[name=loginForm]'),
rules: rules
@@ -31,7 +26,7 @@ define([
form.validator.getRules().should.equal(rules);
});
it("should initialize input views", function() {
it("should initialize input views", function () {
var form = new FormView({
el: $('form[name=loginForm]')
});
@@ -39,7 +34,7 @@ define([
Object.keys(form.inputViews).length.should.equal(5);
});
it("should initialize errors", function() {
it("should initialize errors", function () {
var form = new FormView({
el: $('form[name=loginForm]')
});
@@ -47,14 +42,16 @@ define([
assert.isTrue(_.isEmpty(form.validator.getErrors()));
});
it("should render errors on submit", function() {
it("should render errors on submit", function () {
var form = new FormView({
el: $('form[name=loginForm]'),
rules: [{
"name": "login",
"rules": "required",
"message" : "something is wrong"
}]
rules: [
{
"name": "login",
"rules": "required",
"message": "something is wrong"
}
]
});
form._onSubmit(document.createEvent("Event"));
@@ -62,8 +59,8 @@ define([
});
});
describe("Input View", function() {
it("should initialize error view", function() {
describe("Input View", function () {
it("should initialize error view", function () {
var input = new InputView({
"name": "test",
"errorTemplate": "#field_errors"
@@ -72,9 +69,9 @@ define([
});
});
describe("Error View", function() {
it("should render errors", function() {
var error ={
describe("Error View", function () {
it("should render errors", function () {
var error = {
name: "test",
message: "Something is wrong"
};
@@ -82,7 +79,7 @@ define([
var errorView = new ErrorView({
"name": "test",
"errors": [error],
"el" : $(".error-view").first(),
"el": $(".error-view").first(),
"errorTemplate": "#field_errors"
});
@@ -91,7 +88,7 @@ define([
assert.isTrue(errorView.$el.html().indexOf(error.message) !== -1);
});
it("should empty errors content if there are no errors", function() {
it("should empty errors content if there are no errors", function () {
var $el = $(".error-view").first();
$el.html('previous error here');
@@ -99,7 +96,7 @@ define([
var errorView = new ErrorView({
"name": "test",
"errors": [],
"el" : $el,
"el": $el,
"errorTemplate": "#field_errors"
});

View File

@@ -3,108 +3,108 @@ define([
'models/field',
'models/dcField',
'models/vocabulary'
], function(chai, Field, DcField, Vocabulary) {
], function (chai, Field, DcField, Vocabulary) {
var expect = chai.expect;
var assert = chai.assert;
var should = chai.should();
describe("Models", function(){
describe("Field Model", function(){
describe("Initialization", function() {
describe("Models", function () {
describe("Field Model", function () {
describe("Initialization", function () {
var sbasId = 1;
beforeEach(function() {
beforeEach(function () {
this.field = new Field({
"sbas-id" : sbasId
"sbas-id": sbasId
});
});
it("should throw an exception if 'sbas-id' is missing", function() {
expect(function() {
it("should throw an exception if 'sbas-id' is missing", function () {
expect(function () {
new Field();
}).to.throw("You must set a sbas id");
});
it("should set model url according to provided 'sbas-id'", function() {
this.field.urlRoot().should.equal("/admin/fields/"+sbasId+"/fields");
it("should set model url according to provided 'sbas-id'", function () {
this.field.urlRoot().should.equal("/admin/fields/" + sbasId + "/fields");
});
it("should default business property to 'false'", function() {
it("should default business property to 'false'", function () {
this.field.get('business').should.be.false;
});
it("should default type property to 'string'", function() {
it("should default type property to 'string'", function () {
this.field.get('type').should.equal("string");
});
it("should default thumbtitle property to '0'", function() {
it("should default thumbtitle property to '0'", function () {
this.field.get('thumbtitle').should.equal("0");
});
it("should default tbranch property to 'empty'", function() {
it("should default tbranch property to 'empty'", function () {
this.field.get('tbranch').should.equal("");
});
it("should default separator property to 'empty'", function() {
it("should default separator property to 'empty'", function () {
this.field.get('separator').should.equal("");
});
it("should default required property to 'false'", function() {
it("should default required property to 'false'", function () {
this.field.get('required').should.be.false;
});
it("should default readonly property to 'false'", function() {
it("should default readonly property to 'false'", function () {
this.field.get('readonly').should.be.false;
});
it("should default multi property to 'false'", function() {
it("should default multi property to 'false'", function () {
this.field.get('multi').should.be.false;
});
it("should default vocabulary-restricted property to 'false'", function() {
it("should default vocabulary-restricted property to 'false'", function () {
this.field.get('vocabulary-restricted').should.be.false;
});
it("should default vocabulary-restricted property to 'false'", function() {
it("should default vocabulary-restricted property to 'false'", function () {
this.field.get('vocabulary-restricted').should.be.false;
});
it("should default report property to 'true'", function() {
it("should default report property to 'true'", function () {
this.field.get('report').should.be.true;
});
it("should default indexable property to 'true'", function() {
it("should default indexable property to 'true'", function () {
this.field.get('indexable').should.be.true;
});
it("should default dces-element property to 'null'", function() {
it("should default dces-element property to 'null'", function () {
expect(this.field.get('dces-element')).to.be.null;
});
it("should default vocabulary-type property to 'null'", function() {
it("should default vocabulary-type property to 'null'", function () {
expect(this.field.get('vocabulary-type')).to.be.null;
});
});
});
describe("DcField Model", function(){
describe("Initialization", function() {
beforeEach(function() {
describe("DcField Model", function () {
describe("Initialization", function () {
beforeEach(function () {
this.dcField = new DcField();
});
it("should set proper model url", function() {
it("should set proper model url", function () {
this.dcField.urlRoot().should.equal("/admin/fields/dc-fields");
});
});
});
describe("DcField Model", function(){
describe("Initialization", function() {
beforeEach(function() {
describe("DcField Model", function () {
describe("Initialization", function () {
beforeEach(function () {
this.vocabulary = new Vocabulary();
});
it("should set proper model url", function() {
it("should set proper model url", function () {
this.vocabulary.urlRoot().should.equal("/admin/fields/vocabularies");
});
});

View File

@@ -1,490 +1,611 @@
define([
'chai',
'common/forms/validator'
], function(chai, Validator) {
], function (chai, Validator) {
var expect = chai.expect;
var assert = chai.assert;
var should = chai.should();
describe("Validator", function(){
describe("Validator rules", function(){
describe("Validator", function () {
describe("Validator rules", function () {
beforeEach(function() {
this.validator = new Validator([{
name: "required",
rules: "required"
},{
name: "valid_email",
rules: "valid_email"
},{
name: "equal",
rules: "equal[toto]"
},{
name: "matches",
rules: "matches[to_match]"
},{
name: "valid_emails",
rules: "valid_emails"
},{
name: "min_length",
rules: "min_length[5]"
},{
name: "max_length",
rules: "max_length[5]"
},{
name: "exact_length",
rules: "exact_length[5]"
},{
name: "greater_than",
rules: "greater_than[5]"
},{
name: "less_than",
rules: "less_than[5]"
},{
name: "alpha",
rules: "alpha"
},{
name: "alpha_numeric",
rules: "alpha_numeric"
},{
name: "alpha_dash",
rules: "alpha_dash"
},{
name: "numeric",
rules: "numeric"
},{
name: "integer",
rules: "integer"
},{
name: "decimal",
rules: "decimal"
},{
name: "is_natural",
rules: "is_natural"
},{
name: "is_natural_no_zero",
rules: "is_natural_no_zero"
},{
name: "valid_ip",
rules: "valid_ip"
},{
name: "valid_url",
rules: "valid_url"
}]);
beforeEach(function () {
this.validator = new Validator([
{
name: "required",
rules: "required"
},
{
name: "valid_email",
rules: "valid_email"
},
{
name: "equal",
rules: "equal[toto]"
},
{
name: "matches",
rules: "matches[to_match]"
},
{
name: "valid_emails",
rules: "valid_emails"
},
{
name: "min_length",
rules: "min_length[5]"
},
{
name: "max_length",
rules: "max_length[5]"
},
{
name: "exact_length",
rules: "exact_length[5]"
},
{
name: "greater_than",
rules: "greater_than[5]"
},
{
name: "less_than",
rules: "less_than[5]"
},
{
name: "alpha",
rules: "alpha"
},
{
name: "alpha_numeric",
rules: "alpha_numeric"
},
{
name: "alpha_dash",
rules: "alpha_dash"
},
{
name: "numeric",
rules: "numeric"
},
{
name: "integer",
rules: "integer"
},
{
name: "decimal",
rules: "decimal"
},
{
name: "is_natural",
rules: "is_natural"
},
{
name: "is_natural_no_zero",
rules: "is_natural_no_zero"
},
{
name: "valid_ip",
rules: "valid_ip"
},
{
name: "valid_url",
rules: "valid_url"
}
]);
});
it("should detect an error if field is required and value is blank", function() {
this.validator.validate([{
name :"required",
value: ""
}]);
it("should detect an error if field is required and value is blank", function () {
this.validator.validate([
{
name: "required",
value: ""
}
]);
this.validator.getErrors().length.should.equal(1);
});
it("should detect an error if field is not a valid email", function() {
this.validator.validate([{
name :"valid_email",
value: "email.not.va@"
}]);
it("should detect an error if field is not a valid email", function () {
this.validator.validate([
{
name: "valid_email",
value: "email.not.va@"
}
]);
this.validator.getErrors().length.should.equal(1);
});
it("should not detect an error if field is a valid email", function() {
this.validator.validate([{
name :"valid_email",
value: "valid@email.com"
}]);
it("should not detect an error if field is a valid email", function () {
this.validator.validate([
{
name: "valid_email",
value: "valid@email.com"
}
]);
this.validator.getErrors().length.should.equal(0);
this.validator.validate([{
name :"valid_email",
value: "valid+34@email.com"
}]);
this.validator.validate([
{
name: "valid_email",
value: "valid+34@email.com"
}
]);
this.validator.getErrors().length.should.equal(0);
});
it("should detect an error if field is not a valid emails", function() {
this.validator.validate([{
name :"valid_emails",
value: "valid@email.com, email.not.va@"
}]);
it("should detect an error if field is not a valid emails", function () {
this.validator.validate([
{
name: "valid_emails",
value: "valid@email.com, email.not.va@"
}
]);
this.validator.getErrors().length.should.equal(1);
});
it("should not detect an error if field is a valid emails", function() {
this.validator.validate([{
name :"valid_emails",
value: "valid32@email.com, valid2@email.com"
}]);
it("should not detect an error if field is a valid emails", function () {
this.validator.validate([
{
name: "valid_emails",
value: "valid32@email.com, valid2@email.com"
}
]);
this.validator.getErrors().length.should.equal(0);
this.validator.validate([{
name :"valid_emails",
value: "valid@email.com"
}]);
this.validator.validate([
{
name: "valid_emails",
value: "valid@email.com"
}
]);
this.validator.getErrors().length.should.equal(0);
});
it("should detect an error if field is not equal to default string toto", function() {
this.validator.validate([{
name :"equal",
value: "tata"
}]);
it("should detect an error if field is not equal to default string toto", function () {
this.validator.validate([
{
name: "equal",
value: "tata"
}
]);
this.validator.getErrors().length.should.equal(1);
});
it("should not detect an error if field is equal to default string toto", function() {
this.validator.validate([{
name :"equal",
value: "toto"
}]);
it("should not detect an error if field is equal to default string toto", function () {
this.validator.validate([
{
name: "equal",
value: "toto"
}
]);
this.validator.getErrors().length.should.equal(0);
});
it("should detect an error if field value 'match 'is not equal to field value 'to_match'", function() {
this.validator.validate([{
name :"matches",
value: "toto"
}, {
name: "to_match",
value: "tata"
}]);
it("should detect an error if field value 'match 'is not equal to field value 'to_match'", function () {
this.validator.validate([
{
name: "matches",
value: "toto"
},
{
name: "to_match",
value: "tata"
}
]);
this.validator.getErrors().length.should.equal(1);
});
it("should not detect an error if field value 'match' is equal to field value 'to_match'", function() {
this.validator.validate([{
name :"matches",
value: "toto"
}, {
name: "to_match",
value: "toto"
}]);
it("should not detect an error if field value 'match' is equal to field value 'to_match'", function () {
this.validator.validate([
{
name: "matches",
value: "toto"
},
{
name: "to_match",
value: "toto"
}
]);
this.validator.getErrors().length.should.equal(0);
});
it("should detect an error if field value 'min_length' is < to 5", function() {
this.validator.validate([{
name :"min_length",
value: "toto"
}]);
it("should detect an error if field value 'min_length' is < to 5", function () {
this.validator.validate([
{
name: "min_length",
value: "toto"
}
]);
this.validator.getErrors().length.should.equal(1);
});
it("should not detect an error if field value 'min_length' is >= to 5", function() {
this.validator.validate([{
name :"min_length",
value: "totos"
}]);
it("should not detect an error if field value 'min_length' is >= to 5", function () {
this.validator.validate([
{
name: "min_length",
value: "totos"
}
]);
this.validator.getErrors().length.should.equal(0);
});
it("should detect an error if field value 'max_length' is > to 5", function() {
this.validator.validate([{
name :"max_length",
value: "tostos"
}]);
it("should detect an error if field value 'max_length' is > to 5", function () {
this.validator.validate([
{
name: "max_length",
value: "tostos"
}
]);
this.validator.getErrors().length.should.equal(1);
});
it("should not detect an error if field value 'max_length' is <= to 5", function() {
this.validator.validate([{
name :"max_length",
value: "toto"
}]);
it("should not detect an error if field value 'max_length' is <= to 5", function () {
this.validator.validate([
{
name: "max_length",
value: "toto"
}
]);
this.validator.getErrors().length.should.equal(0);
});
it("should detect an error if field value 'greater_than' is < to 5", function() {
this.validator.validate([{
name :"greater_than",
value: "3"
}]);
it("should detect an error if field value 'greater_than' is < to 5", function () {
this.validator.validate([
{
name: "greater_than",
value: "3"
}
]);
this.validator.getErrors().length.should.equal(1);
});
it("should not detect an error if field value 'greater_than' is > to 5", function() {
this.validator.validate([{
name :"greater_than",
value: "6"
}]);
it("should not detect an error if field value 'greater_than' is > to 5", function () {
this.validator.validate([
{
name: "greater_than",
value: "6"
}
]);
this.validator.getErrors().length.should.equal(0);
});
it("should detect an error if field value 'less_than' is > to 5", function() {
this.validator.validate([{
name :"less_than",
value: "6"
}]);
it("should detect an error if field value 'less_than' is > to 5", function () {
this.validator.validate([
{
name: "less_than",
value: "6"
}
]);
this.validator.getErrors().length.should.equal(1);
});
it("should not detect an error if field value 'less_than' is <= to 5", function() {
this.validator.validate([{
name :"less_than",
value: "3"
}]);
it("should not detect an error if field value 'less_than' is <= to 5", function () {
this.validator.validate([
{
name: "less_than",
value: "3"
}
]);
this.validator.getErrors().length.should.equal(0);
});
it("should detect an error if field value 'exact_length' is = to 5", function() {
this.validator.validate([{
name :"exact_length",
value: "toto"
}]);
it("should detect an error if field value 'exact_length' is = to 5", function () {
this.validator.validate([
{
name: "exact_length",
value: "toto"
}
]);
this.validator.getErrors().length.should.equal(1);
});
it("should not detect an error if field value 'exact_length' is = to 5", function() {
this.validator.validate([{
name :"exact_length",
value: "totos"
}]);
it("should not detect an error if field value 'exact_length' is = to 5", function () {
this.validator.validate([
{
name: "exact_length",
value: "totos"
}
]);
this.validator.getErrors().length.should.equal(0);
});
it("should detect an error if field value 'alpha' is not alpha", function() {
this.validator.validate([{
name :"alpha",
value: "toto12"
}]);
it("should detect an error if field value 'alpha' is not alpha", function () {
this.validator.validate([
{
name: "alpha",
value: "toto12"
}
]);
this.validator.getErrors().length.should.equal(1);
});
it("should not detect an error if field value 'alpha' is alpha", function() {
this.validator.validate([{
name :"alpha",
value: "totos"
}]);
it("should not detect an error if field value 'alpha' is alpha", function () {
this.validator.validate([
{
name: "alpha",
value: "totos"
}
]);
this.validator.getErrors().length.should.equal(0);
});
it("should detect an error if field value 'alpha_numeric' is not alpha numeric", function() {
this.validator.validate([{
name :"alpha_numeric",
value: "toto#"
}]);
it("should detect an error if field value 'alpha_numeric' is not alpha numeric", function () {
this.validator.validate([
{
name: "alpha_numeric",
value: "toto#"
}
]);
this.validator.getErrors().length.should.equal(1);
});
it("should not detect an error if field value 'alpha_numeric' is alpha numeric", function() {
this.validator.validate([{
name :"alpha_numeric",
value: "totos12"
}]);
it("should not detect an error if field value 'alpha_numeric' is alpha numeric", function () {
this.validator.validate([
{
name: "alpha_numeric",
value: "totos12"
}
]);
this.validator.getErrors().length.should.equal(0);
});
it("should detect an error if field value 'numeric' is not numeric", function() {
this.validator.validate([{
name :"numeric",
value: "toto"
}]);
it("should detect an error if field value 'numeric' is not numeric", function () {
this.validator.validate([
{
name: "numeric",
value: "toto"
}
]);
this.validator.getErrors().length.should.equal(1);
});
it("should not detect an error if field value 'numeric' is numeric", function() {
this.validator.validate([{
name :"numeric",
value: "123"
}]);
it("should not detect an error if field value 'numeric' is numeric", function () {
this.validator.validate([
{
name: "numeric",
value: "123"
}
]);
this.validator.getErrors().length.should.equal(0);
});
it("should detect an error if field value 'integer' is not integer", function() {
this.validator.validate([{
name :"integer",
value: "3.44"
}]);
it("should detect an error if field value 'integer' is not integer", function () {
this.validator.validate([
{
name: "integer",
value: "3.44"
}
]);
this.validator.getErrors().length.should.equal(1);
});
it("should not detect an error if field value 'integer' is integer", function() {
this.validator.validate([{
name :"integer",
value: "123"
}]);
it("should not detect an error if field value 'integer' is integer", function () {
this.validator.validate([
{
name: "integer",
value: "123"
}
]);
this.validator.getErrors().length.should.equal(0);
});
it("should detect an error if field value 'decimal' is not decimal", function() {
this.validator.validate([{
name :"decimal",
value: "23a"
}]);
it("should detect an error if field value 'decimal' is not decimal", function () {
this.validator.validate([
{
name: "decimal",
value: "23a"
}
]);
this.validator.getErrors().length.should.equal(1);
});
it("should not detect an error if field value 'decimal' is decimal", function() {
this.validator.validate([{
name :"decimal",
value: "1.23"
}]);
it("should not detect an error if field value 'decimal' is decimal", function () {
this.validator.validate([
{
name: "decimal",
value: "1.23"
}
]);
this.validator.getErrors().length.should.equal(0);
this.validator.validate([{
name :"decimal",
value: "123"
}]);
this.validator.validate([
{
name: "decimal",
value: "123"
}
]);
this.validator.getErrors().length.should.equal(0);
});
it("should detect an error if field value 'natural' is not natural", function() {
this.validator.validate([{
name :"is_natural",
value: "-2"
}]);
it("should detect an error if field value 'natural' is not natural", function () {
this.validator.validate([
{
name: "is_natural",
value: "-2"
}
]);
this.validator.getErrors().length.should.equal(1);
});
it("should not detect an error if field value 'natural' is natural", function() {
this.validator.validate([{
name :"is_natural",
value: "0"
}]);
it("should not detect an error if field value 'natural' is natural", function () {
this.validator.validate([
{
name: "is_natural",
value: "0"
}
]);
this.validator.getErrors().length.should.equal(0);
});
it("should detect an error if field value 'is_natural_no_zero' is not a natural no zero", function() {
this.validator.validate([{
name :"is_natural_no_zero",
value: "0"
}]);
it("should detect an error if field value 'is_natural_no_zero' is not a natural no zero", function () {
this.validator.validate([
{
name: "is_natural_no_zero",
value: "0"
}
]);
this.validator.getErrors().length.should.equal(1);
});
it("should not detect an error if field value 'is_natural_no_zero' is a natural no zero", function() {
this.validator.validate([{
name :"is_natural_no_zero",
value: "1"
}]);
it("should not detect an error if field value 'is_natural_no_zero' is a natural no zero", function () {
this.validator.validate([
{
name: "is_natural_no_zero",
value: "1"
}
]);
this.validator.getErrors().length.should.equal(0);
});
it("should detect an error if field value 'valid_ip' is not a valid ip", function() {
this.validator.validate([{
name :"valid_ip",
value: "12.8.1.187.2"
}]);
it("should detect an error if field value 'valid_ip' is not a valid ip", function () {
this.validator.validate([
{
name: "valid_ip",
value: "12.8.1.187.2"
}
]);
this.validator.getErrors().length.should.equal(1);
this.validator.validate([{
name :"valid_ip",
value: "1234.12.12"
}]);
this.validator.validate([
{
name: "valid_ip",
value: "1234.12.12"
}
]);
this.validator.getErrors().length.should.equal(1);
this.validator.validate([{
name :"valid_ip",
value: "0.0"
}]);
this.validator.validate([
{
name: "valid_ip",
value: "0.0"
}
]);
this.validator.getErrors().length.should.equal(1);
});
it("should not detect an error if field value 'valid_ip' a valid ip", function() {
this.validator.validate([{
name :"valid_ip",
value: "127.0.0.1"
}]);
it("should not detect an error if field value 'valid_ip' a valid ip", function () {
this.validator.validate([
{
name: "valid_ip",
value: "127.0.0.1"
}
]);
this.validator.getErrors().length.should.equal(0);
this.validator.validate([{
name :"valid_ip",
value: "my.domain"
}]);
this.validator.validate([
{
name: "valid_ip",
value: "my.domain"
}
]);
this.validator.getErrors().length.should.equal(0);
});
it("should detect an error if field value 'valid_url' is not a valid http url", function() {
this.validator.validate([{
name :"valid_url",
value: "toto"
}]);
it("should detect an error if field value 'valid_url' is not a valid http url", function () {
this.validator.validate([
{
name: "valid_url",
value: "toto"
}
]);
this.validator.getErrors().length.should.equal(1);
this.validator.validate([{
name :"valid_url",
value: "toto.123s"
}]);
this.validator.validate([
{
name: "valid_url",
value: "toto.123s"
}
]);
this.validator.getErrors().length.should.equal(1);
this.validator.validate([{
name :"valid_url",
value: "http:/#toto.com"
}]);
this.validator.validate([
{
name: "valid_url",
value: "http:/#toto.com"
}
]);
this.validator.getErrors().length.should.equal(1);
this.validator.validate([{
name :"valid_url",
value: "htp:/toto.com"
}]);
this.validator.validate([
{
name: "valid_url",
value: "htp:/toto.com"
}
]);
this.validator.getErrors().length.should.equal(1);
});
it("should not detect an error if field value 'valid_url' is a valid http url", function() {
this.validator.validate([{
name :"valid_url",
value: "http://valid.url.com"
}]);
it("should not detect an error if field value 'valid_url' is a valid http url", function () {
this.validator.validate([
{
name: "valid_url",
value: "http://valid.url.com"
}
]);
this.validator.getErrors().length.should.equal(0);
this.validator.validate([{
name :"valid_url",
value: "https://valid.url.com"
}]);
this.validator.validate([
{
name: "valid_url",
value: "https://valid.url.com"
}
]);
this.validator.getErrors().length.should.equal(0);
this.validator.getErrors().length.should.equal(0);
this.validator.validate([{
name :"valid_url",
value: "http://valid.url.com/?test=3"
}]);
this.validator.validate([
{
name: "valid_url",
value: "http://valid.url.com/?test=3"
}
]);
this.validator.getErrors().length.should.equal(0);
this.validator.validate([{
name :"valid_url",
value: "http://valid.url.com/?test=3#salut"
}]);
this.validator.validate([
{
name: "valid_url",
value: "http://valid.url.com/?test=3#salut"
}
]);
this.validator.getErrors().length.should.equal(0);
});