|
| 1 | +import { test, expect } from '@playwright/test'; |
| 2 | + |
| 3 | +const TEST_SNIPPET_NAME = 'E2E Admin Bar Hide Test'; |
| 4 | + |
| 5 | +test.describe('Code Snippets Evaluation', () => { |
| 6 | + test.beforeEach(async ({ page }) => { |
| 7 | + await page.goto('/wp-admin/admin.php?page=snippets'); |
| 8 | + await page.waitForLoadState('networkidle'); |
| 9 | + await page.waitForSelector('#wpbody-content, .wrap, #wpcontent', { timeout: 10000 }); |
| 10 | + }); |
| 11 | + |
| 12 | + test('Can hide admin bar with activated snippet', async ({ page }) => { |
| 13 | + await page.waitForSelector('h1, .page-title', { timeout: 10000 }); |
| 14 | + await page.click('.page-title-action'); |
| 15 | + await page.waitForLoadState('networkidle'); |
| 16 | + |
| 17 | + await page.waitForSelector('#title'); |
| 18 | + await page.fill('#title', TEST_SNIPPET_NAME); |
| 19 | + |
| 20 | + await page.waitForSelector('.CodeMirror textarea'); |
| 21 | + await page.fill('.CodeMirror textarea', "add_filter('show_admin_bar', '__return_false');"); |
| 22 | + |
| 23 | + await page.click('text=Save and Activate'); |
| 24 | + await expect(page.locator('#message.notice')).toContainText('Snippet created and activated'); |
| 25 | + |
| 26 | + await page.goto('/'); |
| 27 | + await page.waitForLoadState('networkidle'); |
| 28 | + |
| 29 | + await expect(page.locator('#wpadminbar')).not.toBeVisible(); |
| 30 | + |
| 31 | + const adminBarCount = await page.locator('#wpadminbar').count(); |
| 32 | + expect(adminBarCount).toBe(0); |
| 33 | + }); |
| 34 | + |
| 35 | + test.afterEach(async ({ page }) => { |
| 36 | + // Clean up |
| 37 | + await page.goto('/wp-admin/admin.php?page=snippets'); |
| 38 | + await page.waitForLoadState('networkidle'); |
| 39 | + |
| 40 | + const snippetExists = await page.locator(`text=${TEST_SNIPPET_NAME}`).count(); |
| 41 | + if (snippetExists > 0) { |
| 42 | + await page.click(`text=${TEST_SNIPPET_NAME}`); |
| 43 | + await page.waitForLoadState('networkidle'); |
| 44 | + |
| 45 | + await page.click('text=Delete'); |
| 46 | + await page.click('button.components-button.is-destructive.is-primary'); |
| 47 | + } |
| 48 | + }); |
| 49 | +}); |
0 commit comments