2023-08-02 10:37:51 +03:00
|
|
|
import {expect, test} from '@playwright/test';
|
2023-11-23 15:59:48 +03:00
|
|
|
import {globalDataRequests} from '../../utils/acceptance';
|
|
|
|
import {mockApi, responseFixtures, settingsWithStripe} from '@tryghost/admin-x-framework/test/acceptance';
|
2023-07-14 16:04:34 +03:00
|
|
|
|
|
|
|
test.describe('Tier settings', async () => {
|
|
|
|
test('Supports creating a new tier', async ({page}) => {
|
2023-08-03 11:29:14 +03:00
|
|
|
await mockApi({page, requests: {
|
|
|
|
...globalDataRequests,
|
|
|
|
browseSettings: {...globalDataRequests.browseSettings, response: settingsWithStripe},
|
2023-09-25 17:09:35 +03:00
|
|
|
browseTiers: {method: 'GET', path: '/tiers/', response: responseFixtures.tiers}
|
2023-08-01 13:10:40 +03:00
|
|
|
}});
|
2023-07-14 16:04:34 +03:00
|
|
|
|
|
|
|
await page.goto('/');
|
|
|
|
|
|
|
|
const section = page.getByTestId('tiers');
|
|
|
|
|
|
|
|
await section.getByRole('button', {name: 'Add tier'}).click();
|
|
|
|
|
|
|
|
const modal = page.getByTestId('tier-detail-modal');
|
|
|
|
|
|
|
|
await modal.getByRole('button', {name: 'Save & close'}).click();
|
|
|
|
|
2023-09-22 12:05:38 +03:00
|
|
|
await expect(page.getByTestId('toast-error')).toHaveText(/Can't save tier/);
|
2023-07-14 16:04:34 +03:00
|
|
|
await expect(modal).toHaveText(/You must specify a name/);
|
2023-08-30 12:08:31 +03:00
|
|
|
await expect(modal).toHaveText(/Amount must be at least \$1/);
|
2023-07-14 16:04:34 +03:00
|
|
|
|
|
|
|
await modal.getByLabel('Name').fill('Plus tier');
|
|
|
|
await modal.getByLabel('Monthly price').fill('8');
|
|
|
|
await modal.getByLabel('Yearly price').fill('80');
|
|
|
|
|
2023-07-31 20:27:30 +03:00
|
|
|
const newTier = {
|
|
|
|
id: 'new-tier',
|
|
|
|
type: 'paid',
|
|
|
|
active: true,
|
|
|
|
name: 'Plus tier',
|
|
|
|
slug: 'plus-tier',
|
|
|
|
description: null,
|
|
|
|
monthly_price: 800,
|
|
|
|
yearly_price: 8000,
|
|
|
|
benefits: [],
|
|
|
|
welcome_page_url: null,
|
|
|
|
trial_days: 0,
|
|
|
|
visibility: 'public',
|
|
|
|
created_at: new Date().toISOString(),
|
|
|
|
updated_at: new Date().toISOString()
|
2023-08-02 10:37:51 +03:00
|
|
|
};
|
2023-07-31 20:27:30 +03:00
|
|
|
|
2023-08-03 11:29:14 +03:00
|
|
|
const {lastApiRequests} = await mockApi({page, requests: {
|
|
|
|
...globalDataRequests,
|
|
|
|
addTier: {method: 'POST', path: '/tiers/', response: {tiers: [newTier]}},
|
|
|
|
// This request will be reloaded after the new tier is added
|
2023-09-25 17:09:35 +03:00
|
|
|
browseTiers: {method: 'GET', path: '/tiers/', response: {tiers: [...responseFixtures.tiers.tiers, newTier]}}
|
2023-07-31 20:27:30 +03:00
|
|
|
}});
|
|
|
|
|
2023-07-14 16:04:34 +03:00
|
|
|
await modal.getByRole('button', {name: 'Save & close'}).click();
|
|
|
|
|
2023-10-20 11:09:41 +03:00
|
|
|
// await expect(section.getByTestId('tier-card').filter({hasText: /Plus/})).toHaveText(/Plus tier/);
|
|
|
|
// await expect(section.getByTestId('tier-card').filter({hasText: /Plus/})).toHaveText(/\$8\/month/);
|
2023-07-14 16:04:34 +03:00
|
|
|
|
2023-08-03 11:29:14 +03:00
|
|
|
expect(lastApiRequests.addTier?.body).toMatchObject({
|
2023-07-14 16:04:34 +03:00
|
|
|
tiers: [{
|
|
|
|
name: 'Plus tier',
|
|
|
|
monthly_price: 800,
|
|
|
|
yearly_price: 8000,
|
|
|
|
trial_days: null
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Supports updating a tier', async ({page}) => {
|
2023-08-03 11:29:14 +03:00
|
|
|
const {lastApiRequests} = await mockApi({page, requests: {
|
|
|
|
...globalDataRequests,
|
|
|
|
browseSettings: {...globalDataRequests.browseSettings, response: settingsWithStripe},
|
2023-09-25 17:09:35 +03:00
|
|
|
browseTiers: {method: 'GET', path: '/tiers/', response: responseFixtures.tiers},
|
2023-08-03 11:29:14 +03:00
|
|
|
editTier: {method: 'PUT', path: `/tiers/${responseFixtures.tiers.tiers[1].id}/`, response: {
|
|
|
|
tiers: [{
|
|
|
|
...responseFixtures.tiers.tiers[1],
|
|
|
|
name: 'Supporter updated',
|
|
|
|
description: 'Supporter description',
|
|
|
|
monthly_price: 1001,
|
|
|
|
trial_days: 7,
|
|
|
|
benefits: [
|
|
|
|
'Simple benefit',
|
|
|
|
'New benefit'
|
|
|
|
]
|
|
|
|
}]
|
|
|
|
}}
|
2023-07-14 16:04:34 +03:00
|
|
|
}});
|
|
|
|
|
|
|
|
await page.goto('/');
|
|
|
|
|
|
|
|
const section = page.getByTestId('tiers');
|
|
|
|
|
|
|
|
await section.getByTestId('tier-card').filter({hasText: /Supporter/}).click();
|
|
|
|
|
|
|
|
const modal = page.getByTestId('tier-detail-modal');
|
|
|
|
|
2023-10-06 12:06:05 +03:00
|
|
|
const preview = await modal.getByTestId('tier-preview');
|
|
|
|
|
|
|
|
await expect(preview).toContainText('Basic Supporter');
|
|
|
|
await expect(preview).toContainText('$5/month');
|
|
|
|
await expect(preview).toContainText('Simple benefit');
|
|
|
|
|
|
|
|
// Failing validations
|
|
|
|
|
2023-07-14 16:04:34 +03:00
|
|
|
await modal.getByLabel('Name').fill('');
|
|
|
|
await modal.getByRole('button', {name: 'Save & close'}).click();
|
|
|
|
|
2023-09-22 12:05:38 +03:00
|
|
|
await expect(page.getByTestId('toast-error')).toHaveText(/Can't save tier/);
|
2023-07-14 16:04:34 +03:00
|
|
|
await expect(modal).toHaveText(/You must specify a name/);
|
|
|
|
|
2023-10-06 12:06:05 +03:00
|
|
|
// Valid values
|
|
|
|
|
2023-07-14 16:04:34 +03:00
|
|
|
await modal.getByLabel('Name').fill('Supporter updated');
|
|
|
|
await modal.getByLabel('Description').fill('Supporter description');
|
|
|
|
await modal.getByLabel('Monthly price').fill('10.01');
|
2023-10-06 12:06:05 +03:00
|
|
|
await modal.getByLabel('Yearly price').fill('100');
|
2023-07-14 16:04:34 +03:00
|
|
|
await modal.getByLabel('Add a free trial').check();
|
|
|
|
await modal.getByLabel('Trial days').fill('7');
|
|
|
|
await modal.getByLabel('New benefit').fill('New benefit');
|
|
|
|
await modal.getByRole('button', {name: 'Add'}).click();
|
|
|
|
|
2023-10-06 12:06:05 +03:00
|
|
|
// Check that the preview is updated
|
|
|
|
|
|
|
|
await expect(preview).toContainText('Supporter updated');
|
|
|
|
await expect(preview).toContainText('Supporter description');
|
|
|
|
await expect(preview).toContainText('$10.01/month');
|
|
|
|
await expect(preview).toContainText('New benefit');
|
|
|
|
|
|
|
|
await preview.getByRole('button', {name: 'Yearly'}).click();
|
|
|
|
await expect(preview).not.toContainText('$10.01/month');
|
|
|
|
await expect(preview).toContainText('$100/year');
|
|
|
|
await expect(preview).toContainText('17% discount');
|
|
|
|
|
|
|
|
// Save changes
|
|
|
|
|
2023-07-14 16:04:34 +03:00
|
|
|
await modal.getByRole('button', {name: 'Save & close'}).click();
|
|
|
|
|
|
|
|
await expect(section.getByTestId('tier-card').filter({hasText: /Supporter/})).toHaveText(/Supporter updated/);
|
|
|
|
await expect(section.getByTestId('tier-card').filter({hasText: /Supporter/})).toHaveText(/Supporter description/);
|
|
|
|
await expect(section.getByTestId('tier-card').filter({hasText: /Supporter/})).toHaveText(/\$10\.01\/month/);
|
|
|
|
|
2023-08-03 11:29:14 +03:00
|
|
|
expect(lastApiRequests.editTier?.body).toMatchObject({
|
2023-07-14 16:04:34 +03:00
|
|
|
tiers: [{
|
|
|
|
id: responseFixtures.tiers.tiers[1].id,
|
|
|
|
name: 'Supporter updated',
|
|
|
|
description: 'Supporter description',
|
|
|
|
monthly_price: 1001,
|
2023-10-06 12:06:05 +03:00
|
|
|
yearly_price: 10000,
|
2023-07-14 16:04:34 +03:00
|
|
|
trial_days: 7,
|
|
|
|
benefits: [
|
|
|
|
'Simple benefit',
|
|
|
|
'New benefit'
|
|
|
|
]
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Supports editing the free tier', async ({page}) => {
|
2023-08-03 11:29:14 +03:00
|
|
|
const {lastApiRequests} = await mockApi({page, requests: {
|
|
|
|
...globalDataRequests,
|
|
|
|
browseSettings: {...globalDataRequests.browseSettings, response: settingsWithStripe},
|
2023-09-25 17:09:35 +03:00
|
|
|
browseTiers: {method: 'GET', path: '/tiers/', response: responseFixtures.tiers},
|
2023-08-03 11:29:14 +03:00
|
|
|
editTier: {method: 'PUT', path: `/tiers/${responseFixtures.tiers.tiers[0].id}/`, response: {
|
|
|
|
tiers: [{
|
|
|
|
...responseFixtures.tiers.tiers[0],
|
|
|
|
description: 'Free tier description',
|
|
|
|
benefits: [
|
|
|
|
'First benefit',
|
|
|
|
'Second benefit'
|
|
|
|
]
|
|
|
|
}]
|
|
|
|
}}
|
2023-07-14 16:04:34 +03:00
|
|
|
}});
|
|
|
|
|
|
|
|
await page.goto('/');
|
|
|
|
|
|
|
|
const section = page.getByTestId('tiers');
|
|
|
|
|
|
|
|
await section.getByTestId('tier-card').filter({hasText: /Free/}).click();
|
|
|
|
|
|
|
|
const modal = page.getByTestId('tier-detail-modal');
|
|
|
|
|
|
|
|
await modal.getByLabel('Description').fill('Free tier description');
|
2023-10-06 12:06:05 +03:00
|
|
|
await modal.getByLabel('Welcome page').fill('welcome-page');
|
2023-07-14 16:04:34 +03:00
|
|
|
await modal.getByLabel('New benefit').fill('First benefit');
|
|
|
|
await modal.getByRole('button', {name: 'Add'}).click();
|
|
|
|
await modal.getByLabel('New benefit').fill('Second benefit');
|
|
|
|
|
|
|
|
await modal.getByRole('button', {name: 'Save & close'}).click();
|
|
|
|
|
|
|
|
await expect(section.getByTestId('tier-card').filter({hasText: /Free/})).toHaveText(/Free tier description/);
|
|
|
|
|
2023-08-03 11:29:14 +03:00
|
|
|
expect(lastApiRequests.editTier?.body).toMatchObject({
|
2023-07-14 16:04:34 +03:00
|
|
|
tiers: [{
|
|
|
|
id: responseFixtures.tiers.tiers[0].id,
|
|
|
|
description: 'Free tier description',
|
2023-10-06 12:06:05 +03:00
|
|
|
welcome_page_url: '/welcome-page/',
|
2023-07-14 16:04:34 +03:00
|
|
|
benefits: [
|
|
|
|
'First benefit',
|
|
|
|
'Second benefit'
|
|
|
|
]
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|