Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 118a547

Browse files
committed
fixup! add test for detached controls
1 parent c6e12c6 commit 118a547

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

test/ng/directive/formSpec.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,73 @@ describe('form', function() {
557557
expect(child.$submitted).toBeTruthy();
558558
});
559559

560+
561+
it('should not propagate $submitted state on removed child forms when parent is submitted', function() {
562+
doc = jqLite(
563+
'<ng-form name="parent">' +
564+
'<ng-form name="child">' +
565+
'<ng-form name="grandchild">' +
566+
'<input ng:model="modelA" name="inputA">' +
567+
'</ng-form>' +
568+
'</ng-form>' +
569+
'</ng-form>');
570+
$compile(doc)(scope);
571+
572+
var parent = scope.parent,
573+
child = scope.child,
574+
grandchild = scope.grandchild,
575+
ggchild = scope.greatgrandchild;
576+
577+
parent.$removeControl(child);
578+
579+
parent.$setSubmitted();
580+
expect(parent.$submitted).toBeTruthy();
581+
expect(child.$submitted).not.toBeTruthy();
582+
expect(grandchild.$submitted).not.toBeTruthy();
583+
584+
parent.$addControl(child);
585+
586+
expect(parent.$submitted).toBeTruthy();
587+
expect(child.$submitted).not.toBeTruthy();
588+
expect(grandchild.$submitted).not.toBeTruthy();
589+
590+
parent.$setSubmitted();
591+
expect(parent.$submitted).toBeTruthy();
592+
expect(child.$submitted).toBeTruthy();
593+
expect(grandchild.$submitted).toBeTruthy();
594+
595+
parent.$removeControl(child);
596+
597+
expect(parent.$submitted).toBeTruthy();
598+
expect(child.$submitted).toBeTruthy();
599+
expect(grandchild.$submitted).toBeTruthy();
600+
601+
parent.$setPristine(); // sets $submitted to false
602+
expect(parent.$submitted).not.toBeTruthy();
603+
expect(child.$submitted).toBeTruthy();
604+
expect(grandchild.$submitted).toBeTruthy();
605+
606+
grandchild.$setPristine();
607+
expect(grandchild.$submitted).not.toBeTruthy();
608+
609+
child.$setSubmitted();
610+
expect(parent.$submitted).not.toBeTruthy();
611+
expect(child.$submitted).toBeTruthy();
612+
expect(grandchild.$submitted).toBeTruthy();
613+
614+
child.$setPristine();
615+
expect(parent.$submitted).not.toBeTruthy();
616+
expect(child.$submitted).not.toBeTruthy();
617+
expect(grandchild.$submitted).not.toBeTruthy();
618+
619+
// Test upwards submission setting
620+
grandchild.$setSubmitted();
621+
expect(parent.$submitted).not.toBeTruthy();
622+
expect(child.$submitted).toBeTruthy();
623+
expect(grandchild.$submitted).toBeTruthy();
624+
});
625+
626+
560627
it('should set $submitted to true on child and parent forms when form is submitted', function() {
561628
doc = jqLite(
562629
'<ng-form name="parent">' +

0 commit comments

Comments
 (0)