ldc-boutique-cnc-sable/resources/ts/modules/ckeditor.test.ts

33 lines
1 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { normalizeEditorText } from "./ckeditor-utils";
describe("normalizeEditorText", () => {
it("converts null and undefined to empty string", () => {
// GIVEN / WHEN / THEN
expect(normalizeEditorText(null)).toBe("");
expect(normalizeEditorText(undefined)).toBe("");
});
it("converts string 'null' and 'undefined' to empty string", () => {
// GIVEN / WHEN / THEN
expect(normalizeEditorText("null")).toBe("");
expect(normalizeEditorText("undefined")).toBe("");
});
it("preserves valid empty string", () => {
// GIVEN / WHEN / THEN
expect(normalizeEditorText("")).toBe("");
});
it("preserves HTML and text content", () => {
// GIVEN / WHEN / THEN
expect(normalizeEditorText("<p>Hello world</p>")).toBe("<p>Hello world</p>");
expect(normalizeEditorText("Some regular text")).toBe("Some regular text");
});
it("converts numbers to string", () => {
// GIVEN / WHEN / THEN
expect(normalizeEditorText(123)).toBe("123");
});
});