From c0500c1a408ba61bdcdc4d68b5f365fbb35539ac Mon Sep 17 00:00:00 2001 From: Rishabh Date: Fri, 18 Feb 2022 00:26:05 +0530 Subject: [PATCH] Added offer link tests with portal button disabled closes https://github.com/TryGhost/Team/issues/1323 --- ghost/portal/src/tests/SignupFlow.test.js | 76 +++++++++++++++++++++- ghost/portal/src/tests/UpgradeFlow.test.js | 43 +++++++++++- 2 files changed, 115 insertions(+), 4 deletions(-) diff --git a/ghost/portal/src/tests/SignupFlow.test.js b/ghost/portal/src/tests/SignupFlow.test.js index 0b4686bbbc..91d7e8ae38 100644 --- a/ghost/portal/src/tests/SignupFlow.test.js +++ b/ghost/portal/src/tests/SignupFlow.test.js @@ -31,8 +31,8 @@ const offerSetup = async ({site, member = null, offer}) => { ); - const triggerButtonFrame = await utils.findByTitle(/portal-trigger/i); - const popupFrame = utils.queryByTitle(/portal-popup/i); + const popupFrame = await utils.findByTitle(/portal-popup/i); + const triggerButtonFrame = await utils.queryByTitle(/portal-trigger/i); const popupIframeDocument = popupFrame.contentDocument; const emailInput = within(popupIframeDocument).queryByLabelText(/email/i); const nameInput = within(popupIframeDocument).queryByLabelText(/name/i); @@ -481,6 +481,42 @@ describe('Signup', () => { window.location.hash = ''; }); + + test('to an offer via link with portal disabled', async () => { + let site = { + ...FixtureSite.singleTier.basic, + portal_button: false + }; + window.location.hash = `#/portal/offers/${FixtureOffer.id}`; + const { + ghostApi, popupFrame, triggerButtonFrame, emailInput, nameInput, signinButton, submitButton, + siteTitle, + offerName, offerDescription + } = await offerSetup({ + site, + offer: FixtureOffer + }); + let planId = FixtureSite.singleTier.basic.products.find(p => p.type === 'paid').monthlyPrice.id; + let offerId = FixtureOffer.id; + expect(popupFrame).toBeInTheDocument(); + expect(triggerButtonFrame).not.toBeInTheDocument(); + expect(siteTitle).not.toBeInTheDocument(); + expect(emailInput).not.toBeInTheDocument(); + expect(nameInput).not.toBeInTheDocument(); + expect(signinButton).not.toBeInTheDocument(); + expect(submitButton).not.toBeInTheDocument(); + expect(offerName).not.toBeInTheDocument(); + expect(offerDescription).not.toBeInTheDocument(); + + expect(ghostApi.member.checkoutPlan).toHaveBeenLastCalledWith({ + email: undefined, + name: undefined, + offerId: offerId, + plan: planId + }); + + window.location.hash = ''; + }); }); }); @@ -666,5 +702,41 @@ describe('Signup', () => { window.location.hash = ''; }); + + test('to an offer via link with portal disabled', async () => { + let site = { + ...FixtureSite.multipleTiers.basic, + portal_button: false + }; + window.location.hash = `#/portal/offers/${FixtureOffer.id}`; + const { + ghostApi, popupFrame, triggerButtonFrame, emailInput, nameInput, signinButton, submitButton, + siteTitle, + offerName, offerDescription + } = await offerSetup({ + site, + offer: FixtureOffer + }); + let planId = FixtureSite.singleTier.basic.products.find(p => p.type === 'paid').monthlyPrice.id; + let offerId = FixtureOffer.id; + expect(popupFrame).toBeInTheDocument(); + expect(triggerButtonFrame).not.toBeInTheDocument(); + expect(siteTitle).not.toBeInTheDocument(); + expect(emailInput).not.toBeInTheDocument(); + expect(nameInput).not.toBeInTheDocument(); + expect(signinButton).not.toBeInTheDocument(); + expect(submitButton).not.toBeInTheDocument(); + expect(offerName).not.toBeInTheDocument(); + expect(offerDescription).not.toBeInTheDocument(); + + expect(ghostApi.member.checkoutPlan).toHaveBeenLastCalledWith({ + email: undefined, + name: undefined, + offerId: offerId, + plan: planId + }); + + window.location.hash = ''; + }); }); }); diff --git a/ghost/portal/src/tests/UpgradeFlow.test.js b/ghost/portal/src/tests/UpgradeFlow.test.js index f758c2fd32..c8bf98fd8b 100644 --- a/ghost/portal/src/tests/UpgradeFlow.test.js +++ b/ghost/portal/src/tests/UpgradeFlow.test.js @@ -31,8 +31,8 @@ const offerSetup = async ({site, member = null, offer}) => { ); - const triggerButtonFrame = await utils.findByTitle(/portal-trigger/i); - const popupFrame = utils.queryByTitle(/portal-popup/i); + const popupFrame = await utils.findByTitle(/portal-popup/i); + const triggerButtonFrame = utils.queryByTitle(/portal-trigger/i); const popupIframeDocument = popupFrame.contentDocument; const emailInput = within(popupIframeDocument).queryByLabelText(/email/i); const nameInput = within(popupIframeDocument).queryByLabelText(/name/i); @@ -281,6 +281,45 @@ describe('Logged-in free member', () => { window.location.hash = ''; }); + + test('to an offer via link with portal disabled', async () => { + let site = { + ...FixtureSite.singleTier.basic, + portal_button: false + }; + + window.location.hash = `#/portal/offers/${FixtureOffer.id}`; + const { + ghostApi, popupFrame, triggerButtonFrame, emailInput, nameInput, signinButton, submitButton, + siteTitle, + offerName, offerDescription + } = await offerSetup({ + site: site, + member: FixtureMember.altFree, + offer: FixtureOffer + }); + let planId = FixtureSite.singleTier.basic.products.find(p => p.type === 'paid').monthlyPrice.id; + let offerId = FixtureOffer.id; + expect(popupFrame).toBeInTheDocument(); + expect(triggerButtonFrame).not.toBeInTheDocument(); + expect(siteTitle).not.toBeInTheDocument(); + expect(emailInput).not.toBeInTheDocument(); + expect(nameInput).not.toBeInTheDocument(); + expect(signinButton).not.toBeInTheDocument(); + expect(submitButton).not.toBeInTheDocument(); + expect(offerName).not.toBeInTheDocument(); + expect(offerDescription).not.toBeInTheDocument(); + + expect(ghostApi.member.checkoutPlan).toHaveBeenLastCalledWith({ + metadata: { + checkoutType: 'upgrade' + }, + offerId: offerId, + plan: planId + }); + + window.location.hash = ''; + }); }); });