mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-02 09:59:55 +08:00
fix(editor): ci stability (#14704)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Improved Electron shutdown, diagnostics and tab teardown for more reliable exits and forced cleanup on stubborn processes. * **Tests** * Added polling-based test helpers, stronger scroll/page readiness, timeout-tolerant page selection, and async cleanup/worker teardown; updated many tests to wait for UI/model updates and rendering frames. * **Bug Fixes** * Reduced flakiness by awaiting paragraph visibility, nested counts, selection/navigation stability, tab counts, post-action renders, and safer element interactions. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -376,13 +376,28 @@ export async function setEdgelessTool(
|
||||
'shape',
|
||||
false
|
||||
);
|
||||
// Avoid clicking on the shape-element (will trigger dragging mode)
|
||||
await shapeToolButton.click({ position: { x: 5, y: 5 } });
|
||||
const shapeToolBox = await shapeToolButton.boundingBox();
|
||||
if (!shapeToolBox) {
|
||||
throw new Error('shapeToolBox is not found');
|
||||
}
|
||||
|
||||
const squareShapeButton = page
|
||||
.locator('edgeless-slide-menu edgeless-tool-icon-button')
|
||||
await page.mouse.click(shapeToolBox.x + 2, shapeToolBox.y + 2);
|
||||
|
||||
const shapeMenu = page.locator('edgeless-shape-menu');
|
||||
await expect(shapeMenu).toBeVisible();
|
||||
|
||||
const squareShapeButton = shapeMenu
|
||||
.locator('edgeless-tool-icon-button')
|
||||
.filter({ hasText: shape });
|
||||
await squareShapeButton.click();
|
||||
await expect(squareShapeButton).toBeVisible();
|
||||
const squareShapeBox = await squareShapeButton.boundingBox();
|
||||
if (!squareShapeBox) {
|
||||
throw new Error('squareShapeBox is not found');
|
||||
}
|
||||
await page.mouse.click(
|
||||
squareShapeBox.x + squareShapeBox.width / 2,
|
||||
squareShapeBox.y + squareShapeBox.height / 2
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -549,6 +549,7 @@ export async function focusRichText(
|
||||
await page.mouse.move(0, 0);
|
||||
const editor = getEditorHostLocator(page);
|
||||
const locator = editor.locator(RICH_TEXT_SELECTOR).nth(i);
|
||||
await expect(locator).toBeVisible();
|
||||
// need to set `force` to true when clicking on `affine-selected-blocks`
|
||||
await locator.click({ force: true, position: options?.clickPosition });
|
||||
}
|
||||
@@ -1229,43 +1230,37 @@ export async function getCurrentThemeCSSPropertyValue(
|
||||
}
|
||||
|
||||
export async function scrollToTop(page: Page) {
|
||||
await page.mouse.wheel(0, -1000);
|
||||
|
||||
await page.waitForFunction(() => {
|
||||
const scrollContainer = document.querySelector('.affine-page-viewport');
|
||||
if (!scrollContainer) {
|
||||
throw new Error("Can't find scroll container");
|
||||
}
|
||||
return scrollContainer.scrollTop < 10;
|
||||
const scrollContainer = page.locator('.affine-page-viewport');
|
||||
await expect(scrollContainer).toBeVisible();
|
||||
await scrollContainer.evaluate(node => {
|
||||
(node as HTMLElement).scrollTop = 0;
|
||||
});
|
||||
await expect
|
||||
.poll(async () => {
|
||||
return await scrollContainer.evaluate(node => {
|
||||
return (node as HTMLElement).scrollTop;
|
||||
});
|
||||
})
|
||||
.toBeLessThan(10);
|
||||
}
|
||||
|
||||
export async function scrollToBottom(page: Page) {
|
||||
// await page.mouse.wheel(0, 1000);
|
||||
|
||||
await page
|
||||
.locator('.affine-page-viewport')
|
||||
.evaluate(node =>
|
||||
node.scrollTo({ left: 0, top: 1000, behavior: 'smooth' })
|
||||
);
|
||||
// TODO switch to `scrollend`
|
||||
// See https://developer.chrome.com/en/blog/scrollend-a-new-javascript-event/
|
||||
await page.waitForFunction(() => {
|
||||
const scrollContainer = document.querySelector('.affine-page-viewport');
|
||||
if (!scrollContainer) {
|
||||
throw new Error("Can't find scroll container");
|
||||
}
|
||||
|
||||
return (
|
||||
// Wait for scrolled to the bottom
|
||||
// Refer to https://stackoverflow.com/questions/3898130/check-if-a-user-has-scrolled-to-the-bottom-not-just-the-window-but-any-element
|
||||
Math.abs(
|
||||
scrollContainer.scrollHeight -
|
||||
scrollContainer.scrollTop -
|
||||
scrollContainer.clientHeight
|
||||
) < 10
|
||||
);
|
||||
const scrollContainer = page.locator('.affine-page-viewport');
|
||||
await expect(scrollContainer).toBeVisible();
|
||||
await scrollContainer.evaluate(node => {
|
||||
const viewport = node as HTMLElement;
|
||||
viewport.scrollTop = viewport.scrollHeight;
|
||||
});
|
||||
await expect
|
||||
.poll(async () => {
|
||||
return await scrollContainer.evaluate(node => {
|
||||
const viewport = node as HTMLElement;
|
||||
return Math.abs(
|
||||
viewport.scrollHeight - viewport.scrollTop - viewport.clientHeight
|
||||
);
|
||||
});
|
||||
})
|
||||
.toBeLessThan(10);
|
||||
}
|
||||
|
||||
export async function mockParseDocUrlService(
|
||||
|
||||
Reference in New Issue
Block a user