@@ -15,9 +15,10 @@ import { useMarketingMessage } from 'calypso/components/marketing-message/use-ma
15
15
import { getDiscountByName } from 'calypso/lib/discounts' ;
16
16
import { Purchase } from 'calypso/lib/purchases/types' ;
17
17
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' ;
18
19
import { usePlanUpgradeCreditsApplicable } from 'calypso/my-sites/plans-features-main/hooks/use-plan-upgrade-credits-applicable' ;
19
20
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' ;
21
22
import {
22
23
isCurrentUserCurrentPlanOwner ,
23
24
isRequestingSitePlans ,
@@ -31,6 +32,7 @@ jest.mock( '@automattic/calypso-products', () => ( {
31
32
} ) ) ;
32
33
jest . mock ( 'calypso/state/purchases/selectors' , ( ) => ( {
33
34
getByPurchaseId : jest . fn ( ) ,
35
+ hasPurchasedDomain : jest . fn ( ) ,
34
36
} ) ) ;
35
37
jest . mock ( 'calypso/state/sites/plans/selectors' , ( ) => ( {
36
38
isCurrentUserCurrentPlanOwner : jest . fn ( ) ,
@@ -56,6 +58,9 @@ jest.mock(
56
58
jest . mock ( 'calypso/my-sites/plans-features-main/hooks/use-max-plan-upgrade-credits' , ( ) => ( {
57
59
useMaxPlanUpgradeCredits : jest . fn ( ) ,
58
60
} ) ) ;
61
+ jest . mock ( 'calypso/my-sites/plans-features-main/hooks/use-domain-to-plan-credits' , ( ) => ( {
62
+ useDomainToPlanCredits : jest . fn ( ) ,
63
+ } ) ) ;
59
64
jest . mock ( 'calypso/state/currency-code/selectors' , ( ) => ( {
60
65
getCurrentUserCurrencyCode : jest . fn ( ) ,
61
66
} ) ) ;
@@ -74,10 +79,14 @@ const mIsRequestingSitePlans = isRequestingSitePlans as jest.MockedFunction<
74
79
const mUsePlanUpgradeCreditsApplicable = usePlanUpgradeCreditsApplicable as jest . MockedFunction <
75
80
typeof usePlanUpgradeCreditsApplicable
76
81
> ;
82
+ const mUseDomainToPlanCredits = useDomainToPlanCredits as jest . MockedFunction <
83
+ typeof useDomainToPlanCredits
84
+ > ;
77
85
const mGetCurrentUserCurrencyCode = getCurrentUserCurrencyCode as jest . MockedFunction <
78
86
typeof getCurrentUserCurrencyCode
79
87
> ;
80
88
const mGetByPurchaseId = getByPurchaseId as jest . MockedFunction < typeof getByPurchaseId > ;
89
+ const mHasPurchasedDomain = hasPurchasedDomain as jest . MockedFunction < typeof hasPurchasedDomain > ;
81
90
const mIsProPlan = isProPlan as jest . MockedFunction < typeof isProPlan > ;
82
91
83
92
const plansList : PlanSlug [ ] = [
@@ -105,7 +114,9 @@ describe( '<PlanNotice /> Tests', () => {
105
114
mIsRequestingSitePlans . mockImplementation ( ( ) => true ) ;
106
115
mGetCurrentUserCurrencyCode . mockImplementation ( ( ) => 'USD' ) ;
107
116
mUsePlanUpgradeCreditsApplicable . mockImplementation ( ( ) => 100 ) ;
117
+ mUseDomainToPlanCredits . mockImplementation ( ( ) => 100 ) ;
108
118
mGetByPurchaseId . mockImplementation ( ( ) => ( { isInAppPurchase : false } ) as Purchase ) ;
119
+ mHasPurchasedDomain . mockImplementation ( ( ) => false ) ;
109
120
mIsProPlan . mockImplementation ( ( ) => false ) ;
110
121
} ) ;
111
122
@@ -164,6 +175,25 @@ describe( '<PlanNotice /> Tests', () => {
164
175
) ;
165
176
} ) ;
166
177
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
+
167
197
test ( 'A marketing message <PlanNotice /> when no other notices are available and marketing messages are available and the user is not in signup' , ( ) => {
168
198
mIsCurrentUserCurrentPlanOwner . mockImplementation ( ( ) => true ) ;
169
199
mIsCurrentPlanPaid . mockImplementation ( ( ) => true ) ;
0 commit comments