mirror of
https://github.com/toeverything/AFFiNE.git
synced 2025-10-26 11:37:06 +00:00
fix(core): ai flaky tests
This commit is contained in:
parent
4662ee8da7
commit
6f2dd70002
@ -32,13 +32,50 @@ export class ChatPanelUtils {
|
||||
});
|
||||
await page.waitForTimeout(500); // wait the sidebar stable
|
||||
}
|
||||
if (await page.getByTestId('notification-close-button').isVisible()) {
|
||||
await page.getByTestId('notification-close-button').click();
|
||||
}
|
||||
await this.closeNotification(page);
|
||||
await page.getByTestId('sidebar-tab-chat').click();
|
||||
await expect(page.getByTestId('sidebar-tab-content-chat')).toBeVisible();
|
||||
}
|
||||
|
||||
public static async closeNotification(page: Page) {
|
||||
await page.evaluate(() => {
|
||||
return new Promise<void>(resolve => {
|
||||
const observer = new MutationObserver((_mutations, observer) => {
|
||||
const notificationButton = document.querySelector(
|
||||
'[data-testid="notification-close-button"]'
|
||||
);
|
||||
if (notificationButton) {
|
||||
(notificationButton as HTMLElement).click();
|
||||
observer.disconnect();
|
||||
// Slight delay to ensure click is processed
|
||||
setTimeout(() => resolve(), 100);
|
||||
}
|
||||
});
|
||||
|
||||
observer.observe(document.body, {
|
||||
childList: true,
|
||||
subtree: true,
|
||||
});
|
||||
|
||||
// Check if notification already exists
|
||||
const notificationButton = document.querySelector(
|
||||
'[data-testid="notification-close-button"]'
|
||||
);
|
||||
if (notificationButton) {
|
||||
(notificationButton as HTMLElement).click();
|
||||
observer.disconnect();
|
||||
resolve();
|
||||
}
|
||||
|
||||
// Set a timeout to resolve if no notification appears
|
||||
setTimeout(() => {
|
||||
observer.disconnect();
|
||||
resolve();
|
||||
}, 2000);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public static async closeChatPanel(page: Page) {
|
||||
await page.getByTestId('right-sidebar-toggle').click({
|
||||
delay: 200,
|
||||
|
||||
@ -14,6 +14,9 @@ import type {
|
||||
} from '@blocksuite/affine-model';
|
||||
import type { GfxModel } from '@blocksuite/std/gfx';
|
||||
import { type Page } from '@playwright/test';
|
||||
|
||||
import { ChatPanelUtils } from './chat-panel-utils';
|
||||
|
||||
export class EditorUtils {
|
||||
public static async focusToEditor(page: Page) {
|
||||
const title = getBlockSuiteEditorTitle(page);
|
||||
@ -53,20 +56,9 @@ export class EditorUtils {
|
||||
await page.getByTestId('switch-edgeless-mode-button').click();
|
||||
await editor.waitForElementState('hidden');
|
||||
await page.waitForSelector('edgeless-editor');
|
||||
try {
|
||||
const edgelessNotificationClose = page.getByTestId(
|
||||
'notification-close-button'
|
||||
);
|
||||
await edgelessNotificationClose.waitFor({
|
||||
state: 'visible',
|
||||
timeout: 2000,
|
||||
});
|
||||
await edgelessNotificationClose.click();
|
||||
// Focus to the edgeless editor
|
||||
await page.mouse.click(400, 400);
|
||||
} catch {
|
||||
// do nothing if the notification close button is not found
|
||||
}
|
||||
await ChatPanelUtils.closeNotification(page);
|
||||
// Focus to the edgeless editor after closing notification
|
||||
await page.mouse.click(400, 400);
|
||||
}
|
||||
|
||||
public static async switchToPageMode(page: Page) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user