-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5456 from wordpress-mobile/add-visual-tests-support
Add visual tests support
- Loading branch information
Showing
15 changed files
with
948 additions
and
3 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
const { blockNames } = editorPage; | ||
import { takeScreenshot } from './utils'; | ||
|
||
describe( 'Gutenberg Editor Visual test for Gallery Block', () => { | ||
it( 'should be able to render the placeholder correctly', async () => { | ||
await editorPage.addNewBlock( blockNames.gallery ); | ||
await editorPage.closePicker(); | ||
|
||
// Visual test check | ||
const screenshot = await takeScreenshot(); | ||
expect( screenshot ).toMatchImageSnapshot(); | ||
|
||
await editorPage.removeBlockAtPosition( blockNames.gallery ); | ||
} ); | ||
|
||
it( 'should be able to render a gallery correctly', async () => { | ||
await editorPage.setHtmlContent( | ||
[ e2eTestData.galleryBlock ].join( '\n\n' ) | ||
); | ||
const galleryBlock = await editorPage.getBlockAtPosition( | ||
blockNames.gallery | ||
); | ||
expect( galleryBlock ).toBeTruthy(); | ||
|
||
// Wait for images to load | ||
await editorPage.driver.sleep( 5000 ); | ||
|
||
// Visual test check | ||
const screenshot = await takeScreenshot(); | ||
expect( screenshot ).toMatchImageSnapshot(); | ||
} ); | ||
} ); |
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,23 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
const { blockNames } = editorPage; | ||
import { takeScreenshot } from './utils'; | ||
|
||
describe( 'Gutenberg Editor Visual test for Group Block', () => { | ||
it( 'should show the empty placeholder for the unselected state', async () => { | ||
await editorPage.addNewBlock( blockNames.group ); | ||
|
||
// Select title to unfocus the block | ||
const titleElement = await editorPage.getTitleElement(); | ||
titleElement.click(); | ||
|
||
await editorPage.dismissKeyboard(); | ||
// Wait for the keyboard to be hidden | ||
await editorPage.driver.sleep( 3000 ); | ||
|
||
// Visual test check | ||
const screenshot = await takeScreenshot(); | ||
expect( screenshot ).toMatchImageSnapshot(); | ||
} ); | ||
} ); |
Binary file added
BIN
+20.1 KB
...st-for-gallery-block-should-be-able-to-render-a-gallery-correctly-1-android.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+26.2 KB
...l-test-for-gallery-block-should-be-able-to-render-a-gallery-correctly-1-ios.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+13.3 KB
...-gallery-block-should-be-able-to-render-the-placeholder-correctly-1-android.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+19.9 KB
...-for-gallery-block-should-be-able-to-render-the-placeholder-correctly-1-ios.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+15.1 KB
...-block-should-show-the-empty-placeholder-for-the-unselected-state-1-android.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+22.2 KB
...roup-block-should-show-the-empty-placeholder-for-the-unselected-state-1-ios.png
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,22 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import jimp from 'jimp'; | ||
|
||
const { isAndroid } = e2eUtils; | ||
|
||
export async function takeScreenshot() { | ||
const statusBarHeight = isAndroid() ? 100 : 94; | ||
const screenshot = await editorPage.driver.takeScreenshot(); | ||
|
||
const base64Image = Buffer.from( screenshot, 'base64' ); | ||
const image = await jimp.read( base64Image ); | ||
image.crop( | ||
0, | ||
statusBarHeight, | ||
image.getWidth(), | ||
image.getHeight() - statusBarHeight | ||
); | ||
const resizedImage = await image.resize( 320, jimp.AUTO ); | ||
return resizedImage.getBufferAsync( jimp.MIME_PNG ); | ||
} |
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,24 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
const { | ||
isAndroid, | ||
} = require( './gutenberg/packages/react-native-editor/__device-tests__/helpers/utils' ); | ||
|
||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
const { configureToMatchImageSnapshot } = require( 'jest-image-snapshot' ); | ||
|
||
const toMatchImageSnapshot = configureToMatchImageSnapshot( { | ||
failureThreshold: 0.01, // 1% threshold. | ||
failureThresholdType: 'percent', | ||
dumpInlineDiffToConsole: true, | ||
runInProcess: true, | ||
customSnapshotIdentifier( data ) { | ||
return `${ data.defaultIdentifier }-${ | ||
isAndroid() ? 'android' : 'ios' | ||
}`; | ||
}, | ||
customSnapshotsDir: '__device-tests__/image-snapshots', | ||
customDiffDir: '__device-tests__/image-snapshots/diff', | ||
} ); | ||
expect.extend( { toMatchImageSnapshot } ); |
Oops, something went wrong.