@@ -3,8 +3,8 @@ import Overflow from '../src';
3
3
import { mount } from './wrapper' ;
4
4
5
5
interface ItemType {
6
- label : string ;
7
- key : number ;
6
+ label : React . ReactNode ;
7
+ key : React . Key ;
8
8
}
9
9
10
10
function renderItem ( item : ItemType ) {
@@ -15,7 +15,7 @@ describe('Overflow', () => {
15
15
function getData ( count : number ) {
16
16
return new Array ( count ) . fill ( undefined ) . map ( ( _ , index ) => ( {
17
17
label : `Label ${ index } ` ,
18
- key : index ,
18
+ key : `k- ${ index } ` ,
19
19
} ) ) ;
20
20
}
21
21
@@ -41,16 +41,42 @@ describe('Overflow', () => {
41
41
expect ( wrapper . findRest ( ) ) . toHaveLength ( 1 ) ;
42
42
} ) ;
43
43
44
+ it ( 'without renderItem' , ( ) => {
45
+ const wrapper = mount ( < Overflow data = { [ < span > Bamboo Is Light</ span > ] } /> ) ;
46
+ expect ( wrapper . find ( 'Item' ) . text ( ) ) . toEqual ( 'Bamboo Is Light' ) ;
47
+ } ) ;
48
+
44
49
it ( 'renderRest' , ( ) => {
45
50
const wrapper = mount (
46
51
< Overflow
47
52
data = { getData ( 6 ) }
48
53
renderItem = { renderItem }
49
- renderRest = { ( omittedItems ) => `Bamboo: ${ omittedItems . length } ` }
54
+ renderRest = { omittedItems => `Bamboo: ${ omittedItems . length } ` }
50
55
maxCount = { 3 }
51
56
/> ,
52
57
) ;
53
58
54
59
expect ( wrapper . findRest ( ) . text ( ) ) . toEqual ( 'Bamboo: 3' ) ;
55
60
} ) ;
61
+
62
+ describe ( 'itemKey' , ( ) => {
63
+ it ( 'string' , ( ) => {
64
+ const wrapper = mount (
65
+ < Overflow data = { getData ( 1 ) } renderItem = { renderItem } itemKey = "key" /> ,
66
+ ) ;
67
+
68
+ expect ( wrapper . find ( 'Item' ) . key ( ) ) . toEqual ( 'k-0' ) ;
69
+ } ) ;
70
+ it ( 'function' , ( ) => {
71
+ const wrapper = mount (
72
+ < Overflow
73
+ data = { getData ( 1 ) }
74
+ renderItem = { renderItem }
75
+ itemKey = { item => `bamboo-${ item . key } ` }
76
+ /> ,
77
+ ) ;
78
+
79
+ expect ( wrapper . find ( 'Item' ) . key ( ) ) . toEqual ( 'bamboo-k-0' ) ;
80
+ } ) ;
81
+ } ) ;
56
82
} ) ;
0 commit comments