import React from "react"; import { assert } from "chai"; import { DOCXSentenceChildrenRun, HTMLSentenceChildrenRun } from "./sentenceChildrenRun"; import loadEL from "../../node/el/loadEL"; import type * as std from "../../law/std"; import { renderToStaticMarkup } from "../common"; import formatXML from "../../util/formatXml"; import htmlCSS from "./htmlCSS"; import path from "path"; import { promisify } from "util"; import fs from "fs"; import ensureTempTestDir from "../../../test/ensureTempTestDir"; import { renderDocxAsync } from "../common/docx/file"; import { w } from "../common/docx/tags"; describe("Test HTML sentenceChildrenRun", () => { /* eslint-disable no-irregular-whitespace */ it("Success case", async () => { const input = loadEL({ tag: "Sentence", attr: {}, children: [ { tag: "__Text", attr: {}, children: ["この法律において"], }, { tag: "__Parentheses", attr: { depth: "1", type: "square", }, children: [ { tag: "__PStart", attr: { type: "square", }, children: ["「"], }, { tag: "__PContent", attr: { type: "square" }, children: [ { tag: "__Text", attr: {}, children: ["スパイクタイヤ"], }, ], }, { tag: "__PEnd", attr: { "type": "square" }, children: ["」"], }, ], }, { tag: "__Text", attr: {}, children: ["とは、積雪又は凍結の状態にある路面において滑ることを防止するために金属"], }, { tag: "Ruby", attr: {}, children: [ { tag: "__Text", attr: {}, children: ["鋲"], }, { tag: "Rt", attr: {}, children: [ { tag: "__Text", attr: {}, children: ["びよう"], }, ], }, ], }, { tag: "__Text", attr: {}, children: ["その他これに類する物をその接地部に固定したタイヤをいう。"], }, ], }) as std.Sentence; const expectedHTML = /*html*/`\ この法律において「スパイクタイヤ」とは、積雪又は凍結の状態にある路面において滑ることを防止するために金属びようその他これに類する物をその接地部に固定したタイヤをいう。 `; const element = ; const rendered = renderToStaticMarkup(element); const formatted = formatXML(rendered, { collapseContent: true }); assert.strictEqual( formatted, expectedHTML, ); const html = /*html*/`\ ${rendered} `; const tempParsedHtml = path.join(ensureTempTestDir(), "renderer.sentenceChildrenRun.html"); await promisify(fs.writeFile)(tempParsedHtml, html); console.log(` Saved html: ${tempParsedHtml}`); }); }); describe("Test DOCX sentenceChildrenRun", () => { /* eslint-disable no-irregular-whitespace */ it("Success case", async () => { const input = loadEL({ tag: "Sentence", attr: {}, children: [ { tag: "__Text", attr: {}, children: ["この法律において"], }, { tag: "__Parentheses", attr: { depth: "1", type: "square", }, children: [ { tag: "__PStart", attr: { type: "square", }, children: ["「"], }, { tag: "__PContent", attr: { type: "square" }, children: [ { tag: "__Text", attr: {}, children: ["スパイクタイヤ"], }, ], }, { tag: "__PEnd", attr: { "type": "square" }, children: ["」"], }, ], }, { tag: "__Text", attr: {}, children: ["とは、積雪又は凍結の状態にある路面において滑ることを防止するために金属"], }, { tag: "Ruby", attr: {}, children: [ { tag: "__Text", attr: {}, children: ["鋲"], }, { tag: "Rt", attr: {}, children: [ { tag: "__Text", attr: {}, children: ["びよう"], }, ], }, ], }, { tag: "__Text", attr: {}, children: ["その他これに類する物をその接地部に固定したタイヤをいう。"], }, ], }) as std.Sentence; const expectedDOCX = /*xml*/`\ この法律において 「スパイクタイヤ」 とは、積雪又は凍結の状態にある路面において滑ることを防止するために金属 びよう その他これに類する物をその接地部に固定したタイヤをいう。 `; const element = ; const rendered = renderToStaticMarkup(element); const formatted = formatXML(rendered, { collapseContent: true }); assert.strictEqual( formatted, expectedDOCX, ); const u8 = await renderDocxAsync({element}); const tempParsedDocx = path.join(ensureTempTestDir(), "renderer.sentenceChildrenRun.docx"); fs.writeFileSync(tempParsedDocx, u8); console.log(` Saved docx: ${tempParsedDocx}`); }); });