@@ -8,11 +8,14 @@ import { castToJestMock } from '@instantsearch/testutils';
8
8
import { wait } from '@instantsearch/testutils/wait' ;
9
9
import { getByText , fireEvent } from '@testing-library/dom' ;
10
10
11
- import { connectConfigure , connectSearchBox } from '../../connectors' ;
12
- import instantsearch from '../../index.es' ;
13
- import { configure , frequentlyBoughtTogether , searchBox } from '../../widgets' ;
11
+ import {
12
+ instantsearch ,
13
+ connectConfigure ,
14
+ connectSearchBox ,
15
+ connectFrequentlyBoughtTogether ,
16
+ } from '..' ;
14
17
15
- import type { MiddlewareDefinition } from '../../ types' ;
18
+ import type { MiddlewareDefinition } from '../types' ;
16
19
17
20
describe ( 'configure' , ( ) => {
18
21
it ( 'provides up-to-date uiState to onStateChange' , ( ) => {
@@ -38,8 +41,10 @@ describe('configure', () => {
38
41
}
39
42
} ) ;
40
43
search . addWidgets ( [
41
- configure ( {
42
- hitsPerPage : 10 ,
44
+ connectConfigure ( ( ) => { } ) ( {
45
+ searchParameters : {
46
+ hitsPerPage : 10 ,
47
+ } ,
43
48
} ) ,
44
49
customComp ( { searchParameters : { } } ) ,
45
50
] ) ;
@@ -57,7 +62,6 @@ describe('configure', () => {
57
62
58
63
describe ( 'middleware' , ( ) => {
59
64
it ( "runs middlewares' onStateChange when uiState changes" , async ( ) => {
60
- const container = document . createElement ( 'div' ) ;
61
65
const search = instantsearch ( {
62
66
indexName : 'instant_search' ,
63
67
searchClient : createSearchClient ( ) ,
@@ -74,25 +78,17 @@ describe('middleware', () => {
74
78
75
79
search . use ( ( ) => middlewareDefinition ) ;
76
80
77
- search . addWidgets ( [
78
- searchBox ( {
79
- container,
80
- placeholder : 'search' ,
81
- } ) ,
82
- ] ) ;
81
+ search . addWidgets ( [ connectSearchBox ( ( ) => { } ) ( { } ) ] ) ;
83
82
84
83
search . start ( ) ;
85
84
86
- fireEvent . input ( container . querySelector ( 'input' ) ! , {
87
- target : { value : 'q' } ,
88
- } ) ;
85
+ search . renderState . instant_search . searchBox ! . refine ( 'q' ) ;
89
86
90
87
await wait ( 0 ) ;
91
88
expect ( middlewareDefinition . onStateChange ) . toHaveBeenCalledTimes ( 1 ) ;
92
89
} ) ;
93
90
94
91
it ( "runs middlewares' onStateChange when uiState changes with user-provided onStateChange param" , async ( ) => {
95
- const container = document . createElement ( 'div' ) ;
96
92
const search = instantsearch ( {
97
93
indexName : 'instant_search' ,
98
94
searchClient : createSearchClient ( ) ,
@@ -112,27 +108,18 @@ describe('middleware', () => {
112
108
113
109
search . use ( ( ) => middlewareDefinition ) ;
114
110
115
- search . addWidgets ( [
116
- searchBox ( {
117
- container,
118
- placeholder : 'search' ,
119
- } ) ,
120
- ] ) ;
111
+ search . addWidgets ( [ connectSearchBox ( ( ) => { } ) ( { } ) ] ) ;
121
112
122
113
search . start ( ) ;
123
114
124
- fireEvent . input ( container . querySelector ( 'input' ) ! , {
125
- target : { value : 'q' } ,
126
- } ) ;
115
+ search . renderState . instant_search . searchBox ! . refine ( 'q' ) ;
127
116
128
117
await wait ( 0 ) ;
129
118
expect ( middlewareDefinition . onStateChange ) . toHaveBeenCalledTimes ( 1 ) ;
130
119
} ) ;
131
120
} ) ;
132
121
133
122
describe ( 'errors' , ( ) => {
134
- const virtualSearchBox = connectSearchBox ( ( ) => { } ) ;
135
-
136
123
it ( 'client errors can be handled' , ( ) => {
137
124
const search = instantsearch ( {
138
125
searchClient : createSearchClient ( {
@@ -143,7 +130,7 @@ describe('errors', () => {
143
130
indexName : '123' ,
144
131
} ) ;
145
132
146
- search . addWidgets ( [ virtualSearchBox ( { } ) ] ) ;
133
+ search . addWidgets ( [ connectSearchBox ( ( ) => { } ) ( { } ) ] ) ;
147
134
148
135
expect . assertions ( 4 ) ;
149
136
@@ -184,7 +171,7 @@ describe('network requests', () => {
184
171
indexName : 'indexName' ,
185
172
searchClient,
186
173
} )
187
- . addWidgets ( [ searchBox ( { container : document . createElement ( 'div' ) } ) ] )
174
+ . addWidgets ( [ connectSearchBox ( ( ) => { } ) ( { } ) ] )
188
175
. start ( ) ;
189
176
190
177
await wait ( 0 ) ;
@@ -212,9 +199,8 @@ describe('network requests', () => {
212
199
searchClient,
213
200
} )
214
201
. addWidgets ( [
215
- frequentlyBoughtTogether ( {
202
+ connectFrequentlyBoughtTogether ( ( ) => { } ) ( {
216
203
objectIDs : [ 'one' ] ,
217
- container : document . createElement ( 'div' ) ,
218
204
} ) ,
219
205
] )
220
206
. start ( ) ;
@@ -250,10 +236,9 @@ describe('network requests', () => {
250
236
searchClient,
251
237
} )
252
238
. addWidgets ( [
253
- searchBox ( { container : document . createElement ( 'div' ) } ) ,
254
- frequentlyBoughtTogether ( {
239
+ connectSearchBox ( ( ) => { } ) ( { } ) ,
240
+ connectFrequentlyBoughtTogether ( ( ) => { } ) ( {
255
241
objectIDs : [ 'one' ] ,
256
- container : document . createElement ( 'div' ) ,
257
242
} ) ,
258
243
] )
259
244
. start ( ) ;
@@ -327,7 +312,7 @@ describe('network requests', () => {
327
312
searchClient,
328
313
insights : true ,
329
314
} )
330
- . addWidgets ( [ searchBox ( { container : document . createElement ( 'div' ) } ) ] )
315
+ . addWidgets ( [ connectSearchBox ( ( ) => { } ) ( { } ) ] )
331
316
. start ( ) ;
332
317
333
318
await wait ( 0 ) ;
@@ -358,9 +343,8 @@ describe('network requests', () => {
358
343
insights : true ,
359
344
} )
360
345
. addWidgets ( [
361
- frequentlyBoughtTogether ( {
346
+ connectFrequentlyBoughtTogether ( ( ) => { } ) ( {
362
347
objectIDs : [ 'one' ] ,
363
- container : document . createElement ( 'div' ) ,
364
348
} ) ,
365
349
] )
366
350
. start ( ) ;
@@ -397,10 +381,9 @@ describe('network requests', () => {
397
381
insights : true ,
398
382
} )
399
383
. addWidgets ( [
400
- searchBox ( { container : document . createElement ( 'div' ) } ) ,
401
- frequentlyBoughtTogether ( {
384
+ connectSearchBox ( ( ) => { } ) ( { } ) ,
385
+ connectFrequentlyBoughtTogether ( ( ) => { } ) ( {
402
386
objectIDs : [ 'one' ] ,
403
- container : document . createElement ( 'div' ) ,
404
387
} ) ,
405
388
] )
406
389
. start ( ) ;
@@ -476,7 +459,7 @@ describe('network requests', () => {
476
459
searchClient,
477
460
insights : true ,
478
461
} )
479
- . addWidgets ( [ searchBox ( { container : document . createElement ( 'div' ) } ) ] )
462
+ . addWidgets ( [ connectSearchBox ( ( ) => { } ) ( { } ) ] )
480
463
. start ( ) ;
481
464
482
465
await wait ( 0 ) ;
@@ -507,9 +490,8 @@ describe('network requests', () => {
507
490
insights : true ,
508
491
} )
509
492
. addWidgets ( [
510
- frequentlyBoughtTogether ( {
493
+ connectFrequentlyBoughtTogether ( ( ) => { } ) ( {
511
494
objectIDs : [ 'one' ] ,
512
- container : document . createElement ( 'div' ) ,
513
495
} ) ,
514
496
] )
515
497
. start ( ) ;
@@ -546,10 +528,9 @@ describe('network requests', () => {
546
528
insights : true ,
547
529
} )
548
530
. addWidgets ( [
549
- searchBox ( { container : document . createElement ( 'div' ) } ) ,
550
- frequentlyBoughtTogether ( {
531
+ connectSearchBox ( ( ) => { } ) ( { } ) ,
532
+ connectFrequentlyBoughtTogether ( ( ) => { } ) ( {
551
533
objectIDs : [ 'one' ] ,
552
- container : document . createElement ( 'div' ) ,
553
534
} ) ,
554
535
] )
555
536
. start ( ) ;
@@ -592,12 +573,11 @@ describe('network requests', () => {
592
573
describe ( 'interactive life cycle' , ( ) => {
593
574
it ( 'sends no queries when widgets are removed' , async ( ) => {
594
575
const searchClient = createRecommendSearchClient ( ) ;
595
- const searchBoxWidget = searchBox ( {
596
- container : document . createElement ( 'div' ) ,
597
- } ) ;
598
- const frequentlyBoughtTogetherWidget = frequentlyBoughtTogether ( {
576
+ const searchBoxWidget = connectSearchBox ( ( ) => { } ) ( { } ) ;
577
+ const frequentlyBoughtTogetherWidget = connectFrequentlyBoughtTogether (
578
+ ( ) => { }
579
+ ) ( {
599
580
objectIDs : [ 'one' ] ,
600
- container : document . createElement ( 'div' ) ,
601
581
} ) ;
602
582
const search = instantsearch ( {
603
583
indexName : 'indexName' ,
0 commit comments