@@ -260,7 +260,6 @@ describe('Table.tsx', () => {
260
260
const { getByTestId } = render ( < XTable model = { tableProps } /> )
261
261
expect ( getByTestId ( name ) . style . height ) . toBe ( '290px' )
262
262
} )
263
-
264
263
} )
265
264
266
265
describe ( 'Wave calls' , ( ) => {
@@ -366,6 +365,71 @@ describe('Table.tsx', () => {
366
365
expect ( wave . args [ name ] ) . toMatchObject ( [ 'rowname2' ] )
367
366
} )
368
367
368
+ it ( 'Updates single selection' , ( ) => {
369
+ const { getAllByRole, rerender } = render ( < XTable model = { { ...tableProps , single : true } } /> )
370
+ const radioButtons = getAllByRole ( 'radio' )
371
+
372
+ rerender ( < XTable model = { { ...tableProps , single : true , value : 'rowname1' } } /> )
373
+
374
+ expect ( radioButtons [ 0 ] . firstChild ) . toHaveClass ( 'is-checked' )
375
+ expect ( wave . args [ name ] ) . toMatchObject ( [ 'rowname1' ] )
376
+ } )
377
+
378
+ it ( 'Updates multiple selection' , ( ) => {
379
+ const { getAllByRole, rerender } = render ( < XTable model = { { ...tableProps , multiple : true } } /> )
380
+ const checkboxes = getAllByRole ( 'checkbox' )
381
+
382
+ rerender ( < XTable model = { { ...tableProps , multiple : true , values : [ 'rowname1' , 'rowname2' ] } } /> )
383
+
384
+ expect ( checkboxes [ 1 ] . firstChild ) . toHaveClass ( 'is-checked' )
385
+ expect ( checkboxes [ 2 ] . firstChild ) . toHaveClass ( 'is-checked' )
386
+ expect ( wave . args [ name ] ) . toMatchObject ( [ 'rowname1' , 'rowname2' ] )
387
+ } )
388
+
389
+ it ( 'Clears single selection' , ( ) => {
390
+ const { getAllByRole, rerender } = render ( < XTable model = { { ...tableProps , single : true , value : 'rowname1' } } /> )
391
+ const radioButtons = getAllByRole ( 'radio' )
392
+
393
+ expect ( radioButtons [ 0 ] . firstChild ) . toHaveClass ( 'is-checked' )
394
+ expect ( wave . args [ name ] ) . toMatchObject ( [ 'rowname1' ] )
395
+
396
+ rerender ( < XTable model = { { ...tableProps , single : true , value : undefined } } /> )
397
+
398
+ expect ( radioButtons [ 0 ] . firstChild ) . not . toHaveClass ( 'is-checked' )
399
+ expect ( wave . args [ name ] ) . toMatchObject ( [ ] )
400
+ } )
401
+
402
+ it ( 'Clears multiple selection' , ( ) => {
403
+ const { getAllByRole, rerender } = render ( < XTable model = { { ...tableProps , multiple : true , values : [ 'rowname1' , 'rowname2' ] } } /> )
404
+ const checkBoxes = getAllByRole ( 'checkbox' )
405
+
406
+ expect ( checkBoxes [ 1 ] . firstChild ) . toHaveClass ( 'is-checked' )
407
+ expect ( checkBoxes [ 2 ] . firstChild ) . toHaveClass ( 'is-checked' )
408
+ expect ( wave . args [ name ] ) . toMatchObject ( [ 'rowname1' , 'rowname2' ] )
409
+
410
+ rerender ( < XTable model = { { ...tableProps , multiple : true , values : [ ] } } /> )
411
+
412
+ expect ( checkBoxes [ 1 ] . firstChild ) . not . toHaveClass ( 'is-checked' )
413
+ expect ( checkBoxes [ 2 ] . firstChild ) . not . toHaveClass ( 'is-checked' )
414
+ expect ( wave . args [ name ] ) . toMatchObject ( [ ] )
415
+ } )
416
+
417
+ it ( 'Does not fire event on single selection update' , ( ) => {
418
+ const { rerender } = render ( < XTable model = { { ...tableProps , single : true , events : [ 'select' ] } } /> )
419
+
420
+ rerender ( < XTable model = { { ...tableProps , single : true , events : [ 'select' ] , value : 'rowname1' , } } /> )
421
+
422
+ expect ( emitMock ) . toHaveBeenCalledTimes ( 0 )
423
+ } )
424
+
425
+ it ( 'Does not fire event on multiple selection update' , ( ) => {
426
+ const { rerender } = render ( < XTable model = { { ...tableProps , multiple : true , events : [ 'select' ] } } /> )
427
+
428
+ rerender ( < XTable model = { { ...tableProps , multiple : true , events : [ 'select' ] , values : [ 'rowname1' , 'rowname2' ] } } /> )
429
+
430
+ expect ( emitMock ) . toHaveBeenCalledTimes ( 0 )
431
+ } )
432
+
369
433
it ( 'Fires event - multiple selection - select single' , ( ) => {
370
434
const { getAllByRole } = render ( < XTable model = { { ...tableProps , multiple : true , events : [ 'select' ] } } /> )
371
435
const checkboxes = getAllByRole ( 'checkbox' )
@@ -1689,7 +1753,7 @@ describe('Table.tsx', () => {
1689
1753
1690
1754
//collapse all groups
1691
1755
fireEvent . click ( container . querySelector ( '.ms-DetailsHeader-collapseButton' ) ! )
1692
- expect ( emitMock ) . toHaveBeenCalledWith ( tableProps . name , 'group_change' , [ cell21 , cell11 , cell31 ] )
1756
+ expect ( emitMock ) . toHaveBeenCalledWith ( tableProps . name , 'group_change' , [ cell21 , cell11 , cell31 ] )
1693
1757
} )
1694
1758
1695
1759
it ( 'Expands all group by list - fire event' , ( ) => {
@@ -1700,8 +1764,8 @@ describe('Table.tsx', () => {
1700
1764
1701
1765
//open all groups
1702
1766
fireEvent . click ( container . querySelector ( '.ms-DetailsHeader-collapseButton' ) ! )
1703
- expect ( emitMock ) . toHaveBeenCalledWith ( tableProps . name , 'group_change' , [ cell21 , cell11 , cell31 ] )
1704
- } )
1767
+ expect ( emitMock ) . toHaveBeenCalledWith ( tableProps . name , 'group_change' , [ cell21 , cell11 , cell31 ] )
1768
+ } )
1705
1769
1706
1770
it ( 'Collapses group by list - fire event' , ( ) => {
1707
1771
const { container, getAllByText, getByTestId } = render ( < XTable model = { { ...tableProps , events : [ 'group_change' ] } } /> )
@@ -1715,9 +1779,9 @@ describe('Table.tsx', () => {
1715
1779
1716
1780
//collapse 1st group
1717
1781
fireEvent . click ( container . querySelector ( '.ms-GroupHeader-expand' ) ! )
1718
- expect ( emitMock ) . toHaveBeenCalledWith ( tableProps . name , 'group_change' , [ cell21 ] )
1782
+ expect ( emitMock ) . toHaveBeenCalledWith ( tableProps . name , 'group_change' , [ cell21 ] )
1719
1783
} )
1720
-
1784
+
1721
1785
it ( 'Expands group by list - fire event' , ( ) => {
1722
1786
const { container, getAllByText, getByTestId } = render ( < XTable model = { { ...tableProps , events : [ 'group_change' ] } } /> )
1723
1787
@@ -1726,8 +1790,8 @@ describe('Table.tsx', () => {
1726
1790
1727
1791
//open 1st group
1728
1792
fireEvent . click ( container . querySelector ( '.ms-GroupHeader-expand' ) ! )
1729
- expect ( emitMock ) . toHaveBeenCalledWith ( tableProps . name , 'group_change' , [ cell21 ] )
1730
- } )
1793
+ expect ( emitMock ) . toHaveBeenCalledWith ( tableProps . name , 'group_change' , [ cell21 ] )
1794
+ } )
1731
1795
} )
1732
1796
1733
1797
describe ( 'Groups' , ( ) => {
@@ -1836,7 +1900,7 @@ describe('Table.tsx', () => {
1836
1900
//collapse all groups
1837
1901
fireEvent . click ( container . querySelector ( '.ms-DetailsHeader-collapseButton' ) ! )
1838
1902
expect ( emitMock ) . toHaveBeenCalledWith ( tableProps . name , 'group_change' , [ 'GroupA' , 'GroupB' ] )
1839
- expect ( emitMock ) . toHaveBeenCalledTimes ( 1 )
1903
+ expect ( emitMock ) . toHaveBeenCalledTimes ( 1 )
1840
1904
expect ( getAllByRole ( 'row' ) ) . toHaveLength ( headerRow + groupHeaderRowsCount )
1841
1905
} )
1842
1906
@@ -1850,7 +1914,7 @@ describe('Table.tsx', () => {
1850
1914
//open all groups
1851
1915
fireEvent . click ( container . querySelector ( '.ms-DetailsHeader-collapseButton' ) ! )
1852
1916
expect ( emitMock ) . toHaveBeenCalledWith ( tableProps . name , 'group_change' , [ 'GroupA' , 'GroupB' ] )
1853
- expect ( emitMock ) . toHaveBeenCalledTimes ( 1 )
1917
+ expect ( emitMock ) . toHaveBeenCalledTimes ( 1 )
1854
1918
expect ( getAllByRole ( 'row' ) ) . toHaveLength ( headerRow + groupHeaderRowsCount + items )
1855
1919
} )
1856
1920
@@ -1871,40 +1935,40 @@ describe('Table.tsx', () => {
1871
1935
1872
1936
fireEvent . click ( container . querySelector ( '.ms-GroupHeader-expand' ) ! )
1873
1937
expect ( emitMock ) . toHaveBeenCalledWith ( tableProps . name , 'group_change' , [ 'GroupA' ] )
1874
- expect ( emitMock ) . toHaveBeenCalledTimes ( 1 )
1938
+ expect ( emitMock ) . toHaveBeenCalledTimes ( 1 )
1875
1939
expect ( getAllByRole ( 'row' ) ) . toHaveLength ( headerRow + groupHeaderRowsCount + items - filteredItem )
1876
- } )
1940
+ } )
1877
1941
1878
1942
it ( 'Collapses all groups when some already collapsed - fire event' , ( ) => {
1879
1943
const { container, getAllByRole } = render ( < XTable model = { { ...tableProps , events : [ 'group_change' ] } } /> )
1880
1944
1881
1945
//collapse all groups
1882
1946
fireEvent . click ( container . querySelector ( '.ms-DetailsHeader-collapseButton' ) ! )
1883
1947
expect ( emitMock ) . toHaveBeenCalledWith ( tableProps . name , 'group_change' , [ 'GroupA' , 'GroupB' ] )
1884
- expect ( emitMock ) . toHaveBeenCalledTimes ( 1 )
1885
- expect ( getAllByRole ( 'row' ) ) . toHaveLength ( headerRow + groupHeaderRowsCount )
1948
+ expect ( emitMock ) . toHaveBeenCalledTimes ( 1 )
1949
+ expect ( getAllByRole ( 'row' ) ) . toHaveLength ( headerRow + groupHeaderRowsCount )
1886
1950
emitMock . mockClear ( )
1887
1951
1888
1952
//open all groups
1889
1953
fireEvent . click ( container . querySelector ( '.ms-DetailsHeader-collapseButton' ) ! )
1890
1954
expect ( emitMock ) . toHaveBeenCalledWith ( tableProps . name , 'group_change' , [ 'GroupA' , 'GroupB' ] )
1891
- expect ( emitMock ) . toHaveBeenCalledTimes ( 1 )
1892
- expect ( getAllByRole ( 'row' ) ) . toHaveLength ( headerRow + groupHeaderRowsCount + items )
1955
+ expect ( emitMock ) . toHaveBeenCalledTimes ( 1 )
1956
+ expect ( getAllByRole ( 'row' ) ) . toHaveLength ( headerRow + groupHeaderRowsCount + items )
1893
1957
emitMock . mockClear ( )
1894
1958
1895
1959
//collapse GroupA
1896
1960
fireEvent . click ( container . querySelector ( '.ms-GroupHeader-expand' ) ! )
1897
1961
expect ( emitMock ) . toHaveBeenCalledWith ( tableProps . name , 'group_change' , [ 'GroupA' ] )
1898
- expect ( emitMock ) . toHaveBeenCalledTimes ( 1 )
1962
+ expect ( emitMock ) . toHaveBeenCalledTimes ( 1 )
1899
1963
expect ( getAllByRole ( 'row' ) ) . toHaveLength ( headerRow + groupHeaderRowsCount + filteredItem )
1900
1964
emitMock . mockClear ( )
1901
1965
1902
1966
//collapse all groups
1903
1967
fireEvent . click ( container . querySelector ( '.ms-DetailsHeader-collapseButton' ) ! )
1904
1968
expect ( emitMock ) . toHaveBeenCalledWith ( tableProps . name , 'group_change' , [ 'GroupB' ] )
1905
- expect ( emitMock ) . toHaveBeenCalledTimes ( 1 )
1906
- expect ( getAllByRole ( 'row' ) ) . toHaveLength ( headerRow + groupHeaderRowsCount )
1907
- } )
1969
+ expect ( emitMock ) . toHaveBeenCalledTimes ( 1 )
1970
+ expect ( getAllByRole ( 'row' ) ) . toHaveLength ( headerRow + groupHeaderRowsCount )
1971
+ } )
1908
1972
1909
1973
it ( 'Checks if expanded state is preserved after sort' , ( ) => {
1910
1974
const { container, getAllByRole } = render ( < XTable model = { tableProps } /> )
0 commit comments