| 1 |
import { expect, test } from '../../fixtures'; |
| 2 |
|
| 3 |
test.beforeEach(async ({ admin, editor, page, requestUtils }) => { |
| 4 |
await requestUtils.login(); |
| 5 |
await admin.visitAdminPage('post-new.php', 'post_type=page'); |
| 6 |
// Wait for the Draft sidebar toggle so we know our scripts have booted. |
| 7 |
await expect( |
| 8 |
page.locator('button[aria-controls="extendify-draft:draft"]').first(), |
| 9 |
).toBeVisible({ timeout: 15_000 }); |
| 10 |
await editor.insertBlock({ name: 'core/image' }); |
| 11 |
}); |
| 12 |
|
| 13 |
const generateImageWrapper = '.components-form-file-generate-image'; |
| 14 |
const searchUnsplashWrapper = '.components-form-file-search-unsplash'; |
| 15 |
|
| 16 |
test('image placeholder shows two buttons', async ({ editor }) => { |
| 17 |
const generate = editor.canvas.locator(`${generateImageWrapper} button`); |
| 18 |
const unsplash = editor.canvas.locator(`${searchUnsplashWrapper} button`); |
| 19 |
|
| 20 |
await expect(generate).toBeVisible(); |
| 21 |
await expect(generate).toHaveText('Generate Image'); |
| 22 |
await expect(unsplash).toBeVisible(); |
| 23 |
await expect(unsplash).toHaveText('Search Unsplash'); |
| 24 |
|
| 25 |
// The single combined button is gone. |
| 26 |
await expect( |
| 27 |
editor.canvas.getByRole('button', { name: 'Get Personalized Image' }), |
| 28 |
).toHaveCount(0); |
| 29 |
|
| 30 |
// Each wrapper holds exactly one button — they are not nested together. |
| 31 |
await expect( |
| 32 |
editor.canvas.locator(`${generateImageWrapper} button`), |
| 33 |
).toHaveCount(1); |
| 34 |
await expect( |
| 35 |
editor.canvas.locator(`${searchUnsplashWrapper} button`), |
| 36 |
).toHaveCount(1); |
| 37 |
}); |
| 38 |
|
| 39 |
test('"Generate Image" opens the sidebar directly on the AI image generator', async ({ |
| 40 |
editor, |
| 41 |
page, |
| 42 |
}) => { |
| 43 |
await editor.canvas.locator(`${generateImageWrapper} button`).click(); |
| 44 |
|
| 45 |
// Sidebar opens routed to the AI image page (skipping the Home screen). |
| 46 |
await expect( |
| 47 |
page.getByRole('heading', { name: 'AI Image Generator' }), |
| 48 |
).toBeVisible(); |
| 49 |
await expect(page.locator('#draft-ai-image-textarea')).toBeVisible(); |
| 50 |
}); |
| 51 |
|
| 52 |
test('"Search Unsplash" opens the sidebar directly on the Unsplash search', async ({ |
| 53 |
editor, |
| 54 |
page, |
| 55 |
}) => { |
| 56 |
await editor.canvas.locator(`${searchUnsplashWrapper} button`).click(); |
| 57 |
|
| 58 |
// Sidebar opens routed to the Unsplash page (skipping the Home screen). |
| 59 |
await expect( |
| 60 |
page.getByRole('heading', { name: 'Photos from Unsplash' }), |
| 61 |
).toBeVisible(); |
| 62 |
}); |
| 63 |
|