@@ -21,6 +21,7 @@ const NAME_EDIT_TEMPLATE = `
21
21
[cdkEditControlIgnoreSubmitUnlessValid]="ignoreSubmitUnlessValid"
22
22
[cdkEditControlClickOutBehavior]="clickOutBehavior">
23
23
<input [ngModel]="element.name" name="name" required>
24
+ <input [ngModel]="element.weight" name="weight">
24
25
<br>
25
26
<button class="submit" type="submit">Confirm</button>
26
27
<button class="revert" cdkEditRevert>Revert</button>
@@ -114,12 +115,16 @@ abstract class BaseTestComponent {
114
115
return document . querySelector ( '.cdk-overlay-connected-position-bounding-box' ) ;
115
116
}
116
117
117
- getInput ( ) {
118
- return document . querySelector ( 'input' ) as HTMLInputElement | null ;
118
+ getNameInput ( ) {
119
+ return document . querySelector ( 'input[name="name"]' ) as HTMLInputElement | null ;
120
+ }
121
+
122
+ getWeightInput ( ) {
123
+ return document . querySelector ( 'input[name="weight"]' ) as HTMLInputElement | null ;
119
124
}
120
125
121
126
lensIsOpen ( ) {
122
- return ! ! this . getInput ( ) ;
127
+ return ! ! this . getNameInput ( ) ;
123
128
}
124
129
125
130
getSubmitButton ( ) {
@@ -503,7 +508,7 @@ cdkPopoverEditTabOut`, fakeAsync(() => {
503
508
it ( 'shows a lens with the value from the table' , fakeAsync ( ( ) => {
504
509
component . openLens ( ) ;
505
510
506
- expect ( component . getInput ( ) ! . value ) . toBe ( 'Hydrogen' ) ;
511
+ expect ( component . getNameInput ( ) ! . value ) . toBe ( 'Hydrogen' ) ;
507
512
} ) ) ;
508
513
509
514
it ( 'positions the lens at the top left corner and spans the full width of the cell' ,
@@ -552,8 +557,8 @@ cdkPopoverEditTabOut`, fakeAsync(() => {
552
557
it ( 'updates the form and submits, closing the lens' , fakeAsync ( ( ) => {
553
558
component . openLens ( ) ;
554
559
555
- component . getInput ( ) ! . value = 'Hydragon' ;
556
- component . getInput ( ) ! . dispatchEvent ( new Event ( 'input' ) ) ;
560
+ component . getNameInput ( ) ! . value = 'Hydragon' ;
561
+ component . getNameInput ( ) ! . dispatchEvent ( new Event ( 'input' ) ) ;
557
562
558
563
component . clickSubmitButton ( ) ;
559
564
fixture . detectChanges ( ) ;
@@ -565,8 +570,8 @@ cdkPopoverEditTabOut`, fakeAsync(() => {
565
570
it ( 'does not close the lens on submit when form is invalid' , fakeAsync ( ( ) => {
566
571
component . openLens ( ) ;
567
572
568
- component . getInput ( ) ! . value = '' ;
569
- component . getInput ( ) ! . dispatchEvent ( new Event ( 'input' ) ) ;
573
+ component . getNameInput ( ) ! . value = '' ;
574
+ component . getNameInput ( ) ! . dispatchEvent ( new Event ( 'input' ) ) ;
570
575
571
576
component . clickSubmitButton ( ) ;
572
577
@@ -578,8 +583,8 @@ cdkPopoverEditTabOut`, fakeAsync(() => {
578
583
component . ignoreSubmitUnlessValid = false ;
579
584
component . openLens ( ) ;
580
585
581
- component . getInput ( ) ! . value = '' ;
582
- component . getInput ( ) ! . dispatchEvent ( new Event ( 'input' ) ) ;
586
+ component . getNameInput ( ) ! . value = '' ;
587
+ component . getNameInput ( ) ! . dispatchEvent ( new Event ( 'input' ) ) ;
583
588
584
589
component . clickSubmitButton ( ) ;
585
590
@@ -597,8 +602,8 @@ cdkPopoverEditTabOut`, fakeAsync(() => {
597
602
it ( 'closes and reopens a lens with modified value persisted' , fakeAsync ( ( ) => {
598
603
component . openLens ( ) ;
599
604
600
- component . getInput ( ) ! . value = 'Hydragon' ;
601
- component . getInput ( ) ! . dispatchEvent ( new Event ( 'input' ) ) ;
605
+ component . getNameInput ( ) ! . value = 'Hydragon' ;
606
+ component . getNameInput ( ) ! . dispatchEvent ( new Event ( 'input' ) ) ;
602
607
603
608
component . clickCloseButton ( ) ;
604
609
fixture . detectChanges ( ) ;
@@ -608,43 +613,56 @@ cdkPopoverEditTabOut`, fakeAsync(() => {
608
613
609
614
component . openLens ( ) ;
610
615
611
- expect ( component . getInput ( ) ! . value ) . toBe ( 'Hydragon' ) ;
616
+ expect ( component . getNameInput ( ) ! . value ) . toBe ( 'Hydragon' ) ;
612
617
} ) ) ;
613
618
614
619
it ( 'resets the lens to original value' , fakeAsync ( ( ) => {
615
620
component . openLens ( ) ;
616
621
617
- component . getInput ( ) ! . value = 'Hydragon' ;
618
- component . getInput ( ) ! . dispatchEvent ( new Event ( 'input' ) ) ;
622
+ component . getNameInput ( ) ! . value = 'Hydragon' ;
623
+ component . getNameInput ( ) ! . dispatchEvent ( new Event ( 'input' ) ) ;
619
624
620
625
component . clickRevertButton ( ) ;
621
626
622
- expect ( component . getInput ( ) ! . value ) . toBe ( 'Hydrogen' ) ;
627
+ expect ( component . getNameInput ( ) ! . value ) . toBe ( 'Hydrogen' ) ;
623
628
} ) ) ;
624
629
630
+ it ( 'should not reset the values when clicking revert without making changes' ,
631
+ fakeAsync ( ( ) => {
632
+ component . openLens ( ) ;
633
+
634
+ expect ( component . getNameInput ( ) ! . value ) . toBe ( 'Hydrogen' ) ;
635
+ expect ( component . getWeightInput ( ) ! . value ) . toBe ( '1.007' ) ;
636
+
637
+ component . clickRevertButton ( ) ;
638
+
639
+ expect ( component . getNameInput ( ) ! . value ) . toBe ( 'Hydrogen' ) ;
640
+ expect ( component . getWeightInput ( ) ! . value ) . toBe ( '1.007' ) ;
641
+ } ) ) ;
642
+
625
643
it ( 'resets the lens to previously submitted value' , fakeAsync ( ( ) => {
626
644
component . openLens ( ) ;
627
645
628
- component . getInput ( ) ! . value = 'Hydragon' ;
629
- component . getInput ( ) ! . dispatchEvent ( new Event ( 'input' ) ) ;
646
+ component . getNameInput ( ) ! . value = 'Hydragon' ;
647
+ component . getNameInput ( ) ! . dispatchEvent ( new Event ( 'input' ) ) ;
630
648
631
649
component . clickSubmitButton ( ) ;
632
650
fixture . detectChanges ( ) ;
633
651
634
652
component . openLens ( ) ;
635
653
636
- component . getInput ( ) ! . value = 'Hydragon X' ;
637
- component . getInput ( ) ! . dispatchEvent ( new Event ( 'input' ) ) ;
654
+ component . getNameInput ( ) ! . value = 'Hydragon X' ;
655
+ component . getNameInput ( ) ! . dispatchEvent ( new Event ( 'input' ) ) ;
638
656
639
657
component . clickRevertButton ( ) ;
640
658
641
- expect ( component . getInput ( ) ! . value ) . toBe ( 'Hydragon' ) ;
659
+ expect ( component . getNameInput ( ) ! . value ) . toBe ( 'Hydragon' ) ;
642
660
} ) ) ;
643
661
644
662
it ( 'closes the lens on escape' , fakeAsync ( ( ) => {
645
663
component . openLens ( ) ;
646
664
647
- component . getInput ( ) ! . dispatchEvent (
665
+ component . getNameInput ( ) ! . dispatchEvent (
648
666
new KeyboardEvent ( 'keyup' , { bubbles : true , key : 'Escape' } ) ) ;
649
667
650
668
expect ( component . lensIsOpen ( ) ) . toBe ( false ) ;
@@ -653,16 +671,16 @@ cdkPopoverEditTabOut`, fakeAsync(() => {
653
671
it ( 'does not close the lens on click within lens' , fakeAsync ( ( ) => {
654
672
component . openLens ( ) ;
655
673
656
- component . getInput ( ) ! . dispatchEvent ( new Event ( 'click' , { bubbles : true } ) ) ;
674
+ component . getNameInput ( ) ! . dispatchEvent ( new Event ( 'click' , { bubbles : true } ) ) ;
657
675
658
676
expect ( component . lensIsOpen ( ) ) . toBe ( true ) ;
659
677
} ) ) ;
660
678
661
679
it ( 'closes the lens on outside click' , fakeAsync ( ( ) => {
662
680
component . openLens ( ) ;
663
681
664
- component . getInput ( ) ! . value = 'Hydragon' ;
665
- component . getInput ( ) ! . dispatchEvent ( new Event ( 'input' ) ) ;
682
+ component . getNameInput ( ) ! . value = 'Hydragon' ;
683
+ component . getNameInput ( ) ! . dispatchEvent ( new Event ( 'input' ) ) ;
666
684
document . body . dispatchEvent ( new Event ( 'click' , { bubbles : true } ) ) ;
667
685
fixture . detectChanges ( ) ;
668
686
@@ -676,8 +694,8 @@ cdkPopoverEditTabOut`, fakeAsync(() => {
676
694
component . clickOutBehavior = 'submit' ;
677
695
component . openLens ( ) ;
678
696
679
- component . getInput ( ) ! . value = 'Hydragon' ;
680
- component . getInput ( ) ! . dispatchEvent ( new Event ( 'input' ) ) ;
697
+ component . getNameInput ( ) ! . value = 'Hydragon' ;
698
+ component . getNameInput ( ) ! . dispatchEvent ( new Event ( 'input' ) ) ;
681
699
document . body . dispatchEvent ( new Event ( 'click' , { bubbles : true } ) ) ;
682
700
fixture . detectChanges ( ) ;
683
701
@@ -690,8 +708,8 @@ cdkPopoverEditTabOut`, fakeAsync(() => {
690
708
component . clickOutBehavior = 'noop' ;
691
709
component . openLens ( ) ;
692
710
693
- component . getInput ( ) ! . value = 'Hydragon' ;
694
- component . getInput ( ) ! . dispatchEvent ( new Event ( 'input' ) ) ;
711
+ component . getNameInput ( ) ! . value = 'Hydragon' ;
712
+ component . getNameInput ( ) ! . dispatchEvent ( new Event ( 'input' ) ) ;
695
713
document . body . dispatchEvent ( new Event ( 'click' , { bubbles : true } ) ) ;
696
714
fixture . detectChanges ( ) ;
697
715
@@ -702,7 +720,7 @@ cdkPopoverEditTabOut`, fakeAsync(() => {
702
720
it ( 'sets focus on the first input in the lens' , fakeAsync ( ( ) => {
703
721
component . openLens ( ) ;
704
722
705
- expect ( document . activeElement ) . toBe ( component . getInput ( ) ) ;
723
+ expect ( document . activeElement ) . toBe ( component . getNameInput ( ) ) ;
706
724
} ) ) ;
707
725
708
726
it ( 'returns focus to the edited cell after closing' , fakeAsync ( ( ) => {
0 commit comments