File size: 4,338 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
/**
 * @group gutenberg
 */

import {
	DataHelper,
	TestAccount,
	envVariables,
	EditorPage,
	PublishedPostPage,
	getTestAccountByFeature,
	envToFeatureKey,
} from '@automattic/calypso-e2e';
import { Browser, BrowserContext, Page } from 'playwright';

declare const browser: Browser;

describe( DataHelper.createSuiteTitle( 'Editor: Schedule' ), function () {
	const features = envToFeatureKey( envVariables );
	const accountName = getTestAccountByFeature( features, [
		{
			gutenberg: 'stable',
			siteType: 'simple',
			accountName: 'simpleSitePersonalPlanUser',
		},
	] );

	const postTitle = `Scheduled Post: ${ DataHelper.getTimestamp() }`;
	const postContent = DataHelper.getRandomPhrase();
	let postURL: URL;
	let editorPage: EditorPage;
	let context: BrowserContext;
	let page: Page;

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

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

	it( 'Go to the new post page', async function () {
		editorPage = new EditorPage( page );
		await editorPage.visit( 'post' );
	} );

	it( 'Enter page title', async function () {
		editorPage = new EditorPage( page );
		await editorPage.enterTitle( postTitle );
	} );

	it( 'Enter page content', async function () {
		await editorPage.enterText( postContent );
	} );

	describe( 'Schedule: future', function () {
		it( 'Open settings', async function () {
			await editorPage.openSettings();
		} );

		it( 'Schedule the post for next year', async function () {
			const date = new Date();
			date.setUTCFullYear( date.getFullYear() + 1 );

			await editorPage.schedule( {
				year: date.getUTCFullYear(),
				month: date.getUTCMonth(),
				date: date.getUTCDate(),
				hours: 12,
				minutes: 1,
				meridian: 'AM',
			} );
		} );

		it( 'Close settings', async function () {
			// On mobile, the sidebar covers all of the screen.
			// Dismiss it so publish buttons are available.
			await editorPage.closeSettings();
		} );

		it( 'Publish post', async function () {
			postURL = await editorPage.publish();
			await editorPage.closeAllPanels();
		} );

		it( 'View post as the author', async function () {
			const tmpPage = await context.newPage(); // Calling from context opens new tab (same session)

			await tmpPage.goto( postURL.href );
			await new PublishedPostPage( tmpPage ).validateTextInPost( postContent );

			await tmpPage.close();
		} );

		it( 'View post as public', async function () {
			const tmpPage = await browser.newPage(); // Calling from browser opens new incognito window

			await tmpPage.goto( postURL.href );
			await tmpPage.locator( 'body.error404' ).waitFor();
			await tmpPage.close();
		} );
	} );

	describe( 'Schedule: past', function () {
		it( 'Open settings', async function () {
			await editorPage.openSettings();
		} );

		it( 'Schedule post to first of the current month of last year', async function () {
			const date = new Date();
			date.setUTCFullYear( date.getUTCFullYear() - 1 );

			await editorPage.schedule( {
				year: date.getUTCFullYear(),
				date: 1,
				month: date.getUTCMonth(),
				hours: 12,
				minutes: 59,
				meridian: 'PM',
			} );
		} );

		it( 'Close settings', async () => {
			// On mobile, the sidebar covers all of the screen.
			// Dismiss it so publish buttons are available.
			await editorPage.closeSettings();
		} );

		it( 'Publish post', async function () {
			postURL = await editorPage.publish();
		} );

		it( 'View post as the author', async () => {
			const tmpPage = await context.newPage();

			await tmpPage.goto( postURL.href );
			await new PublishedPostPage( tmpPage ).validateTextInPost( postContent );

			await tmpPage.close();
		} );

		it( 'View post as a guest', async () => {
			const tmpPage = await browser.newPage();

			await tmpPage.goto( postURL.href );
			await new PublishedPostPage( tmpPage ).validateTextInPost( postContent );

			await tmpPage.close();
		} );

		it( 'View post as another user', async () => {
			const tmpPage = await browser.newPage();

			const testAccount = new TestAccount( 'defaultUser' );
			await testAccount.authenticate( tmpPage );

			await tmpPage.goto( postURL.href );
			await new PublishedPostPage( tmpPage ).validateTextInPost( postContent );

			await tmpPage.close();
		} );
	} );
} );