mirrored from git://develop.git.wordpress.org/
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Apple
authored and
Apple
committed
Dec 23, 2024
1 parent
9a46500
commit 8ae8910
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
const { test, expect } = require('@wordpress/e2e-test-utils-playwright'); | ||
|
||
test.describe('Preview Existing Post', () => { | ||
test.beforeEach(async ({ admin, editor }, testInfo) => { | ||
const title = 'preview post'; | ||
testInfo.data = { title }; | ||
await admin.createNewPost({ title }); | ||
Check failure on line 10 in tests/e2e/specs/posts/preview-existing-post.test.js GitHub Actions / Test with SCRIPT_DEBUG enabled / Run E2E tests[chromium] › posts/preview-existing-post.test.js:35:3 › Preview Existing Post › Can Preview Existing Post
Check failure on line 10 in tests/e2e/specs/posts/preview-existing-post.test.js GitHub Actions / Test with SCRIPT_DEBUG disabled / Run E2E tests[chromium] › posts/preview-existing-post.test.js:35:3 › Preview Existing Post › Can Preview Existing Post
Check failure on line 10 in tests/e2e/specs/posts/preview-existing-post.test.js GitHub Actions / Test with SCRIPT_DEBUG disabled / Run E2E tests[chromium] › posts/preview-existing-post.test.js:35:3 › Preview Existing Post › Can Preview Existing Post
|
||
await editor.publishPost(); | ||
}); | ||
|
||
test.afterEach(async ({ requestUtils }, testInfo) => { | ||
const { title } = testInfo.data; | ||
await requestUtils.deleteAllPosts(); | ||
}); | ||
|
||
/** | ||
* Selects a menu item radio by its name and verifies `aria-checked=true`. | ||
* | ||
* @param {Page} page - The Playwright page instance. | ||
* @param {string} menuItem - The name of the menu item to select (e.g., 'Tablet', 'Mobile', 'Desktop'). | ||
*/ | ||
async function selectMenuItemRadio(page, menuItem) { | ||
const menuItemRadio = page.getByRole('menuitemradio', { name: menuItem }); | ||
|
||
// Click the menu item radio | ||
await menuItemRadio.click(); | ||
|
||
// Assert that `aria-checked=true` after the click | ||
await expect(menuItemRadio).toHaveAttribute('aria-checked', 'true'); | ||
} | ||
|
||
test('Can Preview Existing Post', async ({ page, admin }, testInfo) => { | ||
const { title } = testInfo.data; | ||
|
||
// Navigate to Posts list | ||
await admin.visitAdminPage('/'); | ||
await page.getByRole('link', { name: 'Posts', exact: true }).click(); | ||
|
||
//Click on the Test Post. | ||
await page.locator(`text="${title}"`).first().click(); | ||
|
||
// Click Preview button | ||
await page.getByRole('button', { name: 'View', exact: true }).click(); | ||
|
||
// Test for 'Tablet' | ||
await selectMenuItemRadio(page, 'Tablet'); | ||
|
||
// Test for 'Mobile' | ||
await selectMenuItemRadio(page, 'Mobile'); | ||
|
||
// Test for 'Desktop' | ||
await selectMenuItemRadio(page, 'Desktop'); | ||
|
||
// Open Preview in a new tab | ||
const [popup] = await Promise.all([ | ||
page.waitForEvent('popup'), | ||
page.locator('text="Preview in new tab"').click(), | ||
]); | ||
await popup.waitForLoadState(); | ||
await expect(popup).toHaveURL(/preview=true/); | ||
await expect(popup.locator('body')).toContainText(title); | ||
}); | ||
}); |