@@ -18,8 +18,14 @@ const defaultCart = {
1818 variant : 'monthly' ,
1919 proratedNetPrice : 3.50 ,
2020 nextBookingDate : '2026-04-01' ,
21+ feature : {
22+ name : 'Pro Plan'
23+ } ,
2124 subscriptionChange : {
25+ type : 'upgrade' ,
2226 isIncludedInPluginLicense : false ,
27+ currentFeatureVariant : 'monthly' ,
28+ currentNetPrice : 2.99 ,
2329 currentFeature : {
2430 name : 'Basic Plan' ,
2531 priceModels : [ {
@@ -95,16 +101,112 @@ describe('sw-in-app-purchase-checkout-subscription-change', () => {
95101 expect ( wrapper . vm . isIncludedInPluginLicense ) . toBe ( true ) ;
96102 } ) ;
97103
98- it ( 'should compute getCurrentPrice from matching variant price model' , ( ) => {
99- expect ( wrapper . vm . getCurrentPrice ) . toContain ( '2.99' ) ;
104+ it ( 'should compute currentPrice from current net price' , ( ) => {
105+ expect ( wrapper . vm . currentPrice ) . toContain ( '2.99' ) ;
106+ } ) ;
107+
108+ it ( 'should compute currentPlanName from current feature' , ( ) => {
109+ expect ( wrapper . vm . currentPlanName ) . toBe ( 'Basic Plan' ) ;
110+ } ) ;
111+
112+ it ( 'should compute currentPlanDuration from currentFeatureVariant' , ( ) => {
113+ expect ( wrapper . vm . currentPlanDuration ) . toBe ( 'sw-in-app-purchase-price-box.duration.monthly' ) ;
114+ } ) ;
115+
116+ it ( 'should return null for currentPlanDuration when currentFeatureVariant is missing' , async ( ) => {
117+ wrapper = await createWrapper ( {
118+ cart : {
119+ ...defaultCart ,
120+ positions : [ {
121+ ...defaultCart . positions [ 0 ] ,
122+ subscriptionChange : {
123+ ...defaultCart . positions [ 0 ] . subscriptionChange ,
124+ currentFeatureVariant : undefined
125+ }
126+ } ]
127+ }
128+ } ) ;
129+
130+ expect ( wrapper . vm . currentPlanDuration ) . toBeNull ( ) ;
131+ } ) ;
132+
133+ it ( 'should compute newPlanName from feature name' , ( ) => {
134+ expect ( wrapper . vm . newPlanName ) . toBe ( 'Pro Plan' ) ;
135+ } ) ;
136+
137+ it ( 'should compute newPlanDuration from variant' , ( ) => {
138+ expect ( wrapper . vm . newPlanDuration ) . toBe ( 'sw-in-app-purchase-price-box.duration.monthly' ) ;
100139 } ) ;
101140
102- it ( 'should compute getCurrentPlanName from current feature' , ( ) => {
103- expect ( wrapper . vm . getCurrentPlanName ) . toBe ( 'Basic Plan' ) ;
141+ it ( 'should return null for newPlanDuration when variant is missing' , async ( ) => {
142+ wrapper = await createWrapper ( {
143+ cart : {
144+ ...defaultCart ,
145+ positions : [ {
146+ ...defaultCart . positions [ 0 ] ,
147+ variant : undefined
148+ } ]
149+ }
150+ } ) ;
151+
152+ expect ( wrapper . vm . newPlanDuration ) . toBeNull ( ) ;
104153 } ) ;
105154
106- it ( 'should compute formattedStartingDate from nextBookingDate' , ( ) => {
107- expect ( wrapper . vm . formattedStartingDate ) . toBeTruthy ( ) ;
155+ it ( 'should compute proratedNetPrice for upgrade' , ( ) => {
156+ expect ( wrapper . vm . proratedNetPrice ) . toContain ( '3.50' ) ;
157+ } ) ;
158+
159+ it ( 'should return zero proratedNetPrice for downgrade' , async ( ) => {
160+ wrapper = await createWrapper ( {
161+ cart : {
162+ ...defaultCart ,
163+ positions : [ {
164+ ...defaultCart . positions [ 0 ] ,
165+ subscriptionChange : {
166+ ...defaultCart . positions [ 0 ] . subscriptionChange ,
167+ type : 'downgrade'
168+ }
169+ } ]
170+ }
171+ } ) ;
172+
173+ expect ( wrapper . vm . proratedNetPrice ) . toContain ( '0.00' ) ;
174+ } ) ;
175+
176+ it ( 'should compute isNextBookingDateInDifferentYear as false for same year' , ( ) => {
177+ expect ( wrapper . vm . isNextBookingDateInDifferentYear ) . toBe ( false ) ;
178+ } ) ;
179+
180+ it ( 'should compute isNextBookingDateInDifferentYear as true for different year' , async ( ) => {
181+ wrapper = await createWrapper ( {
182+ cart : {
183+ ...defaultCart ,
184+ positions : [ {
185+ ...defaultCart . positions [ 0 ] ,
186+ nextBookingDate : '2099-01-01'
187+ } ]
188+ }
189+ } ) ;
190+
191+ expect ( wrapper . vm . isNextBookingDateInDifferentYear ) . toBe ( true ) ;
192+ } ) ;
193+
194+ it ( 'should include year in yearFormat when next booking date is in different year' , async ( ) => {
195+ wrapper = await createWrapper ( {
196+ cart : {
197+ ...defaultCart ,
198+ positions : [ {
199+ ...defaultCart . positions [ 0 ] ,
200+ nextBookingDate : '2099-01-01'
201+ } ]
202+ }
203+ } ) ;
204+
205+ expect ( wrapper . vm . yearFormat ) . toBe ( 'numeric' ) ;
206+ } ) ;
207+
208+ it ( 'should return undefined yearFormat when next booking date is in same year' , ( ) => {
209+ expect ( wrapper . vm . yearFormat ) . toBeUndefined ( ) ;
108210 } ) ;
109211
110212 it ( 'should not render access-grant-hint banner when not included in plugin license' , ( ) => {
@@ -137,8 +239,26 @@ describe('sw-in-app-purchase-checkout-subscription-change', () => {
137239 expect ( wrapper . find ( '.sw-in-app-purchase-checkout-subscription-change__divider' ) . exists ( ) ) . toBe ( true ) ;
138240 } ) ;
139241
140- it ( 'should render the info hint' , ( ) => {
242+ it ( 'should render the info hint for upgrade' , ( ) => {
243+ expect ( wrapper . find ( '.sw-in-app-purchase-checkout-subscription-change__info-hint' ) . exists ( ) ) . toBe ( true ) ;
244+ expect ( wrapper . vm . infoHint ) . toBeTruthy ( ) ;
245+ } ) ;
246+
247+ it ( 'should render the info hint for downgrade' , async ( ) => {
248+ wrapper = await createWrapper ( {
249+ cart : {
250+ ...defaultCart ,
251+ positions : [ {
252+ ...defaultCart . positions [ 0 ] ,
253+ subscriptionChange : {
254+ ...defaultCart . positions [ 0 ] . subscriptionChange ,
255+ type : 'downgrade'
256+ }
257+ } ]
258+ }
259+ } ) ;
260+
141261 expect ( wrapper . find ( '.sw-in-app-purchase-checkout-subscription-change__info-hint' ) . exists ( ) ) . toBe ( true ) ;
142- expect ( wrapper . find ( '.sw-in-app-purchase-checkout-subscription-change__info-hint' ) . text ( ) ) . toBeTruthy ( ) ;
262+ expect ( wrapper . vm . infoHint ) . toBeTruthy ( ) ;
143263 } ) ;
144264} ) ;
0 commit comments