@@ -4,8 +4,13 @@ import dh from '@deephaven/jsapi-shim';
4
4
import { DateUtils , Settings } from '@deephaven/jsapi-utils' ;
5
5
import { TestUtils } from '@deephaven/utils' ;
6
6
import { TypeValue } from '@deephaven/filters' ;
7
+ import {
8
+ ExpandableColumnGridModel ,
9
+ isExpandableColumnGridModel ,
10
+ } from '@deephaven/grid' ;
7
11
import IrisGrid from './IrisGrid' ;
8
12
import IrisGridTestUtils from './IrisGridTestUtils' ;
13
+ import IrisGridProxyModel from './IrisGridProxyModel' ;
9
14
10
15
class MockPath2D {
11
16
// eslint-disable-next-line class-methods-use-this
@@ -14,6 +19,13 @@ class MockPath2D {
14
19
15
20
window . Path2D = MockPath2D as unknown as new ( ) => Path2D ;
16
21
22
+ jest . mock ( '@deephaven/grid' , ( ) => ( {
23
+ ...jest . requireActual ( '@deephaven/grid' ) ,
24
+ isExpandableColumnGridModel : jest . fn ( ) ,
25
+ } ) ) ;
26
+
27
+ const { asMock } = TestUtils ;
28
+
17
29
const VIEW_SIZE = 5000 ;
18
30
19
31
const DEFAULT_SETTINGS : Settings = {
@@ -66,10 +78,12 @@ function createNodeMock(element: ReactElement) {
66
78
67
79
function makeComponent (
68
80
model = irisGridTestUtils . makeModel ( ) ,
69
- settings = DEFAULT_SETTINGS
81
+ settings = DEFAULT_SETTINGS ,
82
+ props = { }
70
83
) {
71
84
const testRenderer = TestRenderer . create (
72
- < IrisGrid model = { model } settings = { settings } /> ,
85
+ // eslint-disable-next-line react/jsx-props-no-spreading
86
+ < IrisGrid model = { model } settings = { settings } { ...props } /> ,
73
87
{
74
88
createNodeMock,
75
89
}
@@ -222,3 +236,96 @@ it('should set gotoValueSelectedColumnName to empty string if no columns are giv
222
236
223
237
expect ( component . state . gotoValueSelectedColumnName ) . toEqual ( '' ) ;
224
238
} ) ;
239
+
240
+ describe ( 'rebuildFilters' , ( ) => {
241
+ it ( 'updates state if filters not empty' , ( ) => {
242
+ const component = makeComponent ( undefined , undefined , {
243
+ quickFilters : [
244
+ [
245
+ '2' ,
246
+ {
247
+ columnType : IrisGridTestUtils . DEFAULT_TYPE ,
248
+ filterList : [
249
+ {
250
+ operator : 'eq' ,
251
+ text : 'null' ,
252
+ value : null ,
253
+ startColumnIndex : 0 ,
254
+ } ,
255
+ ] ,
256
+ } ,
257
+ ] ,
258
+ ] ,
259
+ } ) ;
260
+ jest . spyOn ( component , 'setState' ) ;
261
+ expect ( component . setState ) . not . toBeCalled ( ) ;
262
+ component . rebuildFilters ( ) ;
263
+ expect ( component . setState ) . toBeCalled ( ) ;
264
+ } ) ;
265
+
266
+ it ( 'does not update state for empty filters' , ( ) => {
267
+ const component = makeComponent ( ) ;
268
+ jest . spyOn ( component , 'setState' ) ;
269
+ component . rebuildFilters ( ) ;
270
+ expect ( component . setState ) . not . toBeCalled ( ) ;
271
+ } ) ;
272
+ } ) ;
273
+
274
+ describe ( 'column expand/collapse' , ( ) => {
275
+ let model : IrisGridProxyModel & ExpandableColumnGridModel ;
276
+ let component : IrisGrid ;
277
+
278
+ beforeEach ( ( ) => {
279
+ model = irisGridTestUtils . makeModel ( ) as IrisGridProxyModel &
280
+ ExpandableColumnGridModel ;
281
+ component = makeComponent ( model ) ;
282
+ model . setColumnExpanded = jest . fn ( ) ;
283
+ model . isColumnExpanded = jest . fn ( ( ) => false ) ;
284
+ model . expandAllColumns = jest . fn ( ) ;
285
+ model . collapseAllColumns = jest . fn ( ) ;
286
+ } ) ;
287
+
288
+ afterEach ( ( ) => {
289
+ jest . clearAllMocks ( ) ;
290
+ } ) ;
291
+
292
+ it ( 'calls setColumnExpanded if model supports expandable columns' , ( ) => {
293
+ asMock ( isExpandableColumnGridModel ) . mockReturnValue ( true ) ;
294
+ model . hasExpandableColumns = true ;
295
+ component . toggleExpandColumn ( 0 ) ;
296
+ expect ( model . setColumnExpanded ) . toHaveBeenCalled ( ) ;
297
+ } ) ;
298
+
299
+ it ( 'ignores setColumnExpanded and expand/collapse all if model does not support expandable columns' , ( ) => {
300
+ asMock ( isExpandableColumnGridModel ) . mockReturnValue ( false ) ;
301
+ component . toggleExpandColumn ( 0 ) ;
302
+ expect ( model . setColumnExpanded ) . not . toHaveBeenCalled ( ) ;
303
+
304
+ component . expandAllColumns ( ) ;
305
+ expect ( model . expandAllColumns ) . not . toHaveBeenCalled ( ) ;
306
+
307
+ component . collapseAllColumns ( ) ;
308
+ expect ( model . collapseAllColumns ) . not . toHaveBeenCalled ( ) ;
309
+ } ) ;
310
+
311
+ it ( 'calls expandAllColumns if model supports expandable columns and expand all' , ( ) => {
312
+ asMock ( isExpandableColumnGridModel ) . mockReturnValue ( true ) ;
313
+ model . isExpandAllColumnsAvailable = true ;
314
+ component . expandAllColumns ( ) ;
315
+ expect ( model . expandAllColumns ) . toHaveBeenCalled ( ) ;
316
+
317
+ component . collapseAllColumns ( ) ;
318
+ expect ( model . collapseAllColumns ) . toHaveBeenCalled ( ) ;
319
+ } ) ;
320
+
321
+ it ( 'ignores expandAllColumns if model does not support expand all' , ( ) => {
322
+ asMock ( isExpandableColumnGridModel ) . mockReturnValue ( true ) ;
323
+ model . isExpandAllColumnsAvailable = false ;
324
+
325
+ component . expandAllColumns ( ) ;
326
+ expect ( model . expandAllColumns ) . not . toHaveBeenCalled ( ) ;
327
+
328
+ component . collapseAllColumns ( ) ;
329
+ expect ( model . collapseAllColumns ) . not . toHaveBeenCalled ( ) ;
330
+ } ) ;
331
+ } ) ;
0 commit comments