Files
outline/shared/utils/csv.test.ts
2025-03-13 00:23:48 +00:00

33 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { CSVHelper } from "./csv";
describe("CSVHelper", () => {
describe("sanitizeValue", () => {
it("should leave a value unchanged", () => {
const value = "Hello, World!";
const sanitizedValue = CSVHelper.sanitizeValue(value);
expect(sanitizedValue).toBe(value);
});
it("should escape formula trigger character", () => {
expect(CSVHelper.sanitizeValue("@1x2")).toBe(`'@1x2`);
expect(CSVHelper.sanitizeValue("=1x2")).toBe(`'=1x2`);
expect(CSVHelper.sanitizeValue("1x2")).toBe(`'1x2`);
expect(CSVHelper.sanitizeValue("≠1x2")).toBe(`'≠1x2`);
expect(CSVHelper.sanitizeValue("+1x2")).toBe(`'+1x2`);
expect(CSVHelper.sanitizeValue("∑1x2")).toBe(`'∑1x2`);
});
it("should remove control characters", () => {
expect(CSVHelper.sanitizeValue("\t1x2")).toBe(`1x2`);
});
it("should remove zero-width characters", () => {
expect(CSVHelper.sanitizeValue("\u200B1x2")).toBe(`1x2`);
});
it("should remove whitespace characters", () => {
expect(CSVHelper.sanitizeValue("\u200B1x2")).toBe(`1x2`);
});
});
});