Skip to content

Commit 65121fa

Browse files
authored
🐛 修复脚本设置缺少 context-menu 运行时机 (#1652)
* 🐛 补充 context-menu 运行时机选项 * ✅ 精简 ScriptEditor 单元测试
1 parent 76ead75 commit 65121fa

6 files changed

Lines changed: 18 additions & 45 deletions

File tree

src/pages/options/routes/ScriptEditor/EditorTabs.test.tsx

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,6 @@ function renderTabs() {
3737
}
3838

3939
describe("EditorTabs「+」新建菜单", () => {
40-
it("hover「+」展开脚本类型选择菜单", async () => {
41-
renderTabs();
42-
const plusBtn = screen.getByLabelText("新建脚本");
43-
44-
await act(async () => {
45-
fireEvent.mouseEnter(plusBtn);
46-
});
47-
48-
expect(screen.getByText("新建普通脚本")).toBeInTheDocument();
49-
expect(screen.getByText("新建后台脚本")).toBeInTheDocument();
50-
expect(screen.getByText("新建定时脚本")).toBeInTheDocument();
51-
});
52-
5340
it("点击「新建后台脚本」以 background 模板回调 onNew", async () => {
5441
renderTabs();
5542
const plusBtn = screen.getByLabelText("新建脚本");

src/pages/options/routes/ScriptEditor/EditorToolbar.test.tsx

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,6 @@ const openSub = async (el: HTMLElement) => {
3737
};
3838

3939
describe("EditorToolbar 桌面端编辑器工具栏", () => {
40-
it("应保留原汉堡图标按钮作为菜单入口", () => {
41-
const { getByLabelText } = render(<EditorToolbar {...baseProps()} />);
42-
expect(getByLabelText("更多")).toBeInTheDocument();
43-
});
44-
45-
it("展开后应是「文件」「编辑」「运行」二级子菜单而非全部平铺", async () => {
46-
const { getByLabelText, getByText } = render(<EditorToolbar {...baseProps()} />);
47-
await openRoot(getByLabelText("更多"));
48-
// 顶层只暴露分组(子菜单触发器),具体操作收纳在二级子菜单里,默认不可见
49-
expect(getByText("文件")).toBeInTheDocument();
50-
expect(getByText("编辑")).toBeInTheDocument();
51-
expect(getByText("运行")).toBeInTheDocument();
52-
});
53-
5440
it("文件 → 保存 应回调 onSave", async () => {
5541
const props = baseProps();
5642
const { getByLabelText, getByText } = render(<EditorToolbar {...props} />);

src/pages/options/routes/ScriptEditor/MobileEditor.test.tsx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,6 @@ const baseProps = () => ({
4040
});
4141

4242
describe("MobileEditor 移动端编辑器外壳", () => {
43-
it("应显示脚本标题", () => {
44-
const { getByText } = render(
45-
<MobileEditor {...baseProps()}>
46-
<div>{"editor"}</div>
47-
</MobileEditor>
48-
);
49-
expect(getByText("Bilibili Evolved")).toBeTruthy();
50-
});
51-
5243
it("点击返回按钮应回调 onBack", () => {
5344
const props = baseProps();
5445
const { getByLabelText } = render(

src/pages/options/routes/ScriptEditor/tabs/SettingsPane.test.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ describe("SettingsPane 运行设置", () => {
165165
const trigger = screen.getAllByRole("combobox")[comboIndex];
166166
fireEvent.keyDown(trigger, { key: "Enter" });
167167
await act(() => Promise.resolve());
168-
fireEvent.click(screen.getAllByRole("option").find((o) => o.textContent === optionText)!);
168+
fireEvent.click(screen.getByRole("option", { name: optionText }));
169169
await act(() => Promise.resolve());
170170
};
171171

@@ -180,6 +180,13 @@ describe("SettingsPane 运行设置", () => {
180180
expect(screen.getAllByRole("combobox")[1]).not.toHaveTextContent("early-start");
181181
});
182182

183+
it("运行时机应提供 context-menu 并保存为用户覆盖", async () => {
184+
render(<SettingsPane uuid="u1" />);
185+
await screen.findByText("alpha");
186+
await pickOption(1, "context-menu");
187+
expect(updateMetadata).toHaveBeenCalledWith("u1", "run-at", ["context-menu"]);
188+
});
189+
183190
it("运行环境选「默认」应以 undefined 撤销覆盖而非写入空数组", async () => {
184191
fetchScript.mockResolvedValue({
185192
...sampleScript(),

src/pages/options/routes/ScriptEditor/tabs/SettingsPane.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,19 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@
2828
import { createPreloadableQuery } from "@App/pages/preloadable-query";
2929

3030
const RUN_IN_OPTIONS = ["default", "all", "normal-tabs", "incognito-tabs"];
31-
const RUN_AT_OPTIONS = ["default", "document-start", "document-body", "document-end", "document-idle", "early-start"];
31+
const RUN_AT_OPTIONS = [
32+
"default",
33+
"document-start",
34+
"document-body",
35+
"document-end",
36+
"document-idle",
37+
"context-menu",
38+
"early-start",
39+
];
3240
const PERMISSION_TYPES = ["cors", "cookie"];
3341
const PERMISSION_LABEL: Record<string, string> = { cors: "CORS", cookie: "Cookie" };
3442

35-
// 运行环境/运行时机下拉项的本地化文案;运行时机的 document-* / early-start 保持原始字面值(与 v1.4 一致)
43+
// 运行环境/运行时机下拉项的本地化文案;运行时机保持原始字面值(与 v1.4 一致)
3644
const runInLabel = (o: string, t: TFunction) =>
3745
o === "default" ? t("settings:script_setting.default") : t(`settings:script_run_env.${o}`);
3846
const runAtLabel = (o: string, t: TFunction) => (o === "default" ? t("settings:script_setting.default") : o);

src/pages/options/routes/ScriptEditor/tabs/StoragePane.test.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,4 @@ describe("StoragePane 储存面板", () => {
198198
);
199199
expect(await screen.findByText("newKey")).toBeInTheDocument();
200200
});
201-
202-
it("无数据时应展示空状态", async () => {
203-
getScriptValue.mockResolvedValue({});
204-
render(<StoragePane uuid="u1" />);
205-
expect(await screen.findByText(t("no_data"))).toBeInTheDocument();
206-
});
207201
});

0 commit comments

Comments
 (0)