Files
redefined-designs/frontend/tests/e2e/admin-email-settings.spec.ts
T
bermudalamb 3b3bd06bbe
Linting / lint (push) Successful in 1m53s
SonarQube Analysis / sonarqube (push) Successful in 17m12s
test(e2e): convert the remaining admin specs, completing the POM refactor (#137)
The last nine: admin-taxonomy, admin-save-failures, admin-theme, admin-inline-category, admin-item-preview, admin-disable-customer, admin-reserved-items, admin-inventory-filters, email-templates and admin-email-settings.

Every spec in tests/e2e now goes through page objects. Measured rather than asserted:

- raw CSS and antd-internal locators in spec files: 0 (was 13)
- local `register` helpers: 0 (was 9)
- hardcoded http://localhost:5173: 0 (was 3)

The antd knowledge that was spread across seven spec files is now in four page objects, each with the reason written next to it. Three of those are things no reader could have guessed from the locator:

Segmented hides its real radio behind a styled label, so the input is found by role and cannot be clicked — the title attribute is the handle.

The status multi-select renders an invisible role="listbox" shim beside the real list, so getByRole('option') finds something zero-sized; and a selected status renders again as a tag carrying the same title, so an unscoped getByTitle is ambiguous. Matching the visible option class avoids both. The dropdown is also opened only when closed, because antd keeps it open after a selection in multiple mode.

Select popups render into a portal at the end of <body>, outside the tab panel they belong to, so a dropdown cannot be found by scoping to the panel.

AdminPage.tab gained an `exact` flag for one specific collision: the Emails tab contains a rail that also renders tabs, and "Email verification" contains "Email". Without exact matching, opening the Emails tab is ambiguous with the template inside it.

Two helpers stayed local rather than moving into page objects, because they belong to their file's subject rather than to a surface: favorites-filter's `favorite()`, which settles the opt-in modal and waits for its fade before the wrapper stops intercepting pointer events, and admin-theme's `luminance()`, which is a WCAG calculation and not a locator. Both now take page objects as parameters instead of reaching for locators themselves.

Verified: 26/26 spec files converted, tsc clean over the whole tree, lint at the 30-warning src baseline with nothing added. Full suite 123 passed / 5 failed; all five pass in a 33/33 serial re-run, which is the load-related flakiness this suite has had throughout and not a change here — the backend hashes passwords with bcryptjs, a pure-JS implementation that blocks the event loop for every request while it runs.

Closes #137
2026-08-23 19:54:57 -05:00

71 lines
2.8 KiB
TypeScript

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);
});
});