@@ -3,68 +3,53 @@ import { test, expect } from '@playwright/test';
33const TEST_SNIPPET_NAME = 'E2E Test Snippet' ;
44
55test . describe ( 'Code Snippets Plugin' , ( ) => {
6- test ( 'Complete snippet workflow' , async ( { page } ) => {
7- await test . step ( 'Login to WordPress' , async ( ) => {
8- await page . goto ( '/wp-login.php' ) ;
9- await page . waitForSelector ( '#user_login' ) ;
10- await page . fill ( '#user_login' , 'admin' ) ;
11- await page . fill ( '#user_pass' , 'password' ) ;
12- await page . click ( '#wp-submit' ) ;
13- await page . waitForURL ( / w p - a d m i n / ) ;
14- } ) ;
15-
16- await test . step ( 'Navigate to snippets page' , async ( ) => {
17- await page . goto ( '/wp-admin/admin.php?page=snippets' ) ;
18- await page . waitForLoadState ( 'networkidle' ) ;
19- await page . waitForSelector ( '#wpbody-content, .wrap, #wpcontent' , { timeout : 10000 } ) ;
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+ } ) ;
2011
21- const currentUrl = page . url ( ) ;
22- expect ( currentUrl ) . toContain ( 'page=snippets' ) ;
23- } ) ;
12+ test ( 'Can access snippets admin page' , async ( { page } ) => {
13+ const currentUrl = page . url ( ) ;
14+ expect ( currentUrl ) . toContain ( 'page=snippets' ) ;
2415
25- await test . step ( 'Add a new snippet' , async ( ) => {
26- await page . waitForSelector ( 'h1, .page-title' , { timeout : 10000 } ) ;
27- await page . click ( '.page-title-action' ) ;
28- await page . waitForLoadState ( 'networkidle' ) ;
29-
30- await page . waitForSelector ( '#title' ) ;
31- await page . fill ( '#title' , TEST_SNIPPET_NAME ) ;
16+ await expect ( page . locator ( 'h1, .page-title' ) ) . toBeVisible ( ) ;
17+ } ) ;
3218
33- await page . waitForSelector ( '.CodeMirror textarea' ) ;
34- await page . fill ( '.CodeMirror textarea' , 'echo "Hello World!";' ) ;
19+ test ( 'Can add a new snippet' , async ( { page } ) => {
20+ await page . waitForSelector ( 'h1, .page-title' , { timeout : 10000 } ) ;
21+ await page . click ( '.page-title-action' ) ;
22+ await page . waitForLoadState ( 'networkidle' ) ;
3523
36- await page . click ( 'text=Save Snippet' ) ;
37- await expect ( page . locator ( '#message.notice' ) ) . toContainText ( 'Snippet created' ) ;
38- } ) ;
24+ await page . waitForSelector ( '#title' ) ;
25+ await page . fill ( '#title' , TEST_SNIPPET_NAME ) ;
3926
40- await test . step ( 'Activate the snippet' , async ( ) => {
41- await page . goto ( '/wp-admin/admin.php?page=snippets' ) ;
42- await page . waitForLoadState ( 'networkidle' ) ;
27+ await page . waitForSelector ( '.CodeMirror textarea' ) ;
28+ await page . fill ( '.CodeMirror textarea' , 'echo "Hello World!";' ) ;
4329
44- await page . waitForSelector ( ` text=${ TEST_SNIPPET_NAME } ` ) ;
45- await page . click ( `text= ${ TEST_SNIPPET_NAME } ` ) ;
46- await page . waitForLoadState ( 'networkidle' ) ;
30+ await page . click ( ' text=Save Snippet' ) ;
31+ await expect ( page . locator ( '#message.notice' ) ) . toContainText ( 'Snippet created' ) ;
32+ } ) ;
4733
48- await page . click ( 'text=Save and Activate' ) ;
49- await expect ( page . locator ( '#message.notice p' ) ) . toContainText ( 'Snippet updated and activated' ) ;
50- } ) ;
34+ test ( 'Can activate and deactivate a snippet' , async ( { page } ) => {
35+ await page . waitForSelector ( `text=${ TEST_SNIPPET_NAME } ` ) ;
36+ await page . click ( `text=${ TEST_SNIPPET_NAME } ` ) ;
37+ await page . waitForLoadState ( 'networkidle' ) ;
5138
52- await test . step ( 'Deactivate the snippet' , async ( ) => {
53- await page . click ( 'text=Save and Deactivate' ) ;
54- await expect ( page . locator ( '#message.notice p' ) ) . toContainText ( 'Snippet updated and deactivated' ) ;
55- } ) ;
39+ await page . click ( 'text=Save and Activate' ) ;
40+ await expect ( page . locator ( '#message.notice p' ) ) . toContainText ( 'Snippet updated and activated' ) ;
5641
57- await test . step ( 'Delete the snippet' , async ( ) => {
58- await page . goto ( '/wp-admin/admin.php?page=snippets ') ;
59- await page . waitForLoadState ( 'networkidle' ) ;
42+ await page . click ( 'text=Save and Deactivate' ) ;
43+ await expect ( page . locator ( '#message.notice p' ) ) . toContainText ( 'Snippet updated and deactivated ') ;
44+ } ) ;
6045
61- await page . waitForSelector ( `text=${ TEST_SNIPPET_NAME } ` ) ;
62- await page . click ( `text=${ TEST_SNIPPET_NAME } ` ) ;
63- await page . waitForLoadState ( 'networkidle' ) ;
46+ test ( 'Can delete a snippet' , async ( { page } ) => {
47+ await page . waitForSelector ( `text=${ TEST_SNIPPET_NAME } ` ) ;
48+ await page . click ( `text=${ TEST_SNIPPET_NAME } ` ) ;
49+ await page . waitForLoadState ( 'networkidle' ) ;
6450
65- await page . click ( 'text=Delete' ) ;
66- await page . click ( 'button.components-button.is-destructive.is-primary' ) ;
67- await expect ( page . locator ( 'body' ) ) . not . toContainText ( TEST_SNIPPET_NAME ) ;
68- } ) ;
51+ await page . click ( 'text=Delete' ) ;
52+ await page . click ( 'button.components-button.is-destructive.is-primary' ) ;
53+ await expect ( page . locator ( 'body' ) ) . not . toContainText ( TEST_SNIPPET_NAME ) ;
6954 } ) ;
7055} ) ;
0 commit comments