11/* eslint-disable jest/no-done-callback */
22const { test, expect } = require ( '@playwright/test' ) ;
33
4+ const DOI_SAMPLE = '10.1038/s41586-020-2649-2' ;
5+
46function getPluginRow ( page ) {
57 return page . locator (
68 'tr[data-plugin="borges-bibliography-builder/bibliography-builder.php"]:not(.plugin-update-tr)'
@@ -99,6 +101,48 @@ async function openInserterAndSearch(page, query) {
99101 await inserterSearch . fill ( query ) ;
100102}
101103
104+ async function getEditorFrame ( page ) {
105+ const editorIframe = page . frameLocator ( 'iframe[name="editor-canvas"]' ) ;
106+ const iframeBody = editorIframe . locator ( 'body' ) ;
107+
108+ if ( await iframeBody . isVisible ( { timeout : 3000 } ) . catch ( ( ) => false ) ) {
109+ return editorIframe ;
110+ }
111+
112+ return page ;
113+ }
114+
115+ async function insertBibliographyBlock ( page ) {
116+ await page . waitForFunction (
117+ ( ) =>
118+ window . wp ?. blocks ?. getBlockType (
119+ 'bibliography-builder/bibliography'
120+ ) &&
121+ window . wp ?. blocks ?. createBlock &&
122+ window . wp ?. data ?. dispatch ( 'core/block-editor' ) ?. insertBlock ,
123+ null ,
124+ { timeout : 20_000 }
125+ ) ;
126+
127+ await page . evaluate ( ( ) => {
128+ const block = window . wp . blocks . createBlock (
129+ 'bibliography-builder/bibliography'
130+ ) ;
131+ const editor = window . wp . data . dispatch ( 'core/block-editor' ) ;
132+ editor . insertBlock ( block ) ;
133+ editor . selectBlock ( block . clientId ) ;
134+ } ) ;
135+
136+ const editorFrame = await getEditorFrame ( page ) ;
137+ await expect (
138+ editorFrame
139+ . locator ( '.wp-block-bibliography-builder-bibliography' )
140+ . first ( )
141+ ) . toBeVisible ( { timeout : 30_000 } ) ;
142+
143+ return editorFrame ;
144+ }
145+
102146test ( 'bibliography block is discoverable in the editor inserter' , async ( {
103147 page,
104148} ) => {
@@ -116,3 +160,33 @@ test('bibliography block is discoverable in the editor inserter', async ({
116160 await openInserterAndSearch ( page , 'Bibliography' ) ;
117161 await expect ( page . getByText ( 'Bibliography' ) . first ( ) ) . toBeVisible ( ) ;
118162} ) ;
163+
164+ test ( 'bibliography block imports a DOI in the Playground editor' , async ( {
165+ page,
166+ } ) => {
167+ test . setTimeout ( 90_000 ) ;
168+
169+ await ensurePluginActivated ( page ) ;
170+ await page . goto ( '/wp-admin/post-new.php' ) ;
171+ await page . waitForLoadState ( 'domcontentloaded' ) ;
172+ await dismissEditorOverlay ( page ) ;
173+
174+ const editorFrame = await insertBibliographyBlock ( page ) ;
175+ const textarea = editorFrame
176+ . locator ( '#bibliography-builder-paste-input' )
177+ . first ( ) ;
178+ await expect ( textarea ) . toBeVisible ( { timeout : 20_000 } ) ;
179+ await textarea . fill ( DOI_SAMPLE ) ;
180+
181+ await editorFrame . getByRole ( 'button' , { name : / ^ A d d $ / i } ) . click ( ) ;
182+
183+ const entryText = editorFrame
184+ . locator ( '.bibliography-builder-entry-text' )
185+ . first ( ) ;
186+ await expect ( entryText ) . toBeVisible ( { timeout : 45_000 } ) ;
187+ await expect
188+ . poll ( async ( ) => ( await entryText . textContent ( ) ) ?. trim ( ) || '' , {
189+ timeout : 45_000 ,
190+ } )
191+ . not . toBe ( '' ) ;
192+ } ) ;
0 commit comments