mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-07 18:55:42 +00:00
- Updated ContractDocumentViewModelBuilder to include cargoTypeName, containerType, and cargoSummary in the schedule. - Modified contract dynamic template tests to validate the new cargo fields. - Enhanced contract renderer service tests to reflect changes in cargo data structure. - Updated contract view model interface to include new cargo-related fields. - Improved dynamic template rendering to display cargo type and container type. - Refactored exchange settings controller and service to streamline error handling and feed status management. - Introduced article HTML conversion functions to support Quill editor integration for structured article editing. - Added tests for article HTML conversion to ensure correct round-trip processing of clauses and bullets.
65 lines
2.3 KiB
TypeScript
65 lines
2.3 KiB
TypeScript
// @vitest-environment jsdom
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import { bodyToHtml, htmlToBody } from "./article-html";
|
|
|
|
describe("article body ↔ Quill HTML", () => {
|
|
it("round-trips clauses and bullets unchanged", () => {
|
|
const body = [
|
|
"Provide written instructions for each shipment.",
|
|
"Prepare all necessary documents.",
|
|
"- Commercial invoice",
|
|
"- Packing list",
|
|
"Pay 100% in advance.",
|
|
].join("\n");
|
|
expect(htmlToBody(bodyToHtml(body))).toBe(body);
|
|
});
|
|
|
|
it("keeps a single paragraph a single paragraph", () => {
|
|
const body = "The contract is valid once signed by both parties.";
|
|
expect(htmlToBody(bodyToHtml(body))).toBe(body);
|
|
});
|
|
|
|
it("preserves placeholders verbatim through a round trip", () => {
|
|
const body = "Valid until August 31, {{contractYear}} for {{client.companyName}}.";
|
|
expect(htmlToBody(bodyToHtml(body))).toBe(body);
|
|
});
|
|
|
|
it("escapes and restores characters that are HTML-significant", () => {
|
|
const body = "Rates < 100 & > 50 apply to the Client's cargo.";
|
|
expect(htmlToBody(bodyToHtml(body))).toBe(body);
|
|
});
|
|
|
|
it("maps Quill indent classes onto sub-clause depth", () => {
|
|
const html =
|
|
"<p>Top level clause.</p>" +
|
|
'<p class="ql-indent-1">Nested one level.</p>' +
|
|
'<p class="ql-indent-2">Nested two levels.</p>';
|
|
expect(htmlToBody(html)).toBe(
|
|
["Top level clause.", "1.1. Nested one level.", "1.1.1. Nested two levels."].join(
|
|
"\n",
|
|
),
|
|
);
|
|
});
|
|
|
|
it("turns Quill bullet lists into '- ' lines", () => {
|
|
const html = "<p>Documents:</p><ul><li>Invoice</li><li>Waybill</li></ul>";
|
|
expect(htmlToBody(html)).toBe("Documents:\n- Invoice\n- Waybill");
|
|
});
|
|
|
|
it("treats an ordered list as clause lines, not bullets", () => {
|
|
const html = "<ol><li>First clause.</li><li>Second clause.</li></ol>";
|
|
expect(htmlToBody(html)).toBe("1. First clause.\n1. Second clause.");
|
|
});
|
|
|
|
it("normalises the nbsp Quill inserts and drops empty blocks", () => {
|
|
const html = "<p>Payment in advance.</p><p><br></p><p></p>";
|
|
expect(htmlToBody(html)).toBe("Payment in advance.");
|
|
});
|
|
|
|
it("returns an empty editor for an empty body", () => {
|
|
expect(bodyToHtml("")).toBe("<p><br></p>");
|
|
expect(htmlToBody("<p><br></p>")).toBe("");
|
|
});
|
|
});
|