File size: 6,271 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
/**
* @group gutenberg
* @group calypso-pr
*/
import {
DataHelper,
EditorPage,
envVariables,
TestAccount,
PostsPage,
ParagraphBlock,
WpAdminNoticeComponent,
getTestAccountByFeature,
envToFeatureKey,
ElementHelper,
} from '@automattic/calypso-e2e';
import { Browser, Page } from 'playwright';
declare const browser: Browser;
describe( 'Editor: Advanced Post Flow', function () {
// Authentication setup.
const features = envToFeatureKey( envVariables );
const accountName = getTestAccountByFeature( features, [
{ gutenberg: 'stable', siteType: 'simple', accountName: 'simpleSitePersonalPlanUser' },
] );
// Post content setup.
const postTitle = `Post Life Cycle: ${ DataHelper.getTimestamp() }`;
const originalContent = DataHelper.getRandomPhrase();
const additionalContent = 'Updated post content';
let page: Page;
let testAccount: TestAccount;
let editorPage: EditorPage;
let postsPage: PostsPage;
let paragraphBlock: ParagraphBlock;
let postURL: URL;
beforeAll( async function () {
page = await browser.newPage();
testAccount = new TestAccount( accountName );
await testAccount.authenticate( page );
} );
describe( 'Publish post', function () {
it( 'Start a new post from the Posts page', async function () {
postsPage = new PostsPage( page );
await postsPage.visit();
await postsPage.newPost();
} );
it( 'Enter post title', async function () {
editorPage = new EditorPage( page );
await editorPage.enterTitle( postTitle );
} );
it( 'Enter post content', async function () {
const blockHandle = await editorPage.addBlockFromSidebar(
ParagraphBlock.blockName,
ParagraphBlock.blockEditorSelector,
{ noSearch: true }
);
paragraphBlock = new ParagraphBlock( blockHandle );
await paragraphBlock.enterParagraph( originalContent );
} );
it( 'Publish post', async function () {
postURL = await editorPage.publish();
} );
/**
* Validates post in the same tab to work around an issue with AT caching.
*
* @see https://github.com/Automattic/wp-calypso/pull/67964
*
* Retries due to possible cache issue.
* @see https://github.com/Automattic/wp-calypso/issues/57503
*/
it( 'Validate post', async function () {
await page.goto( postURL.href );
await ElementHelper.reloadAndRetry( page, validatePublishedPage );
async function validatePublishedPage(): Promise< void > {
await ParagraphBlock.validatePublishedContent( page, [ originalContent ] );
}
} );
} );
describe( 'Edit published post', function () {
it( 'Re-open the published post from the Posts page', async function () {
// Redefine the `EditorPage` without the `target`
// optional parameter.
// This is critical because even AT sites load with
// an iframe when the post is opened from the
// PostsPage.
// See: https://github.com/Automattic/wp-calypso/issues/74925
await postsPage.visit();
await postsPage.clickPost( postTitle );
editorPage = new EditorPage( page );
} );
it( 'Editor is shown', async function () {
await editorPage.waitUntilLoaded();
} );
it( 'Append additional content', async function () {
const blockHandle = await editorPage.addBlockFromSidebar(
ParagraphBlock.blockName,
ParagraphBlock.blockEditorSelector,
{ noSearch: true }
);
paragraphBlock = new ParagraphBlock( blockHandle );
await paragraphBlock.enterParagraph( additionalContent );
} );
it( 'Publish post', async function () {
postURL = await editorPage.publish();
} );
/**
* Validates post in the same tab to work around an issue with AT caching.
*
* @see https://github.com/Automattic/wp-calypso/pull/67964
*
* Retries due to possible cache issue.
* @see https://github.com/Automattic/wp-calypso/issues/57503
*/
it( 'Ensure published post contains additional content', async function () {
await page.goto( postURL.href );
await ElementHelper.reloadAndRetry( page, validatePublishedPage );
async function validatePublishedPage(): Promise< void > {
await ParagraphBlock.validatePublishedContent( page, [
originalContent,
additionalContent,
] );
}
} );
} );
describe( 'Revert post to draft', function () {
it( 'Re-open the published post from the Posts page', async function () {
// See: https://github.com/Automattic/wp-calypso/issues/74925
await postsPage.visit();
await postsPage.clickPost( postTitle );
editorPage = new EditorPage( page );
} );
it( 'Switch to draft', async function () {
await editorPage.unpublish();
} );
it( 'Ensure post is no longer visible', async function () {
// It's important that we use another context to confirm that the
// page was reverted to draft. It's also important that we DON'T use
// a separate context to preview this page when it was previously
// published, because it would get cached and wouldn't 404 until the
// cache self-invalidates (300s period). This workaround is specific
// for Atomic sites. See pMz3w-fZ0 for more info.
const tmpPage = await browser.newPage();
await tmpPage.goto( postURL.href );
await tmpPage.waitForSelector( 'body.error404' );
await tmpPage.close();
} );
} );
describe( 'Trash post', function () {
beforeAll( async function () {
await postsPage.visit();
} );
it( 'Trash post', async function () {
await postsPage.clickTab( 'Drafts' );
await postsPage.clickActionItemForPost( { title: postTitle, action: 'Trash' } );
} );
it( 'Confirmation notice is shown', async function () {
const noticeComponent = new WpAdminNoticeComponent( page );
await noticeComponent.noticeShown( '1 post moved to the Trash.', {
type: 'Updated',
} );
} );
} );
describe( 'Permanently delete post', function () {
it( 'View trashed posts', async function () {
await postsPage.clickTab( 'Trash' );
} );
it( 'Hard trash post', async function () {
await postsPage.clickActionItemForPost( { title: postTitle, action: 'Delete Permanently' } );
} );
it( 'Confirmation notice is shown', async function () {
const noticeComponent = new WpAdminNoticeComponent( page );
await noticeComponent.noticeShown( '1 post permanently deleted', {
type: 'Updated',
} );
} );
} );
} );
|