1- import { async , TestBed , fakeAsync } from '@angular/core/testing' ;
1+ import { async , TestBed , fakeAsync , tick } from '@angular/core/testing' ;
22import { By } from '@angular/platform-browser' ;
33import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
44import { IgxColumnComponent , IgxGridComponent , IgxGridModule , IGridEditEventArgs , IGridEditDoneEventArgs } from './public_api' ;
@@ -756,20 +756,23 @@ describe('IgxGrid - Cell Editing #grid', () => {
756756 expect ( grid . cellEdit . emit ) . toHaveBeenCalledWith ( cellArgs ) ;
757757 } ) ;
758758
759- it ( `Should be able to cancel 'cellEdit' event` , ( ) => {
760- spyOn ( grid . cellEdit , 'emit' ) . and . callThrough ( ) ;
759+ it ( `Should be able to cancel 'cellEdit' event` , fakeAsync ( ( ) => {
760+ const emitSpy = spyOn ( grid . cellEdit , 'emit' ) . and . callThrough ( ) ;
761761 grid . cellEdit . subscribe ( ( e : IGridEditEventArgs ) => {
762762 e . cancel = true ;
763763 } ) ;
764- let cell = grid . getCellByColumn ( 0 , 'fullName' ) ;
764+ const cell = grid . getCellByColumn ( 0 , 'fullName' ) ;
765765 let cellArgs : IGridEditEventArgs ;
766766 const initialRowData = { ...cell . rowData } ;
767767
768768 UIInteractions . simulateDoubleClickAndSelectEvent ( cell ) ;
769769 fixture . detectChanges ( ) ;
770+ tick ( 16 ) ; // trigger igxFocus rAF
771+ const editInput = fixture . debugElement . query ( By . css ( 'igx-grid-cell input' ) ) . nativeElement ;
770772
771773 expect ( cell . editMode ) . toBe ( true ) ;
772- let cellValue = cell . value ;
774+ expect ( document . activeElement ) . toBe ( editInput ) ;
775+ const cellValue = cell . value ;
773776 const newValue = 'new value' ;
774777 cell . editValue = newValue ;
775778
@@ -790,29 +793,39 @@ describe('IgxGrid - Cell Editing #grid', () => {
790793 expect ( grid . cellEdit . emit ) . toHaveBeenCalledTimes ( 1 ) ;
791794 expect ( grid . cellEdit . emit ) . toHaveBeenCalledWith ( cellArgs ) ;
792795
796+ emitSpy . calls . reset ( ) ;
793797 UIInteractions . triggerEventHandlerKeyDown ( 'tab' , gridContent ) ;
794798 fixture . detectChanges ( ) ;
795799
796800 expect ( cell . editMode ) . toBe ( true ) ;
797801 expect ( cell . value ) . toBe ( cellValue ) ;
798- expect ( grid . cellEdit . emit ) . toHaveBeenCalledTimes ( 2 ) ;
802+ expect ( document . activeElement ) . toBe ( editInput ) ;
803+ expect ( grid . cellEdit . emit ) . toHaveBeenCalledTimes ( 1 ) ;
799804 expect ( grid . cellEdit . emit ) . toHaveBeenCalledWith ( cellArgs ) ;
800805
801- cell = grid . getCellByColumn ( 0 , 'age' ) ;
802- cellValue = cell . value ;
803- expect ( cell . editMode ) . toBe ( false ) ;
806+ const nextCell = grid . getCellByColumn ( 0 , 'age' ) ;
807+ expect ( nextCell . editMode ) . toBe ( false ) ;
804808
805809 // activate the new cell
806- cell . activate ( null ) ;
810+ emitSpy . calls . reset ( ) ;
811+ nextCell . activate ( null ) ;
807812 fixture . detectChanges ( ) ;
808- expect ( grid . cellEdit . emit ) . toHaveBeenCalledTimes ( 3 ) ;
813+ expect ( grid . cellEdit . emit ) . toHaveBeenCalledTimes ( 1 ) ;
809814 expect ( grid . cellEdit . emit ) . toHaveBeenCalledWith ( cellArgs ) ;
810815
811- expect ( cell . editMode ) . toBe ( false ) ;
816+ expect ( nextCell . editMode ) . toBe ( false ) ;
817+ expect ( cell . editMode ) . toBe ( true ) ;
818+ expect ( document . activeElement ) . toBe ( editInput ) ;
819+
820+ emitSpy . calls . reset ( ) ;
821+ UIInteractions . triggerEventHandlerKeyDown ( 'enter' , gridContent ) ;
822+ fixture . detectChanges ( ) ;
812823
813- cell = grid . getCellByColumn ( 0 , 'fullName' ) ;
814824 expect ( cell . editMode ) . toBe ( true ) ;
815- } ) ;
825+ expect ( document . activeElement ) . toBe ( editInput ) ;
826+ expect ( grid . cellEdit . emit ) . toHaveBeenCalledTimes ( 1 ) ;
827+ expect ( grid . cellEdit . emit ) . toHaveBeenCalledWith ( cellArgs ) ;
828+ } ) ) ;
816829
817830 it ( `Should be able to update other cell in 'cellEdit' event` , ( ) => {
818831 grid . primaryKey = 'personNumber' ;
@@ -1031,7 +1044,7 @@ describe('IgxGrid - Cell Editing #grid', () => {
10311044 expect ( grid . crudService . cellInEditMode ) . toEqual ( true ) ;
10321045 } ) ;
10331046
1034- it ( 'When cellEdit is canceled the new value of the cell should never be commited nor the editing should be closed' , ( ) => {
1047+ it ( 'When cellEdit is canceled the new value of the cell should never be committed nor the editing should be closed' , ( ) => {
10351048 const cell = grid . getCellByColumn ( 0 , 'fullName' ) ;
10361049 grid . cellEdit . pipe ( takeUntil ( $destroyer ) ) . subscribe ( ( evt ) => {
10371050 evt . cancel = true ;
0 commit comments