1+ /**
2+ * WordPress dependencies
3+ */
4+ const { test, expect } = require ( '@wordpress/e2e-test-utils-playwright' ) ;
5+
6+ const PLUGIN_SLUG = 'secure-custom-fields' ;
7+ const PLUGIN_PATH = `${ PLUGIN_SLUG } /${ PLUGIN_SLUG } .php` ;
8+ const TEST_POST_TYPE = 'movie' ;
9+
10+ test . describe ( 'Post Type Creation' , ( ) => {
11+ test . beforeEach ( async ( { page, requestUtils } ) => {
12+ // Login to WordPress admin
13+ await requestUtils . activatePlugin ( PLUGIN_SLUG ) ;
14+ } ) ;
15+
16+ test . afterAll ( async ( { requestUtils } ) => {
17+ await requestUtils . deactivatePlugin ( PLUGIN_SLUG ) ;
18+ } ) ;
19+
20+ test ( 'should be able to create a custom post type' , async ( { page, admin } ) => {
21+ // Navigate to plugins page
22+ await admin . visitAdminPage ( 'edit.php' , 'post_type=acf-post-type' ) ;
23+
24+ // Look for the "Add New" button and click it
25+ const addNewButton = page . locator ( 'a.acf-btn.acf-btn-sm:has(i.acf-icon-plus)' , { hasText : 'Add New' } ) ;
26+ await expect ( addNewButton ) . toBeVisible ( ) ;
27+ await addNewButton . click ( ) ;
28+
29+ // Verify we're on the new post type creation page
30+ await expect ( page ) . toHaveURL ( / .* p o s t - n e w \. p h p \? p o s t _ t y p e = a c f - p o s t - t y p e / ) ;
31+ await expect ( page . locator ( 'div.wrap h1' ) ) . toContainText ( 'Add New Post Type' ) ;
32+
33+ // Fill in the required fields
34+ // Post type name/title
35+ await page . fill ( '#acf_post_type-labels-name' , 'Movies' ) ;
36+
37+ // Post type ID/key
38+ await page . fill ( '#acf_post_type-labels-singular_name' , 'Movie' ) ;
39+
40+
41+ // Submit the form
42+ await page . click ( 'button.acf-btn.acf-publish[type="submit"]' ) ;
43+
44+ // Wait for the success notification
45+ await page . waitForSelector ( '.updated.notice' ) ;
46+ await expect ( page . locator ( '.updated.notice' ) ) . toContainText ( 'Movies post type created' ) ;
47+
48+ // Verify the post type was created by checking if it appears in the list
49+ // await admin.visitAdminPage('edit.php', 'post_type=acf-post-type');
50+ // await expect(page.locator(`a:has-text("Test Post Type")`)).toBeVisible();
51+
52+ // Verify the post type is available in the admin menu
53+ // await expect(page.locator(`#menu-posts-${TEST_POST_TYPE}`)).toBeVisible();
54+
55+ // Navigate to the new post type's admin page to verify it works
56+ // await page.click(`#menu-posts-${TEST_POST_TYPE}`);
57+ // await expect(page.locator('h1.wp-heading-inline')).toContainText('Test Items');
58+
59+ // Clean up - delete the post type
60+ // await admin.visitAdminPage('edit.php', 'post_type=acf-post-type');
61+ // await page.click(`a:has-text("Test Post Type")`);
62+ // await page.click('#trash-action a');
63+ // await expect(page.locator('.updated.notice')).toContainText('moved to the Trash');
64+ } ) ;
65+ } ) ;
0 commit comments