11import { async , TestBed , fakeAsync } from '@angular/core/testing' ;
22import { By } from '@angular/platform-browser' ;
33import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
4- import { IgxColumnComponent , IgxGridComponent , IgxGridModule , IGridEditEventArgs } from './index' ;
4+ import { IgxColumnComponent , IgxGridComponent , IgxGridModule , IGridEditEventArgs } from './index' ;
55import { SortingDirection } from '../../data-operations/sorting-expression.interface' ;
66import { UIInteractions , wait } from '../../test-utils/ui-interactions.spec' ;
77import { configureTestSuite } from '../../test-utils/configure-suite' ;
88import { IgxStringFilteringOperand } from '../../data-operations/filtering-condition' ;
99import { ColumnEditablePropertyTestComponent } from './cell.spec' ;
1010import { GridFunctions } from '../../test-utils/grid-functions.spec' ;
11- import { CellEditingTestComponent , CellEditingScrollTestComponent } from '../../test-utils/grid-samples.spec' ;
11+ import {
12+ CellEditingTestComponent , CellEditingScrollTestComponent ,
13+ SelectionWithTransactionsComponent
14+ } from '../../test-utils/grid-samples.spec' ;
15+ import { getIdentifierPositions } from 'projects/igniteui-angular/migrations/common/tsUtils' ;
1216
1317const DEBOUNCETIME = 30 ;
1418const CELL_CSS_CLASS = '.igx-grid__td' ;
19+ const CELL_CSS_CLASS_NUMBER_FORMAT = '.igx-grid__td--number' ;
1520const CELL_CLASS_IN_EDIT_MODE = 'igx-grid__td--editing' ;
21+ const EDITED_CELL_CSS_CLASS = 'igx-grid__td--edited' ;
1622
1723describe ( 'IgxGrid - Cell Editing #grid' , ( ) => {
1824 configureTestSuite ( ) ;
@@ -21,7 +27,8 @@ describe('IgxGrid - Cell Editing #grid', () => {
2127 declarations : [
2228 CellEditingTestComponent ,
2329 CellEditingScrollTestComponent ,
24- ColumnEditablePropertyTestComponent
30+ ColumnEditablePropertyTestComponent ,
31+ SelectionWithTransactionsComponent
2532 ] ,
2633 imports : [ NoopAnimationsModule , IgxGridModule ]
2734 } ) . compileComponents ( ) ;
@@ -654,7 +661,7 @@ describe('IgxGrid - Cell Editing #grid', () => {
654661 spyOn ( grid . onCellEdit , 'emit' ) . and . callThrough ( ) ;
655662 grid . onCellEdit . subscribe ( ( e : IGridEditEventArgs ) => {
656663 if ( e . cellID . columnID === 0 ) {
657- grid . updateCell ( 1 , e . rowID , 'age' ) ;
664+ grid . updateCell ( 1 , e . rowID , 'age' ) ;
658665 }
659666 } ) ;
660667
@@ -703,8 +710,10 @@ describe('IgxGrid - Cell Editing #grid', () => {
703710 UIInteractions . triggerKeyDownEvtUponElem ( 'escape' , cell . nativeElement , true ) ;
704711 fixture . detectChanges ( ) ;
705712
706- const cellArgs : IGridEditEventArgs = { cellID : cell . cellID ,
707- rowID : cell . row . rowID , oldValue : 'John Brown' , newValue : 'New Name' , cancel : false } ;
713+ const cellArgs : IGridEditEventArgs = {
714+ cellID : cell . cellID ,
715+ rowID : cell . row . rowID , oldValue : 'John Brown' , newValue : 'New Name' , cancel : false
716+ } ;
708717 expect ( grid . onCellEditCancel . emit ) . toHaveBeenCalledTimes ( 1 ) ;
709718 expect ( grid . onCellEditCancel . emit ) . toHaveBeenCalledWith ( cellArgs ) ;
710719
@@ -730,8 +739,10 @@ describe('IgxGrid - Cell Editing #grid', () => {
730739 UIInteractions . triggerKeyDownEvtUponElem ( 'escape' , cell . nativeElement , true ) ;
731740 fixture . detectChanges ( ) ;
732741
733- const cellArgs : IGridEditEventArgs = { cellID : cell . cellID ,
734- rowID : cell . row . rowID , oldValue : 'John Brown' , newValue : 'New Name' , cancel : true } ;
742+ const cellArgs : IGridEditEventArgs = {
743+ cellID : cell . cellID ,
744+ rowID : cell . row . rowID , oldValue : 'John Brown' , newValue : 'New Name' , cancel : true
745+ } ;
735746 expect ( grid . onCellEditCancel . emit ) . toHaveBeenCalledTimes ( 1 ) ;
736747 expect ( grid . onCellEditCancel . emit ) . toHaveBeenCalledWith ( cellArgs ) ;
737748
@@ -861,4 +872,52 @@ describe('IgxGrid - Cell Editing #grid', () => {
861872 expect ( columns [ 4 ] . editable ) . toBeFalsy ( ) ;
862873 expect ( columns [ 5 ] . editable ) . toBeFalsy ( ) ;
863874 } ) ) ;
875+
876+ // Bug #5855
877+ it ( 'should apply proper style on cell editing when new value equals zero or false' , ( ) => {
878+ const fixture = TestBed . createComponent ( SelectionWithTransactionsComponent ) ;
879+ fixture . detectChanges ( ) ;
880+
881+ const grid = fixture . componentInstance . grid ;
882+ grid . getColumnByName ( 'ParentID' ) . hidden = true ;
883+ grid . getColumnByName ( 'Name' ) . hidden = true ;
884+ grid . getColumnByName ( 'HireDate' ) . hidden = true ;
885+ grid . getColumnByName ( 'Age' ) . editable = true ;
886+ grid . getColumnByName ( 'OnPTO' ) . editable = true ;
887+ fixture . detectChanges ( ) ;
888+
889+ let cell = grid . getCellByColumn ( 0 , 'Age' ) ;
890+ let cellDomPK = fixture . debugElement . queryAll ( By . css ( CELL_CSS_CLASS_NUMBER_FORMAT ) ) [ 1 ] ;
891+
892+ cellDomPK . triggerEventHandler ( 'dblclick' , { } ) ;
893+ fixture . detectChanges ( ) ;
894+ expect ( cell . editMode ) . toBe ( true ) ;
895+
896+ let editTemplate = cellDomPK . query ( By . css ( 'input[type=\'number\']' ) ) ;
897+ UIInteractions . sendInput ( editTemplate , 0 ) ;
898+ fixture . detectChanges ( ) ;
899+ UIInteractions . triggerKeyDownEvtUponElem ( 'enter' , cellDomPK . nativeElement , true ) ;
900+ fixture . detectChanges ( ) ;
901+
902+ expect ( cell . editMode ) . toBe ( false ) ;
903+ expect ( cell . value ) . toBe ( 0 ) ;
904+ expect ( cell . nativeElement . classList ) . toContain ( EDITED_CELL_CSS_CLASS ) ;
905+
906+ cell = grid . getCellByColumn ( 1 , 'OnPTO' ) ;
907+ cellDomPK = fixture . debugElement . queryAll ( By . css ( CELL_CSS_CLASS ) ) [ 5 ] ;
908+
909+ cellDomPK . triggerEventHandler ( 'dblclick' , { } ) ;
910+ fixture . detectChanges ( ) ;
911+ expect ( cell . editMode ) . toBe ( true ) ;
912+
913+ editTemplate = cellDomPK . query ( By . css ( '.igx-checkbox' ) ) . query ( By . css ( '.igx-checkbox__label' ) ) ;
914+ editTemplate . nativeElement . click ( ) ;
915+ fixture . detectChanges ( ) ;
916+ UIInteractions . triggerKeyDownEvtUponElem ( 'enter' , cellDomPK . nativeElement , true ) ;
917+ fixture . detectChanges ( ) ;
918+
919+ expect ( cell . editMode ) . toBe ( false ) ;
920+ expect ( cell . value ) . toBe ( false ) ;
921+ expect ( cell . nativeElement . classList ) . toContain ( EDITED_CELL_CSS_CLASS ) ;
922+ } ) ;
864923} ) ;
0 commit comments