import { test, expect } from './fixtures'; // These edit global settings that other specs depend on — cart expiry above // all — so they run serially and put everything back afterwards. test.describe.configure({ mode: 'serial' }); const DEFAULTS = { cartExpiryHours: 24, verifyTokenHours: 24, passwordResetHours: 1, greetingFormat: 'Hi {{firstName}},', greetingFallback: 'Hi,' }; test.describe('The email settings', () => { test.afterEach(async ({ page, adminSettings }) => { await page.request.put('/api/admin/settings', { data: DEFAULTS }); }); test('offers the link lifetimes and the greeting alongside cart expiry', async ({ page, adminSettings }) => { await adminSettings.open(); // antd renders a stepped InputNumber to the step's precision, so "24.0". await expect(adminSettings.cartExpiryHours).toHaveValue('24.0'); await expect(adminSettings.verifyTokenHours).toHaveValue('24.0'); await expect(adminSettings.passwordResetHours).toHaveValue('1.0'); await expect(adminSettings.greetingFormat).toHaveValue('Hi {{firstName}},'); await expect(adminSettings.greetingFallback).toHaveValue('Hi,'); }); test('saves a new lifetime, and the server keeps it', async ({ page, adminSettings }) => { await adminSettings.open(); await adminSettings.passwordResetHours.fill('3'); await adminSettings.saveButton.click(); await expect(page.getByText('Settings saved')).toBeVisible(); const stored = await (await page.request.get('/api/admin/settings')).json(); expect(stored.passwordResetHours).toBe(3); }); // The whole reason the placeholder exists: the sentence in the email is // rendered from the setting rather than written out beside it. test('the password reset preview states the configured lifetime', async ({ page, admin, adminEmails }) => { await page.request.put('/api/admin/settings', { data: { passwordResetHours: 2 } }); await admin.open('Emails'); await adminEmails.openTemplate('Password reset'); await expect(adminEmails.preview('Password reset').getByText('2 hours')).toBeVisible(); }); test('the preview greets through the configured format', async ({ page, admin, adminEmails }) => { await page.request.put('/api/admin/settings', { data: { greetingFormat: 'Salutations {{firstName}}!' } }); await admin.open('Emails'); await adminEmails.openTemplate('Email verification'); await expect(adminEmails.preview('Email verification').getByText('Salutations Ada!')).toBeVisible(); }); test('refuses a lifetime of zero rather than reporting a save', async ({ page, adminSettings }) => { await adminSettings.open(); await adminSettings.passwordResetHours.fill('0'); await adminSettings.saveButton.click(); await expect(page.getByText('Settings saved')).toHaveCount(0); }); });