1
1
/** @jest -environment jsdom */
2
2
3
+ import { isEnabled } from '@automattic/calypso-config' ;
3
4
import {
4
5
PLAN_BUSINESS ,
5
6
PLAN_PREMIUM ,
@@ -15,6 +16,7 @@ import { useMarketingMessage } from 'calypso/components/marketing-message/use-ma
15
16
import { getDiscountByName } from 'calypso/lib/discounts' ;
16
17
import { Purchase } from 'calypso/lib/purchases/types' ;
17
18
import PlanNotice from 'calypso/my-sites/plans-features-main/components/plan-notice' ;
19
+ import { useDomainToPlanCreditsApplicable } from 'calypso/my-sites/plans-features-main/hooks/use-domain-to-plan-credits-applicable' ;
18
20
import { usePlanUpgradeCreditsApplicable } from 'calypso/my-sites/plans-features-main/hooks/use-plan-upgrade-credits-applicable' ;
19
21
import { getCurrentUserCurrencyCode } from 'calypso/state/currency-code/selectors' ;
20
22
import { getByPurchaseId } from 'calypso/state/purchases/selectors' ;
@@ -31,6 +33,7 @@ jest.mock( '@automattic/calypso-products', () => ( {
31
33
} ) ) ;
32
34
jest . mock ( 'calypso/state/purchases/selectors' , ( ) => ( {
33
35
getByPurchaseId : jest . fn ( ) ,
36
+ hasPurchasedDomain : jest . fn ( ) ,
34
37
} ) ) ;
35
38
jest . mock ( 'calypso/state/sites/plans/selectors' , ( ) => ( {
36
39
isCurrentUserCurrentPlanOwner : jest . fn ( ) ,
@@ -53,12 +56,19 @@ jest.mock(
53
56
usePlanUpgradeCreditsApplicable : jest . fn ( ) ,
54
57
} )
55
58
) ;
59
+ jest . mock (
60
+ 'calypso/my-sites/plans-features-main/hooks/use-domain-to-plan-credits-applicable' ,
61
+ ( ) => ( {
62
+ useDomainToPlanCreditsApplicable : jest . fn ( ) ,
63
+ } )
64
+ ) ;
56
65
jest . mock ( 'calypso/my-sites/plans-features-main/hooks/use-max-plan-upgrade-credits' , ( ) => ( {
57
66
useMaxPlanUpgradeCredits : jest . fn ( ) ,
58
67
} ) ) ;
59
68
jest . mock ( 'calypso/state/currency-code/selectors' , ( ) => ( {
60
69
getCurrentUserCurrencyCode : jest . fn ( ) ,
61
70
} ) ) ;
71
+ jest . mock ( '@automattic/calypso-config' ) ;
62
72
63
73
const mGetDiscountByName = getDiscountByName as jest . MockedFunction < typeof getDiscountByName > ;
64
74
const mUseMarketingMessage = useMarketingMessage as jest . MockedFunction <
@@ -74,11 +84,15 @@ const mIsRequestingSitePlans = isRequestingSitePlans as jest.MockedFunction<
74
84
const mUsePlanUpgradeCreditsApplicable = usePlanUpgradeCreditsApplicable as jest . MockedFunction <
75
85
typeof usePlanUpgradeCreditsApplicable
76
86
> ;
87
+ const mUseDomainToPlanCreditsApplicable = useDomainToPlanCreditsApplicable as jest . MockedFunction <
88
+ typeof useDomainToPlanCreditsApplicable
89
+ > ;
77
90
const mGetCurrentUserCurrencyCode = getCurrentUserCurrencyCode as jest . MockedFunction <
78
91
typeof getCurrentUserCurrencyCode
79
92
> ;
80
93
const mGetByPurchaseId = getByPurchaseId as jest . MockedFunction < typeof getByPurchaseId > ;
81
94
const mIsProPlan = isProPlan as jest . MockedFunction < typeof isProPlan > ;
95
+ const mIsEnabled = isEnabled as jest . MockedFunction < typeof isEnabled > ;
82
96
83
97
const plansList : PlanSlug [ ] = [
84
98
PLAN_FREE ,
@@ -105,8 +119,10 @@ describe( '<PlanNotice /> Tests', () => {
105
119
mIsRequestingSitePlans . mockImplementation ( ( ) => true ) ;
106
120
mGetCurrentUserCurrencyCode . mockImplementation ( ( ) => 'USD' ) ;
107
121
mUsePlanUpgradeCreditsApplicable . mockImplementation ( ( ) => 100 ) ;
122
+ mUseDomainToPlanCreditsApplicable . mockImplementation ( ( ) => 100 ) ;
108
123
mGetByPurchaseId . mockImplementation ( ( ) => ( { isInAppPurchase : false } ) as Purchase ) ;
109
124
mIsProPlan . mockImplementation ( ( ) => false ) ;
125
+ mIsEnabled . mockImplementation ( ( key ) => key !== 'domain-to-plan-credit' ) ;
110
126
} ) ;
111
127
112
128
test ( 'A contact site owner <PlanNotice /> should be shown no matter what other conditions are met, when the current site owner is not logged in, and the site plan is paid' , ( ) => {
@@ -164,11 +180,30 @@ describe( '<PlanNotice /> Tests', () => {
164
180
) ;
165
181
} ) ;
166
182
183
+ test ( 'A domain-to-plan credit <PlanNotice /> should be shown in a site where a domain has been purchased without a paid plan' , ( ) => {
184
+ mUsePlanUpgradeCreditsApplicable . mockImplementation ( ( ) => null ) ;
185
+ mUseDomainToPlanCreditsApplicable . mockImplementation ( ( ) => 1000 ) ;
186
+ mIsEnabled . mockImplementation ( ( key ) => key === 'domain-to-plan-credit' ) ;
187
+
188
+ renderWithProvider (
189
+ < PlanNotice
190
+ discountInformation = { { coupon : 'test' , discountEndDate : new Date ( ) } }
191
+ visiblePlans = { plansList }
192
+ isInSignup = { false }
193
+ siteId = { 32234 }
194
+ />
195
+ ) ;
196
+ expect ( screen . getByRole ( 'status' ) . textContent ) . toBe (
197
+ '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!'
198
+ ) ;
199
+ } ) ;
200
+
167
201
test ( 'A marketing message <PlanNotice /> when no other notices are available and marketing messages are available and the user is not in signup' , ( ) => {
168
202
mIsCurrentUserCurrentPlanOwner . mockImplementation ( ( ) => true ) ;
169
203
mIsCurrentPlanPaid . mockImplementation ( ( ) => true ) ;
170
204
mGetDiscountByName . mockImplementation ( ( ) => false ) ;
171
205
mUsePlanUpgradeCreditsApplicable . mockImplementation ( ( ) => null ) ;
206
+ mUseDomainToPlanCreditsApplicable . mockImplementation ( ( ) => null ) ;
172
207
mUseMarketingMessage . mockImplementation ( ( ) => [
173
208
false ,
174
209
[ { id : '12121' , text : 'An important marketing message' } ] ,
0 commit comments