26 lines
817 B
TypeScript
26 lines
817 B
TypeScript
import { describe, expect, test } from "bun:test";
|
|
|
|
import {
|
|
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"]');
|
|
});
|
|
});
|