@@ -6,7 +6,7 @@ import { storageGetItem, storageSetItem } from '../../utils/storage';
66import { ComponentTemplate } from '../Autocomplete/Component' ;
77import { apiKey , onSubmitDefault as onSubmit } from '../../constants' ;
88import { CioAutocompleteProps } from '../../types' ;
9- import { isTrackingRequestSent } from '../../utils/tracking' ;
9+ import { isTrackingRequestSent , captureTrackingRequest } from '../../utils/tracking' ;
1010import { CONSTANTS } from '../../utils/beaconUtils' ;
1111
1212export default {
@@ -76,8 +76,13 @@ FocusFiresTrackingEvent.args = defaultArgs;
7676FocusFiresTrackingEvent . play = async ( { canvasElement } ) => {
7777 await sleep ( 100 ) ;
7878 const canvas = within ( canvasElement ) ;
79- await userEvent . click ( canvas . getByTestId ( 'cio-input' ) ) ;
80- const isFocusTrackingRequestSent = isTrackingRequestSent ( 'action=focus' ) ;
79+ const input = canvas . getByTestId ( 'cio-input' ) ;
80+
81+ // Use the reusable tracking capture utility
82+ const isFocusTrackingRequestSent = await captureTrackingRequest ( 'action=focus' , async ( ) => {
83+ await userEvent . click ( input ) ;
84+ } ) ;
85+
8186 expect ( isFocusTrackingRequestSent ) . toBeTruthy ( ) ;
8287} ;
8388
@@ -357,6 +362,56 @@ SelectProductSuggestionClearsSearchTermStorage.play = async ({ canvasElement })
357362 await sleep ( 1000 ) ;
358363} ;
359364
365+ // - select recommendation from zero state => Search Term Storage is Cleared
366+ export const SelectZeroStateRecommendationClearsSearchTermStorage = ComponentTemplate . bind ( { } ) ;
367+ SelectZeroStateRecommendationClearsSearchTermStorage . args = {
368+ ...defaultArgs ,
369+ autocompleteClassName : 'cio-autocomplete full-example-autocomplete-styles' ,
370+ advancedParameters : {
371+ displaySearchSuggestionImages : true ,
372+ displaySearchSuggestionResultCounts : true ,
373+ numTermsWithGroupSuggestions : 6 ,
374+ } ,
375+ sections : [
376+ {
377+ indexSectionName : 'Search Suggestions' ,
378+ numResults : 8 ,
379+ displaySearchTermHighlights : true ,
380+ } ,
381+ ] ,
382+ zeroStateSections : [
383+ {
384+ podId : 'bestsellers' ,
385+ type : 'recommendations' ,
386+ numResults : 6 ,
387+ } ,
388+ ] ,
389+ } ;
390+ SelectZeroStateRecommendationClearsSearchTermStorage . play = async ( { canvasElement } ) => {
391+ const canvas = within ( canvasElement ) ;
392+ storageSetItem ( CONSTANTS . SEARCH_TERM_STORAGE_KEY , 'test search term' ) ;
393+
394+ await userEvent . click ( canvas . getByTestId ( 'cio-input' ) ) ;
395+ await sleep ( 1000 ) ;
396+ expect ( canvas . getAllByText ( 'Best Sellers' ) . length ) . toBeGreaterThan ( 0 ) ;
397+
398+ const bestSellersSection = canvas . getByTestId ( 'cio-results' ) . querySelector ( '.cio-section' ) ;
399+ const recommendationItems = bestSellersSection ?. querySelectorAll ( '[data-cnstrc-item-id]' ) ;
400+
401+ const firstRecommendation = recommendationItems ?. [ 0 ] ;
402+ const isSelectTrackingRequestSent = await captureTrackingRequest (
403+ '/recommendation_result_click' ,
404+ async ( ) => {
405+ if ( firstRecommendation ) {
406+ await userEvent . click ( firstRecommendation ) ;
407+ }
408+ }
409+ ) ;
410+
411+ expect ( isSelectTrackingRequestSent ) . toBeTruthy ( ) ;
412+ expect ( storageGetItem ( CONSTANTS . SEARCH_TERM_STORAGE_KEY ) ) . toBeNull ( ) ;
413+ } ;
414+
360415// - click search icon => network search submit event
361416export const SearchIconSubmitSearch = ComponentTemplate . bind ( { } ) ;
362417SearchIconSubmitSearch . args = defaultArgs ;
@@ -505,7 +560,7 @@ InGroupSuggestions.play = async ({ canvasElement }) => {
505560 const canvas = within ( canvasElement ) ;
506561 await userEvent . type ( canvas . getByTestId ( 'cio-input' ) , 'socks' , { delay : 100 } ) ;
507562 await sleep ( 1000 ) ;
508- expect ( canvas . getAllByText ( ' in Socks' ) . length ) . toEqual ( 1 ) ;
563+ expect ( canvas . getAllByText ( / i n S o c k s / ) ) . toHaveLength ( 1 ) ;
509564} ;
510565
511566export const InGroupSuggestionsTwo = ComponentTemplate . bind ( { } ) ;
0 commit comments