32 lines
1.0 KiB
TypeScript
32 lines
1.0 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
|
|
import {
|
|
answerCellValue,
|
|
decodeCheckboxAnswer,
|
|
encodeAnswerValue,
|
|
formatStoredAnswer,
|
|
} from "@/lib/form-answer-values";
|
|
|
|
describe("form answer values", () => {
|
|
test("round-trips checkbox choices containing commas", () => {
|
|
const choices = ["Alpha, beta", "Gamma"];
|
|
const stored = encodeAnswerValue(choices);
|
|
|
|
expect(decodeCheckboxAnswer(stored)).toEqual(choices);
|
|
expect(formatStoredAnswer(stored, "checkbox")).toBe("Alpha, beta, Gamma");
|
|
});
|
|
|
|
test("continues to read legacy comma-separated checkbox answers", () => {
|
|
expect(decodeCheckboxAnswer("Alpha, Beta")).toEqual(["Alpha", "Beta"]);
|
|
});
|
|
|
|
test("does not decode JSON-looking text answers", () => {
|
|
expect(formatStoredAnswer('["plain text"]', "text")).toBe('["plain text"]');
|
|
});
|
|
});
|
|
|
|
test("formats CSV answer cells with image URLs", () => {
|
|
expect(answerCellValue("", "text", "img-1")).toBe("/cdn/img-1");
|
|
expect(answerCellValue("Details", "text", "img-1")).toBe("Details\n/cdn/img-1");
|
|
});
|