File size: 2,983 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
/**
 * @group jetpack-wpcom-integration
 */

import {
	DataHelper,
	TestAccount,
	envVariables,
	getTestAccountByFeature,
	envToFeatureKey,
	JetpackDashboardPage,
	DashboardTabs,
	SettingsTabs,
} from '@automattic/calypso-e2e';
import { Page, Browser } from 'playwright';
import { skipDescribeIf, skipItIf } from '../../jest-helpers';

declare const browser: Browser;

/**
 * Smoke tests the various screens added to wp-admin by Jetpack.
 *
 * This test is basic and only checks whether the hidden screen-reader title element
 * is present.
 *
 * Keywords: Jetpack, Smoke Test
 */
skipDescribeIf( envVariables.TEST_ON_ATOMIC !== true )(
	DataHelper.createSuiteTitle( 'Jetpack: Dashboard Smoke Test' ),
	function () {
		const accountName = getTestAccountByFeature( envToFeatureKey( envVariables ) );
		const testAccount = new TestAccount( accountName );

		let page: Page;
		let jetpackDashboardPage: JetpackDashboardPage;

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

			jetpackDashboardPage = new JetpackDashboardPage( page );

			// Atomic tests sites might have local users, so the Jetpack SSO login will
			// show up when visiting the Jetpack dashboard directly. We can bypass it if
			// we simulate a redirect from Calypso to WP Admin with a hardcoded referer.
			// @see https://github.com/Automattic/jetpack/blob/12b3b9a4771169398d4e1982573aaec820babc17/projects/plugins/wpcomsh/wpcomsh.php#L230-L254
			const siteUrl = testAccount.getSiteURL( { protocol: true } );
			await page.goto( `${ siteUrl }wp-admin/`, {
				timeout: 15 * 1000,
				referer: 'https://wordpress.com/',
			} );
		} );

		it( 'Navigate to Jetpack dashboard', async function () {
			await jetpackDashboardPage.visit( testAccount.getSiteURL( { protocol: false } ) );
		} );

		describe( 'Dashboard', function () {
			it.each( [ { tab: 'At a Glance' }, { tab: 'My Plan' } ] )(
				'Click on $tab tab in the Dashboard view',
				async function ( { tab } ) {
					await jetpackDashboardPage.clickTab( { view: 'Dashboard', tab: tab as DashboardTabs } );

					await page
						.getByRole( 'heading', { name: tab, level: 1 } )
						.waitFor( { state: 'attached' } );
				}
			);
		} );

		describe( 'Settings', function () {
			it.each( [
				{ tab: 'Security' },
				{ tab: 'Performance' },
				{ tab: 'Writing' },
				{ tab: 'Sharing' },
				{ tab: 'Discussion' },
				{ tab: 'Traffic' },
				{ tab: 'Newsletter' },
			] )( 'Click on $tab tab in the Settings view', async function ( { tab } ) {
				await jetpackDashboardPage.clickTab( { view: 'Settings', tab: tab as SettingsTabs } );
			} );

			// Private sites are not eligible for monetization, so we only run this step on non-private sites.
			skipItIf( envVariables.ATOMIC_VARIATION === 'private' )(
				'Click on Monetize tab in the Settings view',
				async function () {
					await jetpackDashboardPage.clickTab( { view: 'Settings', tab: 'Monetize' } );
				}
			);
		} );
	}
);