@@ -13,16 +13,18 @@ describe('Table.Hover', () => {
1313 const createTable = ( props ?: TableProps ) => {
1414 const columns = [ { title : 'Name' , dataIndex : 'name' , key : 'name' } ] ;
1515
16- return < Table columns = { columns } data = { data } { ...props } /> ;
16+ return < Table columns = { columns } data = { data } colHoverable { ...props } /> ;
1717 } ;
1818
1919 it ( 'basic' , ( ) => {
2020 const wrapper = mount ( createTable ( ) ) ;
2121 wrapper . find ( 'tbody td' ) . first ( ) . simulate ( 'mouseEnter' ) ;
2222 expect ( wrapper . exists ( '.rc-table-cell-row-hover' ) ) . toBeTruthy ( ) ;
23+ expect ( wrapper . exists ( '.rc-table-cell-col-hover' ) ) . toBeTruthy ( ) ;
2324
2425 wrapper . find ( 'tbody td' ) . first ( ) . simulate ( 'mouseLeave' ) ;
2526 expect ( wrapper . exists ( '.rc-table-cell-row-hover' ) ) . toBeFalsy ( ) ;
27+ expect ( wrapper . exists ( '.rc-table-cell-col-hover' ) ) . toBeFalsy ( ) ;
2628 } ) ;
2729
2830 it ( 'works on shouldCellUpdate' , ( ) => {
@@ -34,9 +36,11 @@ describe('Table.Hover', () => {
3436
3537 wrapper . find ( 'tbody td' ) . first ( ) . simulate ( 'mouseEnter' ) ;
3638 expect ( wrapper . exists ( '.rc-table-cell-row-hover' ) ) . toBeTruthy ( ) ;
39+ expect ( wrapper . exists ( '.rc-table-cell-col-hover' ) ) . toBeTruthy ( ) ;
3740
3841 wrapper . find ( 'tbody td' ) . first ( ) . simulate ( 'mouseLeave' ) ;
3942 expect ( wrapper . exists ( '.rc-table-cell-row-hover' ) ) . toBeFalsy ( ) ;
43+ expect ( wrapper . exists ( '.rc-table-cell-col-hover' ) ) . toBeFalsy ( ) ;
4044 } ) ;
4145
4246 it ( 'warning if use `render` for rowSpan' , ( ) => {
@@ -151,7 +155,7 @@ describe('Table.Hover', () => {
151155 renderTimes = 0 ;
152156 wrapper . find ( 'tbody td' ) . at ( 0 ) . simulate ( 'mouseEnter' ) ;
153157 expect ( wrapper . find ( 'td.rc-table-cell-row-hover' ) ) . toHaveLength ( 1 ) ;
154- expect ( renderTimes ) . toBe ( 1 ) ;
158+ expect ( renderTimes ) . toBe ( 2 ) ;
155159
156160 // Hover 0-1
157161 renderTimes = 0 ;
@@ -163,7 +167,7 @@ describe('Table.Hover', () => {
163167 renderTimes = 0 ;
164168 wrapper . find ( 'tbody td' ) . at ( 1 ) . simulate ( 'mouseLeave' ) ;
165169 expect ( wrapper . exists ( '.rc-table-cell-row-hover' ) ) . toBeFalsy ( ) ;
166- expect ( renderTimes ) . toBe ( 1 ) ;
170+ expect ( renderTimes ) . toBe ( 2 ) ;
167171 } ) ;
168172
169173 it ( 'perf mode to save render times' , ( ) => {
@@ -204,7 +208,7 @@ describe('Table.Hover', () => {
204208 } ) ;
205209 } ) ;
206210
207- it ( 'perf' , ( ) => {
211+ it ( 'perf row ' , ( ) => {
208212 const renderTimes : Record < string , any > = { } ;
209213
210214 const TD = ( props : any ) => {
@@ -217,6 +221,7 @@ describe('Table.Hover', () => {
217221
218222 const wrapper = mount (
219223 createTable ( {
224+ colHoverable : false ,
220225 components : {
221226 body : {
222227 cell : TD ,
@@ -229,11 +234,52 @@ describe('Table.Hover', () => {
229234
230235 wrapper . find ( 'tbody td' ) . first ( ) . simulate ( 'mouseEnter' ) ;
231236 expect ( wrapper . exists ( '.rc-table-cell-row-hover' ) ) . toBeTruthy ( ) ;
237+ expect ( wrapper . exists ( '.rc-table-cell-col-hover' ) ) . toBeFalsy ( ) ;
232238
233239 wrapper . find ( 'tbody td' ) . first ( ) . simulate ( 'mouseLeave' ) ;
234240 expect ( wrapper . exists ( '.rc-table-cell-row-hover' ) ) . toBeFalsy ( ) ;
241+ expect ( wrapper . exists ( '.rc-table-cell-col-hover' ) ) . toBeFalsy ( ) ;
235242
236243 expect ( firstMountTimes ) . toEqual ( renderTimes . Jack ) ;
237244 expect ( renderTimes . Lucy ) . toBeGreaterThan ( renderTimes . Jack ) ;
238245 } ) ;
246+
247+ it ( 'perf col' , ( ) => {
248+ const renderTimes : Record < string , any > = { } ;
249+
250+ const TD = ( props : any ) => {
251+ const children = toArray ( props . children ) ;
252+ const first = children [ 0 ] as unknown as string ;
253+
254+ renderTimes [ first ] = ( renderTimes [ first ] || 0 ) + 1 ;
255+ return < td { ...props } /> ;
256+ } ;
257+
258+ const columns = [
259+ { title : 'index' , dataIndex : 'key' , key : 'key' } ,
260+ { title : 'Name' , dataIndex : 'name' , key : 'name' } ,
261+ ] ;
262+
263+ const wrapper = mount (
264+ createTable ( {
265+ columns,
266+ rowHoverable : false ,
267+ components : {
268+ body : {
269+ cell : TD ,
270+ } ,
271+ } ,
272+ } ) ,
273+ ) ;
274+
275+ wrapper . find ( 'tbody td' ) . at ( 1 ) . simulate ( 'mouseEnter' ) ;
276+ expect ( wrapper . exists ( '.rc-table-cell-row-hover' ) ) . toBeFalsy ( ) ;
277+ expect ( wrapper . exists ( '.rc-table-cell-col-hover' ) ) . toBeTruthy ( ) ;
278+
279+ wrapper . find ( 'tbody td' ) . at ( 1 ) . simulate ( 'mouseLeave' ) ;
280+ expect ( wrapper . exists ( '.rc-table-cell-row-hover' ) ) . toBeFalsy ( ) ;
281+ expect ( wrapper . exists ( '.rc-table-cell-col-hover' ) ) . toBeFalsy ( ) ;
282+
283+ expect ( renderTimes . Lucy ) . toEqual ( renderTimes . Jack ) ;
284+ } ) ;
239285} ) ;
0 commit comments