fix: make SCUM gift management gift-first

This commit is contained in:
npc0-hue
2026-09-20 12:13:06 +08:00
parent e03b33cf25
commit 4b7739a274
4 changed files with 70 additions and 24 deletions
+9 -4
View File
@@ -94,7 +94,7 @@ describe("SCUM plugin feature module", () => {
const list = vi.fn(async (collection: string) => ({ items: [{ key: `${collection}-1`, value: { collection } }], count: 1 }));
const scum = scumActions();
const data = await loadSCUMSurface({ pluginData: pluginDataActions({ list }), scum }, "gifts");
expect(list.mock.calls.map(([collection]) => collection)).toEqual([scumCollections.gifts, scumCollections.giftClaims, scumCollections.pendingGifts, scumCollections.giftDeliveries, scumCollections.timedGiftEvents, scumCollections.tradeGoods]);
expect(list.mock.calls.map(([collection]) => collection)).toEqual([scumCollections.gifts, scumCollections.giftClaims, scumCollections.pendingGifts, scumCollections.giftDeliveries, scumCollections.timedGiftEvents]);
expect(scum.surface).toHaveBeenCalledTimes(1);
expect(data.gifts[0]).toMatchObject({ collection: scumCollections.gifts, _recordKey: `${scumCollections.gifts}-1` });
});
@@ -271,11 +271,12 @@ describe("SCUM plugin feature module", () => {
it("renders gift definitions, claims, and delivery records", () => {
const definitions = renderAndCollect({ pageKey: "gifts", pageTitle: "礼包管理" });
expect(definitions.texts).toContain("礼包定义");
expect(definitions.texts).toContain("物品列表");
expect(definitions.texts).not.toContain("物品列表");
expect(definitions.texts).toContain("Starter Pack");
expect(definitions.texts).toContain("Cargo Drop");
expect(definitions.texts).not.toContain("Cargo Drop");
expect(definitions.texts).toEqual(expect.arrayContaining(["礼包", "领取规则", "礼包内容", "次数 / 门槛", "状态", "最近更新", "操作"]));
expect(definitions.buttons.find((button) => button.label === "新建礼包")?.disabled).toBe(false);
expect(definitions.buttons.map((button) => button.label)).toEqual(expect.arrayContaining(["查看配置", "编辑礼包"]));
expect(definitions.buttons.find((button) => button.label === "保存礼包")).toBeUndefined();
expect(definitions.texts).not.toContain("先定义规则,再配置内容");
expect(definitions.inputs.map((input) => input.label)).toEqual(expect.arrayContaining(["搜索礼包", "礼包状态"]));
@@ -287,6 +288,9 @@ describe("SCUM plugin feature module", () => {
expect(deliveries.texts).toContain("发放记录");
expect(deliveries.texts).toContain("delivered");
expect(deliveries.buttons.find((button) => button.label === "立即发放")?.disabled).toBe(false);
const details = renderAndCollect({ pageKey: "gifts", pageTitle: "礼包管理", giftDialog: { mode: "view", gift: surfaceData.gifts[0] } });
expect(details.texts).toEqual(expect.arrayContaining(["礼包配置详情", "礼包编号", "starter-pack", "领取周期", "一次", "礼包内容", "BP_Cash_01", "#announce Starter pack"]));
expect(details.buttons.map((button) => button.label)).toEqual(expect.arrayContaining(["关闭", "编辑礼包"]));
});
it("renders map layers, filter controls, points, and selected-point details", () => {
@@ -504,7 +508,7 @@ function scumActions(overrides: Partial<NonNullable<SCUMWorkspaceActions["scum"]
};
}
function renderAndCollect(options: { data?: SCUMSurfaceData; permissions?: string[]; pageKey?: string; pageTitle?: string; giftTab?: "definitions" | "claims" | "deliveries" | "timed"; playerSearch?: string; pageQuery?: Record<string, string> } = {}) {
function renderAndCollect(options: { data?: SCUMSurfaceData; permissions?: string[]; pageKey?: string; pageTitle?: string; giftTab?: "definitions" | "claims" | "deliveries" | "timed"; giftDialog?: { mode: "closed" | "view" | "edit"; gift?: RecordMap }; playerSearch?: string; pageQuery?: Record<string, string> } = {}) {
const nodes: string[] = [];
const texts: string[] = [];
const buttons: Array<{ label: string; disabled: boolean; onClick?: () => void }> = [];
@@ -528,6 +532,7 @@ function renderAndCollect(options: { data?: SCUMSurfaceData; permissions?: strin
stateCall += 1;
if (stateCall === 1) return [{ status: "ready", data: options.data ?? surfaceData } as T, () => undefined];
if (stateCall === 3 && options.playerSearch !== undefined) return [options.playerSearch as T, () => undefined];
if (options.giftDialog && typeof initial === "object" && initial !== null && "mode" in initial && (initial as { mode?: string }).mode === "closed") return [options.giftDialog as T, () => undefined];
const value = typeof initial === "function" ? (initial as () => T)() : initial;
if (options.giftTab && value === "definitions") return [options.giftTab as T, () => undefined];
return [value, () => undefined];