From 00f329cb673e05d6b80525e26316e50dfdf4bc29 Mon Sep 17 00:00:00 2001 From: Thomas Mees Date: Fri, 11 Aug 2023 13:12:33 +0200 Subject: [PATCH] Move check to display PremiumFeaturesLink in to SubscriptionDashboard GitOrigin-RevId: 931dcd61e019d889e60a6c7ea5f1facd15dcf905 --- .../dashboard/premium-features-link.tsx | 7 ---- .../dashboard/subscription-dashboard.tsx | 9 +++-- .../dashboard/premium-features-link.test.tsx | 38 +++++++------------ 3 files changed, 19 insertions(+), 35 deletions(-) diff --git a/services/web/frontend/js/features/subscription/components/dashboard/premium-features-link.tsx b/services/web/frontend/js/features/subscription/components/dashboard/premium-features-link.tsx index b63186b58a..f57c0b6a78 100644 --- a/services/web/frontend/js/features/subscription/components/dashboard/premium-features-link.tsx +++ b/services/web/frontend/js/features/subscription/components/dashboard/premium-features-link.tsx @@ -1,15 +1,8 @@ import { Trans } from 'react-i18next' import getMeta from '../../../../utils/meta' import * as eventTracking from '../../../../infrastructure/event-tracking' -import { useSubscriptionDashboardContext } from '../../context/subscription-dashboard-context' function PremiumFeaturesLink() { - const { hasValidActiveSubscription } = useSubscriptionDashboardContext() - - if (!hasValidActiveSubscription) { - return null - } - const featuresPageVariant = getMeta('ol-splitTestVariants')?.['features-page'] || 'default' diff --git a/services/web/frontend/js/features/subscription/components/dashboard/subscription-dashboard.tsx b/services/web/frontend/js/features/subscription/components/dashboard/subscription-dashboard.tsx index c363fcb4ed..69a5ca62db 100644 --- a/services/web/frontend/js/features/subscription/components/dashboard/subscription-dashboard.tsx +++ b/services/web/frontend/js/features/subscription/components/dashboard/subscription-dashboard.tsx @@ -13,8 +13,11 @@ import PremiumFeaturesLink from './premium-features-link' function SubscriptionDashboard() { const { t } = useTranslation() - const { hasDisplayedSubscription, hasSubscription } = - useSubscriptionDashboardContext() + const { + hasDisplayedSubscription, + hasSubscription, + hasValidActiveSubscription, + } = useSubscriptionDashboardContext() const fromPlansPage: boolean = getMeta('ol-fromPlansPage') @@ -38,7 +41,7 @@ function SubscriptionDashboard() { - + {hasValidActiveSubscription && } {!hasDisplayedSubscription && (hasSubscription ? : )} diff --git a/services/web/test/frontend/features/subscription/components/dashboard/premium-features-link.test.tsx b/services/web/test/frontend/features/subscription/components/dashboard/premium-features-link.test.tsx index 6e392ec120..b8a6713218 100644 --- a/services/web/test/frontend/features/subscription/components/dashboard/premium-features-link.test.tsx +++ b/services/web/test/frontend/features/subscription/components/dashboard/premium-features-link.test.tsx @@ -1,14 +1,9 @@ import { expect } from 'chai' import sinon from 'sinon' -import { fireEvent, screen, within } from '@testing-library/react' +import { fireEvent, render, screen, within } from '@testing-library/react' import * as eventTracking from '../../../../../../frontend/js/infrastructure/event-tracking' import PremiumFeaturesLink from '../../../../../../frontend/js/features/subscription/components/dashboard/premium-features-link' import * as useLocationModule from '../../../../../../frontend/js/shared/hooks/use-location' -import { - cleanUpContext, - renderWithSubscriptionDashContext, -} from '../../helpers/render-with-subscription-dash-context' -import { annualActiveSubscription } from '../../fixtures/subscriptions' describe('', function () { const originalLocation = window.location @@ -21,6 +16,7 @@ describe('', function () { ] beforeEach(function () { + window.metaAttributesCache = new Map() sendMBSpy = sinon.spy(eventTracking, 'sendMB') this.locationStub = sinon.stub(useLocationModule, 'useLocation').returns({ assign: sinon.stub(), @@ -29,32 +25,24 @@ describe('', function () { }) afterEach(function () { + window.metaAttributesCache = new Map() sendMBSpy.restore() this.locationStub.restore() - cleanUpContext() - }) - - describe('without an active valid subscription', function () { - it('returns an empty container', function () { - const { container } = renderWithSubscriptionDashContext( - - ) - expect(container.firstChild).to.be.null - }) }) for (const variant of variants) { describe(`${variant.name} variant`, function () { - it('renders the premium features link and sends analytics event', function () { - renderWithSubscriptionDashContext(, { - metaTags: [ - { name: 'ol-subscription', value: annualActiveSubscription }, - { - name: 'ol-splitTestVariants', - value: { 'features-page': variant.name }, - }, - ], + beforeEach(function () { + window.metaAttributesCache.set('ol-splitTestVariants', { + 'features-page': variant.name, }) + }) + afterEach(function () { + window.metaAttributesCache.delete('ol-splitTestVariants') + }) + + it('renders the premium features link and sends analytics event', function () { + render() const premiumText = screen.getByText('Get the most out of your', { exact: false, })