Skip to content

Commit aa341f0

Browse files
committed
small refactor
1 parent 5cf0d9d commit aa341f0

File tree

2 files changed

+31
-23
lines changed

2 files changed

+31
-23
lines changed

tests/e2e/code-snippets-evaluation.spec.ts

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,18 @@ import { test, expect } from '@playwright/test';
22
import { SnippetsTestHelper } from './helpers/SnippetsTestHelper';
33
import { SELECTORS } from './helpers/constants';
44

5-
const TEST_SNIPPET_NAME = 'E2E Admin Bar Hide Test';
5+
const TEST_SNIPPET_NAME = 'E2E Snippet Test';
6+
7+
const BODY_CLASS_TEST_CODE = `
8+
add_filter('admin_body_class', function($classes) {
9+
return $classes . ' custom-admin-class';
10+
});
11+
12+
add_filter('body_class', function($classes) {
13+
$classes[] = 'custom-frontend-class';
14+
return $classes;
15+
});
16+
`;
617

718
test.describe('Code Snippets Evaluation', () => {
819
let helper: SnippetsTestHelper;
@@ -23,20 +34,25 @@ test.describe('Code Snippets Evaluation', () => {
2334
await helper.expectElementCount(SELECTORS.ADMIN_BAR, 0);
2435
});
2536

37+
test('PHP Snippet runs everywhere', async ({ page }) => {
38+
await helper.createAndActivateSnippet({
39+
name: TEST_SNIPPET_NAME,
40+
location: 'EVERYWHERE',
41+
code: BODY_CLASS_TEST_CODE
42+
});
43+
44+
await page.goto('/wp-admin/');
45+
await expect(page.locator('body')).toHaveClass(/custom-admin-class/);
46+
47+
await helper.navigateToFrontend();
48+
await expect(page.locator('body')).toHaveClass(/custom-frontend-class/);
49+
});
50+
2651
test('PHP Snippet runs only in Admin', async ({ page }) => {
2752
await helper.createAndActivateSnippet({
28-
name: 'Admin Only Body Class Test',
53+
name: TEST_SNIPPET_NAME,
2954
location: 'ADMIN_ONLY',
30-
code: `
31-
add_filter('admin_body_class', function($classes) {
32-
return $classes . ' custom-admin-class';
33-
});
34-
35-
add_filter('body_class', function($classes) {
36-
$classes[] = 'custom-frontend-class';
37-
return $classes;
38-
});
39-
`
55+
code: BODY_CLASS_TEST_CODE
4056
});
4157

4258
await page.goto('/wp-admin/');
@@ -48,18 +64,9 @@ test.describe('Code Snippets Evaluation', () => {
4864

4965
test('PHP Snippet runs only in Frontend', async ({ page }) => {
5066
await helper.createAndActivateSnippet({
51-
name: 'Frontend Only Body Class Test',
67+
name: TEST_SNIPPET_NAME,
5268
location: 'FRONTEND_ONLY',
53-
code: `
54-
add_filter('admin_body_class', function($classes) {
55-
return $classes . ' custom-admin-class';
56-
});
57-
58-
add_filter('body_class', function($classes) {
59-
$classes[] = 'custom-frontend-class';
60-
return $classes;
61-
});
62-
`
69+
code: BODY_CLASS_TEST_CODE
6370
});
6471

6572
await page.goto('/wp-admin/');

tests/e2e/helpers/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export const SNIPPET_LOCATIONS = {
4949
IN_EDITOR: 'Where inserted in editor',
5050
ADMIN_ONLY: 'Only run in administration area',
5151
FRONTEND_ONLY: 'Only run on site front-end',
52+
EVERYWHERE: 'Run everywhere',
5253
} as const;
5354

5455
export const BUTTONS = {

0 commit comments

Comments
 (0)