Skip to content

E2E: add waitForNotification and level-specific wrappers #3202

@shouples

Description

@shouples

We have many areas that just wait for a specific notification type with some text following the same general pattern:

const notificationArea = new NotificationArea(page);
const notifications = notificationArea.[infoNotifications|warningNotifications|errorNotifications].filter({
  hasText: // string or RegExp,
});
await expect(notifications.first()).toBeVisible(); // or check count, but same general idea

We could reduce a lot of boilerplate by having some small utility functions here, like:

export async function waitForNotification(
  page: Page,
  level: "info" | "warning" | "error",
  withText: string | RegExp,
) {
  const notificationArea = new NotificationArea(page);
  let notifications: Locator;
  switch (level) {
    case "info":
      notifications = notificationArea.infoNotifications;
      break;
    case "warning":
      notifications = notificationArea.warningNotifications;
      break;
    case "error":
      notifications = notificationArea.errorNotifications;
      break;
    default:
      throw new Error(`Unsupported notification level: ${level}`);
  }
  const notification = notifications.filter({ hasText: withText }).first();
  await expect(notification).toBeVisible();
}

And then the wrappers would look like:

export async function waitForInfoNotification(page: Page, withText: string | RegExp) {
  await waitForNotification(page, "info", withText);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    cleanupGeneral refactoring and/or minor adjustments needed that shouldn't impact overall functionalitytestingInvolves the test suite, click-testing, or tests running in CI

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions