Skip to content

Commit 39ea959

Browse files
committed
improve tests
1 parent d6afc3f commit 39ea959

File tree

5 files changed

+55
-20
lines changed

5 files changed

+55
-20
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ npm-debug.log
1515
# Playwright
1616
playwright-report/
1717
test-results/
18+
auth.json
1819

1920
# Local files (ideally, should be in a global .gitignore)
2021
.idea/

tests/e2e/admin-page.spec.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

tests/e2e/auth.setup.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { test as setup } from '@playwright/test';
2+
3+
setup('authenticate', async ({ page }) => {
4+
await page.goto('/wp-login.php');
5+
await page.waitForSelector('#user_login');
6+
await page.fill('#user_login', 'admin');
7+
await page.fill('#user_pass', 'password');
8+
await page.click('#wp-submit');
9+
await page.waitForURL(/wp-admin/);
10+
11+
await page.context().storageState({ path: 'auth.json' });
12+
});

tests/e2e/code-snippets.spec.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
const TEST_SNIPPET_NAME = 'E2E Test Snippet';
4+
5+
test.describe('Code Snippets Admin Page @admin', () => {
6+
test.beforeEach(async ({ page }) => {
7+
await page.goto('/wp-admin/admin.php?page=snippets');
8+
await page.waitForLoadState('networkidle');
9+
});
10+
11+
test('Can add a new snippet', async ({ page }) => {
12+
await page.click('text=Add New')
13+
await page.fill('#title', TEST_SNIPPET_NAME)
14+
await page.fill('.CodeMirror textarea', 'echo "Hello World!";')
15+
await page.click('text=Save Snippet')
16+
await expect(page.locator('#message.notice')).toContainText('Snippet created')
17+
});
18+
19+
test('Can activate and deactivate a snippet', async ({ page }) => {
20+
await page.click(`text=${TEST_SNIPPET_NAME}`);
21+
await page.click('text=Save and Activate');
22+
await expect(page.locator('#message.notice p')).toContainText('Snippet updated and activated.');
23+
await page.click('text=Save and Deactivate');
24+
await expect(page.locator('#message.notice p')).toContainText('Snippet updated and deactivated');
25+
});
26+
27+
test('Can delete a snippet', async ({ page }) => {
28+
await page.click(`text=${TEST_SNIPPET_NAME}`);
29+
await page.click('text=Delete');
30+
await page.click('button.components-button.is-destructive.is-primary'); // Confirm dialog
31+
await expect(page.locator('body')).not.toContainText(TEST_SNIPPET_NAME);
32+
});
33+
});

tests/playwright/playwright.config.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,17 @@ export default defineConfig({
2323
},
2424

2525
projects: [
26+
{
27+
name: 'setup',
28+
testMatch: /.*\.setup\.ts/,
29+
},
2630
{
2731
name: 'chromium',
28-
use: { ...devices['Desktop Chrome'] },
32+
use: {
33+
...devices['Desktop Chrome'],
34+
storageState: 'auth.json',
35+
},
36+
dependencies: ['setup'],
2937
},
3038
],
3139

0 commit comments

Comments
 (0)