|
| 1 | +import { test, expect } from '@wordpress/e2e-test-utils-playwright'; |
| 2 | +import { v4 as uuidv4 } from 'uuid'; |
| 3 | + |
| 4 | +test.describe( 'Editor: saving a new post', () => { |
| 5 | + let page, postTitle, postId; |
| 6 | + |
| 7 | + test.beforeAll( async ( { browser } ) => { |
| 8 | + page = await browser.newPage(); |
| 9 | + |
| 10 | + const uuid = uuidv4(); |
| 11 | + postTitle = `Test Post ${ uuid }`; // Sometimes this runs more than once within a microsecond so it's a UUID. |
| 12 | + |
| 13 | + // eslint-disable-next-line no-console |
| 14 | + console.log( `New post ${ postTitle }` ); |
| 15 | + |
| 16 | + // Even though we're using WP's npm package, it's more straightforward to do it this way, at least for me in this environment. |
| 17 | + await page.goto( 'http://stream.wpenv.net/wp-login.php?redirect_to=http://stream.wpenv.net/wp-admin/post-new.php%2F&reauth=1' ); |
| 18 | + await page.getByLabel( 'Username or Email Address' ).fill( 'admin' ); |
| 19 | + await page.getByLabel( 'Password', { exact: true } ).fill( 'password' ); |
| 20 | + await page.getByRole( 'button', { name: 'Log In' } ).click(); |
| 21 | + await page.getByLabel( 'Add title' ).click(); |
| 22 | + await page.getByLabel( 'Add title' ).fill( postTitle ); |
| 23 | + await page.getByLabel( 'Add title' ).press( 'Tab' ); |
| 24 | + await page.getByLabel( 'Empty block; start writing or' ).fill( 'I\'m a test post' ); |
| 25 | + await page.getByRole( 'button', { name: 'Publish', exact: true } ).click(); |
| 26 | + |
| 27 | + postId = await page.locator( 'input#post_ID' ).inputValue(); |
| 28 | + |
| 29 | + // eslint-disable-next-line no-console |
| 30 | + console.log( `Post ID: ${ postId }` ); |
| 31 | + |
| 32 | + // We need to wait for both of the editor responses! The post saves to the posts table then the metadata saves to postmeta. |
| 33 | + await Promise.all( [ |
| 34 | + page.waitForResponse( ( resp ) => resp.url().includes( 'meta-box-loader' ) && resp.status() === 302 ), |
| 35 | + page.waitForResponse( ( resp ) => resp.url().includes( `wp-json/wp/v2/posts/${ postId }` ) && resp.status() === 200 ), |
| 36 | + page.getByLabel( 'Editor publish' ).getByRole( 'button', { name: 'Publish', exact: true } ).click(), |
| 37 | + ] ); |
| 38 | + |
| 39 | + // They are too much in the posts table so I'm deleting them. |
| 40 | + await page.goto( 'http://stream.wpenv.net/wp-admin/edit.php?post_type=post' ); |
| 41 | + const listTable = page.getByRole( 'table', { name: 'Table ordered by' } ); |
| 42 | + await expect( listTable ).toBeVisible(); |
| 43 | + |
| 44 | + // Move post to trash. |
| 45 | + await listTable.getByRole( 'link', { name: `“${ postTitle }” (Edit)` } ).hover(); |
| 46 | + await listTable.getByRole( 'link', { name: `Move “${ postTitle }” to the Trash` } ).click(); |
| 47 | + |
| 48 | + // Ok, we're all set up, let's go to our page. |
| 49 | + await page.goto( 'http://stream.wpenv.net/wp-admin/admin.php?page=wp_stream' ); |
| 50 | + } ); |
| 51 | + |
| 52 | + // Do we have a published row? |
| 53 | + test( 'has published row', async () => { |
| 54 | + // Expects Stream log to have "Test Post" post published visible. |
| 55 | + await expect( page.getByText( `"${ postTitle }" post published` ) ).toBeVisible(); |
| 56 | + } ); |
| 57 | + |
| 58 | + // We should not have an updated row. This times out which makes it fail. |
| 59 | + test( 'does not have updated row', async () => { |
| 60 | + // Expects Stream log to have "Test Post" post published visible. |
| 61 | + await expect( page.getByText( `"${ postTitle }" post updated` ) ).not.toBeVisible(); |
| 62 | + } ); |
| 63 | +} ); |
0 commit comments