feat(forms): changed forms to capture submit events and fires synthetic ng-submit events

This commit is contained in:
vsavkin
2015-06-05 14:29:50 -07:00
parent 1a4d23742b
commit 5fc23caef7
3 changed files with 77 additions and 11 deletions

View File

@ -74,6 +74,25 @@ export function main() {
});
}));
it("should emit ng-submit event on submit",
inject([TestBed], fakeAsync(tb => {
var form = new ControlGroup({});
var ctx = MyComp.create({form: form, name: 'old'});
var t =
`<div><form [ng-form-model]="form" (ng-submit)="name='updated'"></form></div>`;
tb.createView(MyComp, {context: ctx, html: t})
.then((view) => {
var form = view.querySelector("form");
dispatchEvent(form, "submit");
tick();
expect(ctx.name).toEqual("updated");
});
})));
it("should work with single controls", inject([TestBed, AsyncTestCompleter], (tb, async) => {
var control = new Control("loginValue");
var ctx = MyComp.create({form: control});
@ -473,6 +492,23 @@ export function main() {
});
})));
it("should emit ng-submit event on submit",
inject([TestBed], fakeAsync(tb => {
var ctx = MyComp.create({name: 'old'});
var t = `<div><form (ng-submit)="name='updated'"></form></div>`;
tb.createView(MyComp, {context: ctx, html: t})
.then((view) => {
var form = view.querySelector("form");
dispatchEvent(form, "submit");
tick();
expect(ctx.name).toEqual("updated");
});
})));
it("should not create a template-driven form when ng-no-form is used",
inject([TestBed], fakeAsync(tb => {
var ctx = MyComp.create({name: null});