Align notification browser test with delivery policy

This commit is contained in:
SimpleTest 2026-08-13 03:09:01 +03:00
parent af90a64afc
commit bd1ccae6ab

View File

@ -36,15 +36,28 @@ test("nearby alerts, private notification inbox, preferences, and data export wo
const requestTitle = projectText("Nearby notification request", scope); const requestTitle = projectText("Nearby notification request", scope);
await gotoLiveView(subscriber.page, "/notifications"); await gotoLiveView(subscriber.page, "/notifications");
await subscriber.page.getByRole("link", { name: "Delivery settings" }).click(); await subscriber.page
const preferenceForm = subscriber.page.locator("#notification-preferences-form"); .getByRole("link", { name: "Delivery settings" })
await preferenceForm.getByLabel("Allow email notifications").check(); .click();
await preferenceForm.getByLabel("Nearby requests by email").check(); const preferenceForm = subscriber.page.locator(
"#notification-preferences-form",
);
await preferenceForm.getByLabel("Allow push notifications").check();
await preferenceForm.getByLabel("Nearby requests").check();
await expect(
preferenceForm.getByText(
"Nearby updates use the in-app inbox and optional push. Email digests are not enabled yet.",
),
).toBeVisible();
await preferenceForm.getByLabel("Use quiet hours").check(); await preferenceForm.getByLabel("Use quiet hours").check();
await preferenceForm.getByLabel("From").fill("22:00"); await preferenceForm.getByLabel("From").fill("22:00");
await preferenceForm.getByLabel("Until").fill("07:00"); await preferenceForm.getByLabel("Until").fill("07:00");
await preferenceForm.getByRole("button", { name: "Save preferences" }).click(); await preferenceForm
await expect(subscriber.page.getByText("Notification preferences saved.")).toBeVisible(); .getByRole("button", { name: "Save preferences" })
.click();
await expect(
subscriber.page.getByText("Notification preferences saved."),
).toBeVisible();
await subscriber.page await subscriber.page
.getByRole("link", { name: "Nearby alerts", exact: true }) .getByRole("link", { name: "Nearby alerts", exact: true })
@ -78,19 +91,27 @@ test("nearby alerts, private notification inbox, preferences, and data export wo
{ timeout: 15_000 }, { timeout: 15_000 },
) )
.not.toBeNull(); .not.toBeNull();
await subscriptionForm.getByLabel("Email notification").check(); await subscriptionForm.getByLabel("Push notification").check();
await subscriptionForm.getByRole("button", { name: "Create nearby alert" }).click(); await subscriptionForm
.getByRole("button", { name: "Create nearby alert" })
.click();
await expect(subscriber.page.getByText("Nearby alert created.")).toBeVisible(); await expect(
subscriber.page.getByText("Nearby alert created."),
).toBeVisible();
const savedAlert = subscriber.page const savedAlert = subscriber.page
.getByRole("heading", { name: "Your nearby alerts" }) .getByRole("heading", { name: "Your nearby alerts" })
.locator(".."); .locator("..");
await expect(savedAlert.getByRole("heading", { name: alertName })).toBeVisible(); await expect(
savedAlert.getByRole("heading", { name: alertName }),
).toBeVisible();
await expect(savedAlert.getByText(`${privateArea} · 3 km`)).toBeVisible(); await expect(savedAlert.getByText(`${privateArea} · 3 km`)).toBeVisible();
await expect(savedAlert.getByText("Push", { exact: true })).toBeVisible(); await expect(savedAlert.getByText("Push", { exact: true })).toBeVisible();
await expect(savedAlert.getByText("Email", { exact: true })).toBeVisible(); await expect(savedAlert.getByText("Email", { exact: true })).toHaveCount(0);
const accessibility = await new AxeBuilder({ page: subscriber.page }).analyze(); const accessibility = await new AxeBuilder({
page: subscriber.page,
}).analyze();
expect( expect(
accessibility.violations, accessibility.violations,
accessibility.violations accessibility.violations
@ -100,7 +121,9 @@ test("nearby alerts, private notification inbox, preferences, and data export wo
await gotoLiveView(requester.page, "/requests/new"); await gotoLiveView(requester.page, "/requests/new");
await selectOptionContaining(requester.page, "Category", "Medicine pickup"); await selectOptionContaining(requester.page, "Category", "Medicine pickup");
await requester.page.getByLabel("Medicine pickup status").selectOption("reserved"); await requester.page
.getByLabel("Medicine pickup status")
.selectOption("reserved");
await requester.page.getByLabel("Short title").fill(requestTitle); await requester.page.getByLabel("Short title").fill(requestTitle);
await requester.page await requester.page
.getByLabel("What help do you need?") .getByLabel("What help do you need?")
@ -116,38 +139,53 @@ test("nearby alerts, private notification inbox, preferences, and data export wo
}); });
await requester.page.locator("#request-form input[type=checkbox]").check(); await requester.page.locator("#request-form input[type=checkbox]").check();
await requester.page.getByRole("button", { name: "Publish request" }).click(); await requester.page.getByRole("button", { name: "Publish request" }).click();
await expect(requester.page.getByRole("heading", { name: requestTitle })).toBeVisible(); await expect(
requester.page.getByRole("heading", { name: requestTitle }),
).toBeVisible();
const requestURL = requester.page.url(); const requestURL = requester.page.url();
await subscriber.page.getByRole("link", { name: "Inbox" }).click(); await subscriber.page.getByRole("link", { name: "Inbox" }).click();
const inbox = subscriber.page const inbox = subscriber.page
.getByRole("heading", { name: "Inbox" }) .getByRole("heading", { name: "Inbox" })
.locator("xpath=ancestor::section"); .locator("xpath=ancestor::section");
const notification = inbox.getByRole("link", { name: /New help request nearby/ }); const notification = inbox.getByRole("link", {
name: /New help request nearby/,
});
await expect(notification).toBeVisible({ timeout: 20_000 }); await expect(notification).toBeVisible({ timeout: 20_000 });
await expect(inbox.getByText(privateArea)).toHaveCount(0); await expect(inbox.getByText(privateArea)).toHaveCount(0);
await notification.click(); await notification.click();
await expect(subscriber.page).toHaveURL(requestURL); await expect(subscriber.page).toHaveURL(requestURL);
await expect(subscriber.page.getByRole("heading", { name: requestTitle })).toBeVisible(); await expect(
subscriber.page.getByRole("heading", { name: requestTitle }),
).toBeVisible();
// WebKit reports cancelled image decoding as a page error when a document // WebKit reports cancelled image decoding as a page error when a document
// destroys a raster map before its worker reaches idle. Waiting here tests // destroys a raster map before its worker reaches idle. Waiting here tests
// the real rendered state and avoids navigating away mid-decode. // the real rendered state and avoids navigating away mid-decode.
await waitForMapIdle(subscriber.page); await waitForMapIdle(subscriber.page);
await gotoWithTransientRetry(subscriber.page, "/users/settings"); await gotoWithTransientRetry(subscriber.page, "/users/settings");
await expect(subscriber.page.getByRole("heading", { name: "Account Settings" })).toBeVisible(); await expect(
subscriber.page.getByRole("heading", { name: "Account Settings" }),
).toBeVisible();
assertSubscriberClean(); assertSubscriberClean();
assertRequesterClean(); assertRequesterClean();
const exportLink = subscriber.page.getByRole("link", { name: "Download my data" }); const exportLink = subscriber.page.getByRole("link", {
name: "Download my data",
});
await expect(exportLink).toHaveAttribute("href", "/users/data-export"); await expect(exportLink).toHaveAttribute("href", "/users/data-export");
const exportURL = new URL("/users/data-export", subscriber.page.url()).toString(); const exportURL = new URL(
"/users/data-export",
subscriber.page.url(),
).toString();
const exportResponse = await subscriber.context.request.get(exportURL); const exportResponse = await subscriber.context.request.get(exportURL);
expect(exportResponse.status()).toBe(200); expect(exportResponse.status()).toBe(200);
expect(exportResponse.headers()["content-disposition"]).toMatch( expect(exportResponse.headers()["content-disposition"]).toMatch(
/^attachment; filename="who-need-help-account-export-\d{4}-\d{2}-\d{2}\.json"$/, /^attachment; filename="who-need-help-account-export-\d{4}-\d{2}-\d{2}\.json"$/,
); );
expect((await exportResponse.json()).format).toBe("who-need-help-account-export"); expect((await exportResponse.json()).format).toBe(
"who-need-help-account-export",
);
await subscriber.context.close(); await subscriber.context.close();
await requester.context.close(); await requester.context.close();