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
21 changes: 18 additions & 3 deletions src/pages/options/routes/ScriptEditor/tabs/SettingsPane.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,25 @@ describe("SettingsPane 更新URL", () => {
it("应展示更新URL并在失焦后调用 setCheckUpdateUrl", async () => {
render(<SettingsPane uuid="u1" />);
await screen.findByText("alpha");
const input = screen.getByDisplayValue("https://example.com/a.meta.js");
fireEvent.change(input, { target: { value: "https://new.example.com/a.meta.js" } });
const input = screen.getByDisplayValue("https://example.com/a.user.js");
fireEvent.change(input, { target: { value: "https://new.example.com/a.user.js" } });
fireEvent.blur(input);
expect(setCheckUpdateUrl).toHaveBeenCalledWith("u1", true, "https://new.example.com/a.meta.js");
expect(setCheckUpdateUrl).toHaveBeenCalledWith("u1", true, "https://new.example.com/a.user.js");
});

// setCheckUpdateUrl 会把同一个值写进 downloadUrl,回显 meta.js 会让失焦/切开关把下载地址改成 meta.js (#1793)
it("未修改直接失焦时应以下载地址提交,而不是 meta.js", async () => {
render(<SettingsPane uuid="u1" />);
await screen.findByText("alpha");
fireEvent.blur(screen.getByDisplayValue("https://example.com/a.user.js"));
expect(setCheckUpdateUrl).toHaveBeenCalledWith("u1", true, "https://example.com/a.user.js");
});

it("切换检查更新开关时应以下载地址提交,而不是 meta.js", async () => {
render(<SettingsPane uuid="u1" />);
await screen.findByText("alpha");
fireEvent.click(screen.getByRole("switch", { name: t("check_update") }));
expect(setCheckUpdateUrl).toHaveBeenCalledWith("u1", false, "https://example.com/a.user.js");
});
});

Expand Down
5 changes: 3 additions & 2 deletions src/pages/options/routes/ScriptEditor/tabs/SettingsPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ function SettingsPaneContent({ uuid, data }: SettingsPaneProps & { data: Setting
return parseTags({ tag: self.tag ?? meta.tag });
});
const [tagInput, setTagInput] = useState("");
const [updateUrl, setUpdateUrl] = useState(data.script.checkUpdateUrl ?? data.script.downloadUrl ?? "");
// 回显 downloadUrl 而非 checkUpdateUrl:保存时 setCheckUpdateUrl 会把该值同时写入两者,回显 meta.js 会把下载地址写坏 (#1793)
const [updateUrl, setUpdateUrl] = useState(data.script.downloadUrl || "");
const [matches, setMatches] = useState<string[]>(() => {
const meta = data.script.metadata || {};
const self = data.script.selfMetadata || {};
Expand Down Expand Up @@ -597,7 +598,7 @@ function SettingsPaneContent({ uuid, data }: SettingsPaneProps & { data: Setting
value={updateUrl}
onChange={(e) => setUpdateUrl(e.target.value)}
onBlur={saveUpdateUrl}
placeholder="https://example.com/script.meta.js"
placeholder="https://example.com/script.user.js"
className="h-8 flex-1 font-mono text-xs"
/>
</Row>
Expand Down
Loading