From 97e5ca1de6ad63483b2573be487e55237fd8c079 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Tue, 6 Dec 2022 19:05:58 +0700 Subject: [PATCH] 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 --- ghost/core/test/e2e-browser/admin.spec.js | 42 ---------------- .../core/test/e2e-browser/admin/posts.spec.js | 11 +++++ .../core/test/e2e-browser/admin/setup.spec.js | 13 +++++ .../core/test/e2e-browser/admin/tiers.spec.js | 24 ++++++++++ ghost/core/test/e2e-browser/frontend.spec.js | 48 ------------------- .../test/e2e-browser/portal/frontend.spec.js | 8 ++++ .../test/e2e-browser/portal/offers.spec.js | 39 +++++++++++++++ 7 files changed, 95 insertions(+), 90 deletions(-) delete mode 100644 ghost/core/test/e2e-browser/admin.spec.js create mode 100644 ghost/core/test/e2e-browser/admin/posts.spec.js create mode 100644 ghost/core/test/e2e-browser/admin/setup.spec.js create mode 100644 ghost/core/test/e2e-browser/admin/tiers.spec.js delete mode 100644 ghost/core/test/e2e-browser/frontend.spec.js create mode 100644 ghost/core/test/e2e-browser/portal/frontend.spec.js create mode 100644 ghost/core/test/e2e-browser/portal/offers.spec.js diff --git a/ghost/core/test/e2e-browser/admin.spec.js b/ghost/core/test/e2e-browser/admin.spec.js deleted file mode 100644 index e11c576019..0000000000 --- a/ghost/core/test/e2e-browser/admin.spec.js +++ /dev/null @@ -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); - }); -}); diff --git a/ghost/core/test/e2e-browser/admin/posts.spec.js b/ghost/core/test/e2e-browser/admin/posts.spec.js new file mode 100644 index 0000000000..047781ab0f --- /dev/null +++ b/ghost/core/test/e2e-browser/admin/posts.spec.js @@ -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}/); + }); +}); diff --git a/ghost/core/test/e2e-browser/admin/setup.spec.js b/ghost/core/test/e2e-browser/admin/setup.spec.js new file mode 100644 index 0000000000..297de03a5d --- /dev/null +++ b/ghost/core/test/e2e-browser/admin/setup.spec.js @@ -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/); + }); +}); diff --git a/ghost/core/test/e2e-browser/admin/tiers.spec.js b/ghost/core/test/e2e-browser/admin/tiers.spec.js new file mode 100644 index 0000000000..c7a50635d0 --- /dev/null +++ b/ghost/core/test/e2e-browser/admin/tiers.spec.js @@ -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); + }); +}); diff --git a/ghost/core/test/e2e-browser/frontend.spec.js b/ghost/core/test/e2e-browser/frontend.spec.js deleted file mode 100644 index 45ea8d9733..0000000000 --- a/ghost/core/test/e2e-browser/frontend.spec.js +++ /dev/null @@ -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(); - }); - }); -}); diff --git a/ghost/core/test/e2e-browser/portal/frontend.spec.js b/ghost/core/test/e2e-browser/portal/frontend.spec.js new file mode 100644 index 0000000000..b898607855 --- /dev/null +++ b/ghost/core/test/e2e-browser/portal/frontend.spec.js @@ -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); + }); +}); diff --git a/ghost/core/test/e2e-browser/portal/offers.spec.js b/ghost/core/test/e2e-browser/portal/offers.spec.js new file mode 100644 index 0000000000..bc40153fa7 --- /dev/null +++ b/ghost/core/test/e2e-browser/portal/offers.spec.js @@ -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(); + }); +});