Skip to content

Commit

Permalink
Fix flaky Nav block user permissions e2e test (#38025)
Browse files Browse the repository at this point in the history
* Move user creation back to the top level

* Make unique contributor username

Acts a safeguard against duplicate users.
  • Loading branch information
getdave authored Jan 21, 2022
1 parent 1ad6636 commit 210af7e
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions packages/e2e-tests/specs/editor/blocks/navigation.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* External dependencies
*/
import { uniqueId } from 'lodash';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -211,6 +216,18 @@ async function getNavigationMenuRawContent() {
// Disable reason - these tests are to be re-written.
// eslint-disable-next-line jest/no-disabled-tests
describe( 'Navigation', () => {
const contributorUsername = uniqueId( 'contributoruser_' );
let contributorPassword;

beforeAll( async () => {
// Creation of the contributor user **MUST** be at the top level describe block
// otherwise this test will become unstable. This action only happens once
// so there is no huge performance hit.
contributorPassword = await createUser( contributorUsername, {
role: 'contributor',
} );
} );

beforeEach( async () => {
await deleteAll( [
POSTS_ENDPOINT,
Expand All @@ -233,6 +250,10 @@ describe( 'Navigation', () => {
NAVIGATION_MENUS_ENDPOINT,
] );
await deleteAllClassicMenus();

// As per the creation in the beforeAll() above, this
// action must be done at the root level describe() block.
await deleteUser( contributorUsername );
} );

describe( 'placeholder', () => {
Expand Down Expand Up @@ -760,24 +781,11 @@ describe( 'Navigation', () => {
expect( tagCount ).toBe( 1 );
} );

describe.skip( 'Permission based restrictions', () => {
const contributorUsername = 'contributoruser';
let contributorPassword;

beforeAll( async () => {
contributorPassword = await createUser( contributorUsername, {
role: 'contributor',
} );
} );

describe( 'Permission based restrictions', () => {
afterEach( async () => {
await switchUserToAdmin();
} );

afterAll( async () => {
await deleteUser( contributorUsername );
} );

it( 'shows a warning if user does not have permission to edit or update navigation menus', async () => {
await createNewPost();
await insertBlock( 'Navigation' );
Expand Down

0 comments on commit 210af7e

Please sign in to comment.