Skip to content

High performance, self-hosted, newsletter and mailing list manager with a modern dashboard. Single binary app.

Apply fixes/adjustments to Playwright tests.

Kailash Nadhc04c5bd4f6df
diff --git a/dev/docker-compose.yml b/dev/docker-compose.yml
index fb2d03c0..69142c46 100644
--- a/dev/docker-compose.yml
+++ b/dev/docker-compose.yml
@@ -47,6 +47,8 @@ services:
depends_on:
db:
condition: service_healthy
+ mailhog:
+ condition: service_started
volumes:
- ../:/app
- go-mod:/go/pkg/mod
diff --git a/tests/global-setup.js b/tests/global-setup.js
index 39f9071d..4387a270 100644
--- a/tests/global-setup.js
+++ b/tests/global-setup.js
@@ -1,10 +1,17 @@
import { chromium } from '@playwright/test';
import { mkdirSync } from 'node:fs';
-import { login } from './helpers.js';
+import { getMail, login } from './helpers.js';
import { launchOptions } from './browser.js';
// Login and create a persistent session for tests.
export default async function globalSetup() {
+ // Check the shared mail service once before every test tries to reset it.
+ try {
+ await getMail();
+ } catch (err) {
+ throw new Error(`Cannot reach MailHog at ${process.env.MAILHOG_URL || 'http://localhost:8025'}. Ensure the service is running and reachable from the test container.`, { cause: err });
+ }
+
mkdirSync(new URL('.auth', import.meta.url).pathname, { recursive: true });
const browser = await chromium.launch(launchOptions);
diff --git a/tests/helpers.js b/tests/helpers.js
index 00132dda..1376e03f 100644
--- a/tests/helpers.js
+++ b/tests/helpers.js
@@ -56,7 +56,9 @@ export async function clearMail() {
// All mail captured by MailHog, newest first.
export async function getMail() {
- return (await (await fetch(`${MAILHOG_URL}/api/v2/messages`)).json()).items;
+ const response = await fetch(`${MAILHOG_URL}/api/v2/messages`, { signal: AbortSignal.timeout(10000) });
+ if (!response.ok) throw new Error(`MailHog returned HTTP ${response.status}`);
+ return (await response.json()).items;
}
// Run a SQL statement against the listmonk DB. Credentials come from the
diff --git a/tests/specs/settings.spec.js b/tests/specs/settings.spec.js
index e37358f2..8f21d2a2 100644
--- a/tests/specs/settings.spec.js
+++ b/tests/specs/settings.spec.js
@@ -43,13 +43,20 @@ test.describe('Settings', () => {
const longSender = `${'a'.repeat(2000)} <[email protected]>`;
for (const addresses of [null, [], [' '], ['invalid'], ['{{ .Subscriber.Email }}'],
[' ', '{{ .Subscriber.Email }}'], ['{{ .Subscriber.Name }} <[email protected]>'], [first, 'invalid'],
- [longSender], [first, `${templated}${longSender}`], Array(101).fill(first)]) {
+ [longSender], [first, `${templated}${longSender}`], Array(251).fill(first)]) {
const res = await page.request.put('/api/settings', {
data: { ...current, 'app.from_email': addresses },
});
expect(res.status()).toBe(400);
}
+ const maxAddresses = Array.from({ length: 250 }, (_, i) => `sender${i}@example.com`);
+ const res = await page.request.put('/api/settings', {
+ data: { ...current, 'app.from_email': maxAddresses },
+ });
+ expect(res.status()).toBe(200);
+ expect((await settings(page))['app.from_email']).toEqual(maxAddresses);
+
await page.locator('[name="app.from_email"]').fill(`\n ${first} \n${second}\n${first}\n${templated}\n`);
await save(page);
expect((await settings(page))['app.from_email']).toEqual([first, second, templated]);
@@ -352,9 +359,10 @@ test.describe('Maintenance: bulk deletion', () => {
email: '[email protected]', name: 'Orphan', status: 'enabled', lists: [],
} }));
await page.goto('/admin/settings/maintenance');
+ const subscribers = page.getByRole('group', { name: 'Subscribers', exact: true });
for (const type of ['blocklisted', 'orphan']) {
- await page.locator('select[x-model=subscriberType]').selectOption(type);
- await page.locator('[data-cy=btn-delete-subscribers]').click();
+ await subscribers.getByRole('combobox', { name: 'Data', exact: true }).selectOption(type);
+ await subscribers.getByRole('button', { name: 'Delete', exact: true }).click();
const [res] = await Promise.all([
page.waitForResponse((r) => r.url().endsWith(`/api/maintenance/subscribers/${type}`)), confirm(page),
]);