110 lines
4.2 KiB
TypeScript
110 lines
4.2 KiB
TypeScript
import { expect, test } from "@playwright/test";
|
|
import { loginAsUser } from "./fixtures";
|
|
import { mockApi, primeMockSession } from "./support/network.js";
|
|
|
|
async function openUserNotifications(page) {
|
|
await loginAsUser(page);
|
|
await page.goto("/user/profile");
|
|
const notificationsCard = page.getByTestId("user-profile-notifications-card");
|
|
await expect(notificationsCard).toBeVisible();
|
|
await notificationsCard.locator(".card-header").click();
|
|
await expect(page.getByTestId("user-profile-notifications-edit-booking-email")).toBeVisible();
|
|
}
|
|
|
|
async function openUserNotificationsWithMockSession(
|
|
page,
|
|
{
|
|
permissions = ["user"],
|
|
notifications = {},
|
|
}: {
|
|
permissions?: string[];
|
|
notifications?: Record<string, unknown>;
|
|
} = {}
|
|
) {
|
|
await mockApi(page, {
|
|
authenticated: true,
|
|
permissions,
|
|
sessionData: {
|
|
display_name: "Notification Settings User",
|
|
permissions,
|
|
notifications: {
|
|
wash_certificate_email: null,
|
|
email_notifications_enabled: true,
|
|
sms_notifications_enabled: false,
|
|
superuser_new_customer_email_notifications_enabled: false,
|
|
...notifications,
|
|
},
|
|
},
|
|
});
|
|
await primeMockSession(page, { bootPath: "/user" });
|
|
await page.goto("/user/profile");
|
|
const notificationsCard = page.getByTestId("user-profile-notifications-card");
|
|
await expect(notificationsCard).toBeVisible();
|
|
await notificationsCard.locator(".card-header").click();
|
|
await expect(page.getByTestId("user-profile-notifications-edit-booking-email")).toBeVisible();
|
|
}
|
|
|
|
test("[PROFILE][User][Notifications] renders the current notification controls", async ({ page }) => {
|
|
await openUserNotifications(page);
|
|
|
|
await expect(page.getByTestId("user-profile-notifications-edit-booking-email")).toBeVisible();
|
|
await expect(page.getByTestId("user-profile-notifications-edit-sms-phone")).toBeVisible();
|
|
await expect(
|
|
page.getByTestId("user-profile-notifications-email-switch").locator('input[type="checkbox"]')
|
|
).toBeVisible();
|
|
await expect(
|
|
page.getByTestId("user-profile-notifications-sms-switch").locator('input[type="checkbox"]')
|
|
).toBeVisible();
|
|
});
|
|
|
|
test("[PROFILE][User][Notifications] opens the booking-email dialog", async ({ page }) => {
|
|
await openUserNotifications(page);
|
|
|
|
await page.getByTestId("user-profile-notifications-edit-booking-email").click();
|
|
await expect(page.locator(".swal2-popup")).toBeVisible();
|
|
await expect(page.locator(".swal2-input")).toBeVisible();
|
|
});
|
|
|
|
test("[PROFILE][User][Notifications] validates booking-email input", async ({ page }) => {
|
|
await openUserNotifications(page);
|
|
|
|
await page.getByTestId("user-profile-notifications-edit-booking-email").click();
|
|
await page.fill(".swal2-input", "invalid-email");
|
|
await page.click(".swal2-confirm");
|
|
await expect(page.locator(".swal2-validation-message")).toBeVisible();
|
|
});
|
|
|
|
test("[PROFILE][User][Notifications] hides superuser notifications without superuser permission", async ({ page }) => {
|
|
await openUserNotificationsWithMockSession(page, {
|
|
permissions: ["user", "user_notifications_update"],
|
|
});
|
|
|
|
await expect(page.getByTestId("user-profile-notifications-superuser-new-customer-email-switch")).toHaveCount(0);
|
|
});
|
|
|
|
test("[PROFILE][User][Notifications] saves superuser new customer email notifications", async ({ page }) => {
|
|
await openUserNotificationsWithMockSession(page, {
|
|
permissions: ["user", "user_notifications_update", "superuser"],
|
|
notifications: {
|
|
superuser_new_customer_email_notifications_enabled: false,
|
|
},
|
|
});
|
|
|
|
const switchRoot = page.getByTestId("user-profile-notifications-superuser-new-customer-email-switch");
|
|
const checkbox = switchRoot.locator('input[type="checkbox"]');
|
|
const switchLabel = switchRoot.locator("label[for]").last();
|
|
await expect(switchRoot).toBeVisible();
|
|
await expect(checkbox).not.toBeChecked();
|
|
|
|
const updateRequest = page.waitForRequest((request) => {
|
|
return request.method() === "PUT" && request.url().includes("/account/notifications");
|
|
});
|
|
await switchLabel.click();
|
|
const request = await updateRequest;
|
|
|
|
expect(request.postDataJSON()).toEqual({
|
|
superuser_new_customer_email_notifications_enabled: true,
|
|
});
|
|
await expect(checkbox).toBeChecked();
|
|
});
|