@@ -13,15 +13,7 @@ const containerId = 'demo-container';
1313const template =
1414 `<div id="${ containerId } " style="height: 800px; width: 600px; overflow: hidden; display: block;">
1515 <div id="slickGridContainer-${ gridId } " class="grid-pane" style="width: 100%;">
16- <div id="${ gridId } " class="${ gridUid } " style="width: 100%">
17- <div class="slick-pane slick-pane-header slick-pane-left" tabindex="0" style="width: 100%;">
18- <div class="slick-viewport slick-viewport-top slick-viewport-left" style="overflow:hidden;position:relative;width:500px">
19- <div class="grid-canvas" style="height: 12500px; width: 500px;"></div>
20- </div>
21- <div class="slick-viewport slick-viewport-bottom slick-viewport-left" style="overflow:hidden;position:relative;">
22- <div class="grid-canvas" style="height: 100px; width: 500px;"></div>
23- </div>
24- </div>
16+ <div id="${ gridId } " class="${ gridUid } " style="width: 100%"></div>
2517 </div>
2618 </div>` ;
2719
@@ -800,6 +792,21 @@ describe('SlickGrid core file', () => {
800792
801793 expect ( result ) . toEqual ( viewportElm ) ;
802794 } ) ;
795+
796+ it ( 'should call getCellNode() and return null when dataset is empty' , ( ) => {
797+ grid = new SlickGrid < any , Column > ( container , [ ] , columns , options ) ;
798+ const result = grid . getCellNode ( 0 , 3 ) ;
799+
800+ expect ( result ) . toBeNull ( ) ;
801+ } ) ;
802+
803+ it ( 'should call getCellNode() and return null trying to retrieve cell higher than what is in the dataset' , ( ) => {
804+ const data = [ { id : 0 , firstName : 'John' , lastName : 'Doe' , age : 30 } , { id : 1 , firstName : 'Jane' , lastName : 'Doe' , age : 28 } ] ;
805+ grid = new SlickGrid < any , Column > ( container , data , columns , options ) ;
806+ const result = grid . getCellNode ( 0 , 3 ) ;
807+
808+ expect ( result ) . toBeNull ( ) ;
809+ } ) ;
803810 } ) ;
804811
805812 describe ( 'getViewportNode() function' , ( ) => {
@@ -1229,6 +1236,60 @@ describe('SlickGrid core file', () => {
12291236 } ) ;
12301237 } ) ;
12311238
1239+ describe ( 'Scrolling' , ( ) => {
1240+ const columns = [
1241+ { id : 'firstName' , field : 'firstName' , name : 'First Name' , sortable : true } ,
1242+ { id : 'lastName' , field : 'lastName' , name : 'Last Name' , sortable : true } ,
1243+ { id : 'age' , field : 'age' , name : 'Age' , sortable : true } ,
1244+ ] as Column [ ] ;
1245+ const data = [ { id : 0 , firstName : 'John' , lastName : 'Doe' , age : 30 } , { id : 1 , firstName : 'Jane' , lastName : 'Doe' , age : 28 } ] ;
1246+ const options = { enableCellNavigation : true , devMode : { ownerNodeIndex : 0 } } as GridOption ;
1247+
1248+ it ( 'should not scroll when calling scrollCellIntoView() with same position to frozen column' , ( ) => {
1249+ grid = new SlickGrid < any , Column > ( container , data , columns , { ...options , frozenColumn : 1 } ) ;
1250+ const renderSpy = jest . spyOn ( grid , 'render' ) ;
1251+ grid . scrollCellIntoView ( 1 , 1 , true ) ;
1252+
1253+ expect ( renderSpy ) . toHaveBeenCalledTimes ( 1 ) ; // 1x by the grid initialization
1254+ } ) ;
1255+
1256+ it ( 'should scroll when calling scrollCellIntoView() with lower position than frozen column' , ( ) => {
1257+ grid = new SlickGrid < any , Column > ( container , data , columns , { ...options , frozenColumn : 0 } ) ;
1258+ const renderSpy = jest . spyOn ( grid , 'render' ) ;
1259+ grid . scrollCellIntoView ( 1 , 1 , true ) ;
1260+
1261+ expect ( renderSpy ) . toHaveBeenCalledTimes ( 3 ) ;
1262+ } ) ;
1263+
1264+ it ( 'should call scrollColumnIntoView() and expect left scroll to become 80 which is default column width' , ( ) => {
1265+ grid = new SlickGrid < any , Column > ( container , data , columns , { ...options , frozenColumn : 0 } ) ;
1266+ let viewportElm = container . querySelector ( '.slick-viewport-top.slick-viewport-right' ) as HTMLDivElement ;
1267+ Object . defineProperty ( viewportElm , 'scrollLeft' , { writable : true , value : 20 } ) ;
1268+ Object . defineProperty ( viewportElm , 'scrollWidth' , { writable : true , value : 10 } ) ;
1269+ viewportElm . dispatchEvent ( new CustomEvent ( 'scroll' ) ) ;
1270+ const renderSpy = jest . spyOn ( grid , 'render' ) ;
1271+ grid . scrollColumnIntoView ( 2 ) ;
1272+ viewportElm = container . querySelector ( '.slick-viewport-top.slick-viewport-right' ) as HTMLDivElement ;
1273+
1274+ expect ( renderSpy ) . toHaveBeenCalledTimes ( 1 ) ;
1275+ expect ( viewportElm . scrollLeft ) . toBe ( 80 ) ;
1276+ } ) ;
1277+
1278+ it ( 'should call scrollColumnIntoView() and expect left scroll to be lower than scrollLeft and become 0' , ( ) => {
1279+ grid = new SlickGrid < any , Column > ( container , data , columns , { ...options , frozenColumn : 0 } ) ;
1280+ let viewportElm = container . querySelector ( '.slick-viewport-top.slick-viewport-right' ) as HTMLDivElement ;
1281+ Object . defineProperty ( viewportElm , 'scrollLeft' , { writable : true , value : 10 } ) ;
1282+ Object . defineProperty ( viewportElm , 'scrollWidth' , { writable : true , value : 20 } ) ;
1283+ viewportElm . dispatchEvent ( new CustomEvent ( 'scroll' ) ) ;
1284+ const renderSpy = jest . spyOn ( grid , 'render' ) ;
1285+ grid . scrollColumnIntoView ( 1 ) ;
1286+ viewportElm = container . querySelector ( '.slick-viewport-top.slick-viewport-right' ) as HTMLDivElement ;
1287+
1288+ expect ( renderSpy ) . toHaveBeenCalledTimes ( 1 ) ;
1289+ expect ( viewportElm . scrollLeft ) . toBe ( 0 ) ;
1290+ } ) ;
1291+ } ) ;
1292+
12321293 describe ( 'Navigation' , ( ) => {
12331294 const columns = [
12341295 { id : 'firstName' , field : 'firstName' , name : 'First Name' , sortable : true } ,
@@ -1321,9 +1382,7 @@ describe('SlickGrid core file', () => {
13211382
13221383 it ( 'should navigate to left then page down and expect active cell to change with previous cell position that was activated by the left navigation' , ( ) => {
13231384 const data = [ { id : 0 , firstName : 'John' } , { id : 1 , firstName : 'Jane' } ] ;
1324- const viewportElm = container . querySelector ( '.slick-viewport-top' ) as HTMLDivElement ;
13251385 grid = new SlickGrid < any , Column > ( container , data , columns , { ...options , enableCellNavigation : true } ) ;
1326- Object . defineProperty ( viewportElm , 'scrollLeft' , { writable : true , configurable : true , value : 10 } ) ;
13271386 const scrollCellSpy = jest . spyOn ( grid , 'scrollCellIntoView' ) ;
13281387 const resetCellSpy = jest . spyOn ( grid , 'resetActiveCell' ) ;
13291388 const canCellActiveSpy = jest . spyOn ( grid , 'canCellBeActive' ) ;
@@ -1507,6 +1566,7 @@ describe('SlickGrid core file', () => {
15071566 const onActiveCellSpy = jest . spyOn ( grid . onActiveCellChanged , 'notify' ) ;
15081567 grid . setActiveCell ( 0 , 0 ) ;
15091568 const result = grid . navigateUp ( ) ;
1569+ grid . focus ( ) ;
15101570
15111571 expect ( result ) . toBe ( false ) ;
15121572 expect ( scrollCellSpy ) . toHaveBeenCalledWith ( 0 , 0 , false ) ;
0 commit comments