File size: 6,007 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/**
 * @group calypso-release
 */
import {
	DataHelper,
	TestAccount,
	envVariables,
	getTestAccountByFeature,
	envToFeatureKey,
	BrowserManager,
	SignupDomainPage,
	SignupPickPlanPage,
	NewSiteResponse,
	StartSiteFlow,
	MyHomePage,
	EditorPage,
	RestAPIClient,
} from '@automattic/calypso-e2e';
import { Page, Browser } from 'playwright';
import { apiDeleteSite } from '../shared';

declare const browser: Browser;

describe( DataHelper.createSuiteTitle( 'Plugins: Browse' ), function () {
	let page: Page;
	let newSiteDetails: NewSiteResponse;
	let siteCreatedFlag = false;
	let testAccount: TestAccount;

	beforeAll( async () => {
		page = await browser.newPage();
		const testUser = getTestAccountByFeature( envToFeatureKey( envVariables ), [
			{
				gutenberg: 'stable',
				siteType: 'simple',
				accountName: 'defaultUser',
			},
		] );
		testAccount = new TestAccount( testUser );
		await testAccount.authenticate( page );
	} );

	describe( 'Log in, select a goal and theme', function () {
		const themeName = 'Retrospect';
		let startSiteFlow: StartSiteFlow;

		beforeAll( async function () {
			await BrowserManager.setStoreCookie( page, { currency: 'GBP' } );
			startSiteFlow = new StartSiteFlow( page );
		} );

		it( 'Visit onboarding page', async function () {
			await page.goto( DataHelper.getCalypsoURL( '/setup/onboarding' ) );
		} );

		it( 'Skip domain selection', async function () {
			const signupDomainPage = new SignupDomainPage( page );
			await signupDomainPage.searchForFooDomains();
			await signupDomainPage.skipDomainSelection();
		} );

		it( 'Select WordPress.com Free plan', async function () {
			const signupPickPlanPage = new SignupPickPlanPage( page );
			newSiteDetails = await signupPickPlanPage.selectPlan( 'Free' );

			siteCreatedFlag = true;
		} );

		it( 'Select "Publish a blog" goal', async function () {
			await startSiteFlow.selectGoal( 'Publish a blog' );
			await startSiteFlow.clickButton( 'Next' );
		} );

		it( 'Select theme', async function () {
			await startSiteFlow.selectTheme( themeName );
			await startSiteFlow.clickButton( 'Continue' );
		} );
	} );

	describe( 'Launch the site', function () {
		let editorPage: EditorPage;

		it( 'Visit Focused Launchpad page', async function () {
			const title = await page.getByText( "Let's get started!" );
			await title.waitFor( { timeout: 30 * 1000 } );
		} );

		it( 'Start building your audience', async function () {
			const addSubscribersButton = await page.getByText( 'Start building your audience' );
			await addSubscribersButton.waitFor();
			await addSubscribersButton.click();
			await new Promise( ( r ) => setTimeout( r, 1000 ) );

			await page.goto(
				DataHelper.getCalypsoURL( `/home/${ newSiteDetails.blog_details.site_slug }` )
			);
		} );

		it( 'Complete your profile', async function () {
			const completeProfileButton = await page.getByText( 'Complete your profile' );
			await completeProfileButton.waitFor();
			await completeProfileButton.click();
			await new Promise( ( r ) => setTimeout( r, 1000 ) );

			await page.goto(
				DataHelper.getCalypsoURL( `/home/${ newSiteDetails.blog_details.site_slug }` )
			);
		} );

		it( 'Give your site a name', async function () {
			const giveSiteNameButton = await page.getByText( 'Give your site a name' );
			await giveSiteNameButton.waitFor();
			await giveSiteNameButton.click();
		} );

		it( 'Once at the /wp-admin settings page, update site name', async function () {
			await page.fill( 'input[name="blogname"]', DataHelper.getRandomPhrase() );
			const saveChangesButton = await page.getByRole( 'button', { name: 'Save Changes' } );
			await saveChangesButton.click();

			// The first time we save, we need to wait for the page to reload because it redirects to Calypo's settings page
			// before loading /wp-admin settings page again, so we'd lose the settings updated notice
			// We can probably remove this after the ungangling is completed.
			await new Promise( ( r ) => setTimeout( r, 5000 ) );
			await saveChangesButton.click();
			// Wait for the success notice that appears after saving
			await page.waitForSelector( '#setting-error-settings_updated' );
			await page.goto(
				DataHelper.getCalypsoURL( `/home/${ newSiteDetails.blog_details.site_slug }` )
			);
		} );

		it( "It will write the user's first post", async function () {
			const writeFirstPostButton = await page.getByText( 'Write your first post' );
			await writeFirstPostButton.waitFor( { timeout: 30 * 1000 } );
			await writeFirstPostButton.click();
		} );

		it( 'Editor loads', async function () {
			editorPage = new EditorPage( page );
			await editorPage.waitUntilLoaded();
			await new Promise( ( r ) => setTimeout( r, 2000 ) );
			await editorPage.closeWelcomeGuideIfNeeded();
		} );

		it( 'Enter blog title', async function () {
			await editorPage.enterTitle( DataHelper.getRandomPhrase() );
		} );

		it( 'Publish post', async function () {
			await editorPage.publish();
			await page.goto(
				DataHelper.getCalypsoURL( `/home/${ newSiteDetails.blog_details.site_slug }` )
			);
		} );

		it( 'Should show Launch Site button and update title', async function () {
			const header = await page.getByText( "You're all set!" );
			await header.waitFor();
			const launchSiteButton = await page.getByText( 'Launch your site' );
			await launchSiteButton.waitFor();
			await launchSiteButton.click();
		} );

		it( 'Make sure launch modal shows', async function () {
			const myHomePage = new MyHomePage( page );
			await myHomePage.validateTaskHeadingMessage( 'Congrats, your site is live!' );
		} );
	} );

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

		const restAPIClient = new RestAPIClient( {
			username: testAccount.credentials.username,
			password: testAccount.credentials.password,
		} );

		await apiDeleteSite( restAPIClient, {
			url: newSiteDetails.blog_details.url,
			id: newSiteDetails.blog_details.blogid,
			name: newSiteDetails.blog_details.blogname,
		} );
	} );
} );