import React from "react";
import { assert } from "chai";
import { DOCXArithFormulaRun, HTMLArithFormulaRun } from "./arithFormulaRun";
import loadEL from "../../node/el/loadEL";
import * 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";
import { DOCXColumnsOrSentencesRun, HTMLColumnsOrSentencesRun } from "./columnsOrSentencesRun";
describe("Test HTML arithFormulaRun", () => {
/* eslint-disable no-irregular-whitespace */
it("Success case", async () => {
const input = loadEL({
tag: "ArithFormula",
attr: {},
children: [
{
tag: "Sentence",
attr: {},
children: ["Pc′/Pc×0.8+Pi′/Pi×0.2"],
},
],
}) as std.ArithFormula;
const expectedHTML = /*html*/`\
Pc′/Pc×0.8+Pi′/Pi×0.2
`;
const element = ;
const rendered = renderToStaticMarkup(element);
console;
const formatted = formatXML(rendered, { collapseContent: true });
assert.strictEqual(
formatted,
expectedHTML,
);
const html = /*html*/`\
${rendered}
`;
const tempParsedHtml = path.join(ensureTempTestDir(), "renderer.arithFormulaRun-1.html");
await promisify(fs.writeFile)(tempParsedHtml, html);
console.log(` Saved html: ${tempParsedHtml}`);
});
it("Success case", async () => {
const input = loadEL({
tag: "Sentence",
attr: {},
children: [
"testtest1",
{
tag: "ArithFormula",
attr: {},
children: [
{
tag: "Item",
attr: {
},
children: [
{
tag: "ItemTitle",
attr: {},
children: ["一"],
},
{
tag: "ItemSentence",
attr: {},
children: [
{
tag: "Column",
attr: {},
children: [
{
tag: "Sentence",
attr: {},
children: ["法令"],
},
],
},
{
tag: "Column",
attr: {},
children: [
{
tag: "Sentence",
attr: {},
children: ["法律、法律に基づく命令(告示を含む。)、条例及び地方公共団体の執行機関の規則(規程を含む。以下「規則」という。)をいう。"],
},
],
},
],
},
],
},
],
},
"testtest2",
],
}) as std.Sentence;
const expectedHTML = /*html*/`\
testtest1一 法令 法律、法律に基づく命令(告示を含む。)、条例及び地方公共団体の執行機関の規則(規程を含む。以下「規則」という。)をいう。
testtest2
`;
const element = ;
const rendered = renderToStaticMarkup(element);
console;
const formatted = formatXML(rendered, { collapseContent: true });
assert.strictEqual(
formatted,
expectedHTML,
);
const html = /*html*/`\
${rendered}
`;
const tempParsedHtml = path.join(ensureTempTestDir(), "renderer.arithFormulaRun-2.html");
await promisify(fs.writeFile)(tempParsedHtml, html);
console.log(` Saved html: ${tempParsedHtml}`);
});
});
describe("Test DOCX arithFormulaRun", () => {
/* eslint-disable no-irregular-whitespace */
it("Success case", async () => {
const input = loadEL({
tag: "ArithFormula",
attr: {},
children: [
{
tag: "Sentence",
attr: {},
children: ["Pc′/Pc×0.8+Pi′/Pi×0.2"],
},
],
}) as std.ArithFormula;
const expectedDOCX = /*xml*/`\
Pc′/Pc×0.8+Pi′/Pi×0.2
`;
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.arithFormulaRun-1.docx");
fs.writeFileSync(tempParsedDocx, u8);
console.log(` Saved docx: ${tempParsedDocx}`);
});
it("Success case", async () => {
const input = loadEL({
tag: "Sentence",
attr: {},
children: [
"testtest1",
{
tag: "ArithFormula",
attr: {},
children: [
{
tag: "Item",
attr: {
},
children: [
{
tag: "ItemTitle",
attr: {},
children: ["一"],
},
{
tag: "ItemSentence",
attr: {},
children: [
{
tag: "Column",
attr: {},
children: [
{
tag: "Sentence",
attr: {},
children: ["法令"],
},
],
},
{
tag: "Column",
attr: {},
children: [
{
tag: "Sentence",
attr: {},
children: ["法律、法律に基づく命令(告示を含む。)、条例及び地方公共団体の執行機関の規則(規程を含む。以下「規則」という。)をいう。"],
},
],
},
],
},
],
},
],
},
"testtest2",
],
}) as std.Sentence;
const arithFormula = input.children.find(std.isArithFormula);
if (arithFormula) arithFormula.id = 1111;
const expectedDOCX = /*xml*/`\
testtest1
一
法令
法律、法律に基づく命令(告示を含む。)、条例及び地方公共団体の執行機関の規則(規程を含む。以下「規則」という。)をいう。
testtest2
`;
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.arithFormulaRun-2.docx");
fs.writeFileSync(tempParsedDocx, u8);
console.log(` Saved docx: ${tempParsedDocx}`);
});
});