From 512deae883c6868e3908188058ed80838b2afa25 Mon Sep 17 00:00:00 2001 From: Syed Sajjad Hussain Shah <52817156+syedsajjadkazmii@users.noreply.github.com> Date: Fri, 8 Sep 2023 15:37:33 +0500 Subject: [PATCH] fix: recs skip btn event gets cancelled on redirection (#1058) --- src/recommendations/RecommendationsPage.jsx | 4 ++-- src/recommendations/tests/RecommendationsPage.test.jsx | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/recommendations/RecommendationsPage.jsx b/src/recommendations/RecommendationsPage.jsx index d06cb9f909..61a10ae34b 100644 --- a/src/recommendations/RecommendationsPage.jsx +++ b/src/recommendations/RecommendationsPage.jsx @@ -19,7 +19,7 @@ import useAlgoliaRecommendations from './data/hooks/useAlgoliaRecommendations'; import messages from './messages'; import RecommendationsLargeLayout from './RecommendationsPageLayouts/LargeLayout'; import RecommendationsSmallLayout from './RecommendationsPageLayouts/SmallLayout'; -import { trackRecommendationsViewed, trackSkipButtonClicked } from './track'; +import { LINK_TIMEOUT, trackRecommendationsViewed, trackSkipButtonClicked } from './track'; import { DEFAULT_REDIRECT_URL } from '../data/constants'; const RecommendationsPage = () => { @@ -56,7 +56,7 @@ const RecommendationsPage = () => { const handleSkip = (e) => { e.preventDefault(); trackSkipButtonClicked(userId); - handleSkipRecommendationPage(); + setTimeout(() => { handleSkipRecommendationPage(); }, LINK_TIMEOUT); }; if (!registrationResponse) { diff --git a/src/recommendations/tests/RecommendationsPage.test.jsx b/src/recommendations/tests/RecommendationsPage.test.jsx index 496923a2a0..238d1b4af5 100644 --- a/src/recommendations/tests/RecommendationsPage.test.jsx +++ b/src/recommendations/tests/RecommendationsPage.test.jsx @@ -92,9 +92,10 @@ describe('RecommendationsPageTests', () => { it('should redirect user if they click "Skip for now" button', () => { mockUseLocation(); + jest.useFakeTimers(); const recommendationsPage = mount(reduxWrapper()); recommendationsPage.find('.pgn__stateful-btn-state-default').first().simulate('click'); - + jest.advanceTimersByTime(300); expect(window.location.href).toEqual(redirectUrl); });