@@ -10,8 +10,11 @@ import { IgxStringFilteringOperand } from '../../data-operations/filtering-condi
1010import { SampleTestData } from '../../test-utils/sample-test-data.spec' ;
1111import { HammerGesturesManager } from '../../core/touch' ;
1212import { PlatformUtil } from '../../core/utils' ;
13+ import { SelectionWithTransactionsComponent } from '../../test-utils/grid-samples.spec' ;
1314
1415const DEBOUNCETIME = 30 ;
16+ const CELL_CSS_CLASS_NUMBER_FORMAT = '.igx-grid__td--number' ;
17+ const EDITED_CELL_CSS_CLASS = 'igx-grid__td--edited' ;
1518
1619describe ( 'IgxGrid - Cell component' , ( ) => {
1720 configureTestSuite ( ) ;
@@ -28,7 +31,8 @@ describe('IgxGrid - Cell component', () => {
2831 CellEditingScrollTestComponent ,
2932 ConditionalCellStyleTestComponent ,
3033 ColumnEditablePropertyTestComponent ,
31- GridColumnWidthsComponent
34+ GridColumnWidthsComponent ,
35+ SelectionWithTransactionsComponent
3236 ] ,
3337 imports : [ NoopAnimationsModule , IgxGridModule ]
3438 } ) . compileComponents ( ) ;
@@ -90,9 +94,9 @@ describe('IgxGrid - Cell component', () => {
9094
9195 expect ( spy . calls . count ( ) ) . toEqual ( 1 ) ;
9296
93- cell . nativeElement . dispatchEvent ( new KeyboardEvent ( 'keydown' , { key : 'Enter' } ) ) ;
97+ cell . nativeElement . dispatchEvent ( new KeyboardEvent ( 'keydown' , { key : 'Enter' } ) ) ;
9498 fix . detectChanges ( ) ;
95- cell . nativeElement . dispatchEvent ( new KeyboardEvent ( 'keydown' , { key : 'Escape' } ) ) ;
99+ cell . nativeElement . dispatchEvent ( new KeyboardEvent ( 'keydown' , { key : 'Escape' } ) ) ;
96100 fix . detectChanges ( ) ;
97101
98102 expect ( spy . calls . count ( ) ) . toEqual ( 1 ) ;
@@ -206,7 +210,7 @@ describe('IgxGrid - Cell component', () => {
206210
207211 // should attach 'doubletap'
208212 expect ( addListenerSpy . calls . count ( ) ) . toBeGreaterThan ( 1 ) ;
209- expect ( addListenerSpy ) . toHaveBeenCalledWith ( firstCell . nativeElement , 'doubletap' , firstCell . onDoubleClick , { cssProps : { } } ) ;
213+ expect ( addListenerSpy ) . toHaveBeenCalledWith ( firstCell . nativeElement , 'doubletap' , firstCell . onDoubleClick , { cssProps : { } } ) ;
210214
211215 spyOn ( grid . onDoubleClick , 'emit' ) . and . callThrough ( ) ;
212216
@@ -528,7 +532,7 @@ describe('IgxGrid - Cell component', () => {
528532 UIInteractions . sendInput ( editTemplate , 9 ) ;
529533 fixture . detectChanges ( ) ;
530534
531- expect ( ( ) => previousCell . onClick ( new MouseEvent ( 'click' ) ) ) . not . toThrow ( ) ;
535+ expect ( ( ) => previousCell . onClick ( new MouseEvent ( 'click' ) ) ) . not . toThrow ( ) ;
532536 } ) ;
533537
534538 it ( 'should exit edit mode on sorting' , ( ) => {
@@ -550,7 +554,7 @@ describe('IgxGrid - Cell component', () => {
550554 } ) ;
551555
552556 it ( 'should update correct cell when sorting is applied' , ( ) => {
553- grid . sort ( { fieldName : 'age' , dir : SortingDirection . Desc , ignoreCase : false } ) ;
557+ grid . sort ( { fieldName : 'age' , dir : SortingDirection . Desc , ignoreCase : false } ) ;
554558 fixture . detectChanges ( ) ;
555559
556560 const cell = grid . getCellByColumn ( 0 , 'fullName' ) ;
@@ -959,17 +963,17 @@ describe('IgxGrid - Cell component', () => {
959963 } ) ) ;
960964
961965 it ( 'should not make last column smaller when vertical scrollbar is on the right of last cell' ,
962- fakeAsync ( /** height/width setter rAF */ ( ) => {
963- GridColumnWidthsComponent . COLUMN_WIDTH = '30px' ;
964- const fix = TestBed . createComponent ( GridColumnWidthsComponent ) ;
965- fix . detectChanges ( ) ;
966- const grid = fix . componentInstance . instance ;
967-
968- const lastColumnCells = grid . columns [ grid . columns . length - 1 ] . cells ;
969- lastColumnCells . forEach ( function ( item ) {
970- expect ( item . width ) . toEqual ( '30px' ) ;
971- } ) ;
972- } ) ) ;
966+ fakeAsync ( /** height/width setter rAF */ ( ) => {
967+ GridColumnWidthsComponent . COLUMN_WIDTH = '30px' ;
968+ const fix = TestBed . createComponent ( GridColumnWidthsComponent ) ;
969+ fix . detectChanges ( ) ;
970+ const grid = fix . componentInstance . instance ;
971+
972+ const lastColumnCells = grid . columns [ grid . columns . length - 1 ] . cells ;
973+ lastColumnCells . forEach ( function ( item ) {
974+ expect ( item . width ) . toEqual ( '30px' ) ;
975+ } ) ;
976+ } ) ) ;
973977
974978 it ( 'should not make last column smaller when vertical scrollbar is on the left of last cell' , async ( ) => {
975979 GridColumnWidthsComponent . COLUMN_WIDTH = '500px' ;
@@ -1024,6 +1028,54 @@ describe('IgxGrid - Cell component', () => {
10241028 expect ( columns [ 4 ] . editable ) . toBeFalsy ( ) ;
10251029 expect ( columns [ 5 ] . editable ) . toBeFalsy ( ) ;
10261030 } ) ) ;
1031+
1032+ // Bug #5855
1033+ it ( 'should apply proper style on cell editing when new value equals zero or false' , ( ) => {
1034+ const fixture = TestBed . createComponent ( SelectionWithTransactionsComponent ) ;
1035+ fixture . detectChanges ( ) ;
1036+
1037+ const grid = fixture . componentInstance . grid ;
1038+ grid . getColumnByName ( 'ParentID' ) . hidden = true ;
1039+ grid . getColumnByName ( 'Name' ) . hidden = true ;
1040+ grid . getColumnByName ( 'HireDate' ) . hidden = true ;
1041+ grid . getColumnByName ( 'Age' ) . editable = true ;
1042+ grid . getColumnByName ( 'OnPTO' ) . editable = true ;
1043+ fixture . detectChanges ( ) ;
1044+
1045+ let cell = grid . getCellByColumn ( 0 , 'Age' ) ;
1046+ let cellDomPK = fixture . debugElement . queryAll ( By . css ( CELL_CSS_CLASS_NUMBER_FORMAT ) ) [ 1 ] ;
1047+
1048+ cellDomPK . triggerEventHandler ( 'dblclick' , { } ) ;
1049+ fixture . detectChanges ( ) ;
1050+ expect ( cell . editMode ) . toBe ( true ) ;
1051+
1052+ let editTemplate = cellDomPK . query ( By . css ( 'input[type=\'number\']' ) ) ;
1053+ UIInteractions . sendInput ( editTemplate , 0 ) ;
1054+ fixture . detectChanges ( ) ;
1055+ UIInteractions . triggerKeyDownEvtUponElem ( 'enter' , cellDomPK . nativeElement , true ) ;
1056+ fixture . detectChanges ( ) ;
1057+
1058+ expect ( cell . editMode ) . toBe ( false ) ;
1059+ expect ( cell . value ) . toBe ( 0 ) ;
1060+ expect ( cell . nativeElement . classList ) . toContain ( EDITED_CELL_CSS_CLASS ) ;
1061+
1062+ cell = grid . getCellByColumn ( 1 , 'OnPTO' ) ;
1063+ cellDomPK = fixture . debugElement . queryAll ( By . css ( CELL_CSS_CLASS ) ) [ 5 ] ;
1064+
1065+ cellDomPK . triggerEventHandler ( 'dblclick' , { } ) ;
1066+ fixture . detectChanges ( ) ;
1067+ expect ( cell . editMode ) . toBe ( true ) ;
1068+
1069+ editTemplate = cellDomPK . query ( By . css ( '.igx-checkbox' ) ) . query ( By . css ( '.igx-checkbox__label' ) ) ;
1070+ editTemplate . nativeElement . click ( ) ;
1071+ fixture . detectChanges ( ) ;
1072+ UIInteractions . triggerKeyDownEvtUponElem ( 'enter' , cellDomPK . nativeElement , true ) ;
1073+ fixture . detectChanges ( ) ;
1074+
1075+ expect ( cell . editMode ) . toBe ( false ) ;
1076+ expect ( cell . value ) . toBe ( false ) ;
1077+ expect ( cell . nativeElement . classList ) . toContain ( EDITED_CELL_CSS_CLASS ) ;
1078+ } ) ;
10271079} ) ;
10281080
10291081@Component ( {
@@ -1286,7 +1338,7 @@ export class ConditionalCellStyleTestComponent implements OnInit {
12861338 { field : 'ProductID' , width : 100 , cellClasses : this . cellClasses } ,
12871339 { field : 'ProductName' , width : 200 , cellClasses : this . cellClasses1 } ,
12881340 { field : 'InStock' , width : 150 , cellClasses : this . cellClasses1 } ,
1289- { field : 'UnitsInStock' , width : 150 , cellClasses : { 'test1' : true } } ,
1341+ { field : 'UnitsInStock' , width : 150 , cellClasses : { 'test1' : true } } ,
12901342 { field : 'OrderDate' , width : 150 , cellClasses : this . cellClasses1 }
12911343 ] ;
12921344 this . data = SampleTestData . foodProductDataExtended ( ) ;
0 commit comments