File size: 1,879 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
/**
 * @group calypso-release
 */

import {
	CartCheckoutPage,
	TestAccount,
	RestAPIClient,
	BrowserManager,
	SecretsManager,
	PluginsPage,
} from '@automattic/calypso-e2e';
import { Page, Browser } from 'playwright';

declare const browser: Browser;

describe( 'Plugins: Add multiple to cart', function () {
	const credentials = SecretsManager.secrets.testAccounts.simpleSiteFreePlanUser;
	const plugin1Name = 'Sensei Pro';
	const plugin2Name = 'AutomateWoo';

	let pluginsPage: PluginsPage;
	let cartCheckoutPage: CartCheckoutPage;
	let page: Page;
	let restAPIClient: RestAPIClient;
	let testAccount: TestAccount;

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

		testAccount = new TestAccount( 'simpleSiteFreePlanUser' );
		await testAccount.authenticate( page );

		restAPIClient = new RestAPIClient( testAccount.credentials );
		await restAPIClient.clearShoppingCart(
			testAccount.credentials.testSites?.primary.id as number
		);

		await BrowserManager.setStoreCookie( page );
		pluginsPage = new PluginsPage( page );
	} );

	describe.each( [ plugin1Name, plugin2Name ] )( 'Add %s plugin to cart', function ( pluginName ) {
		it( `Go to plugins page for ${ pluginName }`, async function () {
			await pluginsPage.visitPage(
				pluginName.toLowerCase().replace( ' ', '-' ),
				testAccount.credentials.testSites?.primary.url
			);
		} );

		it( 'Click on install button', async function () {
			await pluginsPage.clickInstallPlugin();
		} );

		it.each( [ 'WordPress.com', pluginName ] )( '%s is added to cart', async function ( target ) {
			cartCheckoutPage = new CartCheckoutPage( page );
			await cartCheckoutPage.validateCartItem( target );
		} );
	} );

	afterAll( async function () {
		const restAPIClient = new RestAPIClient( credentials );
		await restAPIClient.clearShoppingCart( credentials.testSites?.primary?.id as number );
	} );
} );