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52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
import React from 'react';
import { spy, stub } from 'sinon';
import { mount, shallow } from 'enzyme';
import { assert, expect } from 'chai';
import cloneDeep from 'lodash.clonedeep';
import MUIDataTable from '../src/MUIDataTable';
import TableFilterList from '../src/components/TableFilterList';
import TablePagination from '../src/components/TablePagination';
import TableToolbar from '../src/components/TableToolbar';
import TableToolbarSelect from '../src/components/TableToolbarSelect';
import getTextLabels from '../src/textLabels';
import Chip from '@mui/material/Chip';
import Cities from '../examples/component/cities';
import { getCollatorComparator } from '../src/utils';
import TableFooter from '@mui/material/TableFooter';
import TableRow from '@mui/material/TableRow';
import TableCell from '@mui/material/TableCell';

describe('<MUIDataTable />', function() {
  const tableId = 'tableID';
  let data;
  let displayData;
  let columns;
  let tableData;
  let renderCities = (value, tableMeta, updateValueFn) => (
    <Cities value={value} index={tableMeta.rowIndex} change={event => updateValueFn(event)} />
  );
  let renderName = value => value.split(' ')[1] + ', ' + value.split(' ')[0];
  let renderState = value => value;
  let renderHead = columnMeta => columnMeta.name + 's';
  let defaultRenderCustomFilterList = f => f;
  let renderCustomFilterList = f => `Name: ${f}`;

  before(() => {
    columns = [
      {
        name: 'Name',
        options: {
          customBodyRender: renderName,
          customFilterListOptions: { render: renderCustomFilterList },
        },
      },
      'Company',
      { name: 'City', label: 'City Label', options: { customBodyRender: renderCities, filterType: 'textField' } },
      {
        name: 'State',
        options: { customBodyRender: renderState, filterType: 'multiselect', customHeadRender: renderHead },
      },
      { name: 'Empty', options: { empty: true, filterType: 'checkbox' } },
    ];
    data = [
      ['Joe James', 'Test Corp', 'Yonkers', 'NY'],
      ['John Walsh', 'Test Corp', 'Hartford', null],
      ['Bob Herm', 'Test Corp', 'Tampa', 'FL'],
      ['James Houston', 'Test Corp', 'Dallas', 'TX'],
    ];
    // internal table data built from source data provided
    displayData = JSON.stringify([
      {
        data: ['James, Joe', 'Test Corp', renderCities('Yonkers', { rowIndex: 0 }), 'NY', undefined],
        dataIndex: 0,
      },
      {
        data: ['Walsh, John', 'Test Corp', renderCities('Hartford', { rowIndex: 1 }), null, undefined],
        dataIndex: 1,
      },
      {
        data: ['Herm, Bob', 'Test Corp', renderCities('Tampa', { rowIndex: 2 }), 'FL', undefined],
        dataIndex: 2,
      },
      {
        data: ['Houston, James', 'Test Corp', renderCities('Dallas', { rowIndex: 3 }), 'TX', undefined],
        dataIndex: 3,
      },
    ]);
    tableData = [
      { index: 0, data: ['James, Joe', 'Test Corp', renderCities('Yonkers', { rowIndex: 0 }), 'NY', undefined] },
      { index: 1, data: ['Walsh, John', 'Test Corp', renderCities('Hartford', { rowIndex: 1 }), null, undefined] },
      { index: 2, data: ['Herm, Bob', 'Test Corp', renderCities('Tampa', { rowIndex: 2 }), 'FL', undefined] },
      { index: 3, data: ['Houston, James', 'Test Corp', renderCities('Dallas', { rowIndex: 3 }), 'TX', undefined] },
    ];
    renderCities = renderCities;
    renderName = renderName;
    renderState = renderState;
  });

  it('should render a table', () => {
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />);
    assert.include(
      ['Paper', 'ForwardRef(Paper)'],
      shallowWrapper
        .dive()
        .dive()
        .name(),
    );
  });

  it('should correctly build internal columns data structure', () => {
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />);
    const actualResult = shallowWrapper.dive().state().columns;

    const expectedResult = [
      {
        display: 'true',
        empty: false,
        print: true,
        name: 'Name',
        sort: true,
        filter: true,
        label: 'Name',
        download: true,
        searchable: true,
        viewColumns: true,
        customFilterListOptions: { render: renderCustomFilterList },
        customBodyRender: renderName,
        sortCompare: null,
        sortThirdClickReset: false,
        sortDescFirst: false,
      },
      {
        display: 'true',
        empty: false,
        print: true,
        name: 'Company',
        sort: true,
        filter: true,
        label: 'Company',
        download: true,
        searchable: true,
        viewColumns: true,
        sortCompare: null,
        sortThirdClickReset: false,
        sortDescFirst: false,
      },
      {
        display: 'true',
        empty: false,
        print: true,
        name: 'City',
        sort: true,
        filter: true,
        filterType: 'textField',
        label: 'City Label',
        download: true,
        searchable: true,
        viewColumns: true,
        customBodyRender: renderCities,
        sortCompare: null,
        sortThirdClickReset: false,
        sortDescFirst: false,
      },
      {
        display: 'true',
        empty: false,
        print: true,
        name: 'State',
        sort: true,
        filter: true,
        filterType: 'multiselect',
        label: 'State',
        download: true,
        searchable: true,
        viewColumns: true,
        customBodyRender: renderState,
        customHeadRender: renderHead,
        sortCompare: null,
        sortThirdClickReset: false,
        sortDescFirst: false,
      },
      {
        display: 'true',
        empty: true,
        print: true,
        name: 'Empty',
        sort: true,
        filter: true,
        filterType: 'checkbox',
        label: 'Empty',
        download: true,
        searchable: true,
        viewColumns: true,
        sortCompare: null,
        sortThirdClickReset: false,
        sortDescFirst: false,
      },
    ];

    assert.deepEqual(actualResult, expectedResult);
  });

  it('should correctly rebuild internal columns data structure', () => {
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />);

    shallowWrapper.setProps({
      columns: [
        {
          name: 'Test Name',
          options: {
            filter: false,
            display: 'excluded',
            customBodyRender: renderName,
            customFilterListOptions: { render: renderCustomFilterList },
          },
        },
        'Company',
        { name: 'City', label: 'City Label', options: { customBodyRender: renderCities, filterType: 'textField' } },
        {
          name: 'State',
          options: { customBodyRender: renderState, filterType: 'multiselect', customHeadRender: renderHead },
        },
        { name: 'Empty', options: { empty: true, filterType: 'checkbox' } },
      ],
    });

    const actualResult = shallowWrapper.dive().state().columns;

    const expectedResult = [
      {
        display: 'excluded',
        empty: false,
        print: true,
        name: 'Test Name',
        sort: true,
        filter: false,
        label: 'Test Name',
        download: true,
        searchable: true,
        viewColumns: true,
        customFilterListOptions: { render: renderCustomFilterList },
        customBodyRender: renderName,
        sortCompare: null,
        sortThirdClickReset: false,
        sortDescFirst: false,
      },
      {
        display: 'true',
        empty: false,
        print: true,
        name: 'Company',
        sort: true,
        filter: true,
        label: 'Company',
        download: true,
        searchable: true,
        viewColumns: true,
        sortCompare: null,
        sortThirdClickReset: false,
        sortDescFirst: false,
      },
      {
        display: 'true',
        empty: false,
        print: true,
        name: 'City',
        sort: true,
        filter: true,
        filterType: 'textField',
        label: 'City Label',
        download: true,
        searchable: true,
        viewColumns: true,
        customBodyRender: renderCities,
        sortCompare: null,
        sortThirdClickReset: false,
        sortDescFirst: false,
      },
      {
        display: 'true',
        empty: false,
        print: true,
        name: 'State',
        sort: true,
        filter: true,
        filterType: 'multiselect',
        label: 'State',
        download: true,
        searchable: true,
        viewColumns: true,
        customBodyRender: renderState,
        customHeadRender: renderHead,
        sortCompare: null,
        sortThirdClickReset: false,
        sortDescFirst: false,
      },
      {
        display: 'true',
        empty: true,
        print: true,
        name: 'Empty',
        sort: true,
        filter: true,
        filterType: 'checkbox',
        label: 'Empty',
        download: true,
        searchable: true,
        viewColumns: true,
        sortCompare: null,
        sortThirdClickReset: false,
        sortDescFirst: false,
      },
    ];

    assert.deepEqual(actualResult, expectedResult);
  });

  it('should correctly build internal table data and displayData structure', () => {
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />);
    const state = shallowWrapper.dive().state();
    //assert.deepEqual(state.data, data);
    assert.deepEqual(JSON.stringify(state.displayData), displayData);
  });

  it('should correctly build internal table data and displayData structure when using nested data (option enableNestedDataAccess omitted )', () => {
    const columns = [
      {
        name: 'Name',
        options: {
          customBodyRender: renderName,
          customFilterListOptions: { render: renderCustomFilterList },
        },
      },
      'Company',
      { name: 'Location.City', label: 'City Label' },
      { name: 'Location.State' },
      { name: 'Empty', options: { empty: true, filterType: 'checkbox' } },
    ];
    const data = [
      { Name: 'Joe James', Company: 'Test Corp', Location: { City: 'Yonkers', State: 'NY' } },
      { Name: 'John Walsh', Company: 'Test Corp', Location: { City: 'Hartford', State: null } },
      { Name: 'Bob Herm', Company: 'Test Corp', Location: { Town: 'Tampa', State: 'FL' } },
      { Name: 'James Houston', Company: 'Test Corp', Location: { City: 'Dallas', State: 'TX' } },
    ];
    const displayData = JSON.stringify([
      { data: ['James, Joe', 'Test Corp', null, null, null], dataIndex: 0 },
      { data: ['Walsh, John', 'Test Corp', null, null, null], dataIndex: 1 },
      { data: ['Herm, Bob', 'Test Corp', null, null, null], dataIndex: 2 },
      { data: ['Houston, James', 'Test Corp', null, null, null], dataIndex: 3 },
    ]);
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />);
    const state = shallowWrapper.dive().state();

    assert.deepEqual(JSON.stringify(state.displayData), displayData);
  });

  it('should correctly build internal table data and displayData structure with enabled nested data custom marker (option enableNestedDataAccess : "/OK/" )', () => {
    const columns = [
      {
        name: 'Name',
        options: {
          customBodyRender: renderName,
          customFilterListOptions: { render: renderCustomFilterList },
        },
      },
      'Company',
      { name: 'Location/OK/City', label: 'City Label' },
      { name: 'Location/OK/State' },
      { name: 'Empty', options: { empty: true, filterType: 'checkbox' } },
    ];
    const data = [
      { Name: 'Joe James', Company: 'Test Corp', Location: { City: 'Yonkers', State: 'NY' } },
      { Name: 'John Walsh', Company: 'Test Corp', Location: { City: 'Hartford', State: null } },
      { Name: 'Bob Herm', Company: 'Test Corp', Location: { Town: 'Tampa', State: 'FL' } },
      { Name: 'James Houston', Company: 'Test Corp', Location: { City: 'Dallas', State: 'TX' } },
    ];
    const displayData = JSON.stringify([
      { data: ['James, Joe', 'Test Corp', 'Yonkers', 'NY', undefined], dataIndex: 0 },
      { data: ['Walsh, John', 'Test Corp', 'Hartford', null, undefined], dataIndex: 1 },
      { data: ['Herm, Bob', 'Test Corp', undefined, 'FL', undefined], dataIndex: 2 },
      { data: ['Houston, James', 'Test Corp', 'Dallas', 'TX', undefined], dataIndex: 3 },
    ]);
    const shallowWrapper = shallow(
      <MUIDataTable columns={columns} data={data} options={{ enableNestedDataAccess: '/OK/' }} />,
    );
    const state = shallowWrapper.dive().state();

    assert.deepEqual(JSON.stringify(state.displayData), displayData);
  });

  it('should correctly build internal table data and displayData structure with disabled nested data (option enableNestedDataAccess : "" )', () => {
    const columns = [
      {
        name: 'Name',
        options: {
          customBodyRender: renderName,
          customFilterListOptions: { render: renderCustomFilterList },
        },
      },
      'Company',
      { name: 'Location/OK/City', label: 'City Label' },
      { name: 'Location.State' },
      { name: 'Empty', options: { empty: true, filterType: 'checkbox' } },
    ];
    const data = [
      { Name: 'Joe James', Company: 'Test Corp', Location: { City: 'Yonkers', State: 'NY' } },
      { Name: 'John Walsh', Company: 'Test Corp', Location: { City: 'Hartford', State: null } },
      { Name: 'Bob Herm', Company: 'Test Corp', Location: { Town: 'Tampa', State: 'FL' } },
      { Name: 'James Houston', Company: 'Test Corp', Location: { City: 'Dallas', State: 'TX' } },
    ];
    const displayData = JSON.stringify([
      { data: ['James, Joe', 'Test Corp', null, null, undefined], dataIndex: 0 },
      { data: ['Walsh, John', 'Test Corp', null, null, undefined], dataIndex: 1 },
      { data: ['Herm, Bob', 'Test Corp', null, null, undefined], dataIndex: 2 },
      { data: ['Houston, James', 'Test Corp', null, null, undefined], dataIndex: 3 },
    ]);
    const shallowWrapper = shallow(
      <MUIDataTable columns={columns} data={data} options={{ enableNestedDataAccess: '' }} />,
    );
    const state = shallowWrapper.dive().state();

    assert.deepEqual(JSON.stringify(state.displayData), displayData);
  });

  it('should correctly build internal table data and displayData structure with sortOrder set', () => {
    const columns = ['Name', 'Company', 'Location'];

    const data = [
      { Name: 'Joe James', Company: 'Test Corp', Location: 'Las Cruces' },
      { Name: 'John Walsh', Company: 'Test Corp', Location: 'El Paso' },
      { Name: 'Bob Herm', Company: 'Test Corp', Location: 'Albuquerque' },
      { Name: 'James Houston', Company: 'Test Corp', Location: 'Santa Fe' },
    ];
    const displayData = JSON.stringify([
      { data: ['Bob Herm', 'Test Corp', 'Albuquerque'], dataIndex: 2 },
      { data: ['John Walsh', 'Test Corp', 'El Paso'], dataIndex: 1 },
      { data: ['Joe James', 'Test Corp', 'Las Cruces'], dataIndex: 0 },
      { data: ['James Houston', 'Test Corp', 'Santa Fe'], dataIndex: 3 },
    ]);
    const shallowWrapper = shallow(
      <MUIDataTable columns={columns} data={data} options={{ sortOrder: { name: 'Location', direction: 'asc' } }} />,
    );
    const state = shallowWrapper.dive().state();

    assert.deepEqual(JSON.stringify(state.displayData), displayData);
  });

  it('should correctly re-build display after xhr with serverSide=true', done => {
    const fullWrapper = mount(<MUIDataTable columns={columns} data={[]} options={{ serverSide: true }} />);
    assert.strictEqual(fullWrapper.find('tbody tr').length, 1);

    // simulate xhr and test number of displayed rows
    new Promise((resolve, reject) => {
      setTimeout(() => {
        fullWrapper.setProps({ data });
        fullWrapper.update();
        assert.strictEqual(fullWrapper.find('tbody tr').length, 4);

        fullWrapper.unmount();
        done();
      }, 10);
    });
  });

  it('should correctly set tableId', () => {
    const fullWrapper = mount(<MUIDataTable columns={columns} data={[]} options={{ tableId: 'myTable123' }} />);
    assert.strictEqual(fullWrapper.find('[data-tableid="myTable123"]').length, 12);
  });

  it('should correctly re-build internal table data and displayData structure with prop change', () => {
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />);
    let state = shallowWrapper.dive().state();

    assert.deepEqual(JSON.stringify(state.displayData), displayData);

    // now use updated props
    let newData = data.map(item => [...item]);
    newData[0][0] = 'testing';
    shallowWrapper.setProps({ data: newData });
    shallowWrapper.update();

    state = shallowWrapper.dive().state();
    const expectedResult = [
      { index: 0, data: ['testing', 'Test Corp', 'Yonkers', 'NY', undefined] },
      { index: 1, data: ['John Walsh', 'Test Corp', 'Hartford', null, undefined] },
      { index: 2, data: ['Bob Herm', 'Test Corp', 'Tampa', 'FL', undefined] },
      { index: 3, data: ['James Houston', 'Test Corp', 'Dallas', 'TX', undefined] },
    ];

    assert.deepEqual(state.data, expectedResult);
  });

  it('should correctly re-build table options before and after prop change', () => {
    const options = {
      textLabels: {
        newObj: {
          test: 'foo',
        },
      },
      downloadOptions: {
        separator: ':',
      },
    };
    const newOptions = {
      textLabels: {
        newObj: {
          test: 'bar',
        },
      },
      downloadOptions: {
        separator: ';',
      },
    };
    const fullWrapper = mount(<MUIDataTable columns={columns} data={[]} options={options} />);
    let props = fullWrapper.props();

    assert.deepEqual(props.options, options);

    fullWrapper.setProps({ options: newOptions, data });
    fullWrapper.update();
    props = fullWrapper.props();

    assert.deepEqual(props.options, newOptions);
    fullWrapper.unmount();
  });

  it('should correctly sort', () => {
    const columns = [
      {
        name: 'Name',
        options: {},
      },
      'Company',
      'Location',
    ];

    const data = [
      { Name: 'Joe James', Company: 'Test Corp', Location: 'Las Cruces' },
      { Name: 'John Walsh', Company: 'Test Corp', Location: 'El Paso' },
      { Name: 'Bob Herm', Company: 'Test Corp', Location: 'Albuquerque' },
      { Name: 'James Houston', Company: 'Test Corp', Location: 'Santa Fe' },
    ];
    const displayData1 = JSON.stringify([
      { data: ['Bob Herm', 'Test Corp', 'Albuquerque'], dataIndex: 2 },
      { data: ['James Houston', 'Test Corp', 'Santa Fe'], dataIndex: 3 },
      { data: ['Joe James', 'Test Corp', 'Las Cruces'], dataIndex: 0 },
      { data: ['John Walsh', 'Test Corp', 'El Paso'], dataIndex: 1 },
    ]);
    const displayData2 = JSON.stringify([
      { data: ['John Walsh', 'Test Corp', 'El Paso'], dataIndex: 1 },
      { data: ['Joe James', 'Test Corp', 'Las Cruces'], dataIndex: 0 },
      { data: ['James Houston', 'Test Corp', 'Santa Fe'], dataIndex: 3 },
      { data: ['Bob Herm', 'Test Corp', 'Albuquerque'], dataIndex: 2 },
    ]);

    const wrapper = mount(<MUIDataTable columns={columns} data={data} options={{}} />);

    wrapper
      .find('[data-testid="headcol-0"]')
      .at(0)
      .simulate('click');
    const fetchedDD1 = JSON.stringify(wrapper.childAt(0).state('displayData'));

    wrapper
      .find('[data-testid="headcol-0"]')
      .at(0)
      .simulate('click');
    const fetchedDD2 = JSON.stringify(wrapper.childAt(0).state('displayData'));

    wrapper
      .find('[data-testid="headcol-0"]')
      .at(0)
      .simulate('click');
    const fetchedDD3 = JSON.stringify(wrapper.childAt(0).state('displayData'));

    wrapper
      .find('[data-testid="headcol-0"]')
      .at(0)
      .simulate('click');
    const fetchedDD4 = JSON.stringify(wrapper.childAt(0).state('displayData'));

    assert.deepEqual(fetchedDD1, displayData1);
    assert.deepEqual(fetchedDD2, displayData2);
    assert.deepEqual(fetchedDD3, displayData1);
    assert.deepEqual(fetchedDD4, displayData2);
  });

  it('should correctly sort when sortThirdClickReset is true', () => {
    const columns = [
      {
        name: 'Name',
        options: {
          sortThirdClickReset: true,
        },
      },
      'Company',
      'Location',
    ];

    const data = [
      { Name: 'Joe James', Company: 'Test Corp', Location: 'Las Cruces' },
      { Name: 'John Walsh', Company: 'Test Corp', Location: 'El Paso' },
      { Name: 'Bob Herm', Company: 'Test Corp', Location: 'Albuquerque' },
      { Name: 'James Houston', Company: 'Test Corp', Location: 'Santa Fe' },
    ];
    const displayData1 = JSON.stringify([
      { data: ['Bob Herm', 'Test Corp', 'Albuquerque'], dataIndex: 2 },
      { data: ['James Houston', 'Test Corp', 'Santa Fe'], dataIndex: 3 },
      { data: ['Joe James', 'Test Corp', 'Las Cruces'], dataIndex: 0 },
      { data: ['John Walsh', 'Test Corp', 'El Paso'], dataIndex: 1 },
    ]);
    const displayData2 = JSON.stringify([
      { data: ['John Walsh', 'Test Corp', 'El Paso'], dataIndex: 1 },
      { data: ['Joe James', 'Test Corp', 'Las Cruces'], dataIndex: 0 },
      { data: ['James Houston', 'Test Corp', 'Santa Fe'], dataIndex: 3 },
      { data: ['Bob Herm', 'Test Corp', 'Albuquerque'], dataIndex: 2 },
    ]);
    const displayData3 = JSON.stringify([
      { data: ['Joe James', 'Test Corp', 'Las Cruces'], dataIndex: 0 },
      { data: ['John Walsh', 'Test Corp', 'El Paso'], dataIndex: 1 },
      { data: ['Bob Herm', 'Test Corp', 'Albuquerque'], dataIndex: 2 },
      { data: ['James Houston', 'Test Corp', 'Santa Fe'], dataIndex: 3 },
    ]);

    const wrapper = mount(<MUIDataTable columns={columns} data={data} options={{}} />);

    wrapper
      .find('[data-testid="headcol-0"]')
      .at(0)
      .simulate('click');
    const fetchedDD1 = JSON.stringify(wrapper.childAt(0).state('displayData'));

    wrapper
      .find('[data-testid="headcol-0"]')
      .at(0)
      .simulate('click');
    const fetchedDD2 = JSON.stringify(wrapper.childAt(0).state('displayData'));

    wrapper
      .find('[data-testid="headcol-0"]')
      .at(0)
      .simulate('click');
    const fetchedDD3 = JSON.stringify(wrapper.childAt(0).state('displayData'));

    wrapper
      .find('[data-testid="headcol-0"]')
      .at(0)
      .simulate('click');
    const fetchedDD4 = JSON.stringify(wrapper.childAt(0).state('displayData'));

    assert.deepEqual(fetchedDD1, displayData1);
    assert.deepEqual(fetchedDD2, displayData2);
    assert.deepEqual(fetchedDD3, displayData3);
    assert.deepEqual(fetchedDD4, displayData1);
  });

  it('should correctly sort when sortDescFirst and sortThirdClickReset are true', () => {
    const columns = [
      {
        name: 'Name',
        options: {
          sortDescFirst: true,
          sortThirdClickReset: true,
        },
      },
      'Company',
      'Location',
    ];

    const data = [
      { Name: 'Joe James', Company: 'Test Corp', Location: 'Las Cruces' },
      { Name: 'John Walsh', Company: 'Test Corp', Location: 'El Paso' },
      { Name: 'Bob Herm', Company: 'Test Corp', Location: 'Albuquerque' },
      { Name: 'James Houston', Company: 'Test Corp', Location: 'Santa Fe' },
    ];
    const displayData1 = JSON.stringify([
      { data: ['John Walsh', 'Test Corp', 'El Paso'], dataIndex: 1 },
      { data: ['Joe James', 'Test Corp', 'Las Cruces'], dataIndex: 0 },
      { data: ['James Houston', 'Test Corp', 'Santa Fe'], dataIndex: 3 },
      { data: ['Bob Herm', 'Test Corp', 'Albuquerque'], dataIndex: 2 },
    ]);
    const displayData2 = JSON.stringify([
      { data: ['Bob Herm', 'Test Corp', 'Albuquerque'], dataIndex: 2 },
      { data: ['James Houston', 'Test Corp', 'Santa Fe'], dataIndex: 3 },
      { data: ['Joe James', 'Test Corp', 'Las Cruces'], dataIndex: 0 },
      { data: ['John Walsh', 'Test Corp', 'El Paso'], dataIndex: 1 },
    ]);
    const displayData3 = JSON.stringify([
      { data: ['Joe James', 'Test Corp', 'Las Cruces'], dataIndex: 0 },
      { data: ['John Walsh', 'Test Corp', 'El Paso'], dataIndex: 1 },
      { data: ['Bob Herm', 'Test Corp', 'Albuquerque'], dataIndex: 2 },
      { data: ['James Houston', 'Test Corp', 'Santa Fe'], dataIndex: 3 },
    ]);

    const wrapper = mount(<MUIDataTable columns={columns} data={data} options={{}} />);

    wrapper
      .find('[data-testid="headcol-0"]')
      .at(0)
      .simulate('click');
    const fetchedDD1 = JSON.stringify(wrapper.childAt(0).state('displayData'));

    wrapper
      .find('[data-testid="headcol-0"]')
      .at(0)
      .simulate('click');
    const fetchedDD2 = JSON.stringify(wrapper.childAt(0).state('displayData'));

    wrapper
      .find('[data-testid="headcol-0"]')
      .at(0)
      .simulate('click');
    const fetchedDD3 = JSON.stringify(wrapper.childAt(0).state('displayData'));

    wrapper
      .find('[data-testid="headcol-0"]')
      .at(0)
      .simulate('click');
    const fetchedDD4 = JSON.stringify(wrapper.childAt(0).state('displayData'));

    assert.deepEqual(fetchedDD1, displayData1);
    assert.deepEqual(fetchedDD2, displayData2);
    assert.deepEqual(fetchedDD3, displayData3);
    assert.deepEqual(fetchedDD4, displayData1);
  });

  it('should correctly pass the sorted column name and direction to onColumnSortChange', () => {
    let sortedCol, sortedDir;
    const options = {
      rowsPerPage: 1,
      rowsPerPageOptions: [1, 2, 4],
      page: 1,
      onColumnSortChange: (col, dir) => {
        sortedCol = col;
        sortedDir = dir;
      },
    };
    const fullWrapper = mount(<MUIDataTable columns={columns} data={data} options={options} />);

    // simulate sorting a column
    fullWrapper
      .find('[data-testid="headcol-1"]')
      .at(0)
      .simulate('click');

    assert.strictEqual(sortedCol, 'Company');
    assert.strictEqual(sortedDir, 'asc');

    // simulate toggling the sort
    fullWrapper
      .find('[data-testid="headcol-1"]')
      .at(0)
      .simulate('click');

    assert.strictEqual(sortedCol, 'Company');
    assert.strictEqual(sortedDir, 'desc');
  });

  it('should correctly re-build internal table data while maintaining pagination after state change', () => {
    let currentPage;
    const options = {
      rowsPerPage: 1,
      rowsPerPageOptions: [1, 2, 4],
      page: 1,
      onChangePage: current => (currentPage = current),
    };
    const fullWrapper = mount(<MUIDataTable columns={columns} data={data} options={options} />);

    // simulate paging backward to set `currentPage`
    fullWrapper
      .find('#pagination-back')
      .at(0)
      .simulate('click');
    assert.strictEqual(currentPage, 0);

    /*
    TODO: simulating a click on #pagination-rows no longer seems to bring up the menu.
          doing "document.querySelector('#pagination-rows').click()" in the console doesn't
          work either. However, that method does work for #pagination-back and #pagination-next.
          Something was probably updated in Material UI, it's unclear at the moment how to simulate
          an event to bring up the select menu.

    // simulate changing pagination to set `rowsPerPage`
    fullWrapper.find('#pagination-rows').simulate('click');

    fullWrapper
      .find('#pagination-menu-list li')
      .at(1)
      .simulate('click');
*/
    let inputValue = fullWrapper
      .find('#pagination-input')
      .at(0)
      .text();
    assert.strictEqual(inputValue, '1'); // TODO: see above comment, was 2

    // add data to simulate state change
    let newData = data.map(item => [...item]);
    newData.push(['Harry Smith', 'Test Corp', 'Philadelphia', 'PA', undefined]);
    fullWrapper.setProps({ data: newData });

    // simulate paging forward to test whether or not the `currentPage` was reset
    fullWrapper
      .find('#pagination-next')
      .at(0)
      .simulate('click');
    assert.strictEqual(currentPage, 2);

    // grab pagination value to test whether or not `rowsPerPage` was reset
    inputValue = fullWrapper
      .find('#pagination-input')
      .at(0)
      .text();
    assert.strictEqual(inputValue, '1'); // TODO: see above comment, was 2

    // test that data updated properly
    let props = fullWrapper.props();
    const expectedResult = [
      ['Joe James', 'Test Corp', 'Yonkers', 'NY'],
      ['John Walsh', 'Test Corp', 'Hartford', null],
      ['Bob Herm', 'Test Corp', 'Tampa', 'FL'],
      ['James Houston', 'Test Corp', 'Dallas', 'TX'],
      ['Harry Smith', 'Test Corp', 'Philadelphia', 'PA', undefined],
    ];
    assert.deepEqual(props.data, expectedResult);
    fullWrapper.unmount();
  });

  it('should not re-build internal table data and displayData structure with no prop change to data or columns', () => {
    const setTableDataSpy = spy(MUIDataTable.Naked.prototype, 'setTableData');
    const mountWrapper = mount(shallow(<MUIDataTable columns={columns} data={data} />).get(0));

    let state = mountWrapper.state();
    assert.deepEqual(JSON.stringify(state.displayData), displayData);

    // now update props with no change
    mountWrapper.setProps({});
    mountWrapper.update();

    state = mountWrapper.state();

    assert.deepEqual(JSON.stringify(state.displayData), displayData);
    assert.deepEqual(setTableDataSpy.callCount, 1);
  });

  it('should add custom props to table if setTableProps provided', () => {
    const options = { setTableProps: stub().returns({ myProp: 'test', className: 'testClass' }) };
    const fullWrapper = mount(<MUIDataTable columns={columns} data={[]} options={options} />);
    const props = fullWrapper
      .find('table')
      .first()
      .props();

    const classNames = props.className.split(' ');
    const finalClass = classNames[classNames.length - 1];

    assert.strictEqual(props.myProp, 'test');
    assert.strictEqual(finalClass, 'testClass');
    assert.isAtLeast(options.setTableProps.callCount, 1);
  });

  it('should correctly build internal filterList structure', () => {
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />);
    const state = shallowWrapper.dive().state();
    const expectedResult = [[], [], [], [], []];

    assert.deepEqual(state.filterList, expectedResult);
  });

  it('should correctly build internal unique column data for filterData structure', () => {
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />);
    const state = shallowWrapper.dive().state();
    const expectedResult = [
      ['Herm, Bob', 'Houston, James', 'James, Joe', 'Walsh, John'],
      ['Test Corp'],
      ['Dallas', 'Hartford', 'Tampa', 'Yonkers'],
      ['FL', null, 'NY', 'TX'],
      [undefined],
    ];

    assert.deepEqual(state.filterData, expectedResult);
  });

  it('should correctly build internal rowsPerPage when provided in options', () => {
    const options = {
      rowsPerPage: 20,
      textLabels: getTextLabels(),
    };

    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options} />);
    const state = shallowWrapper.dive().state();
    assert.strictEqual(state.rowsPerPage, 20);
  });

  it('should correctly build internal rowsPerPageOptions when provided in options', () => {
    const options = {
      rowsPerPageOptions: [5, 10, 15],
    };

    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options} />);
    const state = shallowWrapper.dive().state();
    assert.deepEqual(state.rowsPerPageOptions, [5, 10, 15]);
  });

  it('should allow empty array rowsPerPageOptions when provided in options', () => {
    const options = {
      rowsPerPageOptions: [],
    };

    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options} />);
    const state = shallowWrapper.dive().state();
    assert.deepEqual(state.rowsPerPageOptions, []);
  });

  it('should render pagination when enabled in options', () => {
    const options = {
      pagination: true,
    };

    const mountWrapper = mount(<MUIDataTable columns={columns} data={data} options={options} />);
    const actualResult = mountWrapper.find(TablePagination);
    assert.lengthOf(actualResult, 1);
  });

  it('should not render pagination when disabled in options', () => {
    const options = {
      pagination: false,
    };

    const mountWrapper = mount(<MUIDataTable columns={columns} data={data} options={options} />);
    const actualResult = mountWrapper.find(TablePagination);
    assert.lengthOf(actualResult, 0);
  });

  it('should not render toolbar when all its displayable items are missing', () => {
    const options = {
      filter: false,
      search: false,
      print: false,
      download: false,
      viewColumns: false,
    };

    const mountWrapper = mount(<MUIDataTable columns={columns} data={data} options={options} />);
    const actualResult = mountWrapper.find(TableToolbar);
    assert.lengthOf(actualResult, 0);
  });

  it('should not render select toolbar when disableToolbarSelect=true', () => {
    const options = { disableToolbarSelect: true };
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options} />).dive();
    const instance = shallowWrapper.instance();

    // Simulate a selection
    instance.selectRowUpdate('cell', { index: 0, dataIndex: 0 });

    const actualResult = shallowWrapper.find(TableToolbarSelect);
    assert.lengthOf(actualResult, 0);
  });

  it('should not render select toolbar when selectToolbarPlacement="none"', () => {
    const options = { selectToolbarPlacement: 'none' };
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options} />).dive();
    const instance = shallowWrapper.instance();

    // Simulate a selection
    instance.selectRowUpdate('cell', { index: 0, dataIndex: 0 });

    const actualResult = shallowWrapper.find(TableToolbarSelect);
    assert.lengthOf(actualResult, 0);
    const actualResult2 = shallowWrapper.find(TableToolbar);
    assert.lengthOf(actualResult2, 1);
  });

  it('should not render select toolbar when selectToolbarPlacement="none" and rowsSelected is inputted', () => {
    const options = { selectToolbarPlacement: 'none', rowsSelected: [] };

    // make all rows selected
    data.forEach((item, idx) => {
      options.rowsSelected.push(idx);
    });
    options.rowsSelected.pop(); // all but 1 row is selected

    options.searchText = 'J';

    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options} />).dive();
    const instance = shallowWrapper.instance();

    const actualResult = shallowWrapper.find(TableToolbarSelect);
    assert.lengthOf(actualResult, 0);
    const actualResult2 = shallowWrapper.find(TableToolbar);
    assert.lengthOf(actualResult2, 1);
  });

  it('should render both select toolbar and toolbar when selectToolbarPlacement="above"', () => {
    const options = { selectToolbarPlacement: 'above' };
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options} />).dive();
    const instance = shallowWrapper.instance();

    // Simulate a selection
    instance.selectRowUpdate('cell', { index: 0, dataIndex: 0 });

    const actualResult = shallowWrapper.find(TableToolbarSelect);
    assert.lengthOf(actualResult, 1);
    const actualResult2 = shallowWrapper.find(TableToolbar);
    assert.lengthOf(actualResult2, 1);
  });

  it('should render select toolbar by default', () => {
    const options = {};
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options} />).dive();
    const instance = shallowWrapper.instance();

    // Simulate a selection
    instance.selectRowUpdate('cell', { index: 0, dataIndex: 0 });

    const actualResult = shallowWrapper.find(TableToolbarSelect);
    assert.lengthOf(actualResult, 1);
    const actualResult2 = shallowWrapper.find(TableToolbar);
    assert.lengthOf(actualResult2, 0);
  });

  it('should properly set internal filterList when calling filterUpdate method with type=checkbox', () => {
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />);
    const table = shallowWrapper.dive();
    const instance = table.instance();
    instance.filterUpdate(0, 'Joe James', 'Name', 'checkbox');
    table.update();
    const state = table.state();
    assert.deepEqual(state.filterList, [['Joe James'], [], [], [], []]);
  });

  it('should remove entry from filterList when calling filterUpdate method with type=checkbox and same arguments a second time', () => {
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />);
    const table = shallowWrapper.dive();
    const instance = table.instance();
    instance.filterUpdate(0, 'Joe James', 'Name', 'checkbox');
    table.update();

    let state = table.state();
    assert.deepEqual(state.filterList, [['Joe James'], [], [], [], []]);

    instance.filterUpdate(0, 'Joe James', 'checkbox');
    table.update();

    state = table.state();
    assert.deepEqual(state.filterList, [[], [], [], [], []]);
  });

  it('should properly set internal filterList when calling filterUpdate method with type=dropdown', () => {
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />);
    const table = shallowWrapper.dive();
    const instance = table.instance();
    instance.filterUpdate(0, ['Joe James'], 'Name', 'dropdown');
    table.update();

    const state = table.state();
    assert.deepEqual(state.filterList, [['Joe James'], [], [], [], []]);
  });

  it('should apply columns prop change for filterList', () => {
    const mountShallowWrapper = mount(shallow(<MUIDataTable columns={columns} data={data} />).get(0));
    const instance = mountShallowWrapper.instance();

    // now use updated columns props
    const newColumns = cloneDeep(columns);
    newColumns[0].options.filterList = ['Joe James'];
    mountShallowWrapper.setProps({ columns: newColumns });
    mountShallowWrapper.update();
    instance.setTableData(mountShallowWrapper.props(), 1 /* instance.TABLE_LOAD.INITIAL */);

    const updatedState = mountShallowWrapper.state();
    assert.deepEqual(updatedState.filterList, [['Joe James'], [], [], [], []]);
  });

  it('should create Chip when filterList is populated', () => {
    const filterList = [['Joe James'], [], [], [], []];
    const filterListRenderers = [
      defaultRenderCustomFilterList,
      defaultRenderCustomFilterList,
      defaultRenderCustomFilterList,
      defaultRenderCustomFilterList,
      defaultRenderCustomFilterList,
    ];
    const columnNames = columns.map(column => ({ name: column.name }));

    const mountWrapper = mount(
      <TableFilterList
        options={{ serverSide: false }}
        filterList={filterList}
        filterListRenderers={filterListRenderers}
        filterUpdate={() => true}
        columnNames={columnNames}
      />,
    );
    const actualResult = mountWrapper.find(Chip);
    assert.strictEqual(actualResult.length, 1);
  });

  it('should create Chip with custom label when filterList and customFilterListOptions are populated', () => {
    const filterList = [['Joe James'], [], [], [], []];
    const filterListRenderers = columns.map(c => {
      return c.options && c.options.customFilterListOptions && c.options.customFilterListOptions.render
        ? c.options.customFilterListOptions.render
        : defaultRenderCustomFilterList;
    });
    const columnNames = columns.map(column => ({ name: column.name }));

    const mountWrapper = mount(
      <TableFilterList
        options={{ serverSide: false }}
        filterList={filterList}
        filterListRenderers={filterListRenderers}
        filterUpdate={() => true}
        columnNames={columnNames}
      />,
    );
    const actualResult = mountWrapper.find(Chip);
    assert.strictEqual(actualResult.length, 1);
    assert.strictEqual(actualResult.prop('label'), 'Name: Joe James');
  });

  it('should call custom filter update function when it is passed into custom filter update', () => {
    const customFilterListUpdate = spy(() => [[], [], [], [], []]);
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />);
    const table = shallowWrapper.dive();
    const instance = table.instance();

    instance.filterUpdate(0, ['Joe James'], 'Name', 'custom', customFilterListUpdate);
    table.update();

    assert.deepEqual(customFilterListUpdate.callCount, 1);
  });

  it('should render filter Chip(s) when options.serverSide = true and serverSideFilterList is populated', () => {
    const serverSideFilterList = [['Joe James'], [], [], [], []];
    const filterListRenderers = [
      defaultRenderCustomFilterList,
      defaultRenderCustomFilterList,
      defaultRenderCustomFilterList,
      defaultRenderCustomFilterList,
      defaultRenderCustomFilterList,
    ];
    const columnNames = columns.map(column => ({ name: column.name }));

    const mountWrapper = mount(
      <TableFilterList
        options={{ serverSide: true }}
        serverSideFilterList={serverSideFilterList}
        filterListRenderers={filterListRenderers}
        filterUpdate={() => true}
        columnNames={columnNames}
      />,
    );

    const actualResult = mountWrapper.find(Chip);
    assert.strictEqual(actualResult.length, 1);
  });

  it('should not render filter Chip(s) when options.serverSide = true and serverSideFilterList is not populated', () => {
    const filterListRenderers = [
      defaultRenderCustomFilterList,
      defaultRenderCustomFilterList,
      defaultRenderCustomFilterList,
      defaultRenderCustomFilterList,
      defaultRenderCustomFilterList,
    ];
    const columnNames = columns.map(column => ({ name: column.name }));

    const mountWrapper = mount(
      <TableFilterList
        options={{ serverSide: true }}
        serverSideFilterList={[]}
        filterListRenderers={filterListRenderers}
        filterUpdate={() => true}
        columnNames={columnNames}
      />,
    );

    const actualResult = mountWrapper.find(Chip);
    assert.strictEqual(actualResult.length, 0);
  });

  it('should remove entry from filterList when calling filterUpdate method with type=dropdown and an empty array', () => {
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />);
    const table = shallowWrapper.dive();
    const instance = table.instance();
    instance.filterUpdate(0, ['Joe James'], 'Name', 'dropdown');
    table.update();

    let state = table.state();
    assert.deepEqual(state.filterList, [['Joe James'], [], [], [], []]);

    instance.filterUpdate(0, [], 'Name', 'dropdown');
    table.update();

    state = table.state();
    assert.deepEqual(state.filterList, [[], [], [], [], []]);
  });

  it('should properly reset internal filterList when calling resetFilters method', () => {
    // set a filter
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />);
    const table = shallowWrapper.dive();
    const instance = table.instance();
    instance.filterUpdate(0, 'Joe James', 'Name', 'checkbox');
    table.update();

    // now remove it
    let state = table.state();
    assert.deepEqual(state.filterList, [['Joe James'], [], [], [], []]);

    instance.resetFilters();
    table.update();
    state = table.state();
    assert.deepEqual(state.filterList, [[], [], [], [], []]);
  });

  it('should have the proper column name in onFilterChange when applying filters', () => {
    let changedColumn;
    const options = {
      onFilterChange: column => (changedColumn = column),
    };

    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options} />);
    const table = shallowWrapper.dive();
    const instance = table.instance();

    // test checkbox filter
    instance.filterUpdate(0, 'Joe James', 'Name', 'checkbox');
    table.update();
    assert.strictEqual(changedColumn, 'Name');

    // test dropdown filter
    instance.filterUpdate(0, ['Test Corp'], 'Company', 'dropdown');
    table.update();
    assert.strictEqual(changedColumn, 'Company');

    // test textField filter
    instance.filterUpdate(0, 'Joe James', 'Name', 'textField');
    table.update();
    assert.strictEqual(changedColumn, 'Name');

    // test multiselect filter
    instance.filterUpdate(0, 'Test Corp', 'Company', 'multiselect');
    table.update();
    assert.strictEqual(changedColumn, 'Company');

    // test reset filters
    instance.resetFilters();
    table.update();
    assert.strictEqual(changedColumn, null);
  });

  it('should have the proper type in onFilterChange when calling resetFilters method', () => {
    let type;
    const options = {
      onFilterChange: (changedColumn, filterList, changeType) => (type = changeType),
    };

    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options} />);
    const table = shallowWrapper.dive();
    const instance = table.instance();

    instance.resetFilters();
    table.update();
    assert.strictEqual(type, 'reset');
  });

  it('should render a footer after the tbody element when customTableBodyFooterRender is called', () => {
    const options = {};

    const mountWrapper = mount(<MUIDataTable columns={columns} data={data} options={options} />);
    const actualResult = mountWrapper.find('#custom_column_footer');
    assert.strictEqual(actualResult.exists(), false);

    mountWrapper.unmount();
  });

  it('should properly set searchText when calling searchTextUpdate method', () => {
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />);
    const table = shallowWrapper.dive();
    const instance = table.instance();

    instance.searchTextUpdate('Joe');
    table.update();
    const state = table.state();

    const expectedResult = JSON.stringify([
      { data: ['James, Joe', 'Test Corp', renderCities('Yonkers', { rowIndex: 0 }), 'NY', undefined], dataIndex: 0 },
    ]);

    assert.deepEqual(JSON.stringify(state.displayData), expectedResult);
  });

  it('should properly set searchText when hiding the search bar', () => {
    const options = {
      rowsPerPage: 1,
      textLabels: getTextLabels(),
    };
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />);
    const table = shallowWrapper.dive();
    const instance = table.instance();
    const shallowWrapperTableToolbar = shallow(
      <TableToolbar
        options={options}
        searchTextUpdate={spy()}
        searchClose={instance.searchClose}
        columns={columns}
        data={data}
        setTableAction={spy()}
      />,
    );
    const instanceTableToolbar = shallowWrapperTableToolbar.dive().instance();

    instance.searchTextUpdate('Joe');
    table.update();
    instanceTableToolbar.searchButton = { focus: () => {} };
    instanceTableToolbar.hideSearch();
    table.update();
    const searchText = table.state().searchText;

    assert.strictEqual(searchText, null);
  });

  it('should not change page when hiding the search bar', () => {
    const options = {
      rowsPerPage: 1,
      textLabels: getTextLabels(),
    };
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options} />);
    const table = shallowWrapper.dive();
    const instance = table.instance();
    const shallowWrapperTableToolbar = shallow(
      <TableToolbar
        options={options}
        searchTextUpdate={spy()}
        searchClose={instance.searchClose}
        columns={columns}
        data={data}
        setTableAction={spy()}
      />,
    );
    const instanceTableToolbar = shallowWrapperTableToolbar.dive().instance();

    // Simulate a search that has multiple pages of results
    instanceTableToolbar.setActiveIcon('search');
    instanceTableToolbar.searchButton = { focus: () => {} };
    instance.searchTextUpdate('j');
    table.update();

    // Simulate changing the page and then hiding the search bar
    instance.changePage(1);
    instanceTableToolbar.hideSearch();
    table.update();

    const page = table.state().page;
    assert.strictEqual(page, 1);
  });

  it('should filter displayData when searchText is set', () => {
    const options = {
      searchText: 'Joe',
    };
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options} />);
    const state = shallowWrapper.dive().state();

    const expectedResult = JSON.stringify([
      { data: ['James, Joe', 'Test Corp', renderCities('Yonkers', { rowIndex: 0 }), 'NY', undefined], dataIndex: 0 },
    ]);

    assert.deepEqual(JSON.stringify(state.displayData), expectedResult);
  });

  it('should sort provided column with defined data, in ascending order when calling toggleSortColum method for the first time', () => {
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />).dive();
    const instance = shallowWrapper.instance();

    instance.toggleSortColumn(0);
    shallowWrapper.update();
    const state = shallowWrapper.state();

    const expectedResult = JSON.stringify([
      { data: ['Herm, Bob', 'Test Corp', renderCities('Tampa', { rowIndex: 0 }), 'FL', undefined], dataIndex: 2 },
      { data: ['Houston, James', 'Test Corp', renderCities('Dallas', { rowIndex: 1 }), 'TX', undefined], dataIndex: 3 },
      { data: ['James, Joe', 'Test Corp', renderCities('Yonkers', { rowIndex: 2 }), 'NY', undefined], dataIndex: 0 },
      { data: ['Walsh, John', 'Test Corp', renderCities('Hartford', { rowIndex: 3 }), null, undefined], dataIndex: 1 },
    ]);

    assert.deepEqual(JSON.stringify(state.displayData), expectedResult);
  });

  it('should sort provided column with undefined data as though it were an empty string, in ascending order when calling toggleSortColum method for the first time', () => {
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />).dive();
    const instance = shallowWrapper.instance();

    instance.toggleSortColumn(4);
    shallowWrapper.update();
    const state = shallowWrapper.state();

    const expectedResult = JSON.stringify([
      { data: ['James, Joe', 'Test Corp', renderCities('Yonkers', { rowIndex: 0 }), 'NY', undefined], dataIndex: 0 },
      { data: ['Walsh, John', 'Test Corp', renderCities('Hartford', { rowIndex: 1 }), null, undefined], dataIndex: 1 },
      { data: ['Herm, Bob', 'Test Corp', renderCities('Tampa', { rowIndex: 2 }), 'FL', undefined], dataIndex: 2 },
      { data: ['Houston, James', 'Test Corp', renderCities('Dallas', { rowIndex: 3 }), 'TX', undefined], dataIndex: 3 },
    ]);

    assert.deepEqual(JSON.stringify(state.displayData), expectedResult);
  });

  it('should sort provided column in descending order when calling toggleSortColum method twice', () => {
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />).dive();
    const instance = shallowWrapper.instance();

    instance.toggleSortColumn(0);
    instance.toggleSortColumn(0);
    shallowWrapper.update();
    const state = shallowWrapper.state();

    const expectedResult = JSON.stringify([
      { data: ['Walsh, John', 'Test Corp', renderCities('Hartford', { rowIndex: 0 }), null, undefined], dataIndex: 1 },
      { data: ['James, Joe', 'Test Corp', renderCities('Yonkers', { rowIndex: 1 }), 'NY', undefined], dataIndex: 0 },
      { data: ['Houston, James', 'Test Corp', renderCities('Dallas', { rowIndex: 2 }), 'TX', undefined], dataIndex: 3 },
      { data: ['Herm, Bob', 'Test Corp', renderCities('Tampa', { rowIndex: 3 }), 'FL', undefined], dataIndex: 2 },
    ]);

    assert.deepEqual(JSON.stringify(state.displayData), expectedResult);
  });

  it('should sort provided column with custom column sort function (sort by name length) in descending order', () => {
    columns[0].options.sortCompare = order => ({ data: val1 }, { data: val2 }) =>
      (val1.length - val2.length) * (order === 'asc' ? -1 : 1);
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />).dive();
    const instance = shallowWrapper.instance();

    instance.toggleSortColumn(0);
    shallowWrapper.update();
    const state = shallowWrapper.state();

    const expectedResult = JSON.stringify([
      { data: ['Houston, James', 'Test Corp', renderCities('Dallas', { rowIndex: 0 }), 'TX', undefined], dataIndex: 3 },
      { data: ['Walsh, John', 'Test Corp', renderCities('Hartford', { rowIndex: 1 }), null, undefined], dataIndex: 1 },
      { data: ['James, Joe', 'Test Corp', renderCities('Yonkers', { rowIndex: 2 }), 'NY', undefined], dataIndex: 0 },
      { data: ['Herm, Bob', 'Test Corp', renderCities('Tampa', { rowIndex: 3 }), 'FL', undefined], dataIndex: 2 },
    ]);

    assert.deepEqual(JSON.stringify(state.displayData), expectedResult);

    columns[0].options.sortCompare = null;
  });

  it('should toggle provided column when calling toggleViewCol method', () => {
    const options = {
      onViewColumnsChange: spy(),
    };
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options} />).dive();
    const instance = shallowWrapper.instance();

    instance.toggleViewColumn(0);
    shallowWrapper.update();
    const state = shallowWrapper.state();

    const expectedResult = [
      {
        name: 'Name',
        display: 'false',
        empty: false,
        print: true,
        sort: true,
        filter: true,
        label: 'Name',
        download: true,
        searchable: true,
        customBodyRender: renderName,
        viewColumns: true,
        sortCompare: null,
        sortThirdClickReset: false,
        sortDescFirst: false,
        customFilterListOptions: { render: renderCustomFilterList },
      },
      {
        name: 'Company',
        display: 'true',
        empty: false,
        print: true,
        sort: true,
        filter: true,
        label: 'Company',
        download: true,
        searchable: true,
        viewColumns: true,
        sortCompare: null,
        sortThirdClickReset: false,
        sortDescFirst: false,
      },
      {
        name: 'City',
        display: 'true',
        empty: false,
        print: true,
        sort: true,
        filter: true,
        filterType: 'textField',
        label: 'City Label',
        download: true,
        searchable: true,
        customBodyRender: renderCities,
        viewColumns: true,
        sortCompare: null,
        sortThirdClickReset: false,
        sortDescFirst: false,
      },
      {
        name: 'State',
        display: 'true',
        empty: false,
        print: true,
        sort: true,
        filter: true,
        filterType: 'multiselect',
        label: 'State',
        download: true,
        searchable: true,
        viewColumns: true,
        customBodyRender: renderState,
        customHeadRender: renderHead,
        sortCompare: null,
        sortThirdClickReset: false,
        sortDescFirst: false,
      },
      {
        name: 'Empty',
        display: 'true',
        empty: true,
        print: true,
        sort: true,
        filter: true,
        filterType: 'checkbox',
        label: 'Empty',
        download: true,
        searchable: true,
        viewColumns: true,
        sortCompare: null,
        sortThirdClickReset: false,
        sortDescFirst: false,
      },
    ];

    assert.deepEqual(state.columns, expectedResult);
    assert.strictEqual(options.onViewColumnsChange.callCount, 1);
  });

  it('should update columns when calling updateColumns method', () => {
    const options = {
      onViewColumnsChange: spy(),
    };
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options} />).dive();
    const instance = shallowWrapper.instance();

    const expectedResult = [
      {
        name: 'Name',
        display: 'false',
        empty: false,
        print: true,
        sort: true,
        filter: true,
        label: 'Name',
        download: true,
        searchable: true,
        customBodyRender: renderName,
        viewColumns: true,
        customFilterListOptions: { render: renderCustomFilterList },
      },
      {
        name: 'Company',
        display: 'false',
        empty: false,
        print: true,
        sort: true,
        filter: true,
        label: 'Company',
        download: true,
        searchable: true,
        viewColumns: true,
      },
      {
        name: 'City',
        display: 'true',
        empty: false,
        print: true,
        sort: true,
        filter: true,
        filterType: 'textField',
        label: 'City Label',
        download: true,
        searchable: true,
        customBodyRender: renderCities,
        viewColumns: true,
      },
      {
        name: 'State',
        display: 'true',
        empty: false,
        print: true,
        sort: true,
        filter: true,
        filterType: 'multiselect',
        label: 'State',
        download: true,
        searchable: true,
        viewColumns: true,
        customBodyRender: renderState,
        customHeadRender: renderHead,
      },
      {
        name: 'Empty',
        display: 'false',
        empty: true,
        print: true,
        sort: true,
        filter: true,
        filterType: 'checkbox',
        label: 'Empty',
        download: true,
        searchable: true,
        viewColumns: true,
      },
    ];

    instance.updateColumns(expectedResult);
    shallowWrapper.update();
    const state = shallowWrapper.state();

    assert.deepEqual(state.columns, expectedResult);
    assert.strictEqual(options.onViewColumnsChange.callCount, 1);
  });

  it('should get displayable data when calling getDisplayData method', () => {
    const wrapper = shallow(<MUIDataTable columns={columns} data={data} />);
    const shallowWrapper = wrapper.dive();
    const instance = shallowWrapper.instance();
    const state = shallowWrapper.state();

    const actualResult = instance.getDisplayData(columns, tableData, state.filterList, '', null, wrapper.props());
    assert.deepEqual(JSON.stringify(actualResult), displayData);
  });

  it('should update rowsPerPage when calling changeRowsPerPage method', () => {
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />).dive();
    const instance = shallowWrapper.instance();

    instance.changeRowsPerPage(10);
    shallowWrapper.update();

    const state = shallowWrapper.state();
    assert.deepEqual(state.rowsPerPage, 10);
  });

  it('should recalculate page when calling changeRowsPerPage method', () => {
    const mountWrapper = mount(
      shallow(
        <MUIDataTable
          columns={columns}
          data={data}
          options={{ rowsPerPageOptions: [2, 4, 10, 15, 100], rowsPerPage: 2 }}
        />,
      ).get(0),
    );
    const instance = mountWrapper.instance();

    instance.changePage(1);
    let state = mountWrapper.state();
    assert.equal(state.page, 1);

    instance.changeRowsPerPage(4);
    state = mountWrapper.state();
    assert.equal(state.page, 0);
  });

  it('should update page position when calling changePage method', () => {
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />).dive();
    const instance = shallowWrapper.instance();

    instance.changePage(2);
    shallowWrapper.update();

    const state = shallowWrapper.state();
    assert.deepEqual(state.page, 2);
  });

  it('should update selectedRows when calling selectRowUpdate method with type=head', () => {
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />).dive();
    const instance = shallowWrapper.instance();

    instance.selectRowUpdate('head', 0);
    shallowWrapper.update();

    const state = shallowWrapper.state();
    const expectedResult = [
      { index: 0, dataIndex: 0 },
      { index: 1, dataIndex: 1 },
      { index: 2, dataIndex: 2 },
      { index: 3, dataIndex: 3 },
    ];
    assert.deepEqual(state.selectedRows.data, expectedResult);
  });

  it('If selectableRows=single, only the last cell must be selected when calling selectRowUpdate method with type=cell.', () => {
    const options = { selectableRows: 'single' };
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options} />).dive();
    const instance = shallowWrapper.instance();

    instance.selectRowUpdate('cell', { index: 0, dataIndex: 0 });
    instance.selectRowUpdate('cell', { index: 1, dataIndex: 1 });
    shallowWrapper.update();

    const state = shallowWrapper.state();
    assert.deepEqual(state.selectedRows.data, [{ index: 1, dataIndex: 1 }]);
  });

  it('should allow multiple cells to be selected when selectableRows=multiple and selectRowUpdate method with type=cell.', () => {
    const options = { selectableRows: 'multiple' };
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options} />).dive();
    const instance = shallowWrapper.instance();

    instance.selectRowUpdate('cell', { index: 0, dataIndex: 0 });
    instance.selectRowUpdate('cell', { index: 1, dataIndex: 1 });
    shallowWrapper.update();

    const expectedResult = [
      { index: 0, dataIndex: 0 },
      { index: 1, dataIndex: 1 },
    ];
    const state = shallowWrapper.state();
    assert.deepEqual(state.selectedRows.data, expectedResult);
  });

  it('should update selectedRows when calling selectRowUpdate method with type=custom', () => {
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />).dive();
    const instance = shallowWrapper.instance();

    instance.selectRowUpdate('custom', [0, 3]);
    shallowWrapper.update();

    const state = shallowWrapper.state();
    const expectedResult = [
      { index: 0, dataIndex: 0 },
      { index: 3, dataIndex: 3 },
    ];

    assert.deepEqual(state.selectedRows.data, expectedResult);
  });

  it('should allow multiple cells to be selected when selectableRows=multiple and selectRowUpdate method with type=cell and there are adjacent rows.', () => {
    const options = { selectableRows: 'multiple' };
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options} />).dive();
    const instance = shallowWrapper.instance();

    instance.selectRowUpdate('cell', { index: 0, dataIndex: 0 }, [
      { index: 0, dataIndex: 0 },
      { index: 1, dataIndex: 1 },
    ]);
    shallowWrapper.update();

    const expectedResult = [
      { index: 0, dataIndex: 0 },
      { index: 1, dataIndex: 1 },
    ];
    const state = shallowWrapper.state();
    assert.deepEqual(state.selectedRows.data, expectedResult);
  });

  it('should allow multiple cells to be selected and then unselected when selectableRows=multiple and selectRowUpdate method with type=cell and there are adjacent rows.', () => {
    const options = { selectableRows: 'multiple' };
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options} />).dive();
    const instance = shallowWrapper.instance();

    instance.selectRowUpdate('cell', { index: 0, dataIndex: 0 }, [
      { index: 1, dataIndex: 1 },
      { index: 2, dataIndex: 2 },
    ]);
    instance.selectRowUpdate('cell', { index: 1, dataIndex: 1 }, [{ index: 0, dataIndex: 0 }]);
    shallowWrapper.update();

    const expectedResult = [{ index: 2, dataIndex: 2 }];
    const state = shallowWrapper.state();
    assert.deepEqual(state.selectedRows.data, expectedResult);
  });

  it('should not update selectedRows when using rowsSelected option with type=none', () => {
    const options = {
      selectableRows: 'none',
      rowsSelected: [0],
    };
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options} />).dive();
    const instance = shallowWrapper.instance();

    const state = shallowWrapper.state();
    const expectedResult = [];

    assert.deepEqual(state.selectedRows.data, expectedResult);
  });

  it('should update selectedRows when using rowsSelected option with type=single', () => {
    const options = {
      selectableRows: 'single',
      rowsSelected: [0],
    };
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options} />).dive();
    const instance = shallowWrapper.instance();

    const state = shallowWrapper.state();
    const expectedResult = [{ index: 0, dataIndex: 0 }];

    assert.deepEqual(state.selectedRows.data, expectedResult);
  });

  it('should update selectedRows when using rowsSelected option with type=multiple', () => {
    const options = {
      selectableRows: 'multiple',
      rowsSelected: [0, 3],
    };
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options} />).dive();
    const instance = shallowWrapper.instance();

    const state = shallowWrapper.state();
    const expectedResult = [
      { index: 0, dataIndex: 0 },
      { index: 3, dataIndex: 3 },
    ];

    assert.deepEqual(state.selectedRows.data, expectedResult);
  });

  it('should update selectedRows (with default type=multiple option) when using rowsSelected with no option specified', () => {
    const options = {
      rowsSelected: [0, 3],
    };
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options} />).dive();
    const instance = shallowWrapper.instance();

    const state = shallowWrapper.state();
    const expectedResult = [
      { index: 0, dataIndex: 0 },
      { index: 3, dataIndex: 3 },
    ];

    assert.deepEqual(state.selectedRows.data, expectedResult);
  });

  it('should update expandedRows when using expandableRows option with default rowsExpanded', () => {
    const options = {
      expandableRows: true,
      rowsExpanded: [0, 3],
      renderExpandableRow: () => (
        <tr>
          <td>opened</td>
        </tr>
      ),
    };
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options} />).dive();
    const instance = shallowWrapper.instance();

    const state = shallowWrapper.state();
    const expectedResult = [
      { index: 0, dataIndex: 0 },
      { index: 3, dataIndex: 3 },
    ];

    assert.deepEqual(state.expandedRows.data, expectedResult);
  });

  it('should expand all rows when toggleAllExpandableRows is called', () => {
    const options = {
      expandableRows: true,
      rowsExpanded: [],
      renderExpandableRow: () => (
        <tr>
          <td>opened</td>
        </tr>
      ),
    };
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options} />).dive();
    const instance = shallowWrapper.instance();

    instance.toggleAllExpandableRows();

    const state = shallowWrapper.state();

    const expectedResult = [
      { index: 0, dataIndex: 0 },
      { index: 1, dataIndex: 1 },
      { index: 2, dataIndex: 2 },
      { index: 3, dataIndex: 3 },
    ];

    assert.deepEqual(state.expandedRows.data, expectedResult);

    assert.equal(instance.areAllRowsExpanded(), true);

    // collapse
    instance.toggleAllExpandableRows();
    const state2 = shallowWrapper.state();
    assert.deepEqual(state2.expandedRows.data, []);
  });

  it('should call onColumnOrderChange when updateColumnOrder is called', () => {
    const options = {
      onColumnOrderChange: spy(),
    };
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options} />).dive();
    const instance = shallowWrapper.instance();

    instance.updateColumnOrder();

    assert.deepEqual(options.onColumnOrderChange.callCount, 1);
  });

  it('should correctly call consoleWarnings', () => {
    const options = {
      consoleWarnings: spy(),
      responsive: 'scroll',
      selectableRows: true,
      onRowsSelect: () => {},
      onRowsExpand: () => {},
      fixedHeaderOptions: {},
      serverSideFilterList: [1],
      selectToolbarPlacement: 'topoftheworld',
      disableToolbarSelect: true,
    };
    let newCols = columns.slice();
    newCols[0] = Object.assign({}, newCols[0]);
    newCols[0].options = Object.assign({}, newCols[0].options);
    newCols[0].options.sortDirection = 'asc';
    newCols[0].options.filterOptions = [];
    newCols[0].options.customFilterListRender = () => {};

    const shallowWrapper = shallow(<MUIDataTable columns={newCols} data={data} options={options} />).dive();
    const instance = shallowWrapper.instance();

    assert.strictEqual(options.consoleWarnings.callCount, 11);

    let warnCallback = spy();
    let oldResponsiveOptions = [
      'scrollMaxHeight',
      'scrollFullHeight',
      'scrollFullHeightFullWidth',
      'stacked',
      'stackedFullWidth',
      'invalid_option',
    ];

    oldResponsiveOptions.forEach(responsive => {
      const options2 = {
        responsive,
        consoleWarnings: warnCallback,
      };
      const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options2} />).dive();
      const instance = shallowWrapper.instance();
    });

    const options3 = {
      consoleWarnings: false,
    };
    const shallowWrapper3 = shallow(<MUIDataTable columns={columns} data={data} options={options3} />).dive();
    const instance3 = shallowWrapper3.instance();

    assert.strictEqual(warnCallback.callCount, 6);
  });

  it('should remove selected data on selectRowDelete when type=cell', () => {
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />).dive();
    const instance = shallowWrapper.instance();
    const onRowsDelete = () => {};
    const selectedRows = { data: [1] };

    instance.selectRowUpdate('cell', { index: 0, dataIndex: 0 });
    shallowWrapper.update();
    instance.selectRowDelete();
    shallowWrapper.update();

    const newDisplayData = shallowWrapper.state().displayData;
    const expectedResult = JSON.stringify([
      { data: ['Walsh, John', 'Test Corp', renderCities('Hartford', { rowIndex: 0 }), null, undefined], dataIndex: 1 },
      { data: ['Herm, Bob', 'Test Corp', renderCities('Tampa', { rowIndex: 1 }), 'FL', undefined], dataIndex: 2 },
      { data: ['Houston, James', 'Test Corp', renderCities('Dallas', { rowIndex: 2 }), 'TX', undefined], dataIndex: 3 },
    ]);

    assert.deepEqual(JSON.stringify(newDisplayData), expectedResult);
  });

  it('should call onRowExpansionChange when row is expanded or collapsed', () => {
    const options = {
      expandableRows: true,
      renderExpandableRow: () => (
        <tr>
          <td>foo</td>
        </tr>
      ),
      expandableRowsOnClick: true,
      onRowExpansionChange: spy(),
    };
    const mountWrapper = mount(<MUIDataTable columns={columns} data={data} options={options} tableId={tableId} />);

    mountWrapper
      .find(`#MUIDataTableBodyRow-${tableId}-2`)
      .first()
      .simulate('click');

    assert.strictEqual(options.onRowExpansionChange.callCount, 1);
    assert(options.onRowExpansionChange.calledWith([{ index: 2, dataIndex: 2 }], [{ index: 2, dataIndex: 2 }]));

    mountWrapper
      .find(`#MUIDataTableBodyRow-${tableId}-2`)
      .first()
      .simulate('click');

    assert.strictEqual(options.onRowExpansionChange.callCount, 2);
    assert(options.onRowExpansionChange.calledWith([{ index: 2, dataIndex: 2 }], []));
  });

  it('should call onRowSelectionChange when row is selected or unselected', () => {
    const options = {
      selectableRows: 'multiple',
      selectableRowsOnClick: true,
      onRowSelectionChange: spy(),
    };
    const mountWrapper = mount(<MUIDataTable columns={columns} data={data} options={options} tableId={tableId} />);

    mountWrapper
      .find(`#MUIDataTableBodyRow-${tableId}-2`)
      .first()
      .simulate('click');

    assert.strictEqual(options.onRowSelectionChange.callCount, 1);
    assert(options.onRowSelectionChange.calledWith([{ index: 2, dataIndex: 2 }], [{ index: 2, dataIndex: 2 }]));

    mountWrapper
      .find(`#MUIDataTableBodyRow-${tableId}-2`)
      .first()
      .simulate('click');

    assert.strictEqual(options.onRowSelectionChange.callCount, 2);
    assert(options.onRowSelectionChange.calledWith([{ index: 2, dataIndex: 2 }], []));
  });

  it('should not remove selected data on selectRowDelete when type=cell when onRowsDelete returns false', () => {
    const options = {
      onRowsDelete: () => false,
    };
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options} />).dive();
    const instance = shallowWrapper.instance();
    const selectedRows = { data: [1] };

    instance.selectRowUpdate('cell', { index: 0, dataIndex: 0 });
    shallowWrapper.update();
    instance.selectRowDelete();
    shallowWrapper.update();

    const myDisplayData = shallowWrapper.state().displayData;

    assert.deepEqual(JSON.stringify(myDisplayData), displayData);
  });

  it('should update value when calling updateValue method in customBodyRender', () => {
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />).dive();
    const instance = shallowWrapper.instance();

    instance.updateDataCol(0, 2, 'Las Vegas');
    shallowWrapper.update();

    const state = shallowWrapper.state();
    assert.deepEqual(state.data[0].data[2], 'Las Vegas');
  });

  it('should call onTableInit when MUIDataTable is initialized', () => {
    const options = { selectableRows: 'multiple', onTableInit: spy() };
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options} />).dive();
    const instance = shallowWrapper.instance();

    assert.strictEqual(options.onTableInit.callCount, 1);
  });

  it('should call onTableInit only 1 time when creating table and calling selectRowUpdate method with type=head', () => {
    const options = { selectableRows: 'multiple', onTableInit: spy() };
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options} />).dive();
    const instance = shallowWrapper.instance();

    instance.selectRowUpdate('head', 0);
    shallowWrapper.update();

    assert.strictEqual(options.onTableInit.callCount, 1);
  });

  it('should call onTableChange when calling selectRowUpdate method with type=head', () => {
    const options = { selectableRows: 'multiple', onTableChange: spy() };
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options} />).dive();
    const instance = shallowWrapper.instance();

    instance.selectRowUpdate('head', 0);
    shallowWrapper.update();

    const state = shallowWrapper.state();
    const expectedResult = [
      { index: 0, dataIndex: 0 },
      { index: 1, dataIndex: 1 },
      { index: 2, dataIndex: 2 },
      { index: 3, dataIndex: 3 },
    ];
    assert.deepEqual(state.selectedRows.data, expectedResult);
    assert.strictEqual(options.onTableChange.callCount, 1);
  });

  it('should call onTableChange when calling selectRowUpdate method with type=cell', () => {
    const options = { selectableRows: 'multiple', onTableChange: spy() };

    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options} />).dive();
    const instance = shallowWrapper.instance();

    instance.selectRowUpdate('cell', 0);
    shallowWrapper.update();

    const state = shallowWrapper.state();
    assert.deepEqual(state.selectedRows.data, [0]);
    assert.strictEqual(options.onTableChange.callCount, 1);
  });

  it('should call onTableChange when calling selectRowUpdate method with type=custom', () => {
    const options = { selectableRows: 'multiple', onTableChange: spy() };
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options} />).dive();
    const instance = shallowWrapper.instance();

    instance.selectRowUpdate('custom', [0, 3]);
    shallowWrapper.update();

    const state = shallowWrapper.state();
    const expectedResult = [
      { index: 0, dataIndex: 0 },
      { index: 3, dataIndex: 3 },
    ];

    assert.deepEqual(state.selectedRows.data, expectedResult);
    assert.strictEqual(options.onTableChange.callCount, 1);
  });

  it('should render only things that match a filter', () => {
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />);
    const table = shallowWrapper.dive();
    const instance = table.instance();
    instance.filterUpdate(0, 'James, Joe', 'Name', 'checkbox');
    table.update();
    const state = table.state();

    const expectedResult = JSON.stringify([
      { data: ['James, Joe', 'Test Corp', renderCities('Yonkers', { rowIndex: 0 }), 'NY', undefined], dataIndex: 0 },
    ]);

    assert.deepEqual(JSON.stringify(state.displayData), expectedResult);
  });

  it('should render all things that match a text field filter', () => {
    const options = { filterType: 'textField' };
    columns[0].options.filterType = 'textField';
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options} />);
    const table = shallowWrapper.dive();
    const instance = table.instance();
    instance.filterUpdate(0, 'James', 'Name', 'textField');
    table.update();
    const state = table.state();

    const expectedResult = JSON.stringify([
      { data: ['James, Joe', 'Test Corp', renderCities('Yonkers', { rowIndex: 0 }), 'NY', undefined], dataIndex: 0 },
      { data: ['Houston, James', 'Test Corp', renderCities('Dallas', { rowIndex: 3 }), 'TX', undefined], dataIndex: 3 },
    ]);

    assert.deepEqual(JSON.stringify(state.displayData), expectedResult);
  });

  it('should skip client side filtering if server side filtering is enabled', () => {
    const options = { filterType: 'textField', serverSide: true };
    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options} />);
    const table = shallowWrapper.dive();
    const instance = table.instance();
    instance.filterUpdate(0, ['Joe James'], 'Name', 'dropdown');
    table.update();
    const state = table.state();

    assert.equal(state.displayData.length, data.length);
  });

  it('should correctly build internal tableProps when setTableProps passed in options', () => {
    const options = {
      setTableProps: () => ({
        className: 'foo bar',
        title: 'baz',
      }),
    };

    const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options} />);
    const instance = shallowWrapper.dive().instance();
    const expectedProps = {
      className: `${instance.props.classes.tableRoot} foo bar`,
      title: 'baz',
    };

    assert.deepEqual(instance.getTableProps(), expectedProps);
  });

  describe('should displayData consider filterOptions with logic', () => {
    it('with one column', () => {
      const customFilterColumns = columns.map(c => {
        if (c.name === 'Name')
          return {
            ...c,
            options: {
              ...c.options,
              filterOptions: {
                names: ['B', 'J'],
                logic(name, filters) {
                  const firstLetter = name[0];
                  return firstLetter !== filters[0];
                },
              },
            },
          };
        return c;
      });

      const shallowWrapper = shallow(<MUIDataTable columns={customFilterColumns} data={data} />);
      const table = shallowWrapper.dive();
      const instance = table.instance();
      instance.filterUpdate(0, 'J', 'checkbox');
      table.update();

      const state = table.state();
      assert.deepEqual(state.filterList, [['J'], [], [], [], []]);

      const expectedResult = JSON.stringify([
        { data: ['James, Joe', 'Test Corp', renderCities('Yonkers', { rowIndex: 0 }), 'NY', undefined], dataIndex: 0 },
      ]);
      assert.deepEqual(JSON.stringify(state.displayData), expectedResult);
    });

    it('operating as AND', () => {
      const customFilterColumns = columns.map(c => {
        if (c.name === 'Name')
          return {
            ...c,
            options: {
              ...c.options,
              filterOptions: {
                names: ['B', 'J', 'H'],
                logic(name, filters) {
                  const firstLetter = name[0];
                  return firstLetter !== filters[0];
                },
              },
            },
          };
        if (c.name === 'State')
          return {
            ...c,
            options: {
              ...c.options,
              filterOptions: {
                names: ['NY', 'FL', 'TX'],
              },
            },
          };
        return c;
      });

      const shallowWrapper = shallow(<MUIDataTable columns={customFilterColumns} data={data} />);
      const table = shallowWrapper.dive();
      const instance = table.instance();
      instance.filterUpdate(0, 'H', 'checkbox');
      instance.filterUpdate(3, 'TX', 'checkbox');
      table.update();

      const state = table.state();
      assert.deepEqual(state.filterList, [['H'], [], [], ['TX'], []]);

      const expectedResult = JSON.stringify([
        {
          data: ['Houston, James', 'Test Corp', renderCities('Dallas', { rowIndex: 3 }), 'TX', undefined],
          dataIndex: 3,
        },
      ]);
      assert.deepEqual(JSON.stringify(state.displayData), expectedResult);
    });
  });

  describe('should correctly handle array data', () => {
    const columns = [
      {
        name: 'otherData',
        options: {
          filter: true,
        },
      },
      {
        name: 'array',
        options: {
          filter: true,
        },
      },
    ];
    const data = [
      ['other-data-1', ['a', 'b', 'c']],
      ['other-data-3', ['a']],
      ['other-data-2', ['a', 'b']],
      ['other-data-4', []],
    ];
    const options = {
      filter: true,
      filterType: 'dropdown',
      responsive: 'standard',
    };

    it('should correctly filter array data', () => {
      const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options} />);
      const table = shallowWrapper.dive();
      const instance = table.instance();
      instance.filterUpdate(1, ['b'], 'Name', 'dropdown');
      table.update();
      const { displayData } = table.state();

      const expectedResult = JSON.stringify([
        { data: ['other-data-1', ['a', 'b', 'c']], dataIndex: 0 },
        { data: ['other-data-2', ['a', 'b']], dataIndex: 2 },
      ]);
      assert.deepEqual(JSON.stringify(displayData), expectedResult);
    });
    it('should correctly extract array data for filterData', () => {
      const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options} />);
      const table = shallowWrapper.dive();
      const { filterData } = table.state();
      const expectedResult = JSON.stringify([
        ['other-data-1', 'other-data-2', 'other-data-3', 'other-data-4'],
        ['a', 'b', 'c'],
      ]);
      assert.deepEqual(JSON.stringify(filterData), expectedResult);
    });
  });

  describe('should correctly handle non-array data', () => {
    const columns = [
      {
        name: 'otherData',
        options: {
          filter: true,
        },
      },
      {
        name: 'non-array',
        options: {
          filter: true,
        },
      },
    ];
    const data = [
      ['other-data-1', 'a'],
      ['other-data-2', 'b'],
      ['other-data-3', 'c'],
      ['other-data-4', 'd'],
    ];
    const options = {
      filter: true,
      filterType: 'dropdown',
      responsive: 'standard',
    };

    it('should correctly filter data when no array data is present', () => {
      const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options} />);
      const table = shallowWrapper.dive();
      const instance = table.instance();
      instance.filterUpdate(1, ['b'], 'Name', 'dropdown');
      table.update();
      const { displayData } = table.state();

      const expectedResult = JSON.stringify([{ data: ['other-data-2', 'b'], dataIndex: 1 }]);
      assert.deepEqual(JSON.stringify(displayData), expectedResult);
    });
    it('should correctly extract filterData when no array data is present', () => {
      const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} options={options} />);
      const table = shallowWrapper.dive();
      const { filterData } = table.state();
      const expectedResult = JSON.stringify([
        ['other-data-1', 'other-data-2', 'other-data-3', 'other-data-4'],
        ['a', 'b', 'c', 'd'],
      ]);
      assert.deepEqual(JSON.stringify(filterData), expectedResult);
    });
  });

  it('should correctly filter data from filter popover menu', () => {
    let filteredData = [];
    const options = {
      filter: true,
      filterType: 'dropdown',
      onFilterChange: (column, filterList, type, index, displayData) => {
        filteredData = displayData;
      },
    };

    const fullWrapper = mount(<MUIDataTable columns={columns} data={data} options={options} />);

    fullWrapper
      .find('[data-testid="Filter Table-iconButton"]')
      .at(0)
      .simulate('click');

    fullWrapper
      .find('[data-testid="filtertextfield-Name"] input')
      .at(0)
      .simulate('change', { target: { value: 'James' } });

    fullWrapper.unmount();

    assert.strictEqual(filteredData.length, 2);
    assert.strictEqual(filteredData[0].data[0], 'James, Joe');
    assert.strictEqual(filteredData[1].data[0], 'Houston, James');
  });

  describe('should correctly run comparator function', () => {
    it('correctly compares two equal strings', () => {
      expect(getCollatorComparator()('testString', 'testString')).to.equal(0);
    });

    it('correctly compares two different strings', () => {
      expect(getCollatorComparator()('testStringA', 'testStringB')).to.equal(-1);
    });
  });

  it('should correctly execute customBodyRender methods based on filtering and data', () => {
    let filteredData = [];
    let customBodyRenderCb = spy();
    let customBodyRenderLiteCb = spy();
    let customBodyRenderNoFilterCb = spy();
    const options = {
      rowsPerPage: 5,
      rowsPerPageOptions: [5],
    };

    const data = [
      ['a', 'b'],
      ['a', 'b'],
      ['a', 'b'],
      ['a', 'b'],
      ['a', 'b'],

      ['a', 'b'],
      ['a', 'b'],
      ['a', 'b'],
      ['a', 'b'],
      ['a', 'b'],

      ['a', 'b'],
      ['a', 'b'],
      ['a', 'b'],
      ['a', 'b'],
      ['a', 'b'],
    ];

    const columns = [
      {
        name: 'firstName',
        label: 'First Name',
        options: {
          customBodyRender: () => {
            customBodyRenderCb();
            return '';
          },
        },
      },
      {
        name: 'lastName',
        label: 'Last Name',
        options: {
          customBodyRenderLite: () => {
            customBodyRenderLiteCb();
            return '';
          },
        },
      },
      {
        name: 'phone',
        label: 'Phone',
        options: {
          filter: false,
          customBodyRender: () => {
            customBodyRenderNoFilterCb();
            return '';
          },
        },
      },
    ];

    const fullWrapper = mount(<MUIDataTable columns={columns} data={data} options={options} />);
    fullWrapper.unmount();

    // lite only gets executed for the 5 entries shown
    assert.strictEqual(customBodyRenderLiteCb.callCount, 5);

    // regular gets executed 15 times for filtering, and 15 more times for display
    assert.strictEqual(customBodyRenderCb.callCount, 30);

    // regular with no filtering gets executed 15 times for display
    assert.strictEqual(customBodyRenderNoFilterCb.callCount, 15);
  });
});