From ad1d4897ee99cf379d2c577da200e7b103f39f22 Mon Sep 17 00:00:00 2001 From: Jin <22962980+JYC333@users.noreply.github.com> Date: Mon, 9 Mar 2026 23:49:04 +0000 Subject: [PATCH] refactor: fix related test --- .agents/migration_plan_autocomplete.md | 9 ++++++++- apps/server-e2e/src/layout/split_pane.spec.ts | 5 ++--- apps/server-e2e/src/support/app.ts | 12 ++++++++++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/.agents/migration_plan_autocomplete.md b/.agents/migration_plan_autocomplete.md index 0d258f7650..1d89f89e6e 100644 --- a/.agents/migration_plan_autocomplete.md +++ b/.agents/migration_plan_autocomplete.md @@ -270,7 +270,7 @@ --- -### Step 10: 更新 E2E 测试 +### Step 10: 更新 E2E 测试 ✅ 完成 **文件变更:** - `apps/server-e2e/src/support/app.ts` - `apps/server-e2e/src/layout/split_pane.spec.ts` @@ -278,6 +278,13 @@ **验证方式:** - E2E 测试全部通过 +**当前完成情况:** +- ✅ `apps/server-e2e/src/support/app.ts` 已新增基于当前 headless DOM 语义的 note autocomplete suggestion helper,不再依赖旧的“第二项就是目标笔记”顺序假设。 +- ✅ `apps/server-e2e/src/layout/split_pane.spec.ts` 已改为复用该 helper,避免被 `create-note` / `search-notes` 等 action 项扰动。 +- ✅ 定向验证 `pnpm run --filter @triliumnext/server-e2e e2e -- src/layout/split_pane.spec.ts` 已通过(2 passed)。 +- ✅ 全量验证 `pnpm run --filter @triliumnext/server-e2e e2e` 已通过退出码校验。 +- ⚠️ 全量 Playwright 结果为 `41 passed, 9 flaky`;`src/layout/split_pane.spec.ts:40` 在全量并发执行中首跑超时、retry 后通过,另有多条非 autocomplete 相关用例也存在同类 flaky 现象。 + --- ## 依赖关系图 diff --git a/apps/server-e2e/src/layout/split_pane.spec.ts b/apps/server-e2e/src/layout/split_pane.spec.ts index 82a97b54e4..7c2a3e003b 100644 --- a/apps/server-e2e/src/layout/split_pane.spec.ts +++ b/apps/server-e2e/src/layout/split_pane.spec.ts @@ -32,8 +32,7 @@ test("Open the note in the correct split pane", async ({ page, context }) => { await noteContent.focus(); // Click the search result in the second split. - await resultsSelector.locator(".aa-suggestion", { hasText: CODE_NOTE_TITLE }) - .nth(1).click(); + await app.getNoteAutocompleteSuggestion(resultsSelector, CODE_NOTE_TITLE).click(); await expect(split2).toContainText(CODE_NOTE_TITLE); }); @@ -69,4 +68,4 @@ test("Can directly focus the autocomplete input within the split", async ({ page await page.waitForTimeout(100); await expect(autocomplete).toBeFocused(); -}); \ No newline at end of file +}); diff --git a/apps/server-e2e/src/support/app.ts b/apps/server-e2e/src/support/app.ts index 3922019192..0cc1f6a35d 100644 --- a/apps/server-e2e/src/support/app.ts +++ b/apps/server-e2e/src/support/app.ts @@ -27,6 +27,7 @@ export default class App { readonly currentNoteSplitContent: Locator; readonly sidebar: Locator; private isMobile: boolean = false; + private readonly noteAutocompleteSuggestionSelector = ".aa-suggestion:not(.create-note-action):not(.search-notes-action):not(.command-action):not(.external-link-action)"; constructor(page: Page, context: BrowserContext) { this.page = page; @@ -76,12 +77,19 @@ export default class App { const resultsSelector = this.currentNoteSplit.locator(".note-detail-empty-results"); await expect(resultsSelector).toContainText(noteTitle); - const suggestionSelector = resultsSelector.locator(".aa-suggestion") - .nth(1); // Select the second one (best candidate), as the first one is "Create a new note" + const suggestionSelector = resultsSelector + .locator(this.noteAutocompleteSuggestionSelector, { hasText: noteTitle }) + .first(); await expect(suggestionSelector).toContainText(noteTitle); await suggestionSelector.click(); } + getNoteAutocompleteSuggestion(resultsContainer: Locator, noteTitle: string) { + return resultsContainer + .locator(this.noteAutocompleteSuggestionSelector, { hasText: noteTitle }) + .first(); + } + async goToSettings() { await this.page.locator(".launcher-button.bx-cog").click(); }