feat(*): 系统渠道与画布 - 支持多规格批量调价及 Agent 入口拖动
This commit is contained in:
1 parent
9afe061d79
commit
8d94bde1f4
26 files changed
+1761
-44
No files matched your search
@@ -45,24 +45,26 @@ const item: ChannelModel = {
|
||||
};
|
||||
const render = (tiers: ChannelModelPriceTier[], capability: ChannelModel["capability"] = "image") => renderToStaticMarkup(<ChannelModelCostSummary item={{ ...item, capability, priceTiers: tiers }} />);
|
||||
|
||||
test("fixed and per-second costs use costPricing, not the sale price", () => {
|
||||
test("fixed and per-second specifications show cost, sale and margin", () => {
|
||||
const fixed = render([tier]);
|
||||
expect(fixed).toContain("默认规格");
|
||||
expect(fixed).toContain("1.25 积分 / 次");
|
||||
expect(fixed).not.toContain("99 积分");
|
||||
expect(render([{ ...tier, billingMode: "per_second" }])).toContain("1.25 积分 / 秒");
|
||||
expect(fixed).toContain("1.25 / 99");
|
||||
expect(fixed).toContain("积分 / 次 · 利润率 98.74%");
|
||||
expect(render([{ ...tier, billingMode: "per_second" }])).toContain("积分 / 秒");
|
||||
});
|
||||
|
||||
test("text token costs include input, output and cached tokens", () => {
|
||||
const html = render([{ ...tier, billingMode: "token" }], "text");
|
||||
expect(html).toContain("输入 2 · 输出 3 · 缓存 0.5");
|
||||
expect(html).toContain("输入 2 / 88");
|
||||
expect(html).toContain("输出 3 / 77");
|
||||
expect(html).toContain("缓存 0.5 / 66");
|
||||
expect(html).toContain("积分 / 百万 Token");
|
||||
expect(html).not.toContain("77");
|
||||
});
|
||||
|
||||
test("video token costs use only output video tokens", () => {
|
||||
const html = render([{ ...tier, billingMode: "token" }], "video");
|
||||
expect(html).toContain("3 积分 / 百万视频 Token");
|
||||
expect(html).toContain("视频 3 / 77");
|
||||
expect(html).toContain("积分 / 百万视频 Token");
|
||||
expect(html).not.toContain("输入");
|
||||
});
|
||||
|
||||
@@ -70,21 +72,23 @@ test("missing and unconfigured costs never fall back to sale prices or zero", ()
|
||||
for (const costPricing of [undefined, { ...tier.costPricing!, configured: false }]) {
|
||||
const html = render([{ ...tier, costPricing }]);
|
||||
expect(html).toContain("未配置成本");
|
||||
expect(html).not.toContain("积分 /");
|
||||
expect(html).toContain("未配置成本 / 99");
|
||||
expect(html).toContain("利润率 —");
|
||||
}
|
||||
});
|
||||
|
||||
test("explicit free costs remain zero even if sale pricing is unconfigured", () => {
|
||||
const html = renderToStaticMarkup(<ChannelModelCostSummary item={{ ...item, priceConfigured: false, priceTiers: [{ ...tier, priceConfigured: false, costPricing: { ...tier.costPricing!, unitPriceMicrocredits: 0 } }] }} />);
|
||||
expect(html).toContain("0 积分 / 次");
|
||||
expect(html).toContain("0 / 未配置售价");
|
||||
expect(html).toContain("利润率 —");
|
||||
expect(html).not.toContain("未配置成本");
|
||||
});
|
||||
|
||||
test("invalid or missing numeric costs are not silently displayed as free", () => {
|
||||
for (const unitPriceMicrocredits of [NaN, Infinity, -1, undefined]) {
|
||||
const html = render([{ ...tier, costPricing: { ...tier.costPricing!, unitPriceMicrocredits: unitPriceMicrocredits as number } }]);
|
||||
expect(html).toContain("— 积分 / 次");
|
||||
expect(html).not.toContain("0 积分");
|
||||
expect(html).toContain("— / 99");
|
||||
expect(html).toContain("利润率 —");
|
||||
}
|
||||
});
|
||||
|
||||
@@ -93,17 +97,23 @@ test("specification labels prefer canonical selectors and additional tiers remai
|
||||
expect(html).toContain("图生视频 / 1080P / 10 秒");
|
||||
expect(html).not.toContain("720P");
|
||||
expect(html).toContain("<details");
|
||||
expect(html).toContain("其余 1 个规格成本");
|
||||
expect(html).toContain("其余 1 个规格价格");
|
||||
});
|
||||
|
||||
test("disabled tiers are excluded and empty costs are explicit", () => {
|
||||
expect(render([{ ...tier, enabled: false }])).toContain("未配置成本");
|
||||
expect(render([])).toContain("未配置成本");
|
||||
expect(render([{ ...tier, enabled: false }])).toContain("无已启用规格");
|
||||
expect(render([])).toContain("无已启用规格");
|
||||
});
|
||||
|
||||
test("model list uses the cost component without gating it on user prices", async () => {
|
||||
const source = await Bun.file(new URL("../src/pages/admin/components/channel-model-manager.tsx", import.meta.url)).text();
|
||||
expect(source).toContain('title: "规格成本价"');
|
||||
expect(source).toContain('title: "规格成本价 / 销售价 / 利润率"');
|
||||
expect(source).toContain("<ChannelModelCostSummary item={item} />");
|
||||
expect(source).not.toContain("billingSummary(item)");
|
||||
});
|
||||
|
||||
test("zero revenue is undefined, free costs have 100% margin and losses stay negative", () => {
|
||||
expect(render([{ ...tier, unitPriceMicrocredits: 0 }])).toContain("利润率 —");
|
||||
expect(render([{ ...tier, unitPriceMicrocredits: 1_000_000 }])).toContain("利润率 -25%");
|
||||
expect(render([{ ...tier, costPricing: { ...tier.costPricing!, unitPriceMicrocredits: 0 } }])).toContain("利润率 100%");
|
||||
});
|
||||
Reference in new issue
Block a user