|
@@ -1,12 +1,14 @@
|
|
|
import { describe, expect, it } from "vitest";
|
|
import { describe, expect, it } from "vitest";
|
|
|
-import { SHARE_TERMS_INCOMPLETE, settlePartsFromSnapshot, settleText, settleTextFromSnapshot } from "../settle-text";
|
|
|
|
|
|
|
+import { SHARE_TERMS_INCOMPLETE, settleText, settleTextFromSnapshot, shareRuleParts, shareRuleText } from "../settle-text";
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 分成取值文案(册 4 settle_text):两行分列的「方式」「取值」两段必须与单行文案同源——
|
|
|
|
|
- * 以空格相接逐字等于 settleText/settleTextFromSnapshot,⛔ 另起一套措辞。
|
|
|
|
|
|
|
+ * 分成取值有两套口径,本文件把两套都钉死:
|
|
|
|
|
+ * - settleText/settleTextFromSnapshot:账单明细、账单详情、只读视图的锁定文案(册 4 settle_text,带千分位);
|
|
|
|
|
+ * - shareRuleParts/shareRuleText:「分成规则」类展示的统一口径(档案台账「分成规则」列=分成管理列表,
|
|
|
|
|
+ * 金额补两位小数、不加千分位;2026-11-24 定案)。
|
|
|
*/
|
|
*/
|
|
|
-describe("settleText · 三模式三文案", () => {
|
|
|
|
|
- it("逐字输出;不成对 ⇒ 配置不完整", () => {
|
|
|
|
|
|
|
+describe("settleText · 账单类锁定文案", () => {
|
|
|
|
|
+ it("三模式三文案逐字输出;不成对 ⇒ 配置不完整", () => {
|
|
|
expect(settleText("ratio", 20)).toBe("按比例 20%");
|
|
expect(settleText("ratio", 20)).toBe("按比例 20%");
|
|
|
expect(settleText("amount", 120)).toBe("每月分成 ¥ 120.00");
|
|
expect(settleText("amount", 120)).toBe("每月分成 ¥ 120.00");
|
|
|
expect(settleText("per_account", 3)).toBe("按每账号 ¥ 3.00/账号");
|
|
expect(settleText("per_account", 3)).toBe("按每账号 ¥ 3.00/账号");
|
|
@@ -14,27 +16,41 @@ describe("settleText · 三模式三文案", () => {
|
|
|
expect(settleText("ratio", null)).toBe(SHARE_TERMS_INCOMPLETE);
|
|
expect(settleText("ratio", null)).toBe(SHARE_TERMS_INCOMPLETE);
|
|
|
expect(settleText("monthly", 1)).toBe(SHARE_TERMS_INCOMPLETE);
|
|
expect(settleText("monthly", 1)).toBe(SHARE_TERMS_INCOMPLETE);
|
|
|
});
|
|
});
|
|
|
|
|
+
|
|
|
|
|
+ it("存储刻度换算:比例分数→百分数;金额带千分位(本口径不改)", () => {
|
|
|
|
|
+ expect(settleTextFromSnapshot("ratio", 0.1)).toBe("按比例 10%");
|
|
|
|
|
+ expect(settleTextFromSnapshot("amount", "1200")).toBe("每月分成 ¥ 1,200.00");
|
|
|
|
|
+ expect(settleTextFromSnapshot("per_account", 3.5)).toBe("按每账号 ¥ 3.50/账号");
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
-describe("settlePartsFromSnapshot · 方式/取值两段", () => {
|
|
|
|
|
- it("两段以空格相接=settleTextFromSnapshot 的文案(三模式)", () => {
|
|
|
|
|
- const cases: [string, string | number][] = [["ratio", 0.2], ["amount", "120"], ["per_account", 3.5]];
|
|
|
|
|
- for (const [mode, value] of cases) {
|
|
|
|
|
- const parts = settlePartsFromSnapshot(mode, value);
|
|
|
|
|
- expect(parts).not.toBeNull();
|
|
|
|
|
- expect(`${parts!.mode} ${parts!.value}`).toBe(settleTextFromSnapshot(mode, value));
|
|
|
|
|
- }
|
|
|
|
|
|
|
+describe("shareRuleParts · 分成规则类统一口径", () => {
|
|
|
|
|
+ it("三模式:取值一行+方式一行(按金额照运营商台账,另两档照分成管理)", () => {
|
|
|
|
|
+ expect(shareRuleParts("ratio", 0.1)).toEqual({ value: "10%", mode: "按比例" });
|
|
|
|
|
+ expect(shareRuleParts("ratio", 0.125)).toEqual({ value: "12.5%", mode: "按比例" });
|
|
|
|
|
+ expect(shareRuleParts("amount", 120)).toEqual({ value: "¥120.00 / 月", mode: "按金额" });
|
|
|
|
|
+ expect(shareRuleParts("per_account", 3.5)).toEqual({ value: "¥ 3.50/账号", mode: "按每账号" });
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- it("存储刻度 → 展示刻度:比例分数→百分数、金额/每账号两位小数", () => {
|
|
|
|
|
- expect(settlePartsFromSnapshot("ratio", 0.1)).toEqual({ mode: "按比例", value: "10%" });
|
|
|
|
|
- expect(settlePartsFromSnapshot("amount", "120")).toEqual({ mode: "每月分成", value: "¥ 120.00" });
|
|
|
|
|
- expect(settlePartsFromSnapshot("per_account", 3.5)).toEqual({ mode: "按每账号", value: "¥ 3.50/账号" });
|
|
|
|
|
|
|
+ it("金额补两位小数、不加千分位", () => {
|
|
|
|
|
+ expect(shareRuleParts("amount", 1200)?.value).toBe("¥1200.00 / 月");
|
|
|
|
|
+ expect(shareRuleParts("per_account", "1200")?.value).toBe("¥ 1200.00/账号");
|
|
|
|
|
+ expect(shareRuleParts("amount", 3.456)?.value).toBe("¥3.46 / 月");
|
|
|
|
|
+ expect(shareRuleParts("amount", 3)?.value).toBe("¥3.00 / 月");
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it("不成对 ⇒ null(⛔ 只出其中一段)", () => {
|
|
it("不成对 ⇒ null(⛔ 只出其中一段)", () => {
|
|
|
- expect(settlePartsFromSnapshot("ratio", null)).toBeNull();
|
|
|
|
|
- expect(settlePartsFromSnapshot(null, 12)).toBeNull();
|
|
|
|
|
- expect(settlePartsFromSnapshot("monthly", 12)).toBeNull();
|
|
|
|
|
|
|
+ expect(shareRuleParts("ratio", null)).toBeNull();
|
|
|
|
|
+ expect(shareRuleParts(null, 12)).toBeNull();
|
|
|
|
|
+ expect(shareRuleParts("monthly", 12)).toBeNull();
|
|
|
|
|
+ });
|
|
|
|
|
+});
|
|
|
|
|
+
|
|
|
|
|
+describe("shareRuleText · 整句写法", () => {
|
|
|
|
|
+ it("方式+空格+取值,与 shareRuleParts 同源", () => {
|
|
|
|
|
+ expect(shareRuleText("ratio", 0.1)).toBe("按比例 10%");
|
|
|
|
|
+ expect(shareRuleText("amount", 120)).toBe("按金额 ¥120.00 / 月");
|
|
|
|
|
+ expect(shareRuleText("per_account", 3.5)).toBe("按每账号 ¥ 3.50/账号");
|
|
|
|
|
+ expect(shareRuleText("ratio", null)).toBe(SHARE_TERMS_INCOMPLETE);
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|