-
Notifications
You must be signed in to change notification settings - Fork 3
[CI-4786] Add removing search term on track recommendation click #230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
88b756c
ad7784d
861030b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ import { storageGetItem, storageSetItem } from '../../utils/storage'; | |
| import { ComponentTemplate } from '../Autocomplete/Component'; | ||
| import { apiKey, onSubmitDefault as onSubmit } from '../../constants'; | ||
| import { CioAutocompleteProps } from '../../types'; | ||
| import { isTrackingRequestSent } from '../../utils/tracking'; | ||
| import { isTrackingRequestSent, captureTrackingRequest } from '../../utils/tracking'; | ||
| import { CONSTANTS } from '../../utils/beaconUtils'; | ||
|
|
||
| export default { | ||
|
|
@@ -76,8 +76,13 @@ FocusFiresTrackingEvent.args = defaultArgs; | |
| FocusFiresTrackingEvent.play = async ({ canvasElement }) => { | ||
| await sleep(100); | ||
| const canvas = within(canvasElement); | ||
| await userEvent.click(canvas.getByTestId('cio-input')); | ||
| const isFocusTrackingRequestSent = isTrackingRequestSent('action=focus'); | ||
| const input = canvas.getByTestId('cio-input'); | ||
|
|
||
| // Use the reusable tracking capture utility | ||
| const isFocusTrackingRequestSent = await captureTrackingRequest('action=focus', async () => { | ||
| await userEvent.click(input); | ||
| }); | ||
|
|
||
| expect(isFocusTrackingRequestSent).toBeTruthy(); | ||
| }; | ||
|
|
||
|
|
@@ -357,6 +362,56 @@ SelectProductSuggestionClearsSearchTermStorage.play = async ({ canvasElement }) | |
| await sleep(1000); | ||
| }; | ||
|
|
||
| // - select recommendation from zero state => Search Term Storage is Cleared | ||
| export const SelectZeroStateRecommendationClearsSearchTermStorage = ComponentTemplate.bind({}); | ||
| SelectZeroStateRecommendationClearsSearchTermStorage.args = { | ||
| ...defaultArgs, | ||
| autocompleteClassName: 'cio-autocomplete full-example-autocomplete-styles', | ||
| advancedParameters: { | ||
| displaySearchSuggestionImages: true, | ||
| displaySearchSuggestionResultCounts: true, | ||
| numTermsWithGroupSuggestions: 6, | ||
| }, | ||
| sections: [ | ||
| { | ||
| indexSectionName: 'Search Suggestions', | ||
| numResults: 8, | ||
| displaySearchTermHighlights: true, | ||
| }, | ||
| ], | ||
| zeroStateSections: [ | ||
| { | ||
| podId: 'bestsellers', | ||
| type: 'recommendations', | ||
| numResults: 6, | ||
| }, | ||
| ], | ||
| }; | ||
| SelectZeroStateRecommendationClearsSearchTermStorage.play = async ({ canvasElement }) => { | ||
| const canvas = within(canvasElement); | ||
| storageSetItem(CONSTANTS.SEARCH_TERM_STORAGE_KEY, 'test search term'); | ||
|
|
||
| await userEvent.click(canvas.getByTestId('cio-input')); | ||
| await sleep(1000); | ||
| expect(canvas.getAllByText('Best Sellers').length).toBeGreaterThan(0); | ||
|
|
||
| const bestSellersSection = canvas.getByTestId('cio-results').querySelector('.cio-section'); | ||
| const recommendationItems = bestSellersSection?.querySelectorAll('[data-cnstrc-item-id]'); | ||
|
|
||
| const firstRecommendation = recommendationItems?.[0]; | ||
| const isSelectTrackingRequestSent = await captureTrackingRequest( | ||
| '/recommendation_result_click', | ||
| async () => { | ||
| if (firstRecommendation) { | ||
| await userEvent.click(firstRecommendation); | ||
| } | ||
| } | ||
| ); | ||
|
|
||
| expect(isSelectTrackingRequestSent).toBeTruthy(); | ||
| expect(storageGetItem(CONSTANTS.SEARCH_TERM_STORAGE_KEY)).toBeNull(); | ||
| }; | ||
|
|
||
| // - click search icon => network search submit event | ||
| export const SearchIconSubmitSearch = ComponentTemplate.bind({}); | ||
| SearchIconSubmitSearch.args = defaultArgs; | ||
|
|
@@ -505,7 +560,7 @@ InGroupSuggestions.play = async ({ canvasElement }) => { | |
| const canvas = within(canvasElement); | ||
| await userEvent.type(canvas.getByTestId('cio-input'), 'socks', { delay: 100 }); | ||
| await sleep(1000); | ||
| expect(canvas.getAllByText('in Socks').length).toEqual(1); | ||
| expect(canvas.getAllByText(/in Socks/)).toHaveLength(1); | ||
|
Comment on lines
-508
to
+563
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for fixing this |
||
| }; | ||
|
|
||
| export const InGroupSuggestionsTwo = ComponentTemplate.bind({}); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -55,3 +55,36 @@ export const trackAutocompleteSelect = (cioClient, itemName, autocompleteData: a | |||||||||||||||||||||||||||||||||||||
| storageRemoveItem(CONSTANTS.SEARCH_TERM_STORAGE_KEY); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| export const trackRecommendationSelect = (cioClient, recommendationData: any = {}) => { | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
| export const trackRecommendationSelect = (cioClient, recommendationData: any = {}) => { | |
| interface RecommendationData { | |
| podId?: string; | |
| numResultsViewed?: number; | |
| url?: string; | |
| section?: string; | |
| items?: Array<{ | |
| itemId?: string; | |
| itemName?: string; | |
| variationId?: string; | |
| }>; | |
| // Add other properties as needed | |
| } | |
| export const trackRecommendationSelect = ( | |
| cioClient: Nullable<ConstructorIOClient>, | |
| recommendationData: RecommendationData = {} | |
| ) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good abstraction
Copilot
AI
Oct 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modifying the global Storage.prototype could cause issues if multiple components use this function simultaneously or if the restoration fails. Consider using a more isolated approach or adding proper error handling to ensure the prototype is always restored.
Copilot
AI
Oct 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using any type for request objects reduces type safety. Consider defining a proper interface for request objects to improve type checking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this particular test is created to ensure that search_term_storage is cleared, but should we also check if the tracking event is fired using that new utility
captureTrackingRequest?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, we can, without any problems
Added this check ✅
Thank you for the review!