Files
Kacper 26236d3d5b feat: enhance ESLint configuration and improve component error handling
- Updated ESLint configuration to include support for `.mjs` and `.cjs` file types, adding necessary global variables for Node.js and browser environments.
- Introduced a new `vite-env.d.ts` file to define environment variables for Vite, improving type safety.
- Refactored error handling in `file-browser-dialog.tsx`, `description-image-dropzone.tsx`, and `feature-image-upload.tsx` to omit error parameters, simplifying the catch blocks.
- Removed unused bug report button functionality from the sidebar, streamlining the component structure.
- Adjusted various components to improve code readability and maintainability, including updates to type imports and component props.

These changes aim to enhance the development experience by improving linting support and simplifying error handling across components.
2025-12-21 23:08:08 +01:00

86 lines
2.4 KiB
TypeScript

import { Page, Locator } from '@playwright/test';
/**
* Wait for a toast notification with specific text to appear
*/
export async function waitForToast(
page: Page,
text: string,
options?: { timeout?: number }
): Promise<Locator> {
const toast = page.locator(`[data-sonner-toast]:has-text("${text}")`).first();
await toast.waitFor({
timeout: options?.timeout ?? 5000,
state: 'visible',
});
return toast;
}
/**
* Wait for an error toast to appear with specific text
*/
export async function waitForErrorToast(
page: Page,
titleText?: string,
options?: { timeout?: number }
): Promise<Locator> {
// Try multiple selectors for error toasts since Sonner versions may differ
// 1. Try with data-type="error" attribute
// 2. Fallback to any toast with the text (error styling might vary)
const timeout = options?.timeout ?? 5000;
if (titleText) {
// First try specific error type, then fallback to any toast with text
const errorToast = page
.locator(
`[data-sonner-toast][data-type="error"]:has-text("${titleText}"), [data-sonner-toast]:has-text("${titleText}")`
)
.first();
await errorToast.waitFor({
timeout,
state: 'visible',
});
return errorToast;
} else {
const errorToast = page.locator('[data-sonner-toast][data-type="error"]').first();
await errorToast.waitFor({
timeout,
state: 'visible',
});
return errorToast;
}
}
/**
* Check if an error toast is visible
*/
export async function isErrorToastVisible(page: Page, titleText?: string): Promise<boolean> {
const toastSelector = titleText
? `[data-sonner-toast][data-type="error"]:has-text("${titleText}")`
: '[data-sonner-toast][data-type="error"]';
const toast = page.locator(toastSelector).first();
return await toast.isVisible();
}
/**
* Wait for a success toast to appear with specific text
*/
export async function waitForSuccessToast(
page: Page,
titleText?: string,
options?: { timeout?: number }
): Promise<Locator> {
// Sonner toasts use data-sonner-toast and data-type="success" for success toasts
const toastSelector = titleText
? `[data-sonner-toast][data-type="success"]:has-text("${titleText}")`
: '[data-sonner-toast][data-type="success"]';
const toast = page.locator(toastSelector).first();
await toast.waitFor({
timeout: options?.timeout ?? 5000,
state: 'visible',
});
return toast;
}