fix: connector label editing (#12282)

Fixes [BS-3373](https://linear.app/affine-design/issue/BS-3373/connector%E7%9A%84%E5%8F%8C%E5%87%BB%E6%B7%BB%E5%8A%A0note%E8%A1%8C%E4%B8%BA%E5%8F%97%E5%88%B0%E4%BA%86%E8%A6%86%E7%9B%96%E8%8C%83%E5%9B%B4%E7%9A%84%E5%BD%B1%E5%93%8D)

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **New Features**
  - Connector label elements now include identity and creator metadata.

- **Bug Fixes**
  - Improved hit-testing for pointer interactions, resulting in more accurate detection of hovered elements.

- **Refactor**
  - Enhanced internal comparison logic for elements, improving sorting and ordering consistency.
  - Strengthened type definitions for search filters, improving result accuracy and clarity.

- **Tests**
  - Added end-to-end tests to verify correct label entry and retrieval for multiple connectors.
  - Introduced utility functions to fetch connector labels and improved connector creation in test actions.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
doouding
2025-05-15 10:31:55 +00:00
parent 6c9f28e08b
commit e98ec93af1
7 changed files with 136 additions and 15 deletions

View File

@@ -4,7 +4,11 @@ import { ConnectorTool } from '@blocksuite/affine/gfx/connector';
import { ShapeTool } from '@blocksuite/affine/gfx/shape';
import type { IPoint, IVec } from '@blocksuite/affine/global/gfx';
import { sleep } from '@blocksuite/affine/global/utils';
import type { NoteBlockModel, NoteDisplayMode } from '@blocksuite/affine/model';
import type {
ConnectorElementModel,
NoteBlockModel,
NoteDisplayMode,
} from '@blocksuite/affine/model';
import type { ToolOptions } from '@blocksuite/affine/std/gfx';
import type { Locator, Page } from '@playwright/test';
import { expect } from '@playwright/test';
@@ -418,6 +422,23 @@ export async function assertEdgelessTool(page: Page, mode: string) {
expect(type).toEqual(mode);
}
export async function getConnectorLabel(page: Page, id: string) {
const text = await page.evaluate(id => {
const container = document.querySelector('affine-edgeless-root');
if (!container) {
throw new Error('Missing edgeless page');
}
const connector = container.gfx.getElementById(id) as ConnectorElementModel;
if (!connector) {
throw new Error('Missing connector');
}
return connector.text?.toString() ?? '';
}, id);
return text;
}
export async function assertEdgelessConnectorToolMode(
page: Page,
mode: ConnectorMode
@@ -524,6 +545,7 @@ export async function addBasicConnectorElement(
) {
await setEdgelessTool(page, 'connector');
await dragBetweenCoords(page, start, end, { steps: 100 });
return (await getSelectedIds(page))[0];
}
export async function addBasicFrameElement(