feat(admin): give the customer emails a tab of their own (#135)
The six email templates lived at the bottom of the Settings tab, under the cart-expiry card and inside a 720px wrapper. Finding them took knowing they were there — "Settings" reads as app configuration and the only thing visible on that tab was a 480px card about cart expiry. Reaching them, the editor was then crushed: EmailTemplateEditor splits a markdown pane and a rendered preview side by side, and 720px left each half under 350px, so the preview showed the email at a width nothing like how it will be read and the markdown toolbar wrapped. Emails is now its own tab, between Customers and Settings, with no width cap. Within it the email types are a left vertical rail rather than a strip across the top: six labels wrapped on narrower displays, and stacking them is what leaves the editor the width the split needs. Settings keeps the cart-expiry card and nothing else. The Default/Customised tag comes off the labels. Six antd tags stacked down a rail stop it being scannable, so a customised template gets a dot and the state in full moves into the editor beside the Restore default button that acts on it. The dot carries aria-label="Customised" so the word stays in the tab's accessible name and the state is not conveyed by a mark alone. Emails owns the fetch it inherited from Settings, and adds a Spin over it. templates starts empty, so the gap before the request lands would otherwise render an empty rail that reads as "there are no emails to edit". Closes #135
This commit is contained in:
@@ -8,10 +8,12 @@ async function restore(page: import('@playwright/test').Page, key: string) {
|
||||
await page.request.delete(`/api/admin/email-templates/${key}`);
|
||||
}
|
||||
|
||||
async function openSettings(page: import('@playwright/test').Page) {
|
||||
async function openEmails(page: import('@playwright/test').Page) {
|
||||
await page.goto('/admin');
|
||||
await page.getByRole('tab', { name: 'Settings' }).click();
|
||||
await expect(page.getByRole('heading', { name: 'Customer emails' })).toBeVisible();
|
||||
await page.getByRole('tab', { name: 'Emails' }).click();
|
||||
// The rail's first entry, rather than a heading — the tab label is the
|
||||
// heading now, so there is no second one inside the page to wait on.
|
||||
await expect(page.getByRole('tab', { name: /Email verification/ })).toBeVisible();
|
||||
}
|
||||
|
||||
// Opens one template's tab. Only the active tab's editor is mounted, which is
|
||||
@@ -36,7 +38,7 @@ test.describe('Editing the customer emails', () => {
|
||||
});
|
||||
|
||||
test('offers every template as a tab, marked default until it is edited', async ({ page }) => {
|
||||
await openSettings(page);
|
||||
await openEmails(page);
|
||||
|
||||
for (const label of [
|
||||
'Email verification',
|
||||
@@ -49,14 +51,15 @@ test.describe('Editing the customer emails', () => {
|
||||
await expect(page.getByRole('tab', { name: new RegExp(label) })).toBeVisible();
|
||||
}
|
||||
|
||||
// The badge lives on the tab now, so which templates have been changed is
|
||||
// visible without opening each one.
|
||||
await expect(page.getByRole('tab', { name: /Password reset.*Default/ })).toBeVisible();
|
||||
// Only a customised template is marked, so which ones have been changed is
|
||||
// visible without opening each one. An untouched template carries nothing.
|
||||
await expect(page.getByRole('tab', { name: /Password reset/ })).toBeVisible();
|
||||
await expect(page.getByRole('tab', { name: /Password reset.*Customised/ })).toHaveCount(0);
|
||||
});
|
||||
|
||||
test('saves a replacement subject and body', async ({ page }) => {
|
||||
const subject = `Reset ${suffix()}`;
|
||||
await openSettings(page);
|
||||
await openEmails(page);
|
||||
await openTemplate(page, 'Password reset');
|
||||
|
||||
await page.getByLabel('Password reset subject').fill(subject);
|
||||
@@ -77,7 +80,7 @@ test.describe('Editing the customer emails', () => {
|
||||
// looks fine in the log, so the save has to be refused rather than warned
|
||||
// about — and the admin has to be told which placeholder is missing.
|
||||
test('refuses a body that drops the required placeholder, and says which', async ({ page }) => {
|
||||
await openSettings(page);
|
||||
await openEmails(page);
|
||||
await openTemplate(page, 'Password reset');
|
||||
|
||||
await page.getByLabel('Password reset body').fill('Just click the thing in your email.');
|
||||
@@ -96,7 +99,10 @@ test.describe('Editing the customer emails', () => {
|
||||
data: { subject: 'Temporary', body: 'Temporary [link]({{resetUrl}}).' }
|
||||
});
|
||||
|
||||
await openSettings(page);
|
||||
await openEmails(page);
|
||||
// Marked in the rail before it is opened, which is the whole point of the
|
||||
// dot — the stored template above was never touched through the UI.
|
||||
await expect(page.getByRole('tab', { name: /Password reset.*Customised/ })).toBeVisible();
|
||||
await openTemplate(page, 'Password reset');
|
||||
await page.getByRole('button', { name: 'Restore default' }).click();
|
||||
|
||||
@@ -116,7 +122,7 @@ test.describe('Previewing the customer emails', () => {
|
||||
|
||||
test('shows the draft being edited, not the stored copy', async ({ page }) => {
|
||||
const wording = `Wording ${suffix()}`;
|
||||
await openSettings(page);
|
||||
await openEmails(page);
|
||||
await openTemplate(page, 'Password reset');
|
||||
|
||||
await page
|
||||
@@ -132,7 +138,7 @@ test.describe('Previewing the customer emails', () => {
|
||||
});
|
||||
|
||||
test('substitutes sample values rather than showing raw placeholders', async ({ page }) => {
|
||||
await openSettings(page);
|
||||
await openEmails(page);
|
||||
await openTemplate(page, 'Password reset');
|
||||
|
||||
const frame = previewFrame(page, 'Password reset');
|
||||
@@ -144,7 +150,7 @@ test.describe('Previewing the customer emails', () => {
|
||||
// markdown-it's html: false on the server. The preview has to show the same
|
||||
// thing the mailer emits, or it would be reassuring about the wrong output.
|
||||
test('escapes raw HTML exactly as the mailer does', async ({ page }) => {
|
||||
await openSettings(page);
|
||||
await openEmails(page);
|
||||
await openTemplate(page, 'Password reset');
|
||||
|
||||
await page
|
||||
@@ -157,7 +163,7 @@ test.describe('Previewing the customer emails', () => {
|
||||
// Appended by the server and not editable, so it has to appear in the preview
|
||||
// of the two templates it belongs to and nowhere else.
|
||||
test('includes the consent footer on a favorite template, and not on others', async ({ page }) => {
|
||||
await openSettings(page);
|
||||
await openEmails(page);
|
||||
|
||||
await openTemplate(page, 'Favorited item sold');
|
||||
await expect(previewFrame(page, 'Favorited item sold').getByText(/account page/)).toBeVisible();
|
||||
|
||||
Reference in New Issue
Block a user