File size: 5,405 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 |
/**
* @group calypso-release
*/
import {
DataHelper,
SidebarComponent,
PlansPage,
CartCheckoutPage,
TestAccount,
RestAPIClient,
BrowserManager,
SecretsManager,
NewSiteResponse,
PostResponse,
PublishedPostPage,
NavbarComponent,
MediaHelper,
TestFile,
MediaPage,
} from '@automattic/calypso-e2e';
import { Page, Browser } from 'playwright';
import { TEST_IMAGE_PATH } from '../constants';
import { apiDeleteSite } from '../shared';
declare const browser: Browser;
const postTitles = Array.from( { length: 2 }, () => DataHelper.getRandomPhrase() );
describe(
DataHelper.createSuiteTitle(
'Plans: Upgrade exising WordPress.com Free site to WordPress.com Premium'
),
function () {
const blogName = DataHelper.getBlogName();
const planName = 'Premium';
const publishedPosts: PostResponse[] = [];
let testMediaFile: TestFile;
let siteCreatedFlag: boolean;
let newSiteDetails: NewSiteResponse;
let restAPIClient: RestAPIClient;
let page: Page;
beforeAll( async function () {
// Set up the test site programmatically against simpleSiteFreePlanUser.
const credentials = SecretsManager.secrets.testAccounts.simpleSiteFreePlanUser;
restAPIClient = new RestAPIClient( credentials );
console.info( 'Creating a new test site.' );
newSiteDetails = await restAPIClient.createSite( {
name: blogName,
title: blogName,
} );
console.info( `New site created: ${ newSiteDetails.blog_details.url }` );
siteCreatedFlag = true;
// Add posts to site.
console.info( 'Adding test posts to the site.' );
for await ( const title of postTitles ) {
publishedPosts.push(
await restAPIClient.createPost( newSiteDetails.blog_details.blogid, {
title: title,
} )
);
}
console.info( 'Adding test image to site.' );
testMediaFile = await MediaHelper.createTestFile( TEST_IMAGE_PATH );
await restAPIClient.uploadMedia( newSiteDetails.blog_details.blogid, {
media: testMediaFile,
} );
// Launch browser.
page = await browser.newPage();
// Authenticate as simpleSiteFreePlanUser.
const testAccount = new TestAccount( 'simpleSiteFreePlanUser' );
await testAccount.authenticate( page );
} );
describe( `Upgrade to WordPress.com ${ planName }`, function () {
let cartCheckoutPage: CartCheckoutPage;
let plansPage: PlansPage;
beforeAll( async function () {
await BrowserManager.setStoreCookie( page );
} );
it( 'Navigate to Upgrades > Plans', async function () {
await page.goto(
DataHelper.getCalypsoURL( `/plans/${ newSiteDetails.blog_details.site_slug }` )
);
} );
it( 'View available plans', async function () {
plansPage = new PlansPage( page );
} );
it( `Click button to upgrade to WordPress.com ${ planName }`, async function () {
await plansPage.selectPlan( 'Premium' );
} );
it( `WordPress.com ${ planName } is added to cart`, async function () {
cartCheckoutPage = new CartCheckoutPage( page );
await cartCheckoutPage.validateCartItem( `WordPress.com ${ planName }` );
} );
it( 'Make purchase', async function () {
try {
await cartCheckoutPage.purchase( { timeout: 75 * 1000 } );
} catch {
// Work around an issue where purchase flow does not
// complete and redirect the user to the next screen
// beyond the timeout.
// See: https://github.com/Automattic/wp-calypso/issues/75867
await page.goto(
DataHelper.getCalypsoURL(
`checkout/thank-you/${ newSiteDetails.blog_details.site_slug }`
)
);
}
} );
it( 'Return to My Home dashboard', async function () {
const navbarComponent = new NavbarComponent( page );
await navbarComponent.clickMySites();
} );
} );
describe( `Validate WordPress.com ${ planName } functionality`, function () {
let sidebarComponent: SidebarComponent;
it( 'Navigate to Upgrades > Plans', async function () {
sidebarComponent = new SidebarComponent( page );
await sidebarComponent.navigate( 'Upgrades', 'Plans' );
} );
it( `Plans page states user is on WordPress.com ${ planName } plan`, async function () {
const plansPage = new PlansPage( page );
await plansPage.validateActivePlan( planName );
} );
} );
describe( 'Validate site content is intact', function () {
let testPage: Page;
beforeAll( async function () {
testPage = await browser.newPage();
} );
it.each( postTitles )( 'Post %s is preserved', async function ( postTitle: string ) {
// Locate the new post response for the post in question.
const postResponse = publishedPosts.find( ( r ) => r.title === postTitle ) as PostResponse;
// Visit the page and validate.
await testPage.goto( postResponse.URL );
const publishedPostPage = new PublishedPostPage( testPage );
await publishedPostPage.validateTitle( postTitle );
} );
it( 'Uploaded media is preserved', async function () {
const mediaPage = new MediaPage( page );
await mediaPage.visit( newSiteDetails.blog_details.site_slug );
await mediaPage.selectItem( { name: testMediaFile.basename } );
} );
} );
afterAll( async function () {
if ( ! siteCreatedFlag ) {
return;
}
await apiDeleteSite( restAPIClient, {
url: newSiteDetails.blog_details.url,
id: newSiteDetails.blog_details.blogid,
name: newSiteDetails.blog_details.blogname,
} );
} );
}
);
|