| 1234567891011121314151617181920212223242526272829 |
- import assert from 'node:assert/strict'
- import { describe, it } from 'node:test'
- import {
- CONTRACT_PRODUCT_COL_WIDTHS_PX,
- normalizeContractProductTableWidths
- } from './contract-product-table-widths'
- const sample = `
- <table style="width: 680px; table-layout: fixed;">
- <colgroup><col style="width: 73px;"><col style="width: 49px;"><col style="width: 34px;"><col style="width: 39px;"><col style="width: 37px;"><col style="width: 34px;"><col style="width: 82px;"><col style="width: 82px;"><col style="width: 68px;"><col style="width: 67px;"><col style="width: 62px;"><col style="width: 53px;"></colgroup>
- <tr><th style="width: 73px;">产品名称</th><th style="width: 49px;">规格</th><th style="width: 34px;">品牌</th><th style="width: 39px;">单位</th><th style="width: 37px;">用量</th><th style="width: 34px;">税率</th><th style="width: 82px;">含税单价(元)</th><th style="width: 82px;">未含税金额(元)</th><th style="width: 68px;">税费(元)</th><th style="width: 67px;">含税金额(元)</th><th style="width: 62px;">包装规格</th><th style="width: 53px;">备注</th></tr>
- </table>`
- describe('normalizeContractProductTableWidths', () => {
- it('rewrites saved pixel columns so the product name is 100px', () => {
- const out = normalizeContractProductTableWidths(sample)
- assert.match(out, /<col style="width: 100px;">/)
- assert.equal(out.includes('width: 73px'), false)
- assert.match(out, /<th style="width: 100px;">产品名称<\/th>/)
- assert.match(out, /<table style="width: 680px;/)
- const amount = CONTRACT_PRODUCT_COL_WIDTHS_PX.slice(2, 6).reduce((sum, n) => sum + n, 0)
- assert.ok(amount >= 180)
- })
- it('leaves unrelated tables unchanged', () => {
- const other = '<table><tr><th style="width: 10px;">其他</th></tr></table>'
- assert.equal(normalizeContractProductTableWidths(other), other)
- })
- })
|