feat: make metric filters field-driven
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
|
||||
import {
|
||||
listNumericMetricFilterGroups,
|
||||
matchesMetricFilterRule,
|
||||
parseDisplayNumber
|
||||
} from "../src/content/market/metric-filter";
|
||||
|
||||
describe("metric-filter", () => {
|
||||
test("keeps only numeric list fields while retaining numeric API and profile groups", () => {
|
||||
const groups = listNumericMetricFilterGroups([
|
||||
"达人信息",
|
||||
"粉丝数",
|
||||
"互动率",
|
||||
"完播率",
|
||||
"内容主题",
|
||||
"21-60s报价"
|
||||
]);
|
||||
const listFields = groups.find((group) => group.label === "列表字段");
|
||||
|
||||
expect(listFields?.headers).toEqual([
|
||||
"粉丝数",
|
||||
"互动率",
|
||||
"完播率",
|
||||
"21-60s报价"
|
||||
]);
|
||||
expect(groups.map((group) => group.label)).toEqual(expect.arrayContaining([
|
||||
"内容数据",
|
||||
"效果预估",
|
||||
"观众画像",
|
||||
"粉丝画像",
|
||||
"铁粉画像"
|
||||
]));
|
||||
});
|
||||
|
||||
test("compares displayed percentages, prices, and wan-unit values with both operators", () => {
|
||||
expect(parseDisplayNumber("28.5%")).toBe(28.5);
|
||||
expect(parseDisplayNumber("¥12,000")).toBe(12000);
|
||||
expect(parseDisplayNumber("6.2w")).toBe(62000);
|
||||
expect(parseDisplayNumber("缺失")).toBeNull();
|
||||
|
||||
expect(matchesMetricFilterRule(
|
||||
{ 完播率: "28.5%" },
|
||||
{ field: "完播率", operator: "gte", threshold: 28 }
|
||||
)).toBe(true);
|
||||
expect(matchesMetricFilterRule(
|
||||
{ 完播率: "28.5%" },
|
||||
{ field: "完播率", operator: "lte", threshold: 28 }
|
||||
)).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user