2023-10-13 14:42:39 +03:00
|
|
|
const {expect} = require('@playwright/test');
|
|
|
|
const test = require('../fixtures/ghost-test');
|
2023-10-09 10:12:46 +03:00
|
|
|
const {createTier, createOffer, getUniqueName, getSlug, goToMembershipPage, openTierModal} = require('../utils');
|
2022-12-06 15:05:58 +03:00
|
|
|
|
2022-12-06 15:18:16 +03:00
|
|
|
test.describe('Admin', () => {
|
|
|
|
test.describe('Tiers', () => {
|
2023-01-11 14:44:34 +03:00
|
|
|
test('Default tier should be $5mo / $50yr', async ({page}) => {
|
2023-10-09 10:12:46 +03:00
|
|
|
const defaultTier = 'default-product';
|
2023-01-11 14:44:34 +03:00
|
|
|
await goToMembershipPage(page);
|
2023-10-09 10:12:46 +03:00
|
|
|
const tierModal = await openTierModal(page, {slug: defaultTier});
|
2023-01-11 14:44:34 +03:00
|
|
|
|
|
|
|
await test.step('Default tier should be $5mo / $50yr', async () => {
|
2023-10-09 10:12:46 +03:00
|
|
|
await expect(tierModal.getByLabel('Monthly price')).toHaveValue('5');
|
|
|
|
await expect(tierModal.getByLabel('Yearly price')).toHaveValue('50');
|
2023-01-11 14:44:34 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-12-06 15:18:16 +03:00
|
|
|
test('Can create a Tier and Offer', async ({page}) => {
|
|
|
|
await page.goto('/ghost');
|
2023-01-11 10:35:55 +03:00
|
|
|
const tierName = getUniqueName('New Test Tier');
|
2022-12-06 15:18:16 +03:00
|
|
|
await createTier(page, {
|
|
|
|
name: tierName,
|
|
|
|
monthlyPrice: 5,
|
|
|
|
yearlyPrice: 50
|
|
|
|
});
|
|
|
|
const offerName = await createOffer(page, {
|
|
|
|
name: 'Get 5% Off!',
|
|
|
|
tierName,
|
2022-12-07 07:29:05 +03:00
|
|
|
offerType: 'discount',
|
|
|
|
amount: 5
|
2022-12-06 15:18:16 +03:00
|
|
|
});
|
2022-12-06 15:05:58 +03:00
|
|
|
|
2023-01-11 10:35:55 +03:00
|
|
|
await test.step('Check that offers and tiers are available on Offers page', async () => {
|
|
|
|
await page.locator('[data-test-nav="offers"]').click();
|
|
|
|
await page.waitForSelector('[data-test-offers-list]');
|
|
|
|
await expect(page.locator('[data-test-offers-list]')).toContainText(tierName);
|
|
|
|
await expect(page.locator('[data-test-offers-list]')).toContainText(offerName);
|
|
|
|
});
|
2022-12-06 15:18:16 +03:00
|
|
|
});
|
2023-01-11 10:35:55 +03:00
|
|
|
|
2022-12-07 19:26:02 +03:00
|
|
|
test('Can create additional Tier', async ({page}) => {
|
|
|
|
await page.goto('/ghost');
|
2023-01-11 10:35:55 +03:00
|
|
|
const tierName = getUniqueName('New Test Tier');
|
2022-12-07 19:26:02 +03:00
|
|
|
const enableInPortal = false;
|
|
|
|
await createTier(page, {
|
|
|
|
name: tierName,
|
2023-01-03 20:59:33 +03:00
|
|
|
monthlyPrice: 100, // ordered by price, this should be the most expensive so we know it's last
|
|
|
|
yearlyPrice: 1000
|
2022-12-07 19:26:02 +03:00
|
|
|
}, enableInPortal);
|
2023-01-03 20:59:33 +03:00
|
|
|
|
2023-01-11 14:44:34 +03:00
|
|
|
await goToMembershipPage(page);
|
2022-12-07 19:26:02 +03:00
|
|
|
|
2023-01-11 14:44:34 +03:00
|
|
|
await test.step('Created tier should be in Portal settings and not selected', async () => {
|
2023-10-09 10:12:46 +03:00
|
|
|
await page.getByTestId('portal').getByRole('button', {name: 'Customize'}).click();
|
|
|
|
|
|
|
|
const portalSettings = page.getByTestId('portal-modal');
|
|
|
|
|
|
|
|
await portalSettings.getByLabel(tierName).first().waitFor();
|
|
|
|
|
|
|
|
await expect(portalSettings.getByLabel(tierName).first()).not.toBeChecked();
|
2023-01-11 10:35:55 +03:00
|
|
|
});
|
2022-12-07 19:26:02 +03:00
|
|
|
});
|
2023-01-11 10:35:55 +03:00
|
|
|
|
2022-12-08 19:40:25 +03:00
|
|
|
test('Can update Tier', async ({page}) => {
|
|
|
|
await page.goto('/ghost');
|
2023-01-11 10:35:55 +03:00
|
|
|
const tierName = getUniqueName('New Test Tier');
|
2023-10-09 10:12:46 +03:00
|
|
|
const slug = getSlug(tierName);
|
2023-01-11 10:35:55 +03:00
|
|
|
const updatedTierName = getUniqueName('Updated Test Tier Name');
|
2022-12-08 19:40:25 +03:00
|
|
|
const updatedMonthlyPrice = '66';
|
|
|
|
const updatedYearlyPrice = '666';
|
|
|
|
const updatedDescription = 'Updated description text';
|
|
|
|
await createTier(page, {
|
|
|
|
name: tierName,
|
|
|
|
monthlyPrice: 5,
|
|
|
|
yearlyPrice: 50
|
2023-01-11 12:53:07 +03:00
|
|
|
});
|
2022-12-08 19:40:25 +03:00
|
|
|
|
2023-01-11 14:44:34 +03:00
|
|
|
await goToMembershipPage(page);
|
2023-10-09 10:12:46 +03:00
|
|
|
const tierModal = await openTierModal(page, {slug});
|
2022-12-08 19:40:25 +03:00
|
|
|
|
2023-01-11 10:35:55 +03:00
|
|
|
await test.step('Open modal and edit tier information', async () => {
|
2023-10-09 10:12:46 +03:00
|
|
|
await tierModal.getByLabel('Name').fill(updatedTierName);
|
|
|
|
await tierModal.getByLabel('Description').fill(updatedDescription);
|
|
|
|
await tierModal.getByLabel('Monthly price').fill(updatedMonthlyPrice);
|
|
|
|
await tierModal.getByLabel('Yearly price').fill(updatedYearlyPrice);
|
|
|
|
await tierModal.getByRole('button', {name: 'Save & close'}).click();
|
2023-01-11 10:35:55 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
const portalFrame = await test.step('Go to website and open portal', async () => {
|
|
|
|
await page.goto('/');
|
|
|
|
const portalTriggerButton = page.frameLocator('[data-testid="portal-trigger-frame"]').locator('[data-testid="portal-trigger-button"]');
|
|
|
|
const frame = page.frameLocator('[data-testid="portal-popup-frame"]');
|
|
|
|
await portalTriggerButton.click();
|
|
|
|
|
|
|
|
return frame;
|
|
|
|
});
|
|
|
|
|
|
|
|
const portalTierCard = await test.step('Find the updated tier card', async () => {
|
|
|
|
await portalFrame.locator('[data-test-tier="paid"]').filter({hasText: updatedTierName}).first().isVisible();
|
|
|
|
const card = portalFrame.locator('[data-test-tier="paid"]').filter({hasText: updatedTierName}).first();
|
|
|
|
await expect(card).toBeVisible();
|
|
|
|
|
|
|
|
return card;
|
|
|
|
});
|
|
|
|
|
|
|
|
await test.step('Check yearly price and description', async () => {
|
|
|
|
await expect(portalTierCard.locator('.amount').first()).toHaveText(updatedYearlyPrice);
|
|
|
|
await expect(portalTierCard.locator('.gh-portal-product-description').first()).toHaveText(updatedDescription);
|
|
|
|
});
|
|
|
|
|
|
|
|
await test.step('Check monthly price', async () => {
|
|
|
|
await portalFrame.locator('[data-test-button="switch-monthly"]').click();
|
2023-10-09 10:12:46 +03:00
|
|
|
await expect(portalTierCard.getByText('/month')).toBeVisible();
|
2023-01-11 10:35:55 +03:00
|
|
|
await expect(portalTierCard.locator('.amount').first()).toHaveText(updatedMonthlyPrice);
|
|
|
|
});
|
2022-12-08 19:40:25 +03:00
|
|
|
});
|
2023-01-11 12:53:07 +03:00
|
|
|
|
2023-10-09 10:12:46 +03:00
|
|
|
// TODO: Add something more useful to this, e.g. checking in the portal
|
2023-01-11 12:53:07 +03:00
|
|
|
test('Can archive and unarchive a Tier', async ({page}) => {
|
|
|
|
await page.goto('/ghost');
|
|
|
|
const tierName = getUniqueName('Archive Tier');
|
2023-10-09 10:12:46 +03:00
|
|
|
const slug = getSlug(tierName);
|
2023-01-11 12:53:07 +03:00
|
|
|
await createTier(page, {
|
|
|
|
name: tierName,
|
|
|
|
monthlyPrice: 5,
|
|
|
|
yearlyPrice: 50
|
|
|
|
});
|
|
|
|
|
2023-01-11 14:44:34 +03:00
|
|
|
await goToMembershipPage(page);
|
2023-01-11 12:53:07 +03:00
|
|
|
await test.step('Archive tier', async () => {
|
2023-10-09 10:12:46 +03:00
|
|
|
const tierModal = await openTierModal(page, {slug});
|
|
|
|
await tierModal.getByRole('button', {name: 'Archive tier'}).click();
|
|
|
|
await page.getByTestId('confirmation-modal').getByRole('button', {name: 'Archive'}).click();
|
|
|
|
await tierModal.getByRole('button', {name: 'Save & close'}).click();
|
2023-01-11 12:53:07 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
await test.step('Archived tier should not be available in active tiers', async () => {
|
2023-10-09 10:12:46 +03:00
|
|
|
await expect(page.locator(`[data-testid="tier-card"][data-tier="${slug}"]`)).toBeHidden();
|
2023-01-11 12:53:07 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
await test.step('Archived tier should be available in archived tiers', async () => {
|
2023-10-09 10:12:46 +03:00
|
|
|
await page.getByTestId('tiers').getByRole('tab', {name: 'Archived'}).click();
|
|
|
|
await expect(page.locator(`[data-testid="tier-card"][data-tier="${slug}"]`)).toBeVisible();
|
2023-01-11 12:53:07 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
await test.step('Archived tier should not be available in portal settings', async () => {
|
2023-10-09 10:12:46 +03:00
|
|
|
await page.getByTestId('portal').getByRole('button', {name: 'Customize'}).click();
|
|
|
|
|
|
|
|
const portalSettings = page.getByTestId('portal-modal');
|
|
|
|
|
|
|
|
await portalSettings.locator('input[type=checkbox]').first().waitFor();
|
|
|
|
|
|
|
|
await expect(portalSettings.getByLabel(tierName).first()).toBeHidden();
|
|
|
|
|
|
|
|
await portalSettings.getByRole('button', {name: 'Close'}).click();
|
2023-01-11 12:53:07 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
await test.step('Unarchive tier', async () => {
|
2023-10-09 10:12:46 +03:00
|
|
|
const tierModal = await openTierModal(page, {slug});
|
|
|
|
await tierModal.getByRole('button', {name: 'Reactivate tier'}).click();
|
|
|
|
await page.getByTestId('confirmation-modal').getByRole('button', {name: 'Reactivate'}).click();
|
|
|
|
await tierModal.getByRole('button', {name: 'Save & close'}).click();
|
2023-01-11 12:53:07 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
await test.step('Unarchived tier should be available in active tiers', async () => {
|
2023-10-09 10:12:46 +03:00
|
|
|
await page.getByTestId('tiers').getByRole('tab', {name: 'Active'}).click();
|
|
|
|
await expect(page.locator(`[data-testid="tier-card"][data-tier="${slug}"]`)).toBeVisible();
|
2023-01-11 12:53:07 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
await test.step('Unarchived tier should be available in portal settings', async () => {
|
2023-10-09 10:12:46 +03:00
|
|
|
await page.getByTestId('portal').getByRole('button', {name: 'Customize'}).click();
|
|
|
|
|
|
|
|
const portalSettings = page.getByTestId('portal-modal');
|
|
|
|
|
|
|
|
await portalSettings.locator('input[type=checkbox]').first().waitFor();
|
|
|
|
|
|
|
|
await expect(portalSettings.getByLabel(tierName).first()).toBeVisible();
|
|
|
|
|
|
|
|
await portalSettings.getByRole('button', {name: 'Close'}).click();
|
2023-01-11 12:53:07 +03:00
|
|
|
});
|
|
|
|
});
|
2022-12-06 15:05:58 +03:00
|
|
|
});
|
|
|
|
});
|