import { test, expect } from '@playwright/test'; import { adminPath, ensureDataSource, cleanupByNames } from './helpers.mjs'; test('mailshots editor: datasource-driven options + overlay editors + create', async ({ page, request }) => { const uniq = `${Date.now()}_${Math.floor(Math.random() * 100000)}`; const dsName = `e2e_ms_ds_${uniq}`; const purpose = `e2e_mailshot_${uniq}`; try { await ensureDataSource(request, dsName, 'contacts'); await page.goto(adminPath('feca-mailshots-mailshots')); await expect(page.locator('h1', { hasText: 'Mailshots' })).toBeVisible(); await page.locator('#ms-open-new').click(); await expect(page.locator('#ms-editor-modal')).toBeVisible(); await page.locator('#ms_purpose').fill(purpose); await page.locator('#ms_ds').selectOption({ label: dsName }); await expect.poll(async () => await page.locator('#ms-token-controls button, #ms-token-controls select option').count()).toBeGreaterThan(0); await expect.poll(async () => await page.locator('#ms_pdfname option').count()).toBeGreaterThan(1); await expect.poll(async () => await page.locator('#ms_email_field option').count()).toBeGreaterThan(1); await page.locator('#ms_subject').fill('Subject {{ contacts.id }}'); await page.locator('#ms-edit-message').click(); await expect(page.locator('#ms-template-modal')).toBeVisible(); await page.evaluate(() => { const html = '
Hello bold {{ contacts.id }}
'; const ed = window.tinymce && window.tinymce.get ? window.tinymce.get('ms-template-html') : null; const raw = /** @type {HTMLTextAreaElement|null} */ (document.getElementById('ms-template-html')); if (ed) { ed.setContent(html); ed.save(); } else if (raw) { raw.value = html; } }); await page.locator('#ms-template-mode-code').click(); await expect(page.locator('#ms-template-code')).toHaveValue(/]*>[\s\S]*\.red-note\s*\{[^}]*color:\s*red;?[^}]*\}[\s\S]*<\/style>/i); await expect(page.locator('#ms-template-code')).toHaveValue(/class=["']red-note["']/i); await expect(page.locator('#ms-template-code')).toHaveValue(/bold<\/strong>/); await page.locator('#ms-template-mode-visual').click(); await page.locator('#ms-template-mode-code').click(); await expect(page.locator('#ms-template-code')).toHaveValue(/class=["']red-note["']/i); await expect(page.locator('#ms-template-code')).not.toHaveValue(/data-mce-type=["']bookmark["']/i); await expect(page.locator('#ms-template-code')).not.toHaveValue(/mce_SELRES_(?:start|end)/i); await expect(page.locator('#ms-template-code')).not.toHaveValue(/]*>[\s\S]*/i); const formattedSource = `
hello
`; await page.locator('#ms-template-code').fill(formattedSource); await page.locator('#ms-template-mode-visual').click(); await page.locator('#ms-template-mode-code').click(); await expect(page.locator('#ms-template-code')).toHaveValue(/