const path = require( 'path' ); const fs = require( 'fs/promises' ); const os = require( 'os' ); const { randomUUID } = require( 'crypto' ); const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); test.use( { galleryBlockUtils: async ( { page }, use ) => { await use( new GalleryBlockUtils( { page } ) ); }, } ); test.describe( 'Gallery', () => { let uploadedMedia; let landscapeMedia; test.beforeAll( async ( { requestUtils } ) => { await requestUtils.deleteAllMedia(); uploadedMedia = await requestUtils.uploadMedia( './assets/10x10_e2e_test_image_z9T8jK.png' ); landscapeMedia = await requestUtils.uploadMedia( './assets/200x150_e2e_test_image_opaque.png' ); } ); test.afterEach( async ( { requestUtils } ) => { await requestUtils.deleteAllPosts(); } ); test.afterAll( async ( { requestUtils } ) => { await requestUtils.deleteAllMedia(); } ); test( 'can be transformed from pasting shortcode, and can undo/redo', async ( { admin, editor, page, pageUtils, } ) => { await admin.createNewPost(); pageUtils.setClipboardData( { plainText: `[gallery ids="${ uploadedMedia.id }"]`, } ); await editor.canvas .locator( 'role=document[name="Add default block"i]' ) .click(); await pageUtils.pressKeys( 'primary+v' ); const img = editor.canvas.locator( 'role=document[name="Block: Image"i] >> role=img' ); await expect( img ).toHaveAttribute( 'src', uploadedMedia.source_url ); await expect( img ).toBeVisible(); const editedPostContent = await editor.getEditedPostContent(); expect( editedPostContent ) .toBe( ` ` ); await page .getByRole( 'region', { name: 'Editor top bar' } ) .getByRole( 'button', { name: 'Undo' } ) .click(); await expect.poll( editor.getEditedPostContent ).toBe( '' ); await page .getByRole( 'region', { name: 'Editor top bar' } ) .getByRole( 'button', { name: 'Redo' } ) .click(); await expect .poll( editor.getEditedPostContent ) .toBe( editedPostContent ); } ); test( 'can be created using uploaded images', async ( { admin, editor, galleryBlockUtils, } ) => { await admin.createNewPost(); await editor.insertBlock( { name: 'core/gallery' } ); const galleryBlock = editor.canvas.locator( 'role=document[name="Block: Gallery"i]' ); await expect( galleryBlock ).toBeVisible(); await galleryBlockUtils.upload( galleryBlock.locator( 'data-testid=form-file-upload-input' ) ); const image = galleryBlock.locator( 'role=img' ); await expect( image ).toBeVisible(); // Wait for upload to complete (includes client-side media processing time). // With client-side processing, the filename may be changed by the server. await expect( image ).toHaveAttribute( 'src', /^https?:\/\//, { timeout: 30_000, } ); // Check that content has a valid gallery with an image. const regex = new RegExp( `\\s*