knowledge-base-context-menu.spec.ts
3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { test, expect } from "@playwright/test";
/**
* 缺陷 1008905 - 知识库右键菜单第一项显示 "KnowledgeBase.open" 而非 "打开"
*
* 验收标准:
* 1. 右键文件夹,第一个菜单项显示「打开」,不显示翻译 key 字符串
* 2. 右键文件,第一个菜单项显示「编辑」
* 3. 菜单包含「重命名」「下载」「删除」
*/
test.describe("知识库右键菜单文字修复 (#1008905)", () => {
test.beforeEach(async ({ page }) => {
await page.goto("/#/app/knowledge-base");
await page.waitForLoadState("domcontentloaded");
});
test("右键菜单第一项不应显示翻译 key 字符串", async ({ page }) => {
// 等待文件列表加载
const fileList = page.locator(".el-table__body-wrapper, .file-list-table");
await fileList.waitFor({ timeout: 15000 }).catch(() => {});
// 查找任意一行(文件夹或文件均可)
const firstRow = page.locator(".el-table__row").first();
const rowCount = await page.locator(".el-table__row").count();
if (rowCount === 0) {
test.skip(true, "没有文件行,跳过右键菜单测试");
return;
}
// 右键触发上下文菜单
await firstRow.click({ button: "right" });
const contextMenu = page.locator(".context-menu");
await contextMenu.waitFor({ timeout: 5000 });
// 核心断言:第一项文本不能包含 "KnowledgeBase."(翻译 key 泄露)
const firstItem = contextMenu.locator(".context-menu-item").first();
const firstItemText = await firstItem.innerText();
expect(firstItemText).not.toContain("KnowledgeBase.");
expect(firstItemText.trim()).not.toBe("");
// 第一项应为「打开」或「编辑」(中文)
const validLabels = ["打开", "编辑", "Open", "Edit"];
const isValid = validLabels.some((label) => firstItemText.includes(label));
expect(isValid, `菜单第一项应为「打开」或「编辑」,实际为:「${firstItemText.trim()}」`).toBe(true);
});
test("右键文件夹菜单包含完整4个选项", async ({ page }) => {
const rowCount = await page.locator(".el-table__row").count();
if (rowCount === 0) {
test.skip(true, "没有文件行,跳过");
return;
}
// 找文件夹行右键
const folderRow = page.locator(".el-table__row").filter({
has: page.locator("td").filter({ hasText: "folder" }),
}).first();
const folderCount = await folderRow.count();
if (folderCount === 0) {
test.skip(true, "没有文件夹行,跳过");
return;
}
await folderRow.click({ button: "right" });
const contextMenu = page.locator(".context-menu");
await contextMenu.waitFor({ timeout: 5000 });
const items = contextMenu.locator(".context-menu-item");
const count = await items.count();
expect(count).toBe(4);
const texts = await items.allInnerTexts();
const allText = texts.join(" ");
expect(allText).toContain("打开");
expect(allText).toContain("重命名");
expect(allText).toContain("下载");
expect(allText).toContain("删除");
});
});