fix: respect selected audience export fields

This commit is contained in:
wxs
2026-07-20 11:16:40 +08:00
parent c683e1c0c2
commit e062be6431
6 changed files with 176 additions and 38 deletions
+39 -2
View File
@@ -201,13 +201,37 @@ describe("audience-profile-csv", () => {
const [headerLine, rowLine] = csv.split("\n");
expect(headerLine).toBe(
"达人信息,连接用户数,内容数据-个人视频-近30天-播放量中位数,观众画像-男性占比"
"达人ID,达人名称,导出状态,失败原因,内容数据-个人视频-近30天-播放量中位数,观众画像-男性占比"
);
expect(rowLine).toBe("达人 A,300w,10913233,71.7%");
expect(rowLine).toBe("123,达人 A,成功,,10913233,71.7%");
expect(headerLine).not.toContain("秒思api-看后搜数");
expect(headerLine).not.toContain("粉丝画像-女性占比");
});
test("omits unselected market-list columns after field settings are saved", () => {
const row = buildSuccessRow({
exportFields: {
: "达人 A",
: "300w",
CPM: "120"
}
});
const csv = buildAudienceProfileCsv([row], {
selectedHeaders: ["内容数据-个人视频-近30天-播放量中位数"]
});
const [headerLine, rowLine] = csv.split("\n");
expect(headerLine).toBe(
"达人ID,达人名称,导出状态,失败原因,内容数据-个人视频-近30天-播放量中位数"
);
expect(rowLine).toBe("123,达人 A,成功,,10913233");
expect(headerLine).not.toContain("达人信息");
expect(headerLine).not.toContain("粉丝数");
expect(headerLine).not.toContain("预期CPM");
});
test("always keeps fixed id export headers when filtering", () => {
const row = buildSuccessRow({
exportFields: {
@@ -267,6 +291,19 @@ describe("audience-profile-csv", () => {
])
);
});
test("includes current market-list columns in the field picker", () => {
expect(
listAudienceProfileSelectableFieldGroups(["达人信息", "粉丝数"])
).toEqual(
expect.arrayContaining([
{
headers: ["达人信息", "粉丝数"],
label: "列表字段"
}
])
);
});
});
function readCsvValue(csv: string, header: string): string {
@@ -0,0 +1,33 @@
/** @vitest-environment jsdom */
import { describe, expect, test } from "vitest";
import { promptForAudienceProfileFields } from "../src/content/market/audience-profile-field-dialog";
describe("audience-profile-field-dialog", () => {
test("keeps an explicitly empty field selection empty", async () => {
const result = promptForAudienceProfileFields(
document,
[
{
headers: ["粉丝数", "观众画像-男性占比"],
label: "测试字段"
}
],
[]
);
const fields = Array.from(
document.querySelectorAll('[data-audience-profile-field-dialog-field="checkbox"]')
) as HTMLInputElement[];
expect(fields).toHaveLength(2);
expect(fields.every((field) => !field.checked)).toBe(true);
const saveButton = document.querySelector(
'[data-audience-profile-field-dialog-save="button"]'
) as HTMLButtonElement;
saveButton.click();
await expect(result).resolves.toEqual([]);
});
});
+2 -2
View File
@@ -2633,7 +2633,7 @@ describe("market-content-entry", () => {
}
],
expect.objectContaining({
selectedHeaders: expect.arrayContaining(["秒思api-看后搜数"])
selectedHeaders: undefined
})
);
expect(onCsvReady).toHaveBeenCalledWith(
@@ -2771,7 +2771,7 @@ describe("market-content-entry", () => {
})
],
expect.objectContaining({
selectedHeaders: expect.arrayContaining(["秒思api-看后搜数"])
selectedHeaders: undefined
})
);
expect(onCsvReady).toHaveBeenCalledWith(