feat(forms): add support for validations

This commit is contained in:
vsavkin
2015-02-11 11:10:31 -08:00
parent 65ebff056a
commit ded83e589b
10 changed files with 283 additions and 8 deletions
+43
View File
@@ -1,7 +1,28 @@
import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach, el} from 'angular2/test_lib';
import {ControlGroup, Control} from 'angular2/forms';
import * as validations from 'angular2/forms';
export function main() {
describe("Control", () => {
describe("validator", () => {
it("should run validator with the initial value", () => {
var c = new Control("value", validations.required);
expect(c.valid).toEqual(true);
});
it("should rerun the validator when the value changes", () => {
var c = new Control("value", validations.required);
c.updateValue(null);
expect(c.valid).toEqual(false);
});
it("should return errors", () => {
var c = new Control(null, validations.required);
expect(c.errors).toEqual({"required" : true});
});
});
});
describe("ControlGroup", () => {
describe("value", () => {
it("should be the reduced value of the child controls", () => {
@@ -17,5 +38,27 @@ export function main() {
expect(g.value).toEqual({})
});
});
describe("validator", () => {
it("should run the validator with the initial value", () => {
var g = new ControlGroup({
"one": new Control(null, validations.required)
});
expect(g.valid).toEqual(false);
expect(g.errors).toEqual({"one": {"required" : true}});
});
it("should run the validator with the value changes", () => {
var c = new Control(null, validations.required);
var g = new ControlGroup({"one": c});
c.updateValue("some value");
expect(g.valid).toEqual(true);
expect(g.errors).toEqual(null);
});
});
});
}