@@ -102,6 +102,65 @@ test.describe('Code Snippets Evaluation', () => {
102102 await helper . expectElementCount ( 'text=Hello World HTML snippet in header!' , 1 ) ;
103103 } ) ;
104104
105+ test ( 'HTML snippet works with shortcode in editor' , async ( { page } ) => {
106+ const snippetId = await createHtmlSnippetForEditor ( ) ;
107+
108+ const pageUrl = await createPageWithShortcode ( snippetId ) ;
109+
110+ await verifyShortcodeRendersCorrectly ( page , pageUrl ) ;
111+
112+ async function createHtmlSnippetForEditor ( ) : Promise < string > {
113+ await helper . createAndActivateSnippet ( {
114+ name : TEST_SNIPPET_NAME ,
115+ code : "<div class='custom-snippet-content'><h3>Custom HTML Content</h3><p>This content was inserted via shortcode!</p></div>" ,
116+ type : 'HTML' ,
117+ location : 'IN_EDITOR'
118+ } ) ;
119+
120+ const currentUrl = page . url ( ) ;
121+ const urlMatch = currentUrl . match ( / [ ? & ] i d = ( \d + ) / ) ;
122+ expect ( urlMatch ) . toBeTruthy ( ) ;
123+ return urlMatch ! [ 1 ] ;
124+ }
125+
126+ async function createPageWithShortcode ( snippetId : string ) : Promise < string > {
127+ const { exec } = require ( 'child_process' ) ;
128+ const util = require ( 'util' ) ;
129+ const execAsync = util . promisify ( exec ) ;
130+
131+ const shortcode = `[code_snippet id=${ snippetId } format name="${ TEST_SNIPPET_NAME } "]` ;
132+ const pageContent = `<p>Page content before shortcode.</p>
133+
134+ ${ shortcode }
135+
136+ <p>Page content after shortcode.</p>` ;
137+
138+ try {
139+ const createPageCmd = `npx wp-env run cli wp post create --post_type=page --post_title="Test Page for Snippet Shortcode" --post_content='${ pageContent } ' --post_status=publish --porcelain` ;
140+ const { stdout } = await execAsync ( createPageCmd ) ;
141+ const pageId = stdout . trim ( ) ;
142+
143+ const getUrlCmd = `npx wp-env run cli wp post url ${ pageId } ` ;
144+ const { stdout : pageUrl } = await execAsync ( getUrlCmd ) ;
145+ return pageUrl . trim ( ) ;
146+ } catch ( error ) {
147+ console . error ( 'Failed to create page via WP-CLI:' , error ) ;
148+ throw error ;
149+ }
150+ }
151+
152+ async function verifyShortcodeRendersCorrectly ( page : any , pageUrl : string ) : Promise < void > {
153+ await page . goto ( pageUrl ) ;
154+
155+ await expect ( page . locator ( '.custom-snippet-content' ) ) . toBeVisible ( ) ;
156+ await expect ( page . locator ( '.custom-snippet-content h3' ) ) . toContainText ( 'Custom HTML Content' ) ;
157+ await expect ( page . locator ( '.custom-snippet-content p' ) ) . toContainText ( 'This content was inserted via shortcode!' ) ;
158+
159+ await expect ( page . locator ( 'text=Page content before shortcode.' ) ) . toBeVisible ( ) ;
160+ await expect ( page . locator ( 'text=Page content after shortcode.' ) ) . toBeVisible ( ) ;
161+ }
162+ } ) ;
163+
105164 test . afterEach ( async ( { page } ) => {
106165 await helper . cleanupSnippet ( TEST_SNIPPET_NAME ) ;
107166 } ) ;
0 commit comments