Skip to content

Commit

Permalink
Updated admin-x-settings acceptance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sagzy committed Dec 16, 2024
1 parent 3c07bf8 commit a05b73f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
13 changes: 13 additions & 0 deletions apps/admin-x-framework/src/test/acceptance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,19 @@ export async function chooseOptionInSelect(select: Locator, optionText: string |
await select.page().locator('[data-testid="select-option"]', {hasText: optionText}).click();
}

export async function getOptionsFromSelect(select: Locator): Promise<string[]> {
// Open the select dropdown
await select.click();

const options = await select.page().locator('[data-testid="select-option"]');
const optionTexts = await options.allTextContents();

// Close the select dropdown
await select.press('Escape');

return optionTexts;
}

export async function testUrlValidation(input: Locator, textToEnter: string, expectedResult: string, expectedError?: string) {
await input.fill(textToEnter);
await input.blur();
Expand Down
22 changes: 16 additions & 6 deletions apps/admin-x-settings/test/acceptance/membership/access.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {chooseOptionInSelect, mockApi, responseFixtures, updatedSettingsResponse} from '@tryghost/admin-x-framework/test/acceptance';
import {chooseOptionInSelect, getOptionsFromSelect, mockApi, responseFixtures, updatedSettingsResponse} from '@tryghost/admin-x-framework/test/acceptance';
import {expect, test} from '@playwright/test';
import {globalDataRequests} from '../../utils/acceptance';

Expand All @@ -17,21 +17,31 @@ test.describe('Access settings', async () => {

const section = page.getByTestId('access');

// Check that the current values are displayed when in view mode
await expect(section.getByText('Anyone can sign up')).toHaveCount(1);
await expect(section.getByText('Public')).toHaveCount(1);
await expect(section.getByText('Nobody')).toHaveCount(1);

// Check available options in access settings in edit mode
await section.getByRole('button', {name: 'Edit'}).click();
const subscriptionAccessSelect = section.getByTestId('subscription-access-select');
const defaultPostAccessSelect = section.getByTestId('default-post-access-select');
const commentingSelect = section.getByTestId('commenting-select');

await chooseOptionInSelect(section.getByTestId('subscription-access-select'), 'Only people I invite');
await chooseOptionInSelect(section.getByTestId('default-post-access-select'), /^Members only$/);
await chooseOptionInSelect(section.getByTestId('commenting-select'), 'All members');
await expect(getOptionsFromSelect(subscriptionAccessSelect)).resolves.toEqual(['Anyone can sign up', 'Paid-members only', 'Invite-only', 'Nobody']);
await expect(getOptionsFromSelect(defaultPostAccessSelect)).resolves.toEqual(['Public', 'Members only', 'Paid-members only', 'Specific tiers']);
await expect(getOptionsFromSelect(commentingSelect)).resolves.toEqual(['All members', 'Paid-members only', 'Nobody']);

await section.getByRole('button', {name: 'Save'}).click();
// Edit access settings to new values
await chooseOptionInSelect(subscriptionAccessSelect, 'Invite-only');
await chooseOptionInSelect(defaultPostAccessSelect, /^Members only$/);
await chooseOptionInSelect(commentingSelect, 'All members');

await section.getByRole('button', {name: 'Save'}).click();
await expect(section.getByTestId('subscription-access-select')).toHaveCount(0);

await expect(section.getByText('Only people I invite')).toHaveCount(1);
// Check that the new values are displayed when in view mode
await expect(section.getByText('Invite-only')).toHaveCount(1);
await expect(section.getByText('Members only')).toHaveCount(1);
await expect(section.getByText('All members')).toHaveCount(1);

Expand Down

0 comments on commit a05b73f

Please sign in to comment.