-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add visual tests support #5456
Merged
Merged
Add visual tests support #5456
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed the previous test has what appears to be clean up code removing the block. Should all tests including this one have that as well? This question applies to
__device-tests__/gutenberg-editor-group-visual.test.js
as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will depend on the test, for this case, to start with a "blank" canvas in the second test you need to remove the blocks you created before, as the other tests in the file will run in the same session.