@@ -6,6 +6,9 @@ import useSetPaddedViewportCallback from './useSetPaddedViewportCallback';
66
77let table : dh . Table ;
88let viewportOptions : dh . ViewportSubscriptionOptions ;
9+ let viewportOptionsMissingRows : Partial < dh . ViewportSubscriptionOptions > ;
10+ let viewportOptionsMissingColumns : Partial < dh . ViewportSubscriptionOptions > ;
11+ let viewportOptionsMissingBoth : Partial < dh . ViewportSubscriptionOptions > ;
912const viewportSize = 10 ;
1013const viewportPadding = 4 ;
1114
@@ -19,6 +22,16 @@ beforeEach(() => {
1922 } ,
2023 columns : table . columns ,
2124 } ;
25+ viewportOptionsMissingRows = {
26+ columns : table . columns ,
27+ } ;
28+ viewportOptionsMissingColumns = {
29+ rows : {
30+ first : 5 ,
31+ last : 15 ,
32+ } ,
33+ } ;
34+ viewportOptionsMissingBoth = { } ;
2235} ) ;
2336
2437it ( 'should create a callback that sets a padded viewport' , ( ) => {
@@ -89,6 +102,68 @@ it('should use TableViewportSubscription if viewport options are provided', () =
89102 expect ( table . setViewport ) . not . toHaveBeenCalled ( ) ;
90103} ) ;
91104
105+ it ( 'should fill missing rows and columns when creating a subscription' , ( ) => {
106+ jest . spyOn ( TableUtils , 'isTreeTable' ) . mockReturnValue ( false ) ;
107+
108+ const mockSubscription = {
109+ update : jest . fn ( ) ,
110+ close : jest . fn ( ) ,
111+ } ;
112+
113+ ( table . createViewportSubscription as jest . Mock ) . mockReturnValue (
114+ mockSubscription
115+ ) ;
116+
117+ const { result, rerender } = renderHook (
118+ options =>
119+ useSetPaddedViewportCallback (
120+ table ,
121+ viewportSize ,
122+ viewportPadding ,
123+ options
124+ ) ,
125+ { initialProps : viewportOptionsMissingRows }
126+ ) ;
127+
128+ const firstRow = 30 ;
129+ result . current ( firstRow ) ;
130+
131+ const expectedRows = {
132+ first : firstRow - viewportPadding ,
133+ last : firstRow + viewportSize + viewportPadding - 1 ,
134+ } ;
135+
136+ expect ( table . createViewportSubscription ) . toHaveBeenCalledWith ( {
137+ columns : table . columns ,
138+ rows : expectedRows ,
139+ } ) ;
140+
141+ jest . clearAllMocks ( ) ;
142+
143+ rerender ( viewportOptionsMissingColumns ) ;
144+ result . current ( firstRow + 5 ) ;
145+
146+ expect ( table . createViewportSubscription ) . toHaveBeenCalledWith ( {
147+ rows : viewportOptionsMissingColumns . rows ,
148+ columns : table . columns ,
149+ } ) ;
150+
151+ jest . clearAllMocks ( ) ;
152+
153+ rerender ( viewportOptionsMissingBoth ) ;
154+ result . current ( firstRow + 10 ) ;
155+
156+ const expectedRows2 = {
157+ first : firstRow + 10 - viewportPadding ,
158+ last : firstRow + 10 + viewportSize + viewportPadding - 1 ,
159+ } ;
160+
161+ expect ( table . createViewportSubscription ) . toHaveBeenCalledWith ( {
162+ rows : expectedRows2 ,
163+ columns : table . columns ,
164+ } ) ;
165+ } ) ;
166+
92167it ( 'should use setViewport if provided a tree table' , ( ) => {
93168 jest . spyOn ( TableUtils , 'isTreeTable' ) . mockReturnValue ( true ) ;
94169
0 commit comments