@@ -24,6 +24,7 @@ import {
24
24
} from '../../tests/helpers' ;
25
25
26
26
import states , { TestOption } from '../../tests/data' ;
27
+ import { TypeaheadState } from "../../types" ;
27
28
28
29
const ID = 'rbt-id' ;
29
30
@@ -115,7 +116,7 @@ describe('<Typeahead>', () => {
115
116
} ) ;
116
117
117
118
it ( 'truncates selections when using `defaultSelected`' , ( ) => {
118
- let selected : TestOption [ ] = states . slice ( 0 , 4 ) ;
119
+ let selected = states . slice ( 0 , 4 ) ;
119
120
render (
120
121
< Default defaultSelected = { selected } >
121
122
{ ( state ) => {
@@ -128,7 +129,7 @@ describe('<Typeahead>', () => {
128
129
} ) ;
129
130
130
131
describe ( 'behaviors when selections are passed in' , ( ) => {
131
- let selected : { name : string } [ ] ;
132
+ let selected : TestOption [ ] ;
132
133
let selectedText : string ;
133
134
134
135
beforeEach ( ( ) => {
@@ -238,7 +239,7 @@ describe('<Typeahead>', () => {
238
239
{ disabled : true , name : 'boo' } ,
239
240
{ name : 'baz' } ,
240
241
{ disabled : true , name : 'bro' } ,
241
- ] ;
242
+ ] as TestOption [ ] ;
242
243
243
244
render ( < Default options = { options } /> ) ;
244
245
getInput ( ) . focus ( ) ;
@@ -412,7 +413,7 @@ describe('<Typeahead>', () => {
412
413
it ( 'acts as a controlled input in single-select mode' , ( ) => {
413
414
let selected : TestOption [ ] = [ ] ;
414
415
415
- const children = ( state ) => {
416
+ const children = ( state : TypeaheadState < TestOption > ) => {
416
417
selected = state . selected ;
417
418
} ;
418
419
const selected1 = states . slice ( 0 , 1 ) ;
@@ -464,7 +465,7 @@ describe('<Typeahead>', () => {
464
465
render (
465
466
< Controlled selected = { states . slice ( 0 , 1 ) } >
466
467
{ ( state ) => {
467
- selected = state . selected ;
468
+ selected = state . selected as TestOption [ ] ;
468
469
} }
469
470
</ Controlled >
470
471
) ;
@@ -485,7 +486,7 @@ describe('<Typeahead>', () => {
485
486
486
487
describe ( '`highlightOnlyResult` behavior' , ( ) => {
487
488
let onChange : jest . Mock ;
488
- let selected : Option [ ] ;
489
+ let selected : TestOption [ ] ;
489
490
490
491
beforeEach ( ( ) => {
491
492
onChange = jest . fn ( ( s ) => ( selected = [ s ] ) ) ;
@@ -542,16 +543,18 @@ describe('<Typeahead>', () => {
542
543
543
544
it ( 'does not highlight or select a disabled result' , async ( ) => {
544
545
const user = userEvent . setup ( ) ;
546
+ const options = [
547
+ { name : 'foo' } ,
548
+ { disabled : true , name : 'bar' } ,
549
+ { disabled : true , name : 'boo' } ,
550
+ { name : 'baz' } ,
551
+ ] as TestOption [ ]
552
+
545
553
render (
546
554
< Default
547
555
highlightOnlyResult
548
556
onChange = { onChange }
549
- options = { [
550
- { name : 'foo' } ,
551
- { disabled : true , name : 'bar' } ,
552
- { disabled : true , name : 'boo' } ,
553
- { name : 'baz' } ,
554
- ] }
557
+ options = { options }
555
558
/>
556
559
) ;
557
560
@@ -1011,7 +1014,7 @@ describe('<Typeahead>', () => {
1011
1014
< Default
1012
1015
renderMenuItemChildren = {
1013
1016
// Render the capital instead of the state name.
1014
- ( o ) => o . capital
1017
+ ( o ) => < span > { o . capital } </ span >
1015
1018
}
1016
1019
/>
1017
1020
) ;
@@ -1121,15 +1124,16 @@ describe('<Typeahead>', () => {
1121
1124
} ) ;
1122
1125
1123
1126
it ( 'adds the custom option when `allowNew` is set to `true`' , async ( ) => {
1124
- let selected : TestOption [ ] = [ ] ;
1127
+ type TestOptionWithId = TestOption & { id : string } ;
1128
+ let selected : TestOptionWithId [ ] = [ ] ;
1125
1129
const user = userEvent . setup ( ) ;
1126
1130
1127
1131
render (
1128
1132
< AllowNew
1129
1133
emptyLabel = { emptyLabel }
1130
1134
newSelectionPrefix = { newSelectionPrefix }
1131
1135
onChange = { ( s ) => {
1132
- selected = s ;
1136
+ selected = s as TestOptionWithId [ ] ;
1133
1137
} }
1134
1138
/>
1135
1139
) ;
@@ -1211,7 +1215,7 @@ describe('<Typeahead>', () => {
1211
1215
1212
1216
describe ( '<Typeahead> Public Methods' , ( ) => {
1213
1217
it ( 'exposes the typeahead instance and public methods' , ( ) => {
1214
- const ref = createRef < Typeahead > ( ) ;
1218
+ const ref = createRef < Typeahead < TestOption > > ( ) ;
1215
1219
render ( < TestComponent ref = { ref } /> ) ;
1216
1220
1217
1221
expect ( typeof ref . current ?. blur ) . toBe ( 'function' ) ;
@@ -1223,7 +1227,7 @@ describe('<Typeahead> Public Methods', () => {
1223
1227
} ) ;
1224
1228
1225
1229
it ( 'calls the public `focus` and `blur` methods' , ( ) => {
1226
- const ref = createRef < Typeahead > ( ) ;
1230
+ const ref = createRef < Typeahead < TestOption > > ( ) ;
1227
1231
render ( < TestComponent ref = { ref } /> ) ;
1228
1232
1229
1233
const input = getInput ( ) ;
@@ -1237,7 +1241,7 @@ describe('<Typeahead> Public Methods', () => {
1237
1241
1238
1242
it ( 'calls the public `clear` method' , async ( ) => {
1239
1243
const user = userEvent . setup ( ) ;
1240
- const ref = createRef < Typeahead > ( ) ;
1244
+ const ref = createRef < Typeahead < TestOption > > ( ) ;
1241
1245
const { container } = render (
1242
1246
< TestComponent multiple ref = { ref } defaultSelected = { states . slice ( 0 , 3 ) } />
1243
1247
) ;
@@ -1256,13 +1260,13 @@ describe('<Typeahead> Public Methods', () => {
1256
1260
} ) ;
1257
1261
1258
1262
it ( 'calls the public `getInput` method' , ( ) => {
1259
- const ref = createRef < Typeahead > ( ) ;
1263
+ const ref = createRef < Typeahead < TestOption > > ( ) ;
1260
1264
render ( < TestComponent ref = { ref } /> ) ;
1261
1265
expect ( ref . current ?. getInput ( ) ) . toEqual ( getInput ( ) ) ;
1262
1266
} ) ;
1263
1267
1264
1268
it ( 'calls the public `hideMenu` method' , async ( ) => {
1265
- const ref = createRef < Typeahead > ( ) ;
1269
+ const ref = createRef < Typeahead < TestOption > > ( ) ;
1266
1270
render ( < TestComponent ref = { ref } /> ) ;
1267
1271
1268
1272
getInput ( ) . focus ( ) ;
@@ -1274,7 +1278,7 @@ describe('<Typeahead> Public Methods', () => {
1274
1278
} ) ;
1275
1279
1276
1280
it ( 'calls the public `toggleMenu` method' , ( ) => {
1277
- const ref = createRef < Typeahead > ( ) ;
1281
+ const ref = createRef < Typeahead < TestOption > > ( ) ;
1278
1282
render ( < TestComponent ref = { ref } /> ) ;
1279
1283
1280
1284
expect ( getMenu ( ) ) . not . toBeInTheDocument ( ) ;
@@ -1288,7 +1292,7 @@ describe('<Typeahead> Public Methods', () => {
1288
1292
1289
1293
it ( 'clears the typeahead after a selection' , async ( ) => {
1290
1294
const user = userEvent . setup ( ) ;
1291
- const ref = createRef < Typeahead > ( ) ;
1295
+ const ref = createRef < Typeahead < TestOption > > ( ) ;
1292
1296
const onChange = jest . fn ( ( ) => {
1293
1297
ref . current ?. clear ( ) ;
1294
1298
} ) ;
@@ -1474,7 +1478,7 @@ describe('<Typeahead> `change` events', () => {
1474
1478
} ) ;
1475
1479
1476
1480
it ( 'does not call either when `clear()` is called externally' , ( ) => {
1477
- const ref = createRef < Typeahead > ( ) ;
1481
+ const ref = createRef < Typeahead < TestOption > > ( ) ;
1478
1482
const selected = states . slice ( 0 , 1 ) ;
1479
1483
render (
1480
1484
< TestComponent
@@ -1497,8 +1501,8 @@ describe('<Typeahead> `change` events', () => {
1497
1501
1498
1502
describe ( '<Typeahead> input value behaviors' , ( ) => {
1499
1503
let defaultInputValue : string ;
1500
- let defaultSelected : Option [ ] ;
1501
- let selected : Option [ ] ;
1504
+ let defaultSelected : TestOption [ ] ;
1505
+ let selected : TestOption [ ] ;
1502
1506
1503
1507
beforeEach ( ( ) => {
1504
1508
defaultInputValue = 'This is a default value' ;
0 commit comments