File size: 3,417 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
/**
 * @group calypso-pr
 * @group jetpack-wpcom-integration
 */

import {
	getTestAccountByFeature,
	envToFeatureKey,
	envVariables,
	DataHelper,
	AdvertisingPage,
	TestAccount,
	MediaHelper,
	BlazeCampaignPage,
	RestAPIClient,
	PostResponse,
} from '@automattic/calypso-e2e';
import { Page, Browser } from 'playwright';
import { skipDescribeIf } from '../../jest-helpers';
import { TEST_IMAGE_PATH } from '../constants';

declare const browser: Browser;

/**
 * Walks through the Advertising/Blaze flow until immediately prior to the checkout.
 *
 * The actual checkout is outside the scope of this spec.
 *
 * @see pdWQjU-rL-p2#comment-575.
 *
 * Keywords: Jetpack, Blaze, Advertising
 */
skipDescribeIf( envVariables.ATOMIC_VARIATION === 'private' )(
	DataHelper.createSuiteTitle( 'Advertising: Promote' ),
	function () {
		// The input has a limit, so let's stay way under to be safe!
		const pageTitle = DataHelper.getRandomPhrase().slice( 0, 20 );
		const snippet = Array( 2 ).fill( DataHelper.getRandomPhrase() ).toString();

		let newPostDetails: PostResponse;
		let page: Page;
		let restAPIClient: RestAPIClient;
		let testAccount: TestAccount;
		let advertisingPage: AdvertisingPage;
		let blazeCampaignPage: BlazeCampaignPage;

		beforeAll( async () => {
			page = await browser.newPage();

			const accountName = getTestAccountByFeature( envToFeatureKey( envVariables ), [
				{ gutenberg: 'stable', siteType: 'simple', accountName: 'defaultUser' },
			] );

			testAccount = new TestAccount( accountName );

			restAPIClient = new RestAPIClient( testAccount.credentials );

			// Createa a new test post before starting the test if site has no published post.
			const hasPosts = await restAPIClient.siteHasPost(
				testAccount.credentials.testSites?.primary.id as number,
				{ state: 'publish' }
			);

			if ( ! hasPosts ) {
				newPostDetails = await restAPIClient.createPost(
					testAccount.credentials.testSites?.primary.id as number,
					{
						title: pageTitle,
					}
				);
			}

			await testAccount.authenticate( page );

			advertisingPage = new AdvertisingPage( page );
		} );

		it( 'Navigate to Tools > Advertising page', async function () {
			await advertisingPage.visit( testAccount.getSiteURL( { protocol: false } ) );
		} );

		it( 'Click on Promote for the first post', async function () {
			await advertisingPage.clickButtonByNameOnRow( 'Promote', { row: 0 } );
		} );

		it( 'Land in Blaze campaign landing page', async function () {
			await page.waitForURL( /advertising/ );

			blazeCampaignPage = new BlazeCampaignPage( page );
		} );

		it( 'Click on Get started', async function () {
			await blazeCampaignPage.clickButton( 'Get started' );
		} );

		it( 'Upload image', async function () {
			const testFile = await MediaHelper.createTestFile( TEST_IMAGE_PATH );
			await blazeCampaignPage.uploadImage( testFile );
		} );

		it( 'Enter title and snippet', async function () {
			await blazeCampaignPage.enterText( 'Site title', pageTitle );
			await blazeCampaignPage.enterText( 'Snippet', snippet );
		} );

		it( 'Validate preview', async function () {
			await blazeCampaignPage.validatePreview( { title: pageTitle, snippet: snippet } );
		} );

		afterAll( async function () {
			if ( ! newPostDetails ) {
				return;
			}

			await restAPIClient.deletePost(
				testAccount.credentials.testSites?.primary.id as number,
				newPostDetails.ID
			);
		} );
	}
);