Skip to content

Commit

Permalink
Update file name
Browse files Browse the repository at this point in the history
  • 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.
66 changes: 66 additions & 0 deletions tests/e2e/specs/posts/preview-existing-post.test.js
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

View workflow job for this annotation

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

2) [chromium] › posts/preview-existing-post.test.js:35:3 › Preview Existing Post › Can Preview Existing Post Error: Not logged in 8 | const title = 'preview post'; 9 | testInfo.data = { title }; > 10 | await admin.createNewPost({ title }); | ^ 11 | await editor.publishPost(); 12 | }); 13 | at Admin.visitAdminPage (/home/runner/work/wordpress-develop/wordpress-develop/node_modules/@wordpress/e2e-test-utils-playwright/src/admin/visit-admin-page.ts:36:9) at Admin.createNewPost (/home/runner/work/wordpress-develop/wordpress-develop/node_modules/@wordpress/e2e-test-utils-playwright/src/admin/create-new-post.ts:41:2) at /home/runner/work/wordpress-develop/wordpress-develop/tests/e2e/specs/posts/preview-existing-post.test.js:10:5

Check failure on line 10 in tests/e2e/specs/posts/preview-existing-post.test.js

View workflow job for this annotation

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

2) [chromium] › posts/preview-existing-post.test.js:35:3 › Preview Existing Post › Can Preview Existing Post Error: Not logged in 8 | const title = 'preview post'; 9 | testInfo.data = { title }; > 10 | await admin.createNewPost({ title }); | ^ 11 | await editor.publishPost(); 12 | }); 13 | at Admin.visitAdminPage (/home/runner/work/wordpress-develop/wordpress-develop/node_modules/@wordpress/e2e-test-utils-playwright/src/admin/visit-admin-page.ts:36:9) at Admin.createNewPost (/home/runner/work/wordpress-develop/wordpress-develop/node_modules/@wordpress/e2e-test-utils-playwright/src/admin/create-new-post.ts:41:2) at /home/runner/work/wordpress-develop/wordpress-develop/tests/e2e/specs/posts/preview-existing-post.test.js:10:5

Check failure on line 10 in tests/e2e/specs/posts/preview-existing-post.test.js

View workflow job for this annotation

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

2) [chromium] › posts/preview-existing-post.test.js:35:3 › Preview Existing Post › Can Preview Existing Post Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: Not logged in 8 | const title = 'preview post'; 9 | testInfo.data = { title }; > 10 | await admin.createNewPost({ title }); | ^ 11 | await editor.publishPost(); 12 | }); 13 | at Admin.visitAdminPage (/home/runner/work/wordpress-develop/wordpress-develop/node_modules/@wordpress/e2e-test-utils-playwright/src/admin/visit-admin-page.ts:36:9) at Admin.createNewPost (/home/runner/work/wordpress-develop/wordpress-develop/node_modules/@wordpress/e2e-test-utils-playwright/src/admin/create-new-post.ts:41:2) at /home/runner/work/wordpress-develop/wordpress-develop/tests/e2e/specs/posts/preview-existing-post.test.js:10:5
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);
});
});

0 comments on commit 8ae8910

Please sign in to comment.