import { test, expect, request as apiRequest, type Page } from '@playwright/test'; import { FRONTEND_URL, createTestAddress, deleteAddress, requestSendAccess, } from '../../fixtures/test-helpers'; const expectEditorOriginsToAlign = async (page: Page) => { const editorOriginDelta = await page.locator('.compose-textarea').evaluate((editor) => { const textareaElement = editor.querySelector('textarea'); const placeholder = editor.querySelector('.n-input__placeholder'); if (!textareaElement) throw new Error('compose textarea element not found'); if (!placeholder) throw new Error('compose placeholder element not found'); const textareaBox = textareaElement.getBoundingClientRect(); const placeholderBox = placeholder.getBoundingClientRect(); const textareaStyle = getComputedStyle(textareaElement); const placeholderStyle = getComputedStyle(placeholder); return { x: textareaBox.x + parseFloat(textareaStyle.paddingLeft) - placeholderBox.x - parseFloat(placeholderStyle.paddingLeft), y: textareaBox.y + parseFloat(textareaStyle.paddingTop) - placeholderBox.y - parseFloat(placeholderStyle.paddingTop), }; }); expect(Math.abs(editorOriginDelta.x)).toBeLessThan(1); expect(Math.abs(editorOriginDelta.y)).toBeLessThan(1); }; test.describe('Send mail composer', () => { test('edits a draft, changes format, and previews HTML', async ({ page }) => { const api = await apiRequest.newContext(); let jwt: string | undefined; try { const created = await createTestAddress(api, 'compose-ui'); jwt = created.jwt; await requestSendAccess(api, jwt); await page.goto(`${FRONTEND_URL}/en/?jwt=${jwt}`); await page.getByText('Send Mail', { exact: true }).click(); await expect(page.getByRole('heading', { name: 'Compose email', exact: true })).toBeVisible(); await expect(page.locator('.composer-title')).toContainText(created.address); const expectedFieldOrder = [ 'send-mail-sender-address', 'send-mail-sender-name', 'send-mail-recipient-address', 'send-mail-recipient-name', ]; const fieldIds = await page.locator('.composer-form .n-grid input').evaluateAll( (inputs) => inputs.map((input) => input.id) ); expect(fieldIds.filter((id) => expectedFieldOrder.includes(id))).toEqual(expectedFieldOrder); const textarea = page.locator('.compose-textarea textarea'); await expectEditorOriginsToAlign(page); const recipient = page.getByRole('textbox', { name: /^Recipient address/ }); const subject = page.getByRole('textbox', { name: /^Subject/ }); await recipient.fill('recipient@test.example.com'); await subject.fill('Composer preview'); await page.getByText('HTML', { exact: true }).click(); const htmlContent = [ '
Preview body
', '