@@ -3,8 +3,8 @@ import Overflow from '../src';
33import { mount } from './wrapper' ;
44
55interface ItemType {
6- label : string ;
7- key : number ;
6+ label : React . ReactNode ;
7+ key : React . Key ;
88}
99
1010function renderItem ( item : ItemType ) {
@@ -15,7 +15,7 @@ describe('Overflow', () => {
1515 function getData ( count : number ) {
1616 return new Array ( count ) . fill ( undefined ) . map ( ( _ , index ) => ( {
1717 label : `Label ${ index } ` ,
18- key : index ,
18+ key : `k- ${ index } ` ,
1919 } ) ) ;
2020 }
2121
@@ -41,16 +41,42 @@ describe('Overflow', () => {
4141 expect ( wrapper . findRest ( ) ) . toHaveLength ( 1 ) ;
4242 } ) ;
4343
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+
4449 it ( 'renderRest' , ( ) => {
4550 const wrapper = mount (
4651 < Overflow
4752 data = { getData ( 6 ) }
4853 renderItem = { renderItem }
49- renderRest = { ( omittedItems ) => `Bamboo: ${ omittedItems . length } ` }
54+ renderRest = { omittedItems => `Bamboo: ${ omittedItems . length } ` }
5055 maxCount = { 3 }
5156 /> ,
5257 ) ;
5358
5459 expect ( wrapper . findRest ( ) . text ( ) ) . toEqual ( 'Bamboo: 3' ) ;
5560 } ) ;
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+ } ) ;
5682} ) ;
0 commit comments