feat: allow selecting audience export fields
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
|
||||
import { buildAudienceProfileCsv } from "../src/content/market/audience-profile-csv";
|
||||
import {
|
||||
buildAudienceProfileCsv,
|
||||
listAudienceProfileSelectableFieldGroups,
|
||||
listAudienceProfileCsvHeaders
|
||||
} from "../src/content/market/audience-profile-csv";
|
||||
import type { AudienceProfileExportRow } from "../src/content/market/audience-profile-types";
|
||||
|
||||
describe("audience-profile-csv", () => {
|
||||
@@ -193,6 +197,83 @@ describe("audience-profile-csv", () => {
|
||||
expect(readCsvValue(csv, "铁粉画像-Z世代占比")).toBe("0%");
|
||||
expect(csv.split("\n")[0]).not.toContain("新一线城市占比");
|
||||
});
|
||||
|
||||
test("filters export columns by selected headers", () => {
|
||||
const row = buildSuccessRow();
|
||||
const csv = buildAudienceProfileCsv([row], {
|
||||
selectedHeaders: [
|
||||
"内容数据-个人视频-播放量中位数",
|
||||
"观众画像-男性占比"
|
||||
]
|
||||
});
|
||||
|
||||
const [headerLine, rowLine] = csv.split("\n");
|
||||
|
||||
expect(headerLine).toBe(
|
||||
"达人信息,连接用户数,内容数据-个人视频-播放量中位数,观众画像-男性占比"
|
||||
);
|
||||
expect(rowLine).toBe("达人 A,300w,3738.4w,71.7%");
|
||||
expect(headerLine).not.toContain("秒思api-看后搜数");
|
||||
expect(headerLine).not.toContain("粉丝画像-女性占比");
|
||||
});
|
||||
|
||||
test("always keeps fixed id export headers when filtering", () => {
|
||||
const row = buildSuccessRow({
|
||||
exportFields: {
|
||||
达人ID: "123",
|
||||
达人名称: "达人 A",
|
||||
导出状态: "成功",
|
||||
失败原因: ""
|
||||
}
|
||||
});
|
||||
const csv = buildAudienceProfileCsv([row], {
|
||||
selectedHeaders: ["内容数据-个人视频-播放量中位数"]
|
||||
});
|
||||
|
||||
const [headerLine, rowLine] = csv.split("\n");
|
||||
|
||||
expect(headerLine).toBe(
|
||||
"达人ID,达人名称,导出状态,失败原因,内容数据-个人视频-播放量中位数"
|
||||
);
|
||||
expect(rowLine).toBe("123,达人 A,成功,,3738.4w");
|
||||
});
|
||||
|
||||
test("lists headers for field picker defaults", () => {
|
||||
expect(listAudienceProfileCsvHeaders([buildSuccessRow()])).toEqual(
|
||||
expect.arrayContaining([
|
||||
"达人信息",
|
||||
"连接用户数",
|
||||
"秒思api-看后搜数",
|
||||
"内容数据-个人视频-播放量中位数",
|
||||
"效果预估-20-60s视频-预期CPM",
|
||||
"观众画像-男性占比",
|
||||
"铁粉画像-小镇青年占比"
|
||||
])
|
||||
);
|
||||
});
|
||||
|
||||
test("groups selectable profile export fields", () => {
|
||||
expect(listAudienceProfileSelectableFieldGroups()).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
headers: expect.arrayContaining(["秒思api-看后搜数"]),
|
||||
label: "秒思api数据"
|
||||
}),
|
||||
expect.objectContaining({
|
||||
headers: expect.arrayContaining(["内容数据-个人视频-播放量中位数"]),
|
||||
label: "内容数据"
|
||||
}),
|
||||
expect.objectContaining({
|
||||
headers: expect.arrayContaining(["效果预估-20-60s视频-预期CPM"]),
|
||||
label: "效果预估"
|
||||
}),
|
||||
expect.objectContaining({
|
||||
headers: expect.arrayContaining(["观众画像-男性占比"]),
|
||||
label: "观众画像"
|
||||
})
|
||||
])
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
function readCsvValue(csv: string, header: string): string {
|
||||
@@ -204,3 +285,47 @@ function readCsvValue(csv: string, header: string): string {
|
||||
expect(index).toBeGreaterThanOrEqual(0);
|
||||
return values[index] ?? "";
|
||||
}
|
||||
|
||||
function buildSuccessRow(
|
||||
overrides: Partial<AudienceProfileExportRow["record"]> = {}
|
||||
): AudienceProfileExportRow {
|
||||
return {
|
||||
profiles: {
|
||||
audience: {
|
||||
age: [{ label: "31-40", value: "50%" }],
|
||||
cityTier: [{ label: "一线城市", value: "100%" }],
|
||||
crowd: [{ label: "都市蓝领", value: "100%" }],
|
||||
gender: [{ label: "男性", value: "71.7%" }],
|
||||
status: "success"
|
||||
},
|
||||
fans: { status: "success" },
|
||||
longtimeFans: { status: "success" }
|
||||
},
|
||||
businessAbility: {
|
||||
estimates: {
|
||||
twentyToSixty: {
|
||||
expectedCpe: "3.7",
|
||||
expectedCpm: "212.0",
|
||||
expectedPlay: "250w",
|
||||
hotRate: "缺失"
|
||||
}
|
||||
},
|
||||
status: "success",
|
||||
videos: {
|
||||
personalVideo: {
|
||||
medianPlay: "3738.4w"
|
||||
}
|
||||
}
|
||||
},
|
||||
record: {
|
||||
authorId: "123",
|
||||
authorName: "达人 A",
|
||||
exportFields: {
|
||||
达人信息: "达人 A",
|
||||
连接用户数: "300w"
|
||||
},
|
||||
status: "success",
|
||||
...overrides
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user