File size: 2,626 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
/**
 * @group jetpack-remote-site
 */

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

declare const browser: Browser;

describe( DataHelper.createSuiteTitle( 'Jetpack: Plugin' ), function () {
	// Use a different plugin name to avoid clash between mobile and desktop
	// build configurations.
	const pluginName = envVariables.VIEWPORT_NAME === 'desktop' ? 'Hello Dolly' : 'Developer';
	let page: Page;
	let pluginsPage: PluginsPage;
	let noticeComponent: NoticeComponent;
	let siteURL: string;
	let restAPIClient: RestAPIClient;

	beforeAll( async function () {
		// Ensure known good state by removing the plugin if already installed.
		restAPIClient = new RestAPIClient( SecretsManager.secrets.testAccounts.jetpackRemoteSiteUser );
		const siteID = SecretsManager.secrets.testAccounts.jetpackRemoteSiteUser.testSites?.primary
			.id as number;
		const response = await restAPIClient.removePluginIfInstalled( siteID, pluginName );

		if ( response ) {
			console.log( `Successfully removed the plugin '${ pluginName }'.` );
		} else {
			console.log( `Unable to remove the plugin '${ pluginName }'; no action performed.` );
		}

		page = await browser.newPage();

		const testAccount = new TestAccount( 'jetpackRemoteSiteUser' );
		await testAccount.authenticate( page );
		siteURL = SecretsManager.secrets.testAccounts.jetpackRemoteSiteUser.testSites?.primary
			.url as string;
		pluginsPage = new PluginsPage( page );
		await pluginsPage.visit( siteURL );
	} );

	describe( 'Plugin: Install', function () {
		it( 'Install plugin', async function () {
			await pluginsPage.visitPage( pluginName.replace( ' ', '-' ).toLowerCase(), siteURL );
			await pluginsPage.clickInstallPlugin();
		} );

		it( 'See confirmation page', async function () {
			await pluginsPage.validateConfirmationPagePostInstall( pluginName );
		} );

		it( 'Click manage plugin', async function () {
			await pluginsPage.clickManageInstalledPluginButton();
		} );
	} );

	describe( 'Plugin: Deactivate', function () {
		it( 'Deactivate plugin', async function () {
			await pluginsPage.clickDeactivatePlugin();
		} );
	} );

	describe( 'Plugin: Remove', function () {
		it( 'Remove plugin', async function () {
			await pluginsPage.clickRemovePlugin();
			noticeComponent = new NoticeComponent( page );
			const message = `Successfully removed ${ pluginName }`;
			await noticeComponent.noticeShown( message, {
				type: 'Success',
			} );
			await noticeComponent.dismiss( message );
		} );
	} );
} );