Skip to content

Commit d1e1342

Browse files
authored
Dashboard: Add site visibility e2e test (#103519)
1 parent 615504a commit d1e1342

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/**
2+
* @group calypso-pr
3+
* @group dashboard
4+
* @group settings
5+
*/
6+
7+
import {
8+
TestAccount,
9+
getTestAccountByFeature,
10+
envToFeatureKey,
11+
envVariables,
12+
DashboardPage,
13+
} from '@automattic/calypso-e2e';
14+
import { Page, Browser } from 'playwright';
15+
16+
declare const browser: Browser;
17+
18+
/**
19+
* Tests that a user can edit privacy settings on a site via the dashboard.
20+
*
21+
* This test verifies that site visibility (privacy) options can be changed
22+
* between Public, Private and Coming Soon modes.
23+
*/
24+
describe( 'Dashboard: Site Visibility Settings', function () {
25+
let page: Page;
26+
let dashboardPage: DashboardPage;
27+
const accountName = getTestAccountByFeature( envToFeatureKey( envVariables ) );
28+
const testAccount = new TestAccount( accountName );
29+
let siteSlug: string;
30+
31+
beforeAll( async function () {
32+
page = await browser.newPage();
33+
await testAccount.authenticate( page );
34+
dashboardPage = new DashboardPage( page );
35+
36+
// We need to extract the site slug for our test
37+
const url = testAccount.getSiteURL();
38+
const urlParts = url.split( '/' );
39+
siteSlug = urlParts[ urlParts.length - 2 ];
40+
41+
// Visit the site visibility settings page
42+
await dashboardPage.visitPath( `sites/${ siteSlug }/settings/site-visibility` );
43+
} );
44+
45+
afterAll( async function () {
46+
const isCurrentlyPublic = await page.getByRole( 'radio', { name: 'Public' } ).isChecked();
47+
if ( ! isCurrentlyPublic ) {
48+
await page.getByRole( 'radio', { name: 'public' } ).click();
49+
await saveChanges( page );
50+
}
51+
} );
52+
53+
it( 'Can change site visibility to Private', async function () {
54+
await page.getByRole( 'radio', { name: 'Private' } ).click();
55+
await saveChanges( page );
56+
57+
// Open the site in a new incognito browser context to verify it's private
58+
const incognitoPage = await browser.newPage();
59+
await incognitoPage.goto( testAccount.getSiteURL() );
60+
const pageContent = await incognitoPage.content();
61+
expect( pageContent ).toContain( 'Private Site' );
62+
await incognitoPage.close();
63+
} );
64+
65+
it( 'Can change site visibility to Coming soon', async function () {
66+
await page.getByRole( 'radio', { name: 'Coming soon' } ).click();
67+
await saveChanges( page );
68+
69+
// Open the site in a new incognito browser context to verify it's private
70+
const incognitoPage = await browser.newPage();
71+
await incognitoPage.goto( testAccount.getSiteURL() );
72+
const pageContent = await incognitoPage.content();
73+
expect( pageContent ).toContain( 'coming soon' );
74+
await incognitoPage.close();
75+
} );
76+
77+
it( 'Can change site visibility to Public', async function () {
78+
await page.getByRole( 'radio', { name: 'Public' } ).click();
79+
await saveChanges( page );
80+
81+
// Open the site in a new incognito browser context to verify it's private
82+
const incognitoPage = await browser.newPage();
83+
await incognitoPage.goto( testAccount.getSiteURL() );
84+
const pageContent = await incognitoPage.content();
85+
expect( pageContent ).not.toContain( 'Private Site' );
86+
expect( pageContent ).not.toContain( 'coming soon' );
87+
await incognitoPage.close();
88+
} );
89+
} );
90+
91+
/**
92+
* Save the changes and wait for the request to finish.
93+
*
94+
* @param page The Playwright page object
95+
*/
96+
async function saveChanges( page: Page ): Promise< void > {
97+
await page.getByRole( 'button', { name: 'Save' } ).click();
98+
await page.waitForSelector( 'button:not(.is-busy)[type="submit"][disabled]', {
99+
state: 'visible',
100+
} );
101+
}

0 commit comments

Comments
 (0)