Skip to content

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

Fix Playwright tets that have deviated from the UI.

Kailash Nadh891d05e1ca62
diff --git a/tests/specs/bounces.spec.js b/tests/specs/bounces.spec.js
index 7282d466..5d2ad5a2 100644
--- a/tests/specs/bounces.spec.js
+++ b/tests/specs/bounces.spec.js
@@ -45,12 +45,11 @@ test.describe('Bounces', () => {
// Hard bounces blocklist.
await postBounce(page, 'hard', a.email);
await postBounce(page, 'hard', a.email);
- expect(await subStatus(page, a.id)).toBe('blocklisted');
+ await expect.poll(() => subStatus(page, a.id)).toBe('blocklisted');
// Complaints delete the subscriber outright.
await postBounce(page, 'complaint', b.email);
- const res = await page.request.get(`/api/subscribers/${b.id}`);
- expect(res.status()).toBe(400);
+ await expect.poll(async () => (await page.request.get(`/api/subscribers/${b.id}`)).status()).toBe(400);
});
test('lists the recorded bounces', async ({ page }) => {
@@ -93,8 +92,11 @@ test.describe('Bounces: bulk actions', () => {
};
const subs = (await data(await page.request.get('/api/subscribers'))).results;
for (const sub of subs) await postBounce(page, 'soft', sub.email);
- const bounces = (await data(await page.request.get('/api/bounces'))).results;
- expect(bounces).toHaveLength(2);
+ let bounces;
+ await expect.poll(async () => {
+ bounces = (await data(await page.request.get('/api/bounces'))).results;
+ return bounces.length;
+ }).toBe(2);
for (const url of ['?all=true&campaign_id=invalid', '?all=true&id=invalid', '']) {
expect((await page.request.delete(`/api/bounces${url}`)).status()).toBe(400);
}
@@ -147,11 +149,15 @@ test.describe('Bounces: bulk actions', () => {
await data(await page.request.post('/webhooks/bounce', { data: { email: sub.email, source, type, campaign_uuid: campaignUUID } }));
// Hard-bounce processing blocklists automatically; restore the fixture so
// accidental bulk blocklisting of an unrelated subscriber is observable.
- if (type === 'hard') await data(await page.request.put(`/api/subscribers/${sub.id}`, { data: {
- email: sub.email, name: sub.name, status: 'enabled', lists: [1],
- } }));
+ if (type === 'hard') {
+ await expect.poll(() => subStatus(page, sub.id)).toBe('blocklisted');
+ await data(await page.request.put(`/api/subscribers/${sub.id}`, { data: {
+ email: sub.email, name: sub.name, status: 'enabled', lists: [1],
+ } }));
+ }
(outside ? outsiders : targets).push(sub.id);
}
+ await expect.poll(async () => (await data(await page.request.get('/api/bounces?per_page=100'))).results.length).toBe(25);
const query = {
source: 'source=target', type: 'type=soft', campaign_id: `campaign_id=${campaign.id}`,
combined: `source=target&type=soft&campaign_id=${campaign.id}`,
diff --git a/tests/specs/campaigns.spec.js b/tests/specs/campaigns.spec.js
index b8372417..70e3638d 100644
--- a/tests/specs/campaigns.spec.js
+++ b/tests/specs/campaigns.spec.js
@@ -145,7 +145,7 @@ for (const format of ['richtext', 'html', 'markdown', 'plain', 'visual']) {
await preview(page, rendered);
await page.goto(CAMPAIGNS);
await expect(row(page, `New ${format}`)).toContainText(`Subject ${format}`);
- await expect(row(page, `New ${format}`).locator('.lists li')).toHaveCount(lists.length);
+ await expect(row(page, `New ${format}`).locator('.lists a.avatar-label')).toHaveCount(lists.length);
});
}
}
@@ -333,7 +333,7 @@ test('searches, filters and sorts campaigns through SSR navigation', async ({ pa
await expect(page).not.toHaveURL(/[?&]tag=/);
await expect(row(page, 'Alpha')).toBeVisible();
await page.goto(CAMPAIGNS);
- await row(page, 'Alpha').getByRole('link', { name: 'View Draft', exact: true }).click();
+ await row(page, 'Alpha').getByTitle('Filter Draft', { exact: true }).click();
await expect(page).toHaveURL(/[?&]status=draft/);
await expect(rows(page)).toHaveCount(3);
for (const [field, orders] of [
@@ -342,7 +342,7 @@ test('searches, filters and sorts campaigns through SSR navigation', async ({ pa
]) {
for (const names of orders) {
await page.locator(`a[data-sort-field="${field}"]`).click();
- await expect(rows(page).locator('td.name .name-stack > div > div > a.unstyled')).toHaveText(names);
+ await expect(rows(page).locator('td.name > .avatar > .avatar-label > div > a.unstyled')).toHaveText(names);
await expect(page).toHaveURL(/[?&]status=draft/);
}
}
@@ -445,7 +445,7 @@ test('uploads an attachment, persists it and delivers it when starting from the
await picker.locator('button[popovertarget="media-upload"]').click();
await picker.locator('input[type="file"]').setInputFiles({ name: 'campaign-example.json', mimeType: 'application/json', buffer: Buffer.from('{"hello":"attachment"}') });
await picker.locator('button[type="submit"]').filter({ hasText: 'Upload' }).click();
- await picker.getByRole('link', { name: 'campaign-example.json', exact: true }).click();
+ await picker.locator('a.thumb').and(picker.getByTitle('campaign-example.json', { exact: true })).click();
await expect(page.locator('.media-picker-modal')).not.toBeVisible();
await save(page, c.id);
await page.reload();
@@ -574,7 +574,7 @@ for (const tracked of [true, false]) {
await button(page, 'Link').click();
await expect(checkbox).toBeChecked({ checked: tracked });
await checkbox.setChecked(!tracked);
- await button(dialog, 'Insert').click();
+ await button(dialog, 'Apply').click();
await expect(link).toHaveAttribute('href', href(!tracked));
await save(page, c.id);
expect((await campaign(page, c.id)).body).toContain(`href="${href(!tracked)}"`);
diff --git a/tests/specs/lists.spec.js b/tests/specs/lists.spec.js
index 67d8dd29..53a320f7 100644
--- a/tests/specs/lists.spec.js
+++ b/tests/specs/lists.spec.js
@@ -110,6 +110,7 @@ test.describe('Lists', () => {
for (const [n, id] of ids.entries()) {
await page.goto(`${LISTS}/${id}`);
+ await page.getByRole('tab', { name: 'Edit', exact: true }).click();
await fillListForm(page, {
name: `list-${n}`,
type: 'public',
@@ -133,6 +134,7 @@ test.describe('Lists', () => {
// The description isn't on the listing; reopen each edit view to confirm it saved.
for (const [n, id] of ids.entries()) {
await page.goto(`${LISTS}/${id}`);
+ await page.getByRole('tab', { name: 'Edit', exact: true }).click();
await expect(page.locator('textarea[name="description"]')).toHaveValue(`desc${n}`);
}
});
@@ -174,6 +176,9 @@ test.describe('Lists', () => {
name, type: c.type, optin: c.optin, tag: `tag${n}`, description: `desc-${c.type}-${n}`,
});
await withListAPI(page, 'POST', () => form.getByTestId('btn-save').click());
+ await expect(page).toHaveURL(/\/admin\/lists\/\d+$/);
+ await expect(page.getByRole('heading', { name, exact: true })).toBeVisible();
+ await page.goto(LISTS);
const row = listRow(page, name);
await expect(row).toBeVisible();
@@ -205,7 +210,7 @@ test.describe('Lists', () => {
await expect(listRow(page, 'list-private-double-1')).toBeVisible();
// The active filter shows as a removable badge.
- await expect(page.locator('.page-title')).toContainText('Private');
+ await expect(page.locator('.page-heading')).toContainText('Private');
await page.getByTestId('btn-remove-filter').click();
await expect(listRow(page)).toHaveCount(4);
});
@@ -221,7 +226,7 @@ test.describe('Lists', () => {
await expect(listRow(page, 'list-private-single-0')).toBeVisible();
await expect(listRow(page, 'list-public-single-2')).toBeVisible();
- await expect(page.locator('.page-title')).toContainText('Single opt-in');
+ await expect(page.locator('.page-heading')).toContainText('Single opt-in');
await page.getByTestId('btn-remove-filter').click();
await expect(listRow(page)).toHaveCount(4);
});
@@ -236,7 +241,7 @@ test.describe('Lists', () => {
await expect(listRow(page)).toHaveCount(1);
await expect(listRow(page, 'list-private-single-0')).toBeVisible();
- await expect(page.locator('.page-title')).toContainText('#tag0');
+ await expect(page.locator('.page-heading')).toContainText('#tag0');
await page.getByTestId('btn-remove-filter').click();
await expect(listRow(page)).toHaveCount(4);
});
@@ -248,8 +253,8 @@ test.describe('Lists', () => {
await expect(listRow(page, 'list-public-double-3')).toBeVisible();
// Both active filters appear as badges in the header.
- await expect(page.locator('.page-title')).toContainText('Public');
- await expect(page.locator('.page-title')).toContainText('Double opt-in');
+ await expect(page.locator('.page-heading')).toContainText('Public');
+ await expect(page.locator('.page-heading')).toContainText('Double opt-in');
});
test('sorts lists by column', async ({ page }) => {
diff --git a/tests/specs/subscribers.spec.js b/tests/specs/subscribers.spec.js
index 2a673a36..338e8dd3 100644
--- a/tests/specs/subscribers.spec.js
+++ b/tests/specs/subscribers.spec.js
@@ -206,7 +206,7 @@ test.describe('Subscribers: create, edit & delete', () => {
const row = subRow(page, '[email protected]');
await expect(row).toBeVisible();
await expect(row).toContainText('Default list');
- await expect(row.locator('td.align-center')).toContainText('1');
+ await expect(row.locator('.lists a.avatar-label')).toHaveText(['Default list']);
});
test('creates a pre-confirmed subscriber on a double opt-in list', async ({ page }) => {
@@ -230,7 +230,7 @@ test.describe('Subscribers: create, edit & delete', () => {
await page.goto(SUBSCRIBERS);
const row = subRow(page, '[email protected]');
await expect(row).toContainText('Opt-in list');
- await expect(row).toContainText('Confirmed');
+ await expect(row.getByRole('link', { name: 'View Opt-in list: Confirmed', exact: true })).toBeVisible();
});
test('edits a subscriber and blocklists via the status field', async ({ page }) => {
@@ -314,7 +314,7 @@ test.describe('Subscribers: filters & pagination', () => {
await page.goto(`${SUBSCRIBERS}/lists/${LIST_OPTIN}`);
await expect(subRow(page)).toHaveCount(1);
await expect(subRow(page, '[email protected]')).toBeVisible();
- await expect(page.locator('.page-title')).toContainText('Opt-in list');
+ await expect(page.locator('.page-heading')).toContainText('Opt-in list');
// Clearing the filter badge returns to the full listing.
await Promise.all([page.waitForLoadState(), page.getByTestId('btn-remove-filter').click()]);
@@ -327,7 +327,7 @@ test.describe('Subscribers: filters & pagination', () => {
await page.goto(`${SUBSCRIBERS}?status=blocklisted`);
await expect(subRow(page)).toHaveCount(1);
await expect(subRow(page, '[email protected]')).toBeVisible();
- await expect(page.locator('.page-title')).toContainText('Blocklisted');
+ await expect(page.locator('.page-heading')).toContainText('Blocklisted');
});
test('filters a list by subscription status', async ({ page }) => {
@@ -338,11 +338,11 @@ test.describe('Subscribers: filters & pagination', () => {
},
});
- // The confirmed filter shows only anon, with a Confirmed badge.
+ // The confirmed filter shows only anon, with a labeled status icon.
await page.goto(`${SUBSCRIBERS}/lists/${LIST_OPTIN}?subscription_status=confirmed`);
- await expect(page.locator('.page-title')).toContainText('Confirmed');
+ await expect(page.locator('.page-heading')).toContainText('Confirmed');
await expect(subRow(page)).toHaveCount(1);
- await expect(subRow(page, '[email protected]')).toContainText('Confirmed');
+ await expect(subRow(page, '[email protected]').getByRole('link', { name: 'View Opt-in list: Confirmed', exact: true })).toBeVisible();
});
});
@@ -650,17 +650,17 @@ test.describe('Subscriber detail: activity tab', () => {
await expect(stats.nth(i)).toHaveText('0');
}
});
-});
-test('subscriber overview links to edit and preserves the activity URL', async ({ page }) => {
- await page.goto(`${SUBSCRIBERS}/1/activity`);
- await expect(page.locator('#chart-subscriber-views')).toBeVisible();
- await page.getByRole('tab', { name: 'Edit', exact: true }).click();
- await expect(page).toHaveURL(/\/subscribers\/1\/edit$/);
- await expect(page.locator('input[name=email]')).toBeVisible();
- await page.getByRole('tab', { name: 'View', exact: true }).click();
- await expect(page).toHaveURL(/\/subscribers\/1$/);
- await expect(page.locator('#chart-subscriber-clicks')).toBeVisible();
+ test('subscriber overview links to edit and back to the overview', async ({ page }) => {
+ await page.goto(`${SUBSCRIBERS}/1`);
+ await expect(page.locator('#chart-subscriber-views')).toBeVisible();
+ await page.getByRole('tab', { name: 'Edit', exact: true }).click();
+ await expect(page).toHaveURL(/\/subscribers\/1\/edit$/);
+ await expect(page.locator('input[name=email]')).toBeVisible();
+ await page.getByRole('tab', { name: 'View', exact: true }).click();
+ await expect(page).toHaveURL(/\/subscribers\/1$/);
+ await expect(page.locator('#chart-subscriber-clicks')).toBeVisible();
+ });
});
test.describe('Domain blocklist', () => {
diff --git a/tests/specs/users.spec.js b/tests/specs/users.spec.js
index a0542ea0..3b15840b 100644
--- a/tests/specs/users.spec.js
+++ b/tests/specs/users.spec.js
@@ -237,7 +237,7 @@ test.describe('Users, roles & login', () => {
// The listing renders each user's role badges. Read the rows and confirm the
// roles match (usernames and role names overlap, so match on the username link).
const rows = await userRow(page).evaluateAll((els) => els.map((el) => ({
- username: el.querySelector('a[href*="/admin/users/"]').textContent.trim(),
+ username: el.querySelector('.avatar-label > a[href*="/admin/users/"]').textContent.trim(),
userRole: el.querySelector('a[href*="user_role_id"]')?.textContent.trim(),
listRole: el.querySelector('a[href*="list_role_id"]')?.textContent.trim(),
})));