|
16 | 16 | import { XFAFactory } from "../../src/core/xfa/factory.js";
|
17 | 17 |
|
18 | 18 | describe("XFAFactory", function () {
|
| 19 | + function searchHtmlNode(root, name, value) { |
| 20 | + if (root[name] === value) { |
| 21 | + return root; |
| 22 | + } |
| 23 | + if (!root.children) { |
| 24 | + return null; |
| 25 | + } |
| 26 | + for (const child of root.children) { |
| 27 | + const node = searchHtmlNode(child, name, value); |
| 28 | + if (node) { |
| 29 | + return node; |
| 30 | + } |
| 31 | + } |
| 32 | + return null; |
| 33 | + } |
| 34 | + |
19 | 35 | describe("toHTML", function () {
|
20 | 36 | it("should convert some basic properties to CSS", function () {
|
21 | 37 | const xml = `
|
@@ -108,5 +124,45 @@ describe("XFAFactory", function () {
|
108 | 124 | pages.children[1].children[0].children[0].attributes.style
|
109 | 125 | );
|
110 | 126 | });
|
| 127 | + |
| 128 | + it("should have a maxLength property", function () { |
| 129 | + const xml = ` |
| 130 | +<?xml version="1.0"?> |
| 131 | +<xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/"> |
| 132 | + <template xmlns="http://www.xfa.org/schema/xfa-template/3.3"> |
| 133 | + <subform name="root" mergeMode="matchTemplate"> |
| 134 | + <pageSet> |
| 135 | + <pageArea> |
| 136 | + <contentArea x="123pt" w="456pt" h="789pt"/> |
| 137 | + <medium stock="default" short="456pt" long="789pt"/> |
| 138 | + <field y="1pt" w="11pt" h="22pt" x="2pt"> |
| 139 | + <ui> |
| 140 | + <textEdit/> |
| 141 | + </ui> |
| 142 | + <value> |
| 143 | + <text maxChars="123"/> |
| 144 | + </value> |
| 145 | + </field> |
| 146 | + </pageArea> |
| 147 | + </pageSet> |
| 148 | + <subform name="first"> |
| 149 | + </subform> |
| 150 | + </subform> |
| 151 | + </template> |
| 152 | + <xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/"> |
| 153 | + <xfa:data> |
| 154 | + </xfa:data> |
| 155 | + </xfa:datasets> |
| 156 | +</xdp:xdp> |
| 157 | + `; |
| 158 | + const factory = new XFAFactory({ "xdp:xdp": xml }); |
| 159 | + |
| 160 | + expect(factory.numberPages).toEqual(1); |
| 161 | + |
| 162 | + const pages = factory.getPages(); |
| 163 | + const field = searchHtmlNode(pages, "name", "textarea"); |
| 164 | + |
| 165 | + expect(field.attributes.maxLength).toEqual(123); |
| 166 | + }); |
111 | 167 | });
|
112 | 168 | });
|
0 commit comments