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

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

declare const browser: Browser;

/**
 * Shallowly tests the Stats feature, including Jetpack/Odyssey stats.
 *
 * Keywords: Stats, Jetpack, Odyssey Stats
 */
describe( DataHelper.createSuiteTitle( 'Stats' ), function () {
	let page: Page;
	let testAccount: TestAccount;
	let statsPage: StatsPage;

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

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

		testAccount = new TestAccount( accountName );
		await testAccount.authenticate( page );
	} );

	it( 'Navigate to Stats', async function () {
		statsPage = new StatsPage( page );

		if ( envVariables.ATOMIC_VARIATION === 'ecomm-plan' ) {
			return await statsPage.visit(
				DataHelper.getAccountSiteURL( accountName, { protocol: false } )
			);
		}
		const sidebarComponent = new SidebarComponent( page );
		await sidebarComponent.navigate( 'Jetpack', 'Stats' );
	} );

	describe( 'Traffic', function () {
		it( 'Click on the Traffic tab', async function () {
			await statsPage.clickTab( 'Traffic' );
		} );

		// TODO: Check if this test should be skipped.
		// it( 'Select "Months" stats period', async function () {
		// 	await statsPage.selectStatsPeriodFromDropdown( 'Months' );
		// } );

		it( 'Filter traffic activity to Likes', async function () {
			await statsPage.showStatsOfType( { tab: 'Traffic', type: 'Likes' } );
		} );
	} );

	describe( 'Insights', function () {
		it( 'Click on Insights tab', async function () {
			await statsPage.clickTab( 'Insights' );
		} );

		it( 'Click link to see all annual insights', async function () {
			await statsPage.clickViewAllAnnualInsights();
			// Right now, we can't actually verify stats data because if run right after a test site purge,
			// there may be nothing in there. We just verify that we can get to the page.

			// TODO: find a reliable way to extend this to check data too.
		} );

		it( 'Go back', async function () {
			await page.goBack();
		} );
	} );

	describe( 'Subscribers', function () {
		it( 'Click on Subscribers tab', async function () {
			await statsPage.clickTab( 'Subscribers' );
		} );
	} );

	// The Store tab is not present unless Business or higher plan is on the site and the
	// site has gone AT.
	skipDescribeIf( accountName !== 'jetpackAtomicEcommPlanUser' )( 'Store', function () {
		it( 'Click on the Store tab', async function () {
			await statsPage.clickTab( 'Store' );
		} );

		it( 'Select "Years" stats period', async function () {
			await statsPage.selectStatsPeriod( 'Years' );
		} );

		it( 'Select "Gross sales" stats type', async function () {
			await statsPage.showStatsOfType( { tab: 'Store', type: 'Gross Sales' } );
		} );
	} );
} );