mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
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.
This commit is contained in:
parent
739bda9bb8
commit
0dbc10a41a
1 changed files with 49 additions and 9 deletions
|
@ -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');
|
||||
|
|
Loading…
Add table
Reference in a new issue