From 0dbc10a41a5d3a51c47c5bcb343a1bd36d13db18 Mon Sep 17 00:00:00 2001 From: Simon Backx Date: Thu, 8 Dec 2022 10:24:35 +0100 Subject: [PATCH] Added Playwright test for publishing a page refs https://github.com/TryGhost/Team/issues/2371 Publish a page and verify that the page is published. --- .../test/e2e-browser/admin/publishing.spec.js | 58 ++++++++++++++++--- 1 file changed, 49 insertions(+), 9 deletions(-) diff --git a/ghost/core/test/e2e-browser/admin/publishing.spec.js b/ghost/core/test/e2e-browser/admin/publishing.spec.js index f0b16fed9d..ff6e0d6191 100644 --- a/ghost/core/test/e2e-browser/admin/publishing.spec.js +++ b/ghost/core/test/e2e-browser/admin/publishing.spec.js @@ -25,6 +25,30 @@ const createPost = async (page, {title = 'Hello world', body = 'This is my post await page.keyboard.type(body); }; +/** + * Start a page draft with a filled in title and body. We can consider to move this to utils later. + * @param {import('@playwright/test').Page} page + * @param {Object} options + * @param {String} [options.title] + * @param {String} [options.body] + */ +const createPage = async (page, {title = 'Hello world', body = 'This is my post body.'} = {}) => { + await page.locator('.gh-nav a[href="#/pages/"]').click(); + + // Create a new post + await page.locator('[data-test-new-page-button]').click(); + + // Fill in the post title + await page.locator('[data-test-editor-title-input]').click(); + await page.locator('[data-test-editor-title-input]').fill(title); + + // Continue to the body by pressing enter + await page.keyboard.press('Enter'); + + await page.waitForTimeout(100); // allow new->draft switch to occur fully, without this some initial typing events can be missed + await page.keyboard.type(body); +}; + /** * @param {import('@playwright/test').Page} page */ @@ -57,16 +81,20 @@ const publishPost = async (page, {type = 'publish', time} = {}) => { await openPublishFlow(page); // set the publish type - await page.locator('[data-test-setting="publish-type"] > button').click(); + if (type) { + // Type is nullable because Pages don't have a publish type button - // NOTE: the if/else below should be reworked into data-test-publish style selectors - // await page.locator(`[data-test-publish-type="${type}"]`).setChecked(true); - if (type === 'publish') { - await page.getByText('Publish only').click(); - } else if (type === 'publish+send') { - await page.getByText('Publish and email').click(); - } else if (type === 'send') { - await page.getByText('Email only').click(); + await page.locator('[data-test-setting="publish-type"] > button').click(); + + // NOTE: the if/else below should be reworked into data-test-publish style selectors + // await page.locator(`[data-test-publish-type="${type}"]`).setChecked(true); + if (type === 'publish') { + await page.getByText('Publish only').click(); + } else if (type === 'publish+send') { + await page.getByText('Publish and email').click(); + } else if (type === 'send') { + await page.getByText('Email only').click(); + } } if (time) { @@ -110,6 +138,18 @@ test.describe('Publishing', () => { }); }); + test.describe('Publish page', () => { + test('Page can be published and become visible on web', async ({page}) => { + await page.goto('/ghost'); + await createPage(page); + const frontendPage = await publishPost(page, {type: null}); + + // Check if 'This is my post body.' is present on page1 + await expect(frontendPage.locator('.gh-canvas .article-title')).toHaveText('Hello world'); + await expect(frontendPage.locator('.gh-content.gh-canvas > p')).toHaveText('This is my post body.'); + }); + }); + test.describe('Update post', () => { test('Can update a published post', async ({page: adminPage, browser}) => { await adminPage.goto('/ghost');