Extracted Playwright tests into separate files

- we should start to keep tests grouped by their area, so first we split
  by Admin tests and then Portal tests, and within that we split into
  setup/Tiers/Offers etc
This commit is contained in:
Daniel Lockyer 2022-12-06 19:05:58 +07:00
parent b68686fe9c
commit 97e5ca1de6
No known key found for this signature in database
7 changed files with 95 additions and 90 deletions

View File

@ -1,42 +0,0 @@
const {expect, test} = require('@playwright/test');
const {setupGhost, createTier, createOffer} = require('./utils');
test.describe('Ghost Admin', () => {
test('Loads admin', async ({page}) => {
const response = await page.goto('/ghost');
expect(response.status()).toEqual(200);
});
test('Is setup correctly', async ({page}) => {
await page.goto('/ghost');
await expect(page.locator('.gh-nav-menu-details-sitetitle')).toHaveText(/The Local Test/);
});
test('Has a set of posts', async ({page}) => {
await page.goto('/ghost');
await page.locator('.gh-nav a[href="#/posts/"]').click();
await page.locator('.gh-post-list-title').first().click();
await page.locator('.settings-menu-toggle').click();
await expect(page.getByPlaceholder('YYYY-MM-DD')).toHaveValue(/[0-9]{4}-[0-9]{2}-[0-9]{2}/);
});
test('Can create a tier and offer', async ({page}) => {
await page.goto('/ghost');
const tierName = 'New Test Tier';
await createTier(page, {
name: tierName,
monthlyPrice: 5,
yearlyPrice: 50
});
const offerName = await createOffer(page, {
name: 'Get 5% Off!',
tierName,
percentOff: 5
});
await page.locator('.gh-nav a[href="#/offers/"]').click();
await page.locator('.gh-offers-list').waitFor({state: 'visible', timeout: 1000});
await expect(page.locator('.gh-offers-list')).toContainText(tierName);
await expect(page.locator('.gh-offers-list')).toContainText(offerName);
});
});

View File

@ -0,0 +1,11 @@
const {expect, test} = require('@playwright/test');
test.describe('Posts', () => {
test('Has a set of posts', async ({page}) => {
await page.goto('/ghost');
await page.locator('.gh-nav a[href="#/posts/"]').click();
await page.locator('.gh-post-list-title').first().click();
await page.locator('.settings-menu-toggle').click();
await expect(page.getByPlaceholder('YYYY-MM-DD')).toHaveValue(/[0-9]{4}-[0-9]{2}-[0-9]{2}/);
});
});

View File

@ -0,0 +1,13 @@
const {expect, test} = require('@playwright/test');
test.describe('Setup', () => {
test('Loads Admin', async ({page}) => {
const response = await page.goto('/ghost');
expect(response.status()).toEqual(200);
});
test('Is setup correctly', async ({page}) => {
await page.goto('/ghost');
await expect(page.locator('.gh-nav-menu-details-sitetitle')).toHaveText(/The Local Test/);
});
});

View File

@ -0,0 +1,24 @@
const {expect, test} = require('@playwright/test');
const {createTier, createOffer} = require('../utils');
test.describe('Tiers', () => {
test('Can create a Tier and Offer', async ({page}) => {
await page.goto('/ghost');
const tierName = 'New Test Tier';
await createTier(page, {
name: tierName,
monthlyPrice: 5,
yearlyPrice: 50
});
const offerName = await createOffer(page, {
name: 'Get 5% Off!',
tierName,
percentOff: 5
});
await page.locator('.gh-nav a[href="#/offers/"]').click();
await page.locator('.gh-offers-list').waitFor({state: 'visible', timeout: 1000});
await expect(page.locator('.gh-offers-list')).toContainText(tierName);
await expect(page.locator('.gh-offers-list')).toContainText(offerName);
});
});

View File

@ -1,48 +0,0 @@
const {expect, test} = require('@playwright/test');
const {setupGhost, deleteAllMembers, createTier, createOffer, completeStripeSubscription} = require('./utils');
test.describe('Ghost Frontend', () => {
test.describe('Basic frontend', () => {
test('Loads the homepage', async ({page}) => {
const response = await page.goto('/');
expect(response.status()).toEqual(200);
});
});
test.describe('Portal flows', () => {
test('Uses an offer successfully', async ({page}) => {
page.goto('/ghost');
await deleteAllMembers(page);
const tierName = 'Portal Tier';
await createTier(page, {
name: tierName,
monthlyPrice: 6,
yearlyPrice: 60
});
const offerName = await createOffer(page, {
name: 'Black Friday Special',
tierName: tierName,
percentOff: 10
});
await page.locator('.gh-offers-list .gh-list-row').filter({hasText: offerName}).click();
const portalUrl = await page.locator('input#url').inputValue();
await page.goto(portalUrl);
const portalFrame = page.frameLocator('#ghost-portal-root div iframe');
await portalFrame.locator('#input-name').fill('Testy McTesterson');
await portalFrame.locator('#input-email').fill('testy@example.com');
await portalFrame.getByRole('button', {name: 'Continue'}).click();
await completeStripeSubscription(page);
await page.waitForSelector('h1.site-title', {state: 'visible'});
await page.goto('/ghost');
await page.locator('.gh-nav a[href="#/members/"]').click();
// 1 member, should be Testy, on Portal Tier
await expect(page.getByRole('link', {name: 'Testy McTesterson testy@example.com'}), 'Should have 1 paid member').toBeVisible();
await expect(page.getByRole('link', {name: tierName}), `Paid member should be on ${tierName}`).toBeVisible();
});
});
});

View File

@ -0,0 +1,8 @@
const {expect, test} = require('@playwright/test');
test.describe('Frontend', () => {
test('Loads the homepage', async ({page}) => {
const response = await page.goto('/');
expect(response.status()).toEqual(200);
});
});

View File

@ -0,0 +1,39 @@
const {expect, test} = require('@playwright/test');
const {deleteAllMembers, createTier, createOffer, completeStripeSubscription} = require('../utils');
test.describe('Offers', () => {
test('Uses an offer successfully', async ({page}) => {
page.goto('/ghost');
await deleteAllMembers(page);
const tierName = 'Portal Tier';
await createTier(page, {
name: tierName,
monthlyPrice: 6,
yearlyPrice: 60
});
const offerName = await createOffer(page, {
name: 'Black Friday Special',
tierName: tierName,
percentOff: 10
});
await page.locator('.gh-offers-list .gh-list-row').filter({hasText: offerName}).click();
const portalUrl = await page.locator('input#url').inputValue();
await page.goto(portalUrl);
const portalFrame = page.frameLocator('#ghost-portal-root div iframe');
await portalFrame.locator('#input-name').fill('Testy McTesterson');
await portalFrame.locator('#input-email').fill('testy@example.com');
await portalFrame.getByRole('button', {name: 'Continue'}).click();
await completeStripeSubscription(page);
await page.waitForSelector('h1.site-title', {state: 'visible'});
await page.goto('/ghost');
await page.locator('.gh-nav a[href="#/members/"]').click();
// 1 member, should be Testy, on Portal Tier
await expect(page.getByRole('link', {name: 'Testy McTesterson testy@example.com'}), 'Should have 1 paid member').toBeVisible();
await expect(page.getByRole('link', {name: tierName}), `Paid member should be on ${tierName}`).toBeVisible();
});
});