Skip to content
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 3 commits into from
Aug 7, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions test/e2e/specs/block-mover.test.js
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();
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member Author

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 so beforeEach it is...

Copy link
Member

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.

Copy link
Member Author

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.

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 );
} );
} );