@@ -3809,6 +3809,57 @@ describe('TableView', function () {
3809
3809
expect ( within ( row ) . getAllByRole ( 'gridcell' ) ) . toHaveLength ( 5 ) ;
3810
3810
}
3811
3811
} ) ;
3812
+
3813
+ it ( 'should update the row widths when removing and adding columns' , function ( ) {
3814
+ function compareWidths ( row , b ) {
3815
+ let newWidth = row . childNodes [ 1 ] . style . width ;
3816
+ expect ( parseInt ( newWidth , 10 ) ) . toBeGreaterThan ( parseInt ( b , 10 ) ) ;
3817
+ return newWidth ;
3818
+ }
3819
+
3820
+ let tree = render ( < HidingColumns /> ) ;
3821
+ let table = tree . getByRole ( 'grid' ) ;
3822
+ let columns = within ( table ) . getAllByRole ( 'columnheader' ) ;
3823
+ expect ( columns ) . toHaveLength ( 6 ) ;
3824
+
3825
+ let rows = tree . getAllByRole ( 'row' ) ;
3826
+ let oldWidth = rows [ 1 ] . childNodes [ 1 ] . style . width ;
3827
+
3828
+ let audienceCheckbox = tree . getByLabelText ( 'Audience Type' ) ;
3829
+ let budgetCheckbox = tree . getByLabelText ( 'Net Budget' ) ;
3830
+ let targetCheckbox = tree . getByLabelText ( 'Target OTP' ) ;
3831
+ let reachCheckbox = tree . getByLabelText ( 'Reach' ) ;
3832
+
3833
+ userEvent . click ( audienceCheckbox ) ;
3834
+ expect ( audienceCheckbox . checked ) . toBe ( false ) ;
3835
+ act ( ( ) => jest . runAllTimers ( ) ) ;
3836
+ oldWidth = compareWidths ( rows [ 1 ] , oldWidth ) ;
3837
+
3838
+ userEvent . click ( budgetCheckbox ) ;
3839
+ expect ( budgetCheckbox . checked ) . toBe ( false ) ;
3840
+ act ( ( ) => jest . runAllTimers ( ) ) ;
3841
+ oldWidth = compareWidths ( rows [ 1 ] , oldWidth ) ;
3842
+
3843
+ userEvent . click ( targetCheckbox ) ;
3844
+ expect ( targetCheckbox . checked ) . toBe ( false ) ;
3845
+ act ( ( ) => jest . runAllTimers ( ) ) ;
3846
+ oldWidth = compareWidths ( rows [ 1 ] , oldWidth ) ;
3847
+
3848
+ // This previously failed, the first column wouldn't update its width
3849
+ // when the 2nd to last column was removed
3850
+ userEvent . click ( reachCheckbox ) ;
3851
+ expect ( reachCheckbox . checked ) . toBe ( false ) ;
3852
+ act ( ( ) => jest . runAllTimers ( ) ) ;
3853
+ oldWidth = compareWidths ( rows [ 1 ] , oldWidth ) ;
3854
+ columns = within ( table ) . getAllByRole ( 'columnheader' ) ;
3855
+ expect ( columns ) . toHaveLength ( 2 ) ;
3856
+
3857
+ // Readd the column and check that the width decreases
3858
+ userEvent . click ( audienceCheckbox ) ;
3859
+ expect ( audienceCheckbox . checked ) . toBe ( true ) ;
3860
+ act ( ( ) => jest . runAllTimers ( ) ) ;
3861
+ expect ( parseInt ( rows [ 1 ] . childNodes [ 1 ] . style . width , 10 ) ) . toBeLessThan ( parseInt ( oldWidth , 10 ) ) ;
3862
+ } ) ;
3812
3863
} ) ;
3813
3864
3814
3865
describe ( 'headerless columns' , function ( ) {
0 commit comments