-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add e2e test * Drop support WordPress6.2
- Loading branch information
Showing
11 changed files
with
237 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.vscode | ||
artifacts/ | ||
build/ | ||
node_modules/ | ||
vendor/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const config = require( '@wordpress/scripts/config/playwright.config.js' ); | ||
const { fileURLToPath } = require( 'url' ); | ||
|
||
export default { | ||
...config, | ||
globalSetup: fileURLToPath( new URL( './test/e2e/global-setup.ts', 'file:' + __filename ).href ), | ||
testDir: './test/e2e', | ||
}; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { request } from '@playwright/test'; | ||
import type { FullConfig } from '@playwright/test'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { RequestUtils } from '@wordpress/e2e-test-utils-playwright'; | ||
|
||
async function globalSetup( config: FullConfig ) { | ||
const { storageState, baseURL } = config.projects[ 0 ].use; | ||
const storageStatePath = typeof storageState === 'string' ? storageState : undefined; | ||
|
||
const requestContext = await request.newContext( { | ||
baseURL, | ||
} ); | ||
|
||
const requestUtils = new RequestUtils( requestContext, { | ||
storageStatePath, | ||
} ); | ||
|
||
// Authenticate and save the storageState to disk. | ||
await requestUtils.setupRest(); | ||
|
||
// Reset the test environment before running the tests. | ||
await Promise.all( [ | ||
requestUtils.activateTheme( 'twentytwentytwo' ), | ||
// Disable this test plugin as it's conflicting with some of the tests. | ||
// We already have reduced motion enabled and Playwright will wait for most of the animations anyway. | ||
requestUtils.deleteAllPosts(), | ||
requestUtils.deleteAllBlocks(), | ||
requestUtils.resetPreferences(), | ||
] ); | ||
|
||
await requestContext.dispose(); | ||
} | ||
|
||
export default globalSetup; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
const path = require( 'path' ); | ||
const fs = require( 'fs/promises' ); | ||
const os = require( 'os' ); | ||
const { v4: uuid } = require( 'uuid' ); | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { test, expect } from '@wordpress/e2e-test-utils-playwright'; | ||
|
||
test.use( { | ||
mediaUtils: async ( { page }, use ) => { | ||
await use( new MediaUtils( { page } ) ); | ||
}, | ||
} ); | ||
|
||
test.describe( 'Block', () => { | ||
test.beforeEach( async ( { admin } ) => { | ||
await admin.createNewPost(); | ||
} ); | ||
|
||
test( 'should create image block', async ( { editor, page, mediaUtils } ) => { | ||
// Insert Image block. | ||
await editor.insertBlock( { name: 'core/image' } ); | ||
|
||
const imageBlock = editor.canvas.locator( 'role=document[name="Block: Image"i]' ); | ||
await expect( imageBlock ).toBeVisible(); | ||
|
||
// Upload image. | ||
await mediaUtils.upload( | ||
imageBlock.locator( 'data-testid=form-file-upload-input' ), | ||
'1000x750.png' | ||
); | ||
|
||
// Add first image source. | ||
await editor.openDocumentSettingsSidebar(); | ||
const firstSourceFilename = await mediaUtils.uploadSource( '600x450.png' ); | ||
const firstSource = page.locator( 'role=region[name="Editor settings"i] >> img' ); | ||
await expect( firstSource ).toBeVisible(); | ||
await expect( firstSource ).toHaveAttribute( 'src', new RegExp( firstSourceFilename ) ); | ||
|
||
const enableResponsiveImagePanel = page.locator( '.enable-responsive-image' ); | ||
|
||
// Change first image setting. | ||
await page.fill( 'role=spinbutton[name="Media query value"i]', '800' ); | ||
await enableResponsiveImagePanel.locator( 'role=combobox[name="Resolution"i]' ).selectOption( { | ||
label: 'Medium', | ||
} ); | ||
|
||
// Add second image source. | ||
await page.click( 'role=button[name="Add image source"i]' ); | ||
const secondSourceFilename = await mediaUtils.uploadSource( '400x300.png' ); | ||
const secondSource = page.locator( 'role=region[name="Editor settings"i] >> img' ).nth( 1 ); | ||
await expect( secondSource ).toBeVisible(); | ||
await expect( secondSource ).toHaveAttribute( 'src', new RegExp( secondSourceFilename ) ); | ||
|
||
// Chage second image setting. | ||
await page.locator( 'role=spinbutton[name="Media query value"i]' ).nth( 1 ).fill( '500' ); | ||
await enableResponsiveImagePanel | ||
.locator( 'role=radiogroup[name="Media query type"i]' ) | ||
.nth( 1 ) | ||
.click( 'role=radio[name="min-width"i]' ); | ||
await enableResponsiveImagePanel | ||
.locator( 'role=combobox[name="Resolution"i]' ) | ||
.nth( 1 ) | ||
.selectOption( { | ||
label: 'Thumbnail', | ||
} ); | ||
|
||
const blocks = await editor.getBlocks(); | ||
|
||
await expect.poll( editor.getBlocks ).toMatchObject( [ | ||
{ | ||
name: 'core/image', | ||
attributes: { | ||
sources: [ | ||
{ | ||
slug: 'medium', | ||
mediaType: 'max-width', | ||
mediaValue: 800, | ||
}, | ||
{ | ||
slug: 'thumbnail', | ||
mediaType: 'min-width', | ||
mediaValue: 500, | ||
}, | ||
], | ||
}, | ||
}, | ||
] ); | ||
|
||
const sources = blocks[ 0 ].attributes.sources; | ||
expect( sources[ 0 ].srcset.includes( firstSourceFilename ) ).toBe( true ); | ||
expect( sources[ 1 ].srcset.includes( secondSourceFilename ) ).toBe( true ); | ||
} ); | ||
} ); | ||
|
||
class MediaUtils { | ||
constructor( { page } ) { | ||
this.page = page; | ||
this.basePath = path.join( __dirname, 'assets' ); | ||
} | ||
|
||
async upload( inputElement, customFile ) { | ||
const tmpDirectory = await fs.mkdtemp( path.join( os.tmpdir(), 'test-image-' ) ); | ||
const filename = uuid(); | ||
const tmpFileName = path.join( tmpDirectory, filename + '.png' ); | ||
const filepath = path.join( this.basePath, customFile ); | ||
await fs.copyFile( filepath, tmpFileName ); | ||
await inputElement.setInputFiles( tmpFileName ); | ||
return filename; | ||
} | ||
|
||
async uploadSource( customFile ) { | ||
await this.page.click( 'role=button[name="Set image source"i]' ); | ||
const filename = await this.upload( | ||
this.page.locator( '.media-modal .moxie-shim input[type=file]' ), | ||
customFile | ||
); | ||
await this.page.click( 'role=dialog >> role=button[name="Select"i]' ); | ||
return filename; | ||
} | ||
} |