refactor(presets): render presets in array order and prioritize partners

Remove the category-based grouping logic from ProviderPresetSelector,
letting the array position in each preset config file be the single
source of truth for display order. Move partner presets (PatewayAI,
火山Agentplan, BytePlus, DouBaoSeed) right after Shengsuanyun across
all 6 config files so they appear earlier in the UI.
This commit is contained in:
Jason
2026-05-15 23:28:59 +08:00
parent 9050442b65
commit ec8afd63ea
11 changed files with 653 additions and 547 deletions
@@ -0,0 +1,71 @@
import { render, screen } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { useForm } from "react-hook-form";
import { Form } from "@/components/ui/form";
import { ProviderPresetSelector } from "@/components/providers/forms/ProviderPresetSelector";
describe("ProviderPresetSelector", () => {
it("按传入的预设数组顺序渲染,不按分类重新排序", () => {
const Wrapper = () => {
const form = useForm();
return (
<Form {...form}>
<ProviderPresetSelector
selectedPresetId="custom"
presetEntries={[
{
id: "preset-0",
preset: {
name: "First",
websiteUrl: "https://first.example.com",
settingsConfig: {},
category: "third_party",
},
},
{
id: "preset-1",
preset: {
name: "Second",
websiteUrl: "https://second.example.com",
settingsConfig: {},
category: "official",
},
},
{
id: "preset-2",
preset: {
name: "Third",
websiteUrl: "https://third.example.com",
settingsConfig: {},
category: "aggregator",
},
},
{
id: "preset-3",
preset: {
name: "Fourth",
websiteUrl: "https://fourth.example.com",
settingsConfig: {},
category: "official",
},
},
]}
presetCategoryLabels={{
official: "官方",
aggregator: "聚合服务",
third_party: "第三方",
}}
onPresetChange={vi.fn()}
/>
</Form>
);
};
render(<Wrapper />);
expect(
screen.getAllByRole("button").map((button) => button.textContent),
).toEqual(["providerPreset.custom", "First", "Second", "Third", "Fourth"]);
});
});
+70
View File
@@ -0,0 +1,70 @@
import { describe, expect, it } from "vitest";
import { providerPresets } from "@/config/claudeProviderPresets";
import { claudeDesktopProviderPresets } from "@/config/claudeDesktopProviderPresets";
import { codexProviderPresets } from "@/config/codexProviderPresets";
import { opencodeProviderPresets } from "@/config/opencodeProviderPresets";
import { openclawProviderPresets } from "@/config/openclawProviderPresets";
import { hermesProviderPresets } from "@/config/hermesProviderPresets";
const namesOf = (presets: Array<{ name: string }>) =>
presets.map((preset) => preset.name);
const expectInOrder = (names: string[], expected: string[]) => {
const indexes = expected.map((name) => names.indexOf(name));
expect(indexes).not.toContain(-1);
expect(indexes).toEqual(expected.map((_, index) => indexes[0] + index));
};
describe("provider preset order", () => {
it("Claude 预设按合作伙伴优先顺序排列", () => {
expectInOrder(namesOf(providerPresets), [
"Shengsuanyun",
"PatewayAI",
"火山Agentplan",
"BytePlus",
"DouBaoSeed",
]);
});
it("Claude Desktop 预设按合作伙伴优先顺序排列", () => {
expectInOrder(namesOf(claudeDesktopProviderPresets), [
"Shengsuanyun",
"PatewayAI",
"火山Agentplan",
"BytePlus",
"DouBaoSeed",
]);
});
it("Codex 预设把 PatewayAI 放在胜算云后面", () => {
expectInOrder(namesOf(codexProviderPresets), ["Shengsuanyun", "PatewayAI"]);
});
it("OpenCode 预设把火山、BytePlus、DouBaoSeed 放在胜算云后面", () => {
expectInOrder(namesOf(opencodeProviderPresets), [
"Shengsuanyun",
"火山Agentplan",
"BytePlus",
"DouBaoSeed",
]);
});
it("OpenClaw 预设把火山、BytePlus、DouBaoSeed 放在胜算云后面", () => {
expectInOrder(namesOf(openclawProviderPresets), [
"Shengsuanyun",
"火山Agentplan",
"BytePlus",
"DouBaoSeed",
]);
});
it("Hermes 预设把火山、BytePlus、DouBaoSeed 放在胜算云后面", () => {
expectInOrder(namesOf(hermesProviderPresets), [
"Shengsuanyun",
"火山Agentplan",
"BytePlus",
"DouBaoSeed",
]);
});
});