import React from "react"; import { assert } from "chai"; import loadEL from "../../node/el/loadEL"; import type * as std from "../../law/std"; import { DOCXTable, HTMLTable } from "./table"; 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 table", () => { /* eslint-disable no-irregular-whitespace */ it("Success case", async () => { const input = loadEL({ tag: "Table", attr: {}, children: [ { tag: "TableHeaderRow", attr: {}, children: [ { tag: "TableHeaderColumn", attr: {}, children: ["項"], }, { tag: "TableHeaderColumn", attr: {}, children: ["種名"], }, ], }, { tag: "TableRow", attr: {}, children: [ { tag: "TableColumn", attr: { colspan: "2", }, children: [ { tag: "Column", attr: {}, children: [ { tag: "Sentence", attr: {}, children: ["(1)"], }, ], }, { tag: "Column", attr: {}, children: [ { tag: "Sentence", attr: {}, children: ["かも科"], }, ], }, ], }, ], }, { tag: "TableRow", attr: {}, children: [ { tag: "TableColumn", attr: {}, children: [ { tag: "Sentence", attr: {}, children: ["1"], }, ], }, { tag: "TableColumn", attr: {}, children: [ { tag: "Sentence", attr: {}, children: ["シジュウカラガン"], }, ], }, ], }, { tag: "TableRow", attr: {}, children: [ { tag: "TableColumn", attr: { rowspan: "2", }, children: [ { tag: "Sentence", attr: {}, children: ["2"], }, ], }, { tag: "TableColumn", attr: {}, children: [ { tag: "Sentence", attr: {}, children: ["2.1"], }, ], }, ], }, { tag: "TableRow", attr: {}, children: [ { tag: "TableColumn", attr: {}, children: [ { tag: "Sentence", attr: {}, children: ["2.2"], }, ], }, ], }, ], }) as std.Table; const expectedHTML = /*html*/`\
種名
(1)   かも科
シジュウカラガン
2.1
2.2
`; 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.table.html"); await promisify(fs.writeFile)(tempParsedHtml, html); console.log(` Saved html: ${tempParsedHtml}`); }); it("Success case", async () => { const input = loadEL({ tag: "Table", attr: {}, children: [ { tag: "TableRow", attr: {}, children: [ { tag: "TableColumn", attr: {}, children: [ { tag: "Sentence", attr: {}, children: ["次に掲げる額の合計額"], }, { tag: "Sentence", attr: {}, children: ["ロ 消滅会社等の株主等に対して交付する存続株式会社等の社債、新株予約権又は新株予約権付社債の帳簿価額の合計額"], }, { tag: "Sentence", attr: {}, children: ["ハ 消滅会社等の株主等に対して交付する存続株式会社等の株式等以外の財産の帳簿価額の合計額"], }, ], }, ], }, ], }) as std.Table; 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.table.html"); await promisify(fs.writeFile)(tempParsedHtml, html); console.log(` Saved html: ${tempParsedHtml}`); }); }); describe("Test DOCX table", () => { /* eslint-disable no-irregular-whitespace */ it("Success case", async () => { const input = loadEL({ tag: "Table", attr: {}, children: [ { tag: "TableHeaderRow", attr: {}, children: [ { tag: "TableHeaderColumn", attr: {}, children: ["項"], }, { tag: "TableHeaderColumn", attr: {}, children: ["種名"], }, ], }, { tag: "TableRow", attr: {}, children: [ { tag: "TableColumn", attr: { colspan: "2", }, children: [ { tag: "Column", attr: {}, children: [ { tag: "Sentence", attr: {}, children: ["(1)"], }, ], }, { tag: "Column", attr: {}, children: [ { tag: "Sentence", attr: {}, children: ["かも科"], }, ], }, ], }, ], }, { tag: "TableRow", attr: {}, children: [ { tag: "TableColumn", attr: {}, children: [ { tag: "Sentence", attr: {}, children: ["1"], }, ], }, { tag: "TableColumn", attr: {}, children: [ { tag: "Sentence", attr: {}, children: ["シジュウカラガン"], }, ], }, ], }, { tag: "TableRow", attr: {}, children: [ { tag: "TableColumn", attr: { rowspan: "2", }, children: [ { tag: "Sentence", attr: {}, children: ["2"], }, ], }, { tag: "TableColumn", attr: {}, children: [ { tag: "Sentence", attr: {}, children: ["2.1"], }, ], }, ], }, { tag: "TableRow", attr: {}, children: [ { tag: "TableColumn", attr: {}, children: [ { tag: "Sentence", attr: {}, children: ["2.2"], }, ], }, ], }, ], }) as std.Table; const expectedDOCX = /*xml*/`\ 種名 (1)   かも科 シジュウカラガン 2.1 2.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.table.docx"); fs.writeFileSync(tempParsedDocx, u8); console.log(` Saved docx: ${tempParsedDocx}`); }); it("Success case", async () => { const input = loadEL({ tag: "Table", attr: {}, children: [ { tag: "TableRow", attr: {}, children: [ { tag: "TableColumn", attr: {}, children: [ { tag: "Sentence", attr: {}, children: ["次に掲げる額の合計額"], }, { tag: "Sentence", attr: {}, children: ["ロ 消滅会社等の株主等に対して交付する存続株式会社等の社債、新株予約権又は新株予約権付社債の帳簿価額の合計額"], }, { tag: "Sentence", attr: {}, children: ["ハ 消滅会社等の株主等に対して交付する存続株式会社等の株式等以外の財産の帳簿価額の合計額"], }, ], }, ], }, ], }) as std.Table; 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.table.docx"); fs.writeFileSync(tempParsedDocx, u8); console.log(` Saved docx: ${tempParsedDocx}`); }); });