@@ -230,8 +230,26 @@ describe('DocsSearchBar', () => {
230
230
231
231
describe ( 'checkArguments' , ( ) => {
232
232
let checkArguments
233
+ let defaultOptions
234
+
233
235
beforeEach ( ( ) => {
234
236
checkArguments = DocsSearchBar . checkArguments
237
+ defaultOptions = {
238
+ hostUrl : 'https://test.getmeili.com' ,
239
+ apiKey : 'apiKey' ,
240
+ indexUid : 'indexUID' ,
241
+ inputSelector : '#input' ,
242
+ debug : false ,
243
+ meilisearchOptions : { } ,
244
+ queryDataCallback : null ,
245
+ autocompleteOptions : { } ,
246
+ transformData : false ,
247
+ queryHook : false ,
248
+ handleSelected : false ,
249
+ enhancedSearchInput : false ,
250
+ layout : 'columns' ,
251
+ enableDarkMode : false ,
252
+ }
235
253
} )
236
254
237
255
afterEach ( ( ) => {
@@ -242,11 +260,8 @@ describe('DocsSearchBar', () => {
242
260
243
261
it ( 'should throw an error if no hostUrl defined' , ( ) => {
244
262
// Given
245
- const options = {
246
- apiKey : 'apiKey' ,
247
- indexUid : 'indexUID' ,
248
- inputSelector : '#' ,
249
- }
263
+ const options = defaultOptions
264
+ delete options . hostUrl
250
265
251
266
// When
252
267
expect ( ( ) => {
@@ -255,10 +270,8 @@ describe('DocsSearchBar', () => {
255
270
} )
256
271
it ( 'should throw an error if no inputSelector defined' , ( ) => {
257
272
// Given
258
- const options = {
259
- hostUrl : 'test.com' ,
260
- indexUid : 'indexUID' ,
261
- }
273
+ const options = defaultOptions
274
+ delete options . inputSelector
262
275
263
276
// When
264
277
expect ( ( ) => {
@@ -267,25 +280,102 @@ describe('DocsSearchBar', () => {
267
280
} )
268
281
it ( 'should throw an error if no indexUid defined' , ( ) => {
269
282
// Given
270
- const options = {
271
- hostUrl : 'test.com' ,
272
- inputSelector : '#' ,
273
- }
283
+ const options = defaultOptions
284
+ delete options . indexUid
274
285
275
286
// When
276
287
expect ( ( ) => {
277
288
checkArguments ( options )
278
289
} ) . toThrow ( / ^ U s a g e : / )
279
290
} )
280
291
it ( 'should throw an error if no selector matches' , ( ) => {
292
+ // Given
293
+ const options = { ...defaultOptions , inputSelector : '#' }
294
+ sinon . stub ( DocsSearchBar , 'getInputFromSelector' ) . returns ( false )
295
+
296
+ // When
297
+ expect ( ( ) => {
298
+ checkArguments ( options )
299
+ } ) . toThrow ( / ^ E r r o r : / )
300
+ } )
301
+ it ( 'should throw an error if enableDarkMode is not a boolean' , ( ) => {
302
+ // Given
303
+ const options = { ...defaultOptions , enableDarkMode : 'yes' }
304
+
305
+ // When
306
+ expect ( ( ) => {
307
+ checkArguments ( options )
308
+ } ) . toThrow ( / ^ E r r o r : / )
309
+ } )
310
+ it ( 'should throw an error if debug is not a boolean' , ( ) => {
311
+ // Given
312
+ const options = { ...defaultOptions , debug : null }
313
+
314
+ // When
315
+ expect ( ( ) => {
316
+ checkArguments ( options )
317
+ } ) . toThrow ( / ^ E r r o r : / )
318
+ } )
319
+ it ( 'should throw an error if enhancedSearchInput is not a boolean' , ( ) => {
320
+ // Given
321
+ const options = { ...defaultOptions , enhancedSearchInput : 'yes' }
322
+
323
+ // When
324
+ expect ( ( ) => {
325
+ checkArguments ( options )
326
+ } ) . toThrow ( / ^ E r r o r : / )
327
+ } )
328
+ it ( 'should throw an error if meilisearchOptions is not an object' , ( ) => {
329
+ // Given
330
+ const options = { ...defaultOptions , meilisearchOptions : 'not-an-object' }
331
+
332
+ // When
333
+ expect ( ( ) => {
334
+ checkArguments ( options )
335
+ } ) . toThrow ( / ^ E r r o r : / )
336
+ } )
337
+ it ( 'should throw an error if autocompleteOptions is not a object' , ( ) => {
281
338
// Given
282
339
const options = {
283
- hostUrl : 'test.com' ,
284
- apiKey : 'apiKey' ,
285
- indexUid : 'indexUID' ,
286
- inputSelector : '#' ,
340
+ ...defaultOptions ,
341
+ autocompleteOptions : 'not-an-object' ,
287
342
}
288
- sinon . stub ( DocsSearchBar , 'getInputFromSelector' ) . returns ( false )
343
+
344
+ // When
345
+ expect ( ( ) => {
346
+ checkArguments ( options )
347
+ } ) . toThrow ( / ^ E r r o r : / )
348
+ } )
349
+ it ( 'should throw an error if queryDataCallback is not a function' , ( ) => {
350
+ // Given
351
+ const options = { ...defaultOptions , queryDataCallback : 'not-a-function' }
352
+
353
+ // When
354
+ expect ( ( ) => {
355
+ checkArguments ( options )
356
+ } ) . toThrow ( / ^ E r r o r : / )
357
+ } )
358
+ it ( 'should throw an error if transformData is not a function' , ( ) => {
359
+ // Given
360
+ const options = { ...defaultOptions , transformData : 'not-a-function' }
361
+
362
+ // When
363
+ expect ( ( ) => {
364
+ checkArguments ( options )
365
+ } ) . toThrow ( / ^ E r r o r : / )
366
+ } )
367
+ it ( 'should throw an error if queryHook is not a function' , ( ) => {
368
+ // Given
369
+ const options = { ...defaultOptions , queryHook : 'not-a-function' }
370
+
371
+ // When
372
+ expect ( ( ) => {
373
+ checkArguments ( options )
374
+ } ) . toThrow ( / ^ E r r o r : / )
375
+ } )
376
+ it ( 'should throw an error if handleSelected is not a function' , ( ) => {
377
+ // Given
378
+ const options = { ...defaultOptions , handleSelected : 'not-a-function' }
289
379
290
380
// When
291
381
expect ( ( ) => {
0 commit comments