Skip to content

Commit 3679872

Browse files
committed
Add test for domain-to-plan credit notice
1 parent 9f2cc39 commit 3679872

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

client/my-sites/plans-features-main/components/test/plan-notice.tsx

+31-1
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ import { useMarketingMessage } from 'calypso/components/marketing-message/use-ma
1515
import { getDiscountByName } from 'calypso/lib/discounts';
1616
import { Purchase } from 'calypso/lib/purchases/types';
1717
import PlanNotice from 'calypso/my-sites/plans-features-main/components/plan-notice';
18+
import { useDomainToPlanCredits } from 'calypso/my-sites/plans-features-main/hooks/use-domain-to-plan-credits';
1819
import { usePlanUpgradeCreditsApplicable } from 'calypso/my-sites/plans-features-main/hooks/use-plan-upgrade-credits-applicable';
1920
import { getCurrentUserCurrencyCode } from 'calypso/state/currency-code/selectors';
20-
import { getByPurchaseId } from 'calypso/state/purchases/selectors';
21+
import { getByPurchaseId, hasPurchasedDomain } from 'calypso/state/purchases/selectors';
2122
import {
2223
isCurrentUserCurrentPlanOwner,
2324
isRequestingSitePlans,
@@ -31,6 +32,7 @@ jest.mock( '@automattic/calypso-products', () => ( {
3132
} ) );
3233
jest.mock( 'calypso/state/purchases/selectors', () => ( {
3334
getByPurchaseId: jest.fn(),
35+
hasPurchasedDomain: jest.fn(),
3436
} ) );
3537
jest.mock( 'calypso/state/sites/plans/selectors', () => ( {
3638
isCurrentUserCurrentPlanOwner: jest.fn(),
@@ -56,6 +58,9 @@ jest.mock(
5658
jest.mock( 'calypso/my-sites/plans-features-main/hooks/use-max-plan-upgrade-credits', () => ( {
5759
useMaxPlanUpgradeCredits: jest.fn(),
5860
} ) );
61+
jest.mock( 'calypso/my-sites/plans-features-main/hooks/use-domain-to-plan-credits', () => ( {
62+
useDomainToPlanCredits: jest.fn(),
63+
} ) );
5964
jest.mock( 'calypso/state/currency-code/selectors', () => ( {
6065
getCurrentUserCurrencyCode: jest.fn(),
6166
} ) );
@@ -74,10 +79,14 @@ const mIsRequestingSitePlans = isRequestingSitePlans as jest.MockedFunction<
7479
const mUsePlanUpgradeCreditsApplicable = usePlanUpgradeCreditsApplicable as jest.MockedFunction<
7580
typeof usePlanUpgradeCreditsApplicable
7681
>;
82+
const mUseDomainToPlanCredits = useDomainToPlanCredits as jest.MockedFunction<
83+
typeof useDomainToPlanCredits
84+
>;
7785
const mGetCurrentUserCurrencyCode = getCurrentUserCurrencyCode as jest.MockedFunction<
7886
typeof getCurrentUserCurrencyCode
7987
>;
8088
const mGetByPurchaseId = getByPurchaseId as jest.MockedFunction< typeof getByPurchaseId >;
89+
const mHasPurchasedDomain = hasPurchasedDomain as jest.MockedFunction< typeof hasPurchasedDomain >;
8190
const mIsProPlan = isProPlan as jest.MockedFunction< typeof isProPlan >;
8291

8392
const plansList: PlanSlug[] = [
@@ -105,7 +114,9 @@ describe( '<PlanNotice /> Tests', () => {
105114
mIsRequestingSitePlans.mockImplementation( () => true );
106115
mGetCurrentUserCurrencyCode.mockImplementation( () => 'USD' );
107116
mUsePlanUpgradeCreditsApplicable.mockImplementation( () => 100 );
117+
mUseDomainToPlanCredits.mockImplementation( () => 100 );
108118
mGetByPurchaseId.mockImplementation( () => ( { isInAppPurchase: false } ) as Purchase );
119+
mHasPurchasedDomain.mockImplementation( () => false );
109120
mIsProPlan.mockImplementation( () => false );
110121
} );
111122

@@ -164,6 +175,25 @@ describe( '<PlanNotice /> Tests', () => {
164175
);
165176
} );
166177

178+
test( 'A domain-to-plan credit <PlanNotice /> should be shown in a site where: a domain has been purchased, has no other active discounts, has free plan', () => {
179+
mHasPurchasedDomain.mockImplementation( () => true );
180+
mIsCurrentPlanPaid.mockImplementation( () => false );
181+
mUsePlanUpgradeCreditsApplicable.mockImplementation( () => null );
182+
mUseDomainToPlanCredits.mockImplementation( () => 1000 );
183+
184+
renderWithProvider(
185+
<PlanNotice
186+
discountInformation={ { coupon: 'test', discountEndDate: new Date() } }
187+
visiblePlans={ plansList }
188+
isInSignup={ false }
189+
siteId={ 32234 }
190+
/>
191+
);
192+
expect( screen.getByRole( 'status' ).textContent ).toBe(
193+
'You have $10.00 in upgrade credits(opens in a new tab) available from your current domain. This credit will be applied to the pricing below at checkout if you purchase a plan today!'
194+
);
195+
} );
196+
167197
test( 'A marketing message <PlanNotice /> when no other notices are available and marketing messages are available and the user is not in signup', () => {
168198
mIsCurrentUserCurrentPlanOwner.mockImplementation( () => true );
169199
mIsCurrentPlanPaid.mockImplementation( () => true );

0 commit comments

Comments
 (0)