@@ -142,19 +142,6 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withBilling] })('pricing tabl
142142 await newFakeUser . deleteIfExists ( ) ;
143143 } ) ;
144144
145- // test('can manage and cancel subscription', async ({ page, context }) => {
146- // const u = createTestUtils({ app, page, context });
147- // await u.po.signIn.goTo();
148- // await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeUser.email, password: fakeUser.password });
149- // await u.po.page.goToRelative('/pricing-table');
150-
151- // await u.po.pricingTable.waitForMounted();
152- // await u.po.pricingTable.clickManageSubscription();
153- // await u.po.page.getByRole('button', { name: 'Cancel subscription' }).click();
154- // await u.po.page.getByRole('alertdialog').getByRole('button', { name: 'Cancel subscription' }).click();
155- // await expect(u.po.page.getByRole('button', { name: /resubscribe|re-subscribe/i }).first()).toBeVisible();
156- // });
157-
158145 test . describe ( 'redirects' , ( ) => {
159146 test ( 'default navigates to afterSignInUrl' , async ( { page, context } ) => {
160147 const u = createTestUtils ( { app, page, context } ) ;
@@ -260,6 +247,51 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withBilling] })('pricing tabl
260247 await fakeUser . deleteIfExists ( ) ;
261248 } ) ;
262249
250+ test ( 'can unsubscribe from a plan' , async ( { page, context } ) => {
251+ const u = createTestUtils ( { app, page, context } ) ;
252+
253+ const fakeUser = u . services . users . createFakeUser ( ) ;
254+ await u . services . users . createBapiUser ( fakeUser ) ;
255+
256+ await u . po . signIn . goTo ( ) ;
257+ await u . po . signIn . signInWithEmailAndInstantPassword ( { email : fakeUser . email , password : fakeUser . password } ) ;
258+ await u . po . page . goToRelative ( '/user' ) ;
259+
260+ await u . po . userProfile . waitForMounted ( ) ;
261+ await u . po . userProfile . switchToBillingTab ( ) ;
262+ await expect ( u . po . page . getByText ( / F r e e / i) ) . toBeVisible ( ) ;
263+ await u . po . page . getByRole ( 'button' , { name : 'Switch plans' } ) . click ( ) ;
264+ await u . po . pricingTable . startCheckout ( { planSlug : 'plus' } ) ;
265+ await u . po . checkout . waitForMounted ( ) ;
266+ await u . po . checkout . fillTestCard ( ) ;
267+ await u . po . checkout . clickPayOrSubscribe ( ) ;
268+ await expect ( u . po . page . getByText ( 'Payment was successful!' ) ) . toBeVisible ( ) ;
269+
270+ await u . po . checkout . confirmAndContinue ( ) ;
271+ await u . po . page . locator ( '.cl-headerBackLink' ) . getByText ( 'Plans' ) . click ( ) ;
272+
273+ await u . page . waitForTimeout ( 1000 ) ;
274+ await expect ( u . po . page . locator ( '.cl-profileSectionContent__subscriptionsList' ) . getByText ( 'Plus' ) ) . toBeVisible ( ) ;
275+ await u . po . page . getByRole ( 'button' , { name : 'Manage subscription' } ) . first ( ) . click ( ) ;
276+ await u . po . subscriptionDetails . waitForMounted ( ) ;
277+ await u . po . subscriptionDetails . root . locator ( '.cl-menuButtonEllipsisBordered' ) . click ( ) ;
278+ await u . po . subscriptionDetails . root . getByText ( 'Cancel subscription' ) . click ( ) ;
279+ await u . po . subscriptionDetails . root . locator ( '.cl-drawerConfirmationRoot' ) . waitFor ( { state : 'visible' } ) ;
280+ await u . po . subscriptionDetails . root . getByText ( 'Cancel subscription' ) . click ( ) ;
281+ await u . po . subscriptionDetails . waitForUnmounted ( ) ;
282+
283+ // Verify the Free plan with Upcoming status exists
284+ await expect (
285+ u . po . page
286+ . locator ( '.cl-profileSectionContent__subscriptionsList' )
287+ . getByText ( 'Free' )
288+ . locator ( 'xpath=..' )
289+ . getByText ( 'Upcoming' ) ,
290+ ) . toBeVisible ( ) ;
291+
292+ await fakeUser . deleteIfExists ( ) ;
293+ } ) ;
294+
263295 test ( 'checkout always revalidates on open' , async ( { page, context } ) => {
264296 const u = createTestUtils ( { app, page, context } ) ;
265297
0 commit comments