-
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.
Showing
11 changed files
with
459 additions
and
106 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,15 @@ | ||
import { test as base } from '@wordpress/e2e-test-utils-playwright'; | ||
|
||
import { MediaUtils } from './mediaUtils'; | ||
|
||
type E2EFixture = { | ||
mediaUtils: MediaUtils; | ||
}; | ||
|
||
export const test = base.extend< E2EFixture, {} >( { | ||
mediaUtils: async ( { page }, use ) => { | ||
await use( new MediaUtils( { page } ) ); | ||
}, | ||
} ); | ||
|
||
export { expect } from '@wordpress/e2e-test-utils-playwright'; |
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,43 @@ | ||
import { join } from 'node:path'; | ||
import { tmpdir } from 'node:os'; | ||
import { copyFile, mkdtemp } from 'node:fs/promises'; | ||
|
||
import { v4 as uuidv4 } from 'uuid'; | ||
import type { Page, ElementHandle, Locator } from '@playwright/test'; | ||
|
||
export class MediaUtils { | ||
page: Page; | ||
basePath: string; | ||
DEFAULT_IMAGE_PATH: string; | ||
|
||
constructor( { page } ) { | ||
this.page = page; | ||
this.basePath = join( __dirname, '..', 'assets' ); | ||
|
||
this.DEFAULT_IMAGE_PATH = join( | ||
this.basePath, | ||
'wordpress-logo-512x512.png' | ||
); | ||
} | ||
|
||
async upload( inputElement: Locator, fileName?: string ) { | ||
const tmpDirectory = await mkdtemp( | ||
join( tmpdir(), 'gutenberg-test-image-' ) | ||
); | ||
const newFileName = uuidv4(); | ||
const tmpFileName = join( tmpDirectory, `${ newFileName }.png` ); | ||
const filepath = fileName | ||
? join( this.basePath, fileName ) | ||
: this.DEFAULT_IMAGE_PATH; | ||
await copyFile( filepath, tmpFileName ); | ||
|
||
await inputElement.setInputFiles( tmpFileName ); | ||
|
||
return newFileName; | ||
} | ||
|
||
async getImageBuffer( url: string ) { | ||
const response = await this.page.request.get( url ); | ||
return await response.body(); | ||
} | ||
} |
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,54 @@ | ||
import { test, expect } from '../fixtures'; | ||
|
||
test.describe( 'Image block', () => { | ||
test.beforeAll( async ( { requestUtils } ) => { | ||
await requestUtils.deleteAllMedia(); | ||
} ); | ||
|
||
test.beforeEach( async ( { admin } ) => { | ||
await admin.createNewPost(); | ||
} ); | ||
|
||
test( 'uploads a file and allows optimizing it afterwards', async ( { | ||
page, | ||
editor, | ||
mediaUtils, | ||
} ) => { | ||
await editor.insertBlock( { name: 'core/image' } ); | ||
|
||
const imageBlock = editor.canvas.locator( | ||
'role=document[name="Block: Image"i]' | ||
); | ||
await expect( imageBlock ).toBeVisible(); | ||
|
||
await mediaUtils.upload( | ||
imageBlock.locator( 'data-testid=form-file-upload-input' ) | ||
); | ||
|
||
const settingsPanel = page | ||
.getByRole( 'region', { | ||
name: 'Editor settings', | ||
} ) | ||
.getByRole( 'tabpanel', { | ||
name: 'Settings', | ||
} ); | ||
|
||
await expect( settingsPanel ).toHaveText( /Mime type: image\/png/ ); | ||
await expect( settingsPanel.getByLabel( '#696969' ) ).toBeVisible(); | ||
|
||
await page.getByRole( 'button', { name: 'Optimize' } ).click(); | ||
|
||
const dialog = page.getByRole( 'dialog', { | ||
name: 'Compare media quality', | ||
} ); | ||
|
||
await expect( dialog ).toBeVisible(); | ||
|
||
await dialog | ||
.getByRole( 'button', { name: 'Use optimized version' } ) | ||
.click(); | ||
|
||
await expect( settingsPanel ).toHaveText( /Mime type: image\/webp/ ); | ||
await expect( settingsPanel.getByLabel( '#696969' ) ).toBeVisible(); | ||
} ); | ||
} ); |
This file was deleted.
Oops, something went wrong.
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,29 @@ | ||
import { test, expect } from '../fixtures'; | ||
|
||
test.describe( 'Preferences Modal', () => { | ||
test.beforeEach( async ( { admin } ) => { | ||
await admin.createNewPost(); | ||
} ); | ||
|
||
test( 'opens from the options menu, closes with its close button and returns focus', async ( { | ||
page, | ||
} ) => { | ||
await page | ||
.getByRole( 'region', { name: 'Editor top bar' } ) | ||
.getByRole( 'button', { name: 'Options' } ) | ||
.click(); | ||
await page | ||
.getByRole( 'menuitem', { | ||
name: 'Media Preferences', | ||
} ) | ||
.click(); | ||
|
||
const dialog = page.getByRole( 'dialog', { | ||
name: 'Preferences', | ||
} ); | ||
await expect( dialog ).toBeVisible(); | ||
|
||
await dialog.getByRole( 'button', { name: 'Close' } ).click(); | ||
await expect( dialog ).toBeHidden(); | ||
} ); | ||
} ); |