41 lines
1.5 KiB
TypeScript
41 lines
1.5 KiB
TypeScript
import assert from 'node:assert/strict'
|
|
import { describe, it } from 'node:test'
|
|
import { countContractPdfPages } from './contract-pdf-pages'
|
|
|
|
function pixels(width: number, height: number, marks: number[]) {
|
|
const data = new Uint8ClampedArray(width * height * 4).fill(255)
|
|
for (const row of marks) data[(row * width + 1) * 4] = 0
|
|
return { width, height, data }
|
|
}
|
|
|
|
describe('countContractPdfPages', () => {
|
|
it('ignores trailing white padding that crosses onto a second page', () => {
|
|
assert.equal(countContractPdfPages(pixels(210, 330, [20, 295])), 1)
|
|
})
|
|
|
|
it('keeps even a single visible pixel on a second page', () => {
|
|
assert.equal(countContractPdfPages(pixels(210, 330, [20, 297])), 2)
|
|
})
|
|
|
|
it('does not add a page when content ends exactly at the page boundary', () => {
|
|
assert.equal(countContractPdfPages(pixels(210, 330, [296])), 1)
|
|
})
|
|
|
|
it('removes only trailing blank pages from a multipage contract', () => {
|
|
assert.equal(countContractPdfPages(pixels(210, 900, [20, 580])), 2)
|
|
})
|
|
|
|
it('keeps one page for an empty document', () => {
|
|
assert.equal(countContractPdfPages(pixels(210, 330, [])), 1)
|
|
})
|
|
|
|
it('keeps faint content while ignoring fully transparent pixels', () => {
|
|
const image = pixels(210, 330, [20, 310])
|
|
const offset = (310 * image.width + 1) * 4
|
|
image.data[offset] = 254
|
|
assert.equal(countContractPdfPages(image), 2)
|
|
image.data[offset + 3] = 0
|
|
assert.equal(countContractPdfPages(image), 1)
|
|
})
|
|
})
|