@@ -27,6 +27,7 @@ const NAME_EDIT_TEMPLATE = `
27
27
[cdkEditControlIgnoreSubmitUnlessValid]="ignoreSubmitUnlessValid"
28
28
[cdkEditControlClickOutBehavior]="clickOutBehavior">
29
29
<input [ngModel]="element.name" name="name" required>
30
+ <input [ngModel]="element.weight" name="weight">
30
31
<br>
31
32
<button class="submit" type="submit">Confirm</button>
32
33
<button class="revert" cdkEditRevert>Revert</button>
@@ -131,12 +132,16 @@ abstract class BaseTestComponent {
131
132
return document . querySelector ( '.cdk-overlay-connected-position-bounding-box' ) ;
132
133
}
133
134
134
- getInput ( ) {
135
- return document . querySelector ( 'input' ) as HTMLInputElement | null ;
135
+ getNameInput ( ) {
136
+ return document . querySelector ( 'input[name="name"]' ) as HTMLInputElement | null ;
137
+ }
138
+
139
+ getWeightInput ( ) {
140
+ return document . querySelector ( 'input[name="weight"]' ) as HTMLInputElement | null ;
136
141
}
137
142
138
143
lensIsOpen ( ) {
139
- return ! ! this . getInput ( ) ;
144
+ return ! ! this . getNameInput ( ) ;
140
145
}
141
146
142
147
getSubmitButton ( ) {
@@ -602,7 +607,7 @@ cdkPopoverEditTabOut`, fakeAsync(() => {
602
607
it ( 'shows a lens with the value from the table' , fakeAsync ( ( ) => {
603
608
component . openLens ( ) ;
604
609
605
- expect ( component . getInput ( ) ! . value ) . toBe ( 'Hydrogen' ) ;
610
+ expect ( component . getNameInput ( ) ! . value ) . toBe ( 'Hydrogen' ) ;
606
611
clearLeftoverTimers ( ) ;
607
612
} ) ) ;
608
613
@@ -654,8 +659,8 @@ cdkPopoverEditTabOut`, fakeAsync(() => {
654
659
it ( 'updates the form and submits, closing the lens' , fakeAsync ( ( ) => {
655
660
component . openLens ( ) ;
656
661
657
- component . getInput ( ) ! . value = 'Hydragon' ;
658
- component . getInput ( ) ! . dispatchEvent ( new Event ( 'input' ) ) ;
662
+ component . getNameInput ( ) ! . value = 'Hydragon' ;
663
+ component . getNameInput ( ) ! . dispatchEvent ( new Event ( 'input' ) ) ;
659
664
660
665
component . clickSubmitButton ( ) ;
661
666
fixture . detectChanges ( ) ;
@@ -667,8 +672,8 @@ cdkPopoverEditTabOut`, fakeAsync(() => {
667
672
it ( 'does not close the lens on submit when form is invalid' , fakeAsync ( ( ) => {
668
673
component . openLens ( ) ;
669
674
670
- component . getInput ( ) ! . value = '' ;
671
- component . getInput ( ) ! . dispatchEvent ( new Event ( 'input' ) ) ;
675
+ component . getNameInput ( ) ! . value = '' ;
676
+ component . getNameInput ( ) ! . dispatchEvent ( new Event ( 'input' ) ) ;
672
677
673
678
component . clickSubmitButton ( ) ;
674
679
@@ -681,8 +686,8 @@ cdkPopoverEditTabOut`, fakeAsync(() => {
681
686
component . ignoreSubmitUnlessValid = false ;
682
687
component . openLens ( ) ;
683
688
684
- component . getInput ( ) ! . value = '' ;
685
- component . getInput ( ) ! . dispatchEvent ( new Event ( 'input' ) ) ;
689
+ component . getNameInput ( ) ! . value = '' ;
690
+ component . getNameInput ( ) ! . dispatchEvent ( new Event ( 'input' ) ) ;
686
691
687
692
component . clickSubmitButton ( ) ;
688
693
@@ -702,8 +707,8 @@ cdkPopoverEditTabOut`, fakeAsync(() => {
702
707
it ( 'closes and reopens a lens with modified value persisted' , fakeAsync ( ( ) => {
703
708
component . openLens ( ) ;
704
709
705
- component . getInput ( ) ! . value = 'Hydragon' ;
706
- component . getInput ( ) ! . dispatchEvent ( new Event ( 'input' ) ) ;
710
+ component . getNameInput ( ) ! . value = 'Hydragon' ;
711
+ component . getNameInput ( ) ! . dispatchEvent ( new Event ( 'input' ) ) ;
707
712
708
713
component . clickCloseButton ( ) ;
709
714
fixture . detectChanges ( ) ;
@@ -713,46 +718,60 @@ cdkPopoverEditTabOut`, fakeAsync(() => {
713
718
714
719
component . openLens ( ) ;
715
720
716
- expect ( component . getInput ( ) ! . value ) . toBe ( 'Hydragon' ) ;
721
+ expect ( component . getNameInput ( ) ! . value ) . toBe ( 'Hydragon' ) ;
717
722
clearLeftoverTimers ( ) ;
718
723
} ) ) ;
719
724
720
725
it ( 'resets the lens to original value' , fakeAsync ( ( ) => {
721
726
component . openLens ( ) ;
722
727
723
- component . getInput ( ) ! . value = 'Hydragon' ;
724
- component . getInput ( ) ! . dispatchEvent ( new Event ( 'input' ) ) ;
728
+ component . getNameInput ( ) ! . value = 'Hydragon' ;
729
+ component . getNameInput ( ) ! . dispatchEvent ( new Event ( 'input' ) ) ;
725
730
726
731
component . clickRevertButton ( ) ;
727
732
728
- expect ( component . getInput ( ) ! . value ) . toBe ( 'Hydrogen' ) ;
733
+ expect ( component . getNameInput ( ) ! . value ) . toBe ( 'Hydrogen' ) ;
729
734
clearLeftoverTimers ( ) ;
730
735
} ) ) ;
731
736
737
+ it ( 'should not reset the values when clicking revert without making changes' ,
738
+ fakeAsync ( ( ) => {
739
+ component . openLens ( ) ;
740
+
741
+ expect ( component . getNameInput ( ) ! . value ) . toBe ( 'Hydrogen' ) ;
742
+ expect ( component . getWeightInput ( ) ! . value ) . toBe ( '1.007' ) ;
743
+
744
+ component . clickRevertButton ( ) ;
745
+
746
+ expect ( component . getNameInput ( ) ! . value ) . toBe ( 'Hydrogen' ) ;
747
+ expect ( component . getWeightInput ( ) ! . value ) . toBe ( '1.007' ) ;
748
+ clearLeftoverTimers ( ) ;
749
+ } ) ) ;
750
+
732
751
it ( 'resets the lens to previously submitted value' , fakeAsync ( ( ) => {
733
752
component . openLens ( ) ;
734
753
735
- component . getInput ( ) ! . value = 'Hydragon' ;
736
- component . getInput ( ) ! . dispatchEvent ( new Event ( 'input' ) ) ;
754
+ component . getNameInput ( ) ! . value = 'Hydragon' ;
755
+ component . getNameInput ( ) ! . dispatchEvent ( new Event ( 'input' ) ) ;
737
756
738
757
component . clickSubmitButton ( ) ;
739
758
fixture . detectChanges ( ) ;
740
759
741
760
component . openLens ( ) ;
742
761
743
- component . getInput ( ) ! . value = 'Hydragon X' ;
744
- component . getInput ( ) ! . dispatchEvent ( new Event ( 'input' ) ) ;
762
+ component . getNameInput ( ) ! . value = 'Hydragon X' ;
763
+ component . getNameInput ( ) ! . dispatchEvent ( new Event ( 'input' ) ) ;
745
764
746
765
component . clickRevertButton ( ) ;
747
766
748
- expect ( component . getInput ( ) ! . value ) . toBe ( 'Hydragon' ) ;
767
+ expect ( component . getNameInput ( ) ! . value ) . toBe ( 'Hydragon' ) ;
749
768
clearLeftoverTimers ( ) ;
750
769
} ) ) ;
751
770
752
771
it ( 'closes the lens on escape' , fakeAsync ( ( ) => {
753
772
component . openLens ( ) ;
754
773
755
- component . getInput ( ) ! . dispatchEvent (
774
+ component . getNameInput ( ) ! . dispatchEvent (
756
775
new KeyboardEvent ( 'keyup' , { bubbles : true , key : 'Escape' } ) ) ;
757
776
758
777
expect ( component . lensIsOpen ( ) ) . toBe ( false ) ;
@@ -762,7 +781,7 @@ cdkPopoverEditTabOut`, fakeAsync(() => {
762
781
it ( 'does not close the lens on click within lens' , fakeAsync ( ( ) => {
763
782
component . openLens ( ) ;
764
783
765
- component . getInput ( ) ! . dispatchEvent ( new Event ( 'click' , { bubbles : true } ) ) ;
784
+ component . getNameInput ( ) ! . dispatchEvent ( new Event ( 'click' , { bubbles : true } ) ) ;
766
785
767
786
expect ( component . lensIsOpen ( ) ) . toBe ( true ) ;
768
787
clearLeftoverTimers ( ) ;
@@ -771,8 +790,8 @@ cdkPopoverEditTabOut`, fakeAsync(() => {
771
790
it ( 'closes the lens on outside click' , fakeAsync ( ( ) => {
772
791
component . openLens ( ) ;
773
792
774
- component . getInput ( ) ! . value = 'Hydragon' ;
775
- component . getInput ( ) ! . dispatchEvent ( new Event ( 'input' ) ) ;
793
+ component . getNameInput ( ) ! . value = 'Hydragon' ;
794
+ component . getNameInput ( ) ! . dispatchEvent ( new Event ( 'input' ) ) ;
776
795
document . body . dispatchEvent ( new Event ( 'click' , { bubbles : true } ) ) ;
777
796
fixture . detectChanges ( ) ;
778
797
@@ -786,8 +805,8 @@ cdkPopoverEditTabOut`, fakeAsync(() => {
786
805
component . clickOutBehavior = 'submit' ;
787
806
component . openLens ( ) ;
788
807
789
- component . getInput ( ) ! . value = 'Hydragon' ;
790
- component . getInput ( ) ! . dispatchEvent ( new Event ( 'input' ) ) ;
808
+ component . getNameInput ( ) ! . value = 'Hydragon' ;
809
+ component . getNameInput ( ) ! . dispatchEvent ( new Event ( 'input' ) ) ;
791
810
document . body . dispatchEvent ( new Event ( 'click' , { bubbles : true } ) ) ;
792
811
fixture . detectChanges ( ) ;
793
812
@@ -801,8 +820,8 @@ cdkPopoverEditTabOut`, fakeAsync(() => {
801
820
component . clickOutBehavior = 'noop' ;
802
821
component . openLens ( ) ;
803
822
804
- component . getInput ( ) ! . value = 'Hydragon' ;
805
- component . getInput ( ) ! . dispatchEvent ( new Event ( 'input' ) ) ;
823
+ component . getNameInput ( ) ! . value = 'Hydragon' ;
824
+ component . getNameInput ( ) ! . dispatchEvent ( new Event ( 'input' ) ) ;
806
825
document . body . dispatchEvent ( new Event ( 'click' , { bubbles : true } ) ) ;
807
826
fixture . detectChanges ( ) ;
808
827
@@ -814,7 +833,7 @@ cdkPopoverEditTabOut`, fakeAsync(() => {
814
833
it ( 'sets focus on the first input in the lens' , fakeAsync ( ( ) => {
815
834
component . openLens ( ) ;
816
835
817
- expect ( document . activeElement ) . toBe ( component . getInput ( ) ) ;
836
+ expect ( document . activeElement ) . toBe ( component . getNameInput ( ) ) ;
818
837
clearLeftoverTimers ( ) ;
819
838
} ) ) ;
820
839
0 commit comments