-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
chore: Add test for block mover (#8011) #8392
Merged
Merged
Changes from all 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import '../support/bootstrap'; | ||
import { newPost, newDesktopBrowserPage } from '../support/utils'; | ||
|
||
describe( 'block mover', () => { | ||
beforeEach( async () => { | ||
await newDesktopBrowserPage(); | ||
await newPost(); | ||
} ); | ||
|
||
it( 'should show block mover when more than one block exists', async () => { | ||
// Create a two blocks on the page. | ||
await page.click( '.editor-default-block-appender' ); | ||
await page.keyboard.type( 'First Paragraph' ); | ||
await page.keyboard.press( 'Enter' ); | ||
await page.keyboard.type( 'Second Paragraph' ); | ||
|
||
// Select a block so the block mover is rendered. | ||
await page.focus( '.editor-block-list__block' ); | ||
|
||
const blockMover = await page.$$( '.editor-block-mover' ); | ||
// There should be a block mover. | ||
expect( blockMover ).toHaveLength( 1 ); | ||
} ); | ||
|
||
it( 'should hide block mover when only one block exists', async () => { | ||
// Create a single block on the page. | ||
await page.click( '.editor-default-block-appender' ); | ||
await page.keyboard.type( 'First Paragraph' ); | ||
|
||
// Select a block so the block mover has the possibility of being rendered. | ||
await page.focus( '.editor-block-list__block' ); | ||
|
||
// Ensure no block mover exists when only one block exists on the page. | ||
const blockMover = await page.$$( '.editor-block-mover' ); | ||
expect( blockMover ).toHaveLength( 0 ); | ||
} ); | ||
} ); |
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.
Normally we open a page for all the tests e.g: await newDesktopBrowserPage(); is in a before all block and not in a beforeEach block. Was there any special reason for this difference? Can the newDesktopBrowserPage call be in a beforeAll block?
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.
Probably not but I'll double-check.
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.
Ah, scratch that; we need an empty post for each test. If we use
beforeAll
we don't have a clean slate that we need to know how many blocks are there.Our tests in the past use
beforeAll
possibly for speed? The globals in the tests are kinda weird... anyway, this needs a fresh state for each test sobeforeEach
it is...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.
But if we use newDesktopBrowserPage in beforeAll and newPost in beforeEach don't we get a fresh state on each test? We will just reuse the same tab but we start with an empty post on each test.
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 tried that out locally and it seemed to hang. I'll give it another go though, I just realised my environment could have been messed up locally from an unstashed, unrelated change.