refactor: fix related test

This commit is contained in:
Jin 2026-03-09 23:49:04 +00:00 committed by JYC333
parent 1340c9ec22
commit ad1d4897ee
3 changed files with 20 additions and 6 deletions

View File

@ -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 现象。
---
## 依赖关系图

View File

@ -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();
});
});

View File

@ -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();
}