import React from "react";
import { assert } from "chai";
import loadEL from "../../node/el/loadEL";
import type * as std from "../../law/std";
import { DOCXAppdxItem, HTMLAppdxItem } from "./appdxItem";
import { renderToStaticMarkup } from "../common";
import { renderDocxAsync } from "../common/docx/file";
import ensureTempTestDir from "../../../test/ensureTempTestDir";
import path from "path";
import fs from "fs";
import formatXML from "../../util/formatXml";
import htmlCSS from "./htmlCSS";
import { promisify } from "util";
describe("Test HTML appdxItem", () => {
/* eslint-disable no-irregular-whitespace */
it("Success case", async () => {
const input = loadEL({
tag: "AppdxTable",
attr: {},
children: [
{
tag: "AppdxTableTitle",
attr: {},
children: ["付録別表第二"],
},
{
tag: "RelatedArticleNum",
attr: {},
children: ["(第十九条、第二十一条関係)"],
},
{
tag: "TableStruct",
attr: {},
children: [
{
tag: "Table",
attr: {},
children: [
{
tag: "TableRow",
attr: {},
children: [
{
tag: "TableColumn",
attr: {},
children: [
{
tag: "Sentence",
attr: {},
children: ["情報照会者"],
},
],
},
{
tag: "TableColumn",
attr: {},
children: [
{
tag: "Sentence",
attr: {},
children: ["事務"],
},
],
},
],
},
],
},
],
},
],
}) as std.AppdxItem;
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.appdxItem.html");
await promisify(fs.writeFile)(tempParsedHtml, html);
console.log(` Saved html: ${tempParsedHtml}`);
});
});
describe("Test DOCX appdxItem", () => {
/* eslint-disable no-irregular-whitespace */
it("Success case", async () => {
const input = loadEL({
tag: "AppdxTable",
attr: {},
children: [
{
tag: "AppdxTableTitle",
attr: {},
children: ["付録別表第二"],
},
{
tag: "RelatedArticleNum",
attr: {},
children: ["(第十九条、第二十一条関係)"],
},
{
tag: "TableStruct",
attr: {},
children: [
{
tag: "Table",
attr: {},
children: [
{
tag: "TableRow",
attr: {},
children: [
{
tag: "TableColumn",
attr: {},
children: [
{
tag: "Sentence",
attr: {},
children: ["情報照会者"],
},
],
},
{
tag: "TableColumn",
attr: {},
children: [
{
tag: "Sentence",
attr: {},
children: ["事務"],
},
],
},
],
},
],
},
],
},
],
}) as std.AppdxItem;
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.appdxItem.docx");
fs.writeFileSync(tempParsedDocx, u8);
console.log(` Saved docx: ${tempParsedDocx}`);
});
});