Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions src/pages/options/routes/ScriptEditor/EditorTabs.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,6 @@ function renderTabs() {
}

describe("EditorTabs「+」新建菜单", () => {
it("hover「+」展开脚本类型选择菜单", async () => {
renderTabs();
const plusBtn = screen.getByLabelText("新建脚本");

await act(async () => {
fireEvent.mouseEnter(plusBtn);
});

expect(screen.getByText("新建普通脚本")).toBeInTheDocument();
expect(screen.getByText("新建后台脚本")).toBeInTheDocument();
expect(screen.getByText("新建定时脚本")).toBeInTheDocument();
});

it("点击「新建后台脚本」以 background 模板回调 onNew", async () => {
renderTabs();
const plusBtn = screen.getByLabelText("新建脚本");
Expand Down
14 changes: 0 additions & 14 deletions src/pages/options/routes/ScriptEditor/EditorToolbar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,6 @@ const openSub = async (el: HTMLElement) => {
};

describe("EditorToolbar 桌面端编辑器工具栏", () => {
it("应保留原汉堡图标按钮作为菜单入口", () => {
const { getByLabelText } = render(<EditorToolbar {...baseProps()} />);
expect(getByLabelText("更多")).toBeInTheDocument();
});

it("展开后应是「文件」「编辑」「运行」二级子菜单而非全部平铺", async () => {
const { getByLabelText, getByText } = render(<EditorToolbar {...baseProps()} />);
await openRoot(getByLabelText("更多"));
// 顶层只暴露分组(子菜单触发器),具体操作收纳在二级子菜单里,默认不可见
expect(getByText("文件")).toBeInTheDocument();
expect(getByText("编辑")).toBeInTheDocument();
expect(getByText("运行")).toBeInTheDocument();
});

it("文件 → 保存 应回调 onSave", async () => {
const props = baseProps();
const { getByLabelText, getByText } = render(<EditorToolbar {...props} />);
Expand Down
9 changes: 0 additions & 9 deletions src/pages/options/routes/ScriptEditor/MobileEditor.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,6 @@ const baseProps = () => ({
});

describe("MobileEditor 移动端编辑器外壳", () => {
it("应显示脚本标题", () => {
const { getByText } = render(
<MobileEditor {...baseProps()}>
<div>{"editor"}</div>
</MobileEditor>
);
expect(getByText("Bilibili Evolved")).toBeTruthy();
});

it("点击返回按钮应回调 onBack", () => {
const props = baseProps();
const { getByLabelText } = render(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ describe("SettingsPane 运行设置", () => {
const trigger = screen.getAllByRole("combobox")[comboIndex];
fireEvent.keyDown(trigger, { key: "Enter" });
await act(() => Promise.resolve());
fireEvent.click(screen.getAllByRole("option").find((o) => o.textContent === optionText)!);
fireEvent.click(screen.getByRole("option", { name: optionText }));
await act(() => Promise.resolve());
};

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

it("运行时机应提供 context-menu 并保存为用户覆盖", async () => {
render(<SettingsPane uuid="u1" />);
await screen.findByText("alpha");
await pickOption(1, "context-menu");
expect(updateMetadata).toHaveBeenCalledWith("u1", "run-at", ["context-menu"]);
});

it("运行环境选「默认」应以 undefined 撤销覆盖而非写入空数组", async () => {
fetchScript.mockResolvedValue({
...sampleScript(),
Expand Down
12 changes: 10 additions & 2 deletions src/pages/options/routes/ScriptEditor/tabs/SettingsPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,19 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@
import { createPreloadableQuery } from "@App/pages/preloadable-query";

const RUN_IN_OPTIONS = ["default", "all", "normal-tabs", "incognito-tabs"];
const RUN_AT_OPTIONS = ["default", "document-start", "document-body", "document-end", "document-idle", "early-start"];
const RUN_AT_OPTIONS = [
"default",
"document-start",
"document-body",
"document-end",
"document-idle",
"context-menu",
"early-start",
];
const PERMISSION_TYPES = ["cors", "cookie"];
const PERMISSION_LABEL: Record<string, string> = { cors: "CORS", cookie: "Cookie" };

// 运行环境/运行时机下拉项的本地化文案;运行时机的 document-* / early-start 保持原始字面值(与 v1.4 一致)
// 运行环境/运行时机下拉项的本地化文案;运行时机保持原始字面值(与 v1.4 一致)
const runInLabel = (o: string, t: TFunction) =>
o === "default" ? t("settings:script_setting.default") : t(`settings:script_run_env.${o}`);
const runAtLabel = (o: string, t: TFunction) => (o === "default" ? t("settings:script_setting.default") : o);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,4 @@ describe("StoragePane 储存面板", () => {
);
expect(await screen.findByText("newKey")).toBeInTheDocument();
});

it("无数据时应展示空状态", async () => {
getScriptValue.mockResolvedValue({});
render(<StoragePane uuid="u1" />);
expect(await screen.findByText(t("no_data"))).toBeInTheDocument();
});
});
Loading