Skip to content

Commit a69ffb9

Browse files
committed
Added playwright test for publishing posts for specific tiers
refs TryGhost/Product#2371 - test publishes a post with access for a single tier then checks the front-end with no member, member on wrong tier, and member on right tier
1 parent abc7e64 commit a69ffb9

File tree

3 files changed

+60
-3
lines changed

3 files changed

+60
-3
lines changed

ghost/admin/app/components/gh-post-settings-menu.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
</GhFormGroup>
8181

8282
{{#if (eq this.post.visibility "tiers")}}
83-
<GhFormGroup @errors={{this.post.errors}} @hasValidated={{this.post.hasValidated}} @property="tiers" class="nt3">
83+
<GhFormGroup @errors={{this.post.errors}} @hasValidated={{this.post.hasValidated}} @property="tiers" class="nt3" data-test-visibility-segment-select>
8484
<GhPostSettingsMenu::VisibilitySegmentSelect
8585
@tiers={{this.post.tiers}}
8686
@onChange={{action "setVisibility"}}

ghost/admin/app/components/gh-token-input/trigger.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
mouseDown=this.handleOptionMouseDown
1919
touchStart=this.handleOptionTouchStart
2020
}}
21-
<span class="ember-power-select-multiple-inner-text">
21+
<span class="ember-power-select-multiple-inner-text" data-test-selected-token>
2222
{{#if @selectedItemComponent}}
2323
{{component @selectedItemComponent option=(readonly opt) select=(readonly @select)}}
2424
{{else}}

ghost/core/test/e2e-browser/admin/publishing.spec.js

+58-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const {expect, test} = require('@playwright/test');
22
const {DateTime} = require('luxon');
3-
const {createMember, createPostDraft} = require('../utils');
43
const {slugify} = require('@tryghost/string');
4+
const {createTier, createMember, createPostDraft, impersonateMember} = require('../utils');
55

66
/**
77
* Test the status of a post in the post editor.
@@ -163,6 +163,11 @@ const publishPost = async (page, {type = 'publish', time, date} = {}) => {
163163
// TODO: assert publish flow has expected completion details
164164
};
165165

166+
/**
167+
* When on the publish flow completed step, click the bookmark
168+
* @param {import('@playwright/test').Page} page
169+
* @returns {Promise<import('@playwright/test').Page>}
170+
*/
166171
const openPublishedPostBookmark = async (page) => {
167172
// open the published post in a new tab
168173
const [frontendPage] = await Promise.all([
@@ -492,4 +497,56 @@ test.describe('Updating post access', () => {
492497
await expect(frontendPage.locator('.gh-content.gh-canvas > p')).toHaveText('This is my post body.');
493498
});
494499
});
500+
501+
test('specific tiers', async ({page}) => {
502+
await page.goto('/ghost');
503+
504+
// tiers and members are needed to test the access levels
505+
await createTier(page, {name: 'Silver', monthlyPrice: 5, yearlyPrice: 50});
506+
await createTier(page, {name: 'Gold', monthlyPrice: 10, yearlyPrice: 100});
507+
await createMember(page, {email: '[email protected]', compedPlan: 'Silver'});
508+
const silverMember = await page.url();
509+
await createMember(page, {email: '[email protected]', compedPlan: 'Gold'});
510+
const goldMember = await page.url();
511+
512+
await createPostDraft(page, {body: 'Only gold members can see this'});
513+
514+
await openPostSettingsMenu(page);
515+
await setPostVisibility(page, 'tiers');
516+
517+
// backspace removes existing tiers
518+
expect(page.locator('[data-test-visibility-segment-select] [data-test-selected-token]')).toHaveCount(3);
519+
await page.locator('[data-test-visibility-segment-select] input').click();
520+
await page.keyboard.press('Backspace');
521+
await page.waitForTimeout(50);
522+
await page.keyboard.press('Backspace');
523+
await page.waitForTimeout(50);
524+
await page.keyboard.press('Backspace');
525+
expect(page.locator('[data-test-visibility-segment-select] [data-test-selected-token]')).toHaveCount(0);
526+
527+
// specific tier can be added back on
528+
await page.keyboard.type('Go');
529+
const goldOption = page.locator('[data-test-visibility-segment-option="Gold"]');
530+
await goldOption.click();
531+
532+
// publish
533+
await publishPost(page);
534+
const frontendPage = await openPublishedPostBookmark(page);
535+
536+
// non-member doesn't have access
537+
await expect(frontendPage.locator('.gh-post-upgrade-cta-content h2')).toContainText('on the Gold tier only');
538+
539+
// member on wrong tier doesn't have access
540+
await page.goto(silverMember);
541+
await impersonateMember(page);
542+
await frontendPage.reload();
543+
await expect(frontendPage.locator('.gh-post-upgrade-cta-content h2')).toContainText('on the Gold tier only');
544+
545+
// member on selected tier has access
546+
await page.goto(goldMember);
547+
await impersonateMember(page);
548+
await frontendPage.reload();
549+
await expect(frontendPage.locator('.gh-post-upgrade-cta-content')).not.toBeVisible();
550+
await expect(frontendPage.locator('.gh-content.gh-canvas > p')).toHaveText('Only gold members can see this');
551+
});
495552
});

0 commit comments

Comments
 (0)