0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Removed all tiers archive from portal tests to reduce relation between tests

refs TryGhost/Team#2667
This commit is contained in:
Elena Baidakova 2023-03-09 12:54:44 +04:00
parent 7539a681fe
commit 8b191a8d01
2 changed files with 88 additions and 89 deletions

View file

@ -28,7 +28,7 @@ test.describe('Portal', () => {
});
// impersonate the member on frontend
impersonateMember(page);
await impersonateMember(page);
// open portal
const portalTriggerButton = page.frameLocator('[data-testid="portal-trigger-frame"]').locator('[data-testid="portal-trigger-button"]');
@ -54,7 +54,7 @@ test.describe('Portal', () => {
const memberUrl = page.url();
// impersonate the member on frontend
impersonateMember(page);
await impersonateMember(page);
const portalTriggerButton = page.frameLocator('[data-testid="portal-trigger-frame"]').locator('[data-testid="portal-trigger-button"]');
const portalFrame = page.frameLocator('[data-testid="portal-popup-frame"]');
@ -64,13 +64,14 @@ test.describe('Portal', () => {
// turn off default newsletter subscription
const defaultNewsletterToggle = portalFrame.locator('[data-testid="default-newsletter-toggle"]');
expect(await defaultNewsletterToggle.isChecked()).toBeTruthy();
await expect(await defaultNewsletterToggle.isChecked()).toBeTruthy();
await defaultNewsletterToggle.click();
expect(await defaultNewsletterToggle.isChecked()).not.toBeTruthy();
await expect(await defaultNewsletterToggle.isChecked()).not.toBeTruthy();
// check that member's newsletters was updated in Admin
await page.waitForLoadState('networkidle');
await page.goto(memberUrl);
expect(await page.locator('[data-test-member-settings-switch] input[type=checkbox]').first().isChecked()).not.toBeTruthy();
await expect(await page.locator('[data-test-member-settings-switch] input[type=checkbox]').first().isChecked()).not.toBeTruthy();
});
test('can unsubscribe from all newsletters from account settings', async ({page}) => {
@ -88,7 +89,7 @@ test.describe('Portal', () => {
// impersonate the member on frontend
await page.goto(memberUrl);
impersonateMember(page);
await impersonateMember(page);
const portalTriggerButton = page.frameLocator('[data-testid="portal-trigger-frame"]').locator('[data-testid="portal-trigger-button"]');
const portalFrame = page.frameLocator('[data-testid="portal-popup-frame"]');
@ -100,11 +101,11 @@ test.describe('Portal', () => {
// check amount of newsletterss
const newsletters = await portalFrame.locator('[data-test-toggle-wrapper="true"]');
const count = await newsletters.count();
expect(count).toEqual(2);
await expect(count).toEqual(2);
// all newsletters should be activated
for (let i = 0; i < count; i++) {
expect(await newsletters.nth(i).locator('input[type="checkbox"]').isChecked()).toBeTruthy();
await expect(await newsletters.nth(i).locator('input[type="checkbox"]').isChecked()).toBeTruthy();
}
// unsubscribe from all emails
@ -112,22 +113,23 @@ test.describe('Portal', () => {
// all newsletters should be disabled
for (let i = 0; i < count; i++) {
expect(await newsletters.nth(i).locator('input[type="checkbox"]').isChecked()).not.toBeTruthy();
await expect(await newsletters.nth(i).locator('input[type="checkbox"]').isChecked()).not.toBeTruthy();
}
// check that member's newsletters was updated in Admin
await page.waitForLoadState('networkidle');
await page.goto(memberUrl);
// check amount of newsletters in member's profile in Admin
await page.waitForSelector('[data-test-member-settings-switch]');
const membersNewsletters = await page.locator('[data-test-member-settings-switch]');
const newslettersCount = await membersNewsletters.count();
expect(newslettersCount).toEqual(2);
await expect(newslettersCount).toEqual(2);
// all newsletters should be disabled
for (let i = 0; i < newslettersCount; i++) {
const isNewsletterChecked = await membersNewsletters.nth(i).locator('input[type="checkbox"]').isChecked();
expect(isNewsletterChecked).not.toBeTruthy();
await expect(isNewsletterChecked).not.toBeTruthy();
}
});
});

View file

@ -1,14 +1,60 @@
const {expect, test} = require('@playwright/test');
const {completeStripeSubscription, createMember, archiveAllTiers, createTier, impersonateMember} = require('../utils');
const {completeStripeSubscription, createMember, impersonateMember} = require('../utils');
test.describe('Portal', () => {
test.describe('Upgrade: Comped Member', () => {
test('allows comped member to upgrade to paid tier', async ({page}) => {
const tierName = 'The Local Test';
// create a new member
await page.goto('/ghost');
await createMember(page, {
name: 'Testy McTest',
email: 'testy+upgradecompedportal@example.com',
note: 'Testy McTest is a test member'
});
//get the url of the current member on admin
const memberUrl = page.url();
// Give member comped subscription
await page.locator('[data-test-button="add-complimentary"]').click();
await page.locator('[data-test-button="save-comp-tier"]').first().click({
delay: 500
});
await page.waitForLoadState('networkidle');
await impersonateMember(page);
const portalTriggerButton = page.frameLocator('[data-testid="portal-trigger-frame"]').locator('[data-testid="portal-trigger-button"]');
const portalFrame = page.frameLocator('[data-testid="portal-popup-frame"]');
//await page.pause();
// open portal, go to plans and click continue to select the first plan(yearly)
await portalTriggerButton.click();
await portalFrame.getByRole('button', {name: 'Change'}).click();
// select the tier for checkout (yearly)
await choseTierByName(portalFrame, tierName);
// complete stripe checkout
await completeStripeSubscription(page);
// open portal and check that member has been upgraded to paid tier
await portalTriggerButton.click();
await expect(portalFrame.getByText('$50.00/year')).toBeVisible();
await expect(portalFrame.getByRole('heading', {name: 'Billing info'})).toBeVisible();
await expect(portalFrame.getByText('**** **** **** 4242')).toBeVisible();
// check that member has been upgraded in admin and a tier exists for them
await page.goto(memberUrl);
await expect(page.locator('[data-test-tier]').first()).toBeVisible();
});
});
test.describe('Upgrade: Single Tier', () => {
let memberUrl;
const tier = {
name: 'Test tier',
monthlyPrice: 5,
yearlyPrice: 50
};
const tierName = 'The Local Test';
const member = {
name: 'Testy McTest',
email: 'testy+upgradeportal@example.com',
@ -16,23 +62,17 @@ test.describe('Portal', () => {
};
test('allows free member upgrade to paid tier', async ({page}) => {
// archive all existing tiers for fresh setup
await page.goto('/ghost');
await archiveAllTiers(page);
// create a new tier
await page.goto('/ghost');
await createTier(page, tier);
// create a new free member
await page.goto('/ghost');
await createMember(page, member);
//store the url of the member detail page
memberUrl = await page.url();
memberUrl = page.url();
// impersonate the member on frontend
impersonateMember(page);
await impersonateMember(page);
const portalTriggerButton = page.frameLocator('[data-testid="portal-trigger-frame"]').locator('[data-testid="portal-trigger-button"]');
const portalFrame = page.frameLocator('[data-testid="portal-popup-frame"]');
@ -43,15 +83,17 @@ test.describe('Portal', () => {
await expect(portalFrame.getByText('testy+upgradeportal@example.com')).toBeVisible();
// view plans button only shows for free member
await portalFrame.getByRole('button', {name: 'View plans'}).click();
// select the default tier for checkout (yearly)
await portalFrame.locator('[data-test-button="select-tier"]').first().click();
// select the tier for checkout (yearly)
await choseTierByName(portalFrame, tierName);
// complete stripe checkout
await completeStripeSubscription(page);
// open portal and check that member has been upgraded to paid tier
await portalTriggerButton.click();
// verify member's tier, price and card details
await expect(portalFrame.getByText('Test tier')).toBeVisible();
await expect(portalFrame.getByText(tierName)).toBeVisible();
await expect(portalFrame.getByText('$50.00/year')).toBeVisible();
await expect(portalFrame.getByText('**** **** **** 4242')).toBeVisible();
@ -60,7 +102,7 @@ test.describe('Portal', () => {
const tierCard = await page.locator('[data-test-tier]').first();
const tierText = await tierCard.locator('[data-test-text="tier-name"]');
await expect(tierCard).toBeVisible();
await expect(tierText, 'Where is tier text').toHaveText(/Test tier/);
await expect(tierText, 'Where is tier text').toHaveText(new RegExp(tierName));
});
test('allows member to switch plans', async ({page}) => {
@ -68,7 +110,7 @@ test.describe('Portal', () => {
await page.goto(memberUrl);
// impersonate the member on frontend
impersonateMember(page);
await impersonateMember(page);
const portalTriggerButton = page.frameLocator('[data-testid="portal-trigger-frame"]').locator('[data-testid="portal-trigger-button"]');
const portalFrame = page.frameLocator('[data-testid="portal-popup-frame"]');
@ -77,79 +119,34 @@ test.describe('Portal', () => {
await portalTriggerButton.click();
// test member can switch to monthly plan from yearly
// await portalFrame.getByRole('button', {name: 'Change'}).click();
await portalFrame.locator('[data-test-button="change-plan"]').click();
// await portalFrame.getByRole('button', {name: 'Monthly'}).click();
await portalFrame.locator('[data-test-button="switch-monthly"]').click();
// await portalFrame.locator('.gh-portal-btn-product .gh-portal-btn').first().click();
// select the monthly plan
await portalFrame.locator('[data-test-button="select-tier"]').first().click();
// await portalFrame.getByRole('button', {name: 'Confirm'}).click();
await choseTierByName(portalFrame, tierName);
// confirm the switch
await portalFrame.locator('[data-test-button="confirm-action"]').first().click();
// verify member has switched to monthly plan
await expect(portalFrame.getByText('Test tier')).toBeVisible({timeout: 10000});
await expect(portalFrame.getByText('$5.00/month')).toBeVisible({timeout: 10000});
await expect(portalFrame.getByText(tierName)).toBeVisible();
await expect(portalFrame.getByText('$5.00/month')).toBeVisible();
// test member can switch back to yearly
await portalFrame.locator('[data-test-button="change-plan"]').click();
await portalFrame.locator('[data-test-button="switch-yearly"]').click();
// select the monthly plan
await portalFrame.locator('[data-test-button="select-tier"]').first().click();
await choseTierByName(portalFrame, tierName);
// confirm the switch
await portalFrame.locator('[data-test-button="confirm-action"]').first().click();
// verify member has switched to yearly plan, timeout added to allow for delays
await expect(portalFrame.getByText('Test tier')).toBeVisible({timeout: 10000});
await expect(portalFrame.getByText('$50.00/year')).toBeVisible({timeout: 10000});
});
test('allows comped member to upgrade to paid tier', async ({page}) => {
// create a new free member
await createMember(page, {
name: 'Testy McTest',
email: 'testy+upgradecompedportal@example.com',
note: 'Testy McTest is a test member'
});
//get the url of the current member on admin
memberUrl = await page.url();
// Give member comped subscription
await page.locator('[data-test-button="add-complimentary"]').click();
await page.locator('[data-test-button="save-comp-tier"]').first().click({
delay: 500
});
// open member impersonation modal
await page.locator('[data-test-button="member-actions"]').click();
await page.locator('[data-test-button="impersonate"]').click();
await page.locator('[data-test-button="copy-impersonate-link"]').click();
await page.waitForSelector('[data-test-button="copy-impersonate-link"] span:has-text("Link copied")');
// get impersonation link from input and redirect to it
const link = await page.locator('[data-test-input="member-signin-url"]').inputValue();
await page.goto(link);
const portalTriggerButton = page.frameLocator('[data-testid="portal-trigger-frame"]').locator('[data-testid="portal-trigger-button"]');
const portalFrame = page.frameLocator('[data-testid="portal-popup-frame"]');
// open portal, go to plans and click continue to select the first plan(yearly)
await portalTriggerButton.click();
await portalFrame.getByRole('button', {name: 'Change'}).click();
await portalFrame.locator('[data-test-button="select-tier"]').first().click();
// complete stripe checkout
await completeStripeSubscription(page);
// open portal and check that member has been upgraded to paid tier
await portalTriggerButton.click();
await expect(portalFrame.getByText('$50.00/year')).toBeVisible({timeout: 10000});
await expect(portalFrame.getByRole('heading', {name: 'Billing info'})).toBeVisible({timeout: 10000});
await expect(portalFrame.getByText('**** **** **** 4242')).toBeVisible({timeout: 10000});
// check that member has been upgraded in admin and a tier exists for them
await page.goto(memberUrl);
await expect(page.locator('[data-test-tier]').first()).toBeVisible({timeout: 10000});
await expect(portalFrame.getByText(tierName)).toBeVisible();
await expect(portalFrame.getByText('$50.00/year')).toBeVisible();
});
});
});
async function choseTierByName(portalFrame, tierName) {
const portalTierCard = await portalFrame.locator('[data-test-tier="paid"]').filter({hasText: tierName}).first();
await portalTierCard.locator('[data-test-button="select-tier"]').click();
}