-
Notifications
You must be signed in to change notification settings - Fork 170
Expand file tree
/
Copy pathutil.spec.ts
More file actions
30 lines (26 loc) · 992 Bytes
/
util.spec.ts
File metadata and controls
30 lines (26 loc) · 992 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { describe, expect, it } from "vitest";
import { parseExpression } from "vega-expression";
import { sanitizeFieldName } from "./util";
describe("sanitizeFieldName", () => {
it("keeps simple field names readable", () => {
expect(sanitizeFieldName("total_sales")).toBe("rill_total_sales");
});
it("returns a valid Vega expression function name for measure names with operators", () => {
const measureNames = [
"Total Sample Revenue",
"Sample Rate* Lift",
"Share(%) | Variant A",
"Share(%) | Baseline",
"Avg Sample Value | Variant A",
"Avg Sample Value | Baseline",
"Success Rate | Variant A",
"Success Rate | Baseline",
"Success Rate | Delta",
];
for (const measureName of measureNames) {
const formatType = sanitizeFieldName(measureName);
expect(formatType).toMatch(/^[A-Za-z_$][A-Za-z0-9_$]*$/);
expect(() => parseExpression(`${formatType}(datum.value)`)).not.toThrow();
}
});
});