confluentinc / confluentinc/vscode
E2E: add `waitForNotification` and level-specific wrappers
- Dominant language
- TypeScript
- Stars
- 34
- Forks
- 17
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 8
Description
We have [many areas](https://github.com/search?q=repo%3Aconfluentinc%2Fvscode+%2F%3D+notificationArea%5C..%2B%5C.filter%2F&type=code) that just wait for a specific notification type with some text following the same general pattern:
```ts
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](https://github.com/confluentinc/vscode/tree/main/tests/e2e/utils) functions here, like:
```ts
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:
```ts
export async function waitForInfoNotification(page: Page, withText: string | RegExp) {
await waitForNotification(page, "info", withText);
}
```
Contributor guide
Assessment
This issue has not been assessed yet.