| 
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 |  |  | import { | 
					
						
							|  |  |  |   ddescribe, | 
					
						
							|  |  |  |   describe, | 
					
						
							|  |  |  |   it, | 
					
						
							|  |  |  |   iit, | 
					
						
							|  |  |  |   xit, | 
					
						
							|  |  |  |   expect, | 
					
						
							|  |  |  |   beforeEach, | 
					
						
							|  |  |  |   afterEach, | 
					
						
							|  |  |  |   el | 
					
						
							|  |  |  | } from 'angular2/test_lib'; | 
					
						
							| 
									
										
										
										
											2015-03-19 14:21:40 -07:00
										 |  |  | import {Control, FormBuilder, Validators} from 'angular2/forms'; | 
					
						
							| 
									
										
										
										
											2015-03-10 18:12:50 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | export function main() { | 
					
						
							|  |  |  |   describe("Form Builder", () => { | 
					
						
							|  |  |  |     var b; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 |  |  |     beforeEach(() => { b = new FormBuilder(); }); | 
					
						
							| 
									
										
										
										
											2015-03-10 18:12:50 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it("should create controls from a value", () => { | 
					
						
							| 
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 |  |  |       var g = b.group({"login": "some value"}); | 
					
						
							| 
									
										
										
										
											2015-03-10 18:12:50 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(g.controls["login"].value).toEqual("some value"); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it("should create controls from an array", () => { | 
					
						
							| 
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 |  |  |       var g = b.group({"login": ["some value"], "password": ["some value", Validators.required]}); | 
					
						
							| 
									
										
										
										
											2015-03-10 18:12:50 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(g.controls["login"].value).toEqual("some value"); | 
					
						
							|  |  |  |       expect(g.controls["password"].value).toEqual("some value"); | 
					
						
							| 
									
										
										
										
											2015-03-19 14:21:40 -07:00
										 |  |  |       expect(g.controls["password"].validator).toEqual(Validators.required); | 
					
						
							| 
									
										
										
										
											2015-03-10 18:12:50 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it("should use controls", () => { | 
					
						
							| 
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 |  |  |       var g = b.group({"login": b.control("some value", Validators.required)}); | 
					
						
							| 
									
										
										
										
											2015-03-10 18:12:50 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(g.controls["login"].value).toEqual("some value"); | 
					
						
							| 
									
										
										
										
											2015-03-19 14:21:40 -07:00
										 |  |  |       expect(g.controls["login"].validator).toBe(Validators.required); | 
					
						
							| 
									
										
										
										
											2015-03-10 18:12:50 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it("should create groups with optional controls", () => { | 
					
						
							| 
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 |  |  |       var g = b.group({"login": "some value"}, {"optionals": {"login": false}}); | 
					
						
							| 
									
										
										
										
											2015-03-10 18:12:50 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(g.contains("login")).toEqual(false); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it("should create groups with a custom validator", () => { | 
					
						
							| 
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 |  |  |       var g = b.group({"login": "some value"}, {"validator": Validators.nullValidator}); | 
					
						
							| 
									
										
										
										
											2015-03-10 18:12:50 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-19 14:21:40 -07:00
										 |  |  |       expect(g.validator).toBe(Validators.nullValidator); | 
					
						
							| 
									
										
										
										
											2015-03-10 18:12:50 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it("should use default validators when no validators are provided", () => { | 
					
						
							| 
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 |  |  |       var g = b.group({"login": "some value"}); | 
					
						
							| 
									
										
										
										
											2015-03-19 14:21:40 -07:00
										 |  |  |       expect(g.controls["login"].validator).toBe(Validators.nullValidator); | 
					
						
							|  |  |  |       expect(g.validator).toBe(Validators.group); | 
					
						
							| 
									
										
										
										
											2015-03-10 18:12:50 -07:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2015-03-25 10:51:05 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it("should create control arrays", () => { | 
					
						
							|  |  |  |       var c = b.control("three"); | 
					
						
							| 
									
										
										
										
											2015-05-22 12:32:49 -07:00
										 |  |  |       var a = b.array(["one", ["two", Validators.required], c, b.array(['four'])]); | 
					
						
							| 
									
										
										
										
											2015-03-25 10:51:05 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(a.value).toEqual(['one', 'two', 'three', ['four']]); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2015-03-10 18:12:50 -07:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2015-03-25 10:51:05 -07:00
										 |  |  | } |