Skip to content

Commit

Permalink
Make taxonomies test relieable.
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed Mar 8, 2019
1 parent b421fc9 commit e1707bb
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions packages/e2e-tests/specs/taxonomies.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import {
publishPost,
} from '@wordpress/e2e-test-utils';

/**
* Module constants
*/
const TAG_TOKEN_SELECTOR = '.components-form-token-field__token-text span:not(.screen-reader-text)';

describe( 'Taxonomies', () => {
const canCreatTermInTaxonomy = ( taxonomy ) => {
return page.evaluate(
Expand Down Expand Up @@ -38,13 +43,13 @@ describe( 'Taxonomies', () => {

const getCurrentTags = async () => {
const tagsPanel = await findSidebarPanelWithTitle( 'Tags' );
return page.evaluate( ( node ) => {
return page.evaluate( ( node, selector ) => {
return Array.from( node.querySelectorAll(
'.components-form-token-field__token-text span:not(.screen-reader-text)'
selector
) ).map( ( field ) => {
return field.innerText;
} );
}, tagsPanel );
}, tagsPanel, TAG_TOKEN_SELECTOR );
};

it( 'should be able to open the categories panel and create a new main category if the user has the right capabilities', async () => {
Expand Down Expand Up @@ -123,6 +128,13 @@ describe( 'Taxonomies', () => {
// Open the tags panel.
await tagsPanel.click( 'button' );

// At the start there are no tag tokens
expect(
await page.$$(
TAG_TOKEN_SELECTOR
)
).toHaveLength( 0 );

const tagInput = await tagsPanel.$( '.components-form-token-field__input' );

// Click the tag input field.
Expand All @@ -134,7 +146,7 @@ describe( 'Taxonomies', () => {
// Press enter to create a new tag.
await tagInput.press( 'Enter' );

await page.waitForSelector( '.components-form-token-field__token' );
await page.waitForSelector( TAG_TOKEN_SELECTOR );

// Get an array with the tags of the post.
let tags = await getCurrentTags();
Expand Down

0 comments on commit e1707bb

Please sign in to comment.