|
|
@@ -5,6 +5,7 @@ import {
|
|
|
inlineRemoteImagesAsDataUrls,
|
|
|
normalizeHeaderMetaFlexLayoutForDocx,
|
|
|
normalizePartyFlexLayoutForDocx,
|
|
|
+ normalizeSealImagesForDocx,
|
|
|
parseContractSupplierCode,
|
|
|
prepareContractHtmlForDocx,
|
|
|
stripContractLogoHtml,
|
|
|
@@ -59,7 +60,7 @@ describe('toAbsoluteAssetUrls', () => {
|
|
|
})
|
|
|
|
|
|
describe('normalizeHeaderMetaFlexLayoutForDocx', () => {
|
|
|
- it('converts supplier/contractNo and demander/signPlace rows into side-by-side tables', () => {
|
|
|
+ it('converts supplier/contractNo and demander/signPlace rows into float text rows', () => {
|
|
|
const html = `
|
|
|
<div style="display: flex; margin-bottom: 0; position: relative;">
|
|
|
<div style="flex: 1;">供方:安庆市山峡化工有限公司</div>
|
|
|
@@ -70,8 +71,8 @@ describe('normalizeHeaderMetaFlexLayoutForDocx', () => {
|
|
|
<div style="position: absolute; right: 0px; min-width: 300px;">签订地点:安徽安庆</div>
|
|
|
</div>`
|
|
|
const out = normalizeHeaderMetaFlexLayoutForDocx(html)
|
|
|
- assert.equal((out.match(/<table/g) || []).length, 2)
|
|
|
- assert.equal(out.includes('text-align:right'), true)
|
|
|
+ assert.equal(out.includes('<table'), false)
|
|
|
+ assert.equal(out.includes('float:right'), true)
|
|
|
assert.equal(out.includes('position: absolute'), false)
|
|
|
assert.equal(out.includes('供方:安庆市山峡化工有限公司'), true)
|
|
|
assert.equal(out.includes('合同编号:SX/X-JT20260828004'), true)
|
|
|
@@ -91,6 +92,17 @@ describe('normalizeHeaderMetaFlexLayoutForDocx', () => {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
+describe('normalizeSealImagesForDocx', () => {
|
|
|
+ it('rewrites absolute seal images to float-over-text styles', () => {
|
|
|
+ const html =
|
|
|
+ '<img src="/yz.png" alt="印章" style="position: absolute; top: 50%; left: 50%; width: 140px; height: 140px;" />'
|
|
|
+ const out = normalizeSealImagesForDocx(html)
|
|
|
+ assert.equal(out.includes('position: absolute'), false)
|
|
|
+ assert.equal(out.includes('float:left'), true)
|
|
|
+ assert.equal(out.includes('alt="印章"'), true)
|
|
|
+ })
|
|
|
+})
|
|
|
+
|
|
|
describe('normalizePartyFlexLayoutForDocx', () => {
|
|
|
it('converts bottom party flex columns into a two-cell table', () => {
|
|
|
const html = `
|
|
|
@@ -144,18 +156,22 @@ describe('prepareContractHtmlForDocx', () => {
|
|
|
<div style="flex: 1;">供方:甲</div>
|
|
|
<div style="position: absolute; right: 0px;">合同编号:NO1</div>
|
|
|
</div>
|
|
|
+ <img src="/yz.png" alt="印章" style="position: absolute; top: 50%; left: 50%;" />
|
|
|
<div style="display: flex; justify-content: space-between; margin-top: 10px;">
|
|
|
- <div style="flex: 1;"><div>供方</div><div>A</div></div>
|
|
|
- <div style="flex: 1;"><div>需方</div><div>B</div></div>
|
|
|
+ <div style="flex: 1;"><div style="border-bottom: 1px solid #000;">供方</div><div>A</div></div>
|
|
|
+ <div style="flex: 1;"><div style="border-bottom: 1px solid #000;">需方</div><div>B</div></div>
|
|
|
</div>`
|
|
|
const out = prepareContractHtmlForDocx({
|
|
|
html,
|
|
|
contractNo: 'SX/X-JT1',
|
|
|
origin: 'http://localhost:3006'
|
|
|
})
|
|
|
- assert.equal((out.match(/<table/g) || []).length >= 2, true)
|
|
|
+ assert.equal(out.includes('float:right'), true)
|
|
|
+ assert.equal(out.includes('<table'), true)
|
|
|
+ assert.equal(out.includes('float:left'), true)
|
|
|
assert.equal(/position:\s*absolute/.test(out), false)
|
|
|
assert.equal(/justify-content:\s*space-between/.test(out), false)
|
|
|
+ assert.equal(out.includes('border-bottom: 1px solid #000'), true)
|
|
|
})
|
|
|
})
|
|
|
|