1
- import { within , userEvent , expect } from '@storybook/test' ;
1
+ import { within , userEvent , expect , fn } from '@storybook/test' ;
2
2
import { CioAutocomplete } from '../../index' ;
3
3
import { argTypes } from '../Autocomplete/argTypes' ;
4
4
import { getCioClient , sleep } from '../../utils/helpers' ;
@@ -26,6 +26,11 @@ export default {
26
26
} ,
27
27
} ;
28
28
29
+ const explicitActionsSpies = {
30
+ onFocus : fn ( ) ,
31
+ onChange : fn ( ) ,
32
+ } ;
33
+
29
34
const defaultArgs : CioAutocompleteProps = {
30
35
apiKey,
31
36
onSubmit,
@@ -37,8 +42,14 @@ const defaultArgs: CioAutocompleteProps = {
37
42
indexSectionName : 'Products' ,
38
43
} ,
39
44
] ,
45
+ ...explicitActionsSpies ,
40
46
} ;
41
47
48
+ // @ts -ignore
49
+ // eslint-disable-next-line
50
+ window . navigator . __defineGetter__ ( 'webdriver' , ( ) => false ) ;
51
+ window . sessionStorage . setItem ( '_constructorio_is_human' , 'true' ) ;
52
+
42
53
// - No Interaction => Correctly render default state
43
54
export const RenderAutocompleteDefaultState = ComponentTemplate . bind ( { } ) ;
44
55
RenderAutocompleteDefaultState . args = defaultArgs ;
@@ -83,6 +94,7 @@ FocusNoZeroStateShowNoResults.play = async ({ canvasElement }) => {
83
94
// - type whitespace search term => doesn't run an autocomplete request
84
95
export const TypeWhitespaceSearchTermNoError = ComponentTemplate . bind ( { } ) ;
85
96
TypeWhitespaceSearchTermNoError . args = {
97
+ ...explicitActionsSpies ,
86
98
apiKey,
87
99
} ;
88
100
let isAutocompleteResultsError = false ;
@@ -120,6 +132,7 @@ TypeWhitespaceSearchTermNoError.play = async ({ canvasElement }) => {
120
132
// - type search term => render term suggestions
121
133
export const TypeSearchTermRenderSearchSuggestions = ComponentTemplate . bind ( { } ) ;
122
134
TypeSearchTermRenderSearchSuggestions . args = {
135
+ ...explicitActionsSpies ,
123
136
apiKey,
124
137
sections : [
125
138
{
@@ -138,6 +151,7 @@ TypeSearchTermRenderSearchSuggestions.play = async ({ canvasElement }) => {
138
151
// - type search term => render products suggestions
139
152
export const TypeSearchTermRenderProducts = ComponentTemplate . bind ( { } ) ;
140
153
TypeSearchTermRenderProducts . args = {
154
+ ...explicitActionsSpies ,
141
155
apiKey,
142
156
sections : [
143
157
{
@@ -158,6 +172,7 @@ TypeSearchTermRenderProducts.play = async ({ canvasElement }) => {
158
172
// - type search term => render recommendations section
159
173
export const TypeSearchTermRenderRecommendations = ComponentTemplate . bind ( { } ) ;
160
174
TypeSearchTermRenderRecommendations . args = {
175
+ ...explicitActionsSpies ,
161
176
apiKey,
162
177
sections : [
163
178
{
@@ -177,6 +192,7 @@ TypeSearchTermRenderRecommendations.play = async ({ canvasElement }) => {
177
192
// - Overwrite recommendations display name set at the dashboard
178
193
export const TypeSearchTermRenderOverriddenRecommendationsDisplayName = ComponentTemplate . bind ( { } ) ;
179
194
TypeSearchTermRenderOverriddenRecommendationsDisplayName . args = {
195
+ ...explicitActionsSpies ,
180
196
apiKey,
181
197
sections : [
182
198
{
@@ -202,6 +218,7 @@ TypeSearchTermRenderOverriddenRecommendationsDisplayName.play = async ({ canvasE
202
218
// - type search term => render all sections in default order
203
219
export const TypeSearchTermRenderSectionsDefaultOrder = ComponentTemplate . bind ( { } ) ;
204
220
TypeSearchTermRenderSectionsDefaultOrder . args = {
221
+ ...explicitActionsSpies ,
205
222
apiKey,
206
223
sections : [
207
224
{
@@ -246,6 +263,7 @@ TypeSearchTermRenderSectionsDefaultOrder.play = async ({ canvasElement }) => {
246
263
// - type search term => render all sections in custom order
247
264
export const TypeSearchTermRenderSectionsCustomOrder = ComponentTemplate . bind ( { } ) ;
248
265
TypeSearchTermRenderSectionsCustomOrder . args = {
266
+ ...explicitActionsSpies ,
249
267
apiKey,
250
268
sections : [
251
269
{
@@ -364,6 +382,7 @@ ClearButtonClearInput.play = async ({ canvasElement }) => {
364
382
// - focus in input field with zero state => render zero state section
365
383
export const FocusRenderZeroStateSection = ComponentTemplate . bind ( { } ) ;
366
384
FocusRenderZeroStateSection . args = {
385
+ ...explicitActionsSpies ,
367
386
apiKey,
368
387
zeroStateSections : [
369
388
{
@@ -402,6 +421,7 @@ NoOpenOnFocusDontRenderZeroStateSection.play = async ({ canvasElement }) => {
402
421
403
422
export const ZeroStateRenderCustomSection = ComponentTemplate . bind ( { } ) ;
404
423
ZeroStateRenderCustomSection . args = {
424
+ ...explicitActionsSpies ,
405
425
apiKey,
406
426
zeroStateSections : [
407
427
{
@@ -438,6 +458,7 @@ ZeroStateRenderCustomSection.play = async ({ canvasElement }) => {
438
458
439
459
export const ZeroStateRenderProductsSection = ComponentTemplate . bind ( { } ) ;
440
460
ZeroStateRenderProductsSection . args = {
461
+ ...explicitActionsSpies ,
441
462
apiKey,
442
463
sections : [
443
464
{
@@ -472,6 +493,7 @@ ZeroStateRenderProductsSection.play = async ({ canvasElement }) => {
472
493
473
494
export const InGroupSuggestions = ComponentTemplate . bind ( { } ) ;
474
495
InGroupSuggestions . args = {
496
+ ...explicitActionsSpies ,
475
497
apiKey,
476
498
advancedParameters : {
477
499
numTermsWithGroupSuggestions : 1 ,
@@ -483,11 +505,12 @@ InGroupSuggestions.play = async ({ canvasElement }) => {
483
505
const canvas = within ( canvasElement ) ;
484
506
await userEvent . type ( canvas . getByTestId ( 'cio-input' ) , 'socks' , { delay : 100 } ) ;
485
507
await sleep ( 1000 ) ;
486
- expect ( canvas . getAllByText ( 'in Socks & Underwear ' ) . length ) . toEqual ( 1 ) ;
508
+ expect ( canvas . getAllByText ( 'in Socks' ) . length ) . toEqual ( 1 ) ;
487
509
} ;
488
510
489
511
export const InGroupSuggestionsTwo = ComponentTemplate . bind ( { } ) ;
490
512
InGroupSuggestionsTwo . args = {
513
+ ...explicitActionsSpies ,
491
514
apiKey,
492
515
advancedParameters : {
493
516
numTermsWithGroupSuggestions : 3 ,
0 commit comments