2023-11-23 15:59:48 +03:00
|
|
|
import {chooseOptionInSelect, mockApi, responseFixtures, updatedSettingsResponse} from '@tryghost/admin-x-framework/test/acceptance';
|
2023-06-06 06:50:07 +03:00
|
|
|
import {expect, test} from '@playwright/test';
|
2023-11-23 15:59:48 +03:00
|
|
|
import {globalDataRequests} from '../../utils/acceptance';
|
2023-06-06 06:50:07 +03:00
|
|
|
|
|
|
|
test.describe('Default recipient settings', async () => {
|
|
|
|
test('Supports editing default recipients', async ({page}) => {
|
2023-08-03 11:29:14 +03:00
|
|
|
const {lastApiRequests} = await mockApi({page, requests: {
|
|
|
|
...globalDataRequests,
|
|
|
|
editSettings: {method: 'PUT', path: '/settings/', response: updatedSettingsResponse([
|
|
|
|
{key: 'editor_default_email_recipients', value: 'filter'},
|
|
|
|
{key: 'editor_default_email_recipients_filter', value: 'status:-free'}
|
|
|
|
])}
|
2023-06-06 06:50:07 +03:00
|
|
|
}});
|
|
|
|
|
|
|
|
await page.goto('/');
|
|
|
|
|
|
|
|
const section = page.getByTestId('default-recipients');
|
|
|
|
|
|
|
|
await expect(section.getByText('Whoever has access to the post')).toHaveCount(1);
|
|
|
|
|
|
|
|
await section.getByRole('button', {name: 'Edit'}).click();
|
2023-10-04 13:09:04 +03:00
|
|
|
await chooseOptionInSelect(section.getByTestId('default-recipients-select'), 'All members');
|
2023-06-06 06:50:07 +03:00
|
|
|
await section.getByRole('button', {name: 'Save'}).click();
|
|
|
|
|
2023-08-03 11:29:14 +03:00
|
|
|
expect(lastApiRequests.editSettings?.body).toEqual({
|
2023-06-06 06:50:07 +03:00
|
|
|
settings: [
|
|
|
|
{key: 'editor_default_email_recipients', value: 'filter'},
|
|
|
|
{key: 'editor_default_email_recipients_filter', value: 'status:free,status:-free'}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
|
|
|
await section.getByRole('button', {name: 'Edit'}).click();
|
2023-10-04 13:09:04 +03:00
|
|
|
await chooseOptionInSelect(section.getByTestId('default-recipients-select'), 'Usually nobody');
|
2023-06-06 06:50:07 +03:00
|
|
|
await section.getByRole('button', {name: 'Save'}).click();
|
|
|
|
|
2023-08-03 11:29:14 +03:00
|
|
|
expect(lastApiRequests.editSettings?.body).toEqual({
|
2023-06-06 06:50:07 +03:00
|
|
|
settings: [
|
|
|
|
{key: 'editor_default_email_recipients', value: 'filter'},
|
|
|
|
{key: 'editor_default_email_recipients_filter', value: null}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
|
|
|
await section.getByRole('button', {name: 'Edit'}).click();
|
2023-10-04 13:09:04 +03:00
|
|
|
await chooseOptionInSelect(section.getByTestId('default-recipients-select'), 'Paid-members only');
|
2023-06-06 06:50:07 +03:00
|
|
|
await section.getByRole('button', {name: 'Save'}).click();
|
|
|
|
|
2023-10-04 13:09:04 +03:00
|
|
|
await expect(section.getByTestId('default-recipients-select')).toHaveCount(0);
|
2023-06-06 06:50:07 +03:00
|
|
|
|
|
|
|
await expect(section.getByText('Paid-members only')).toHaveCount(1);
|
|
|
|
|
2023-08-03 11:29:14 +03:00
|
|
|
expect(lastApiRequests.editSettings?.body).toEqual({
|
2023-06-06 06:50:07 +03:00
|
|
|
settings: [
|
|
|
|
{key: 'editor_default_email_recipients', value: 'filter'},
|
|
|
|
{key: 'editor_default_email_recipients_filter', value: 'status:-free'}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
});
|
2023-06-28 05:59:05 +03:00
|
|
|
|
|
|
|
test('Supports selecting specific tiers, labels and offers', async ({page}) => {
|
2023-08-03 11:29:14 +03:00
|
|
|
const {lastApiRequests} = await mockApi({page, requests: {
|
|
|
|
...globalDataRequests,
|
2023-09-25 16:03:47 +03:00
|
|
|
browseTiers: {method: 'GET', path: '/tiers/?filter=&limit=20', response: responseFixtures.tiers},
|
|
|
|
browseLabels: {method: 'GET', path: '/labels/?filter=&limit=20', response: responseFixtures.labels},
|
|
|
|
browseOffers: {method: 'GET', path: '/offers/?filter=&limit=20', response: responseFixtures.offers},
|
2023-08-03 11:29:14 +03:00
|
|
|
editSettings: {method: 'PUT', path: '/settings/', response: updatedSettingsResponse([
|
|
|
|
{
|
|
|
|
key: 'editor_default_email_recipients',
|
|
|
|
value: 'filter'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'editor_default_email_recipients_filter',
|
|
|
|
value: '645453f4d254799990dd0e22,label:first-label,offer_redemptions:6487ea6464fca78ec2fff5fe'
|
|
|
|
}
|
|
|
|
])}
|
2023-06-28 05:59:05 +03:00
|
|
|
}});
|
|
|
|
|
|
|
|
await page.goto('/');
|
|
|
|
|
|
|
|
const section = page.getByTestId('default-recipients');
|
|
|
|
|
|
|
|
await section.getByRole('button', {name: 'Edit'}).click();
|
|
|
|
|
2023-10-04 13:09:04 +03:00
|
|
|
await chooseOptionInSelect(section.getByTestId('default-recipients-select'), 'Specific people');
|
2023-09-12 18:15:42 +03:00
|
|
|
await section.getByLabel('Filter').click();
|
2023-06-28 05:59:05 +03:00
|
|
|
|
2023-09-18 16:51:59 +03:00
|
|
|
await section.locator('[data-testid="select-option"]', {hasText: 'Basic Supporter'}).click();
|
|
|
|
await section.locator('[data-testid="select-option"]', {hasText: 'first-label'}).click();
|
|
|
|
await section.locator('[data-testid="select-option"]', {hasText: 'First offer'}).click();
|
2023-06-28 05:59:05 +03:00
|
|
|
|
|
|
|
await section.getByRole('button', {name: 'Save'}).click();
|
|
|
|
|
|
|
|
await expect(section.getByText('Specific people')).toHaveCount(1);
|
|
|
|
|
2023-08-03 11:29:14 +03:00
|
|
|
expect(lastApiRequests.editSettings?.body).toEqual({
|
2023-06-28 05:59:05 +03:00
|
|
|
settings: [
|
|
|
|
{
|
|
|
|
key: 'editor_default_email_recipients',
|
|
|
|
value: 'filter'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'editor_default_email_recipients_filter',
|
|
|
|
value: '645453f4d254799990dd0e22,label:first-label,offer_redemptions:6487ea6464fca78ec2fff5fe'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
});
|
2024-06-27 18:47:26 +03:00
|
|
|
|
|
|
|
test('renders existing default recipients filters correctly', async ({page}) => {
|
|
|
|
await mockApi({page, requests: {
|
|
|
|
...globalDataRequests,
|
|
|
|
browseTiers: {method: 'GET', path: '/tiers/?filter=&limit=20', response: responseFixtures.tiers},
|
|
|
|
browseLabels: {method: 'GET', path: '/labels/?filter=&limit=20', response: responseFixtures.labels},
|
|
|
|
browseOffers: {method: 'GET', path: '/offers/?filter=&limit=20', response: responseFixtures.offers},
|
|
|
|
browseSettings: {...globalDataRequests.browseSettings, response: updatedSettingsResponse([
|
|
|
|
{
|
|
|
|
key: 'editor_default_email_recipients',
|
|
|
|
value: 'filter'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'editor_default_email_recipients_filter',
|
|
|
|
value: '645453f4d254799990dd0e22,label:first-label,offer_redemptions:6487ea6464fca78ec2fff5fe'
|
|
|
|
}
|
|
|
|
])}
|
|
|
|
}});
|
|
|
|
|
|
|
|
await page.goto('/');
|
|
|
|
|
|
|
|
const section = page.getByTestId('default-recipients');
|
|
|
|
await section.getByRole('button', {name: 'Edit'}).click();
|
|
|
|
|
|
|
|
await expect(section.getByText('Specific people')).toHaveCount(1);
|
|
|
|
await expect(section.getByText('Basic Supporter')).toHaveCount(1);
|
|
|
|
await expect(section.getByText('first-label')).toHaveCount(1);
|
|
|
|
await expect(section.getByText('First offer')).toHaveCount(1);
|
|
|
|
});
|
2023-06-06 06:50:07 +03:00
|
|
|
});
|