@softwear/latestcollectioncore 1.0.205 → 1.0.207

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -455,4 +455,82 @@ describe('genPDF', () => {
455
455
  const pdfText = Buffer.from(doc.output('arraybuffer')).toString('latin1')
456
456
  expect(pdfText).toMatch(/\(\s*.\s*5\.00\) Tj/)
457
457
  })
458
+
459
+ /**
460
+ * Check multi-page vertical repeat with minHeightBeforeBreak.
461
+ */
462
+ function barcodeSheetLayout(): Layout {
463
+ return {
464
+ name: 'barcodesheet',
465
+ paperSize: { width: 210, height: 297, footerHeight: 10 },
466
+ objects: [
467
+ {
468
+ type: 'container',
469
+ name: 'items',
470
+ source: 'items',
471
+ x: 100,
472
+ y: 100,
473
+ width: 1900,
474
+ height: 220,
475
+ active: true,
476
+ repeatContainer: 'vertical',
477
+ minHeightBeforeBreak: 220,
478
+ children: [
479
+ {
480
+ type: 'barcode',
481
+ name: 'barcode',
482
+ source: 'barcode',
483
+ x: 0,
484
+ y: 20,
485
+ width: 900,
486
+ height: 160,
487
+ active: true,
488
+ },
489
+ {
490
+ type: 'field',
491
+ name: 'barcodeText',
492
+ source: 'barcode',
493
+ x: 0,
494
+ y: 185,
495
+ width: 900,
496
+ height: 30,
497
+ active: true,
498
+ fontFamily: 'Helvetica',
499
+ fontSize: 20,
500
+ fontStyle: 0,
501
+ textAlign: 2,
502
+ },
503
+ ],
504
+ },
505
+ ],
506
+ }
507
+ }
508
+
509
+ function barcodeMarksOnPage(doc: Awaited<ReturnType<typeof genPDF>>, page: number): string[] {
510
+ const pageOps = (doc as any).internal.pages[page] as string[] | undefined
511
+ if (!pageOps) return []
512
+ return [...pageOps.join('\n').matchAll(/\(BC-\d{3}\)/g)].map((m) => m[0].slice(1, -1))
513
+ }
514
+
515
+ it('keeps barcode rows that fit under minHeightBeforeBreak on a single page', async () => {
516
+ const items = Array.from({ length: 12 }, (_, i) => ({ barcode: `BC-${String(i).padStart(3, '0')}` }))
517
+ const doc = await genPDF(barcodeSheetLayout(), { items })
518
+ expect(doc.getNumberOfPages()).toBe(1)
519
+ expect(barcodeMarksOnPage(doc, 1)).toEqual(items.map((item) => item.barcode))
520
+ })
521
+
522
+ it('breaks barcode rows before drawing when minHeightBeforeBreak would overflow', async () => {
523
+ const items = Array.from({ length: 15 }, (_, i) => ({ barcode: `BC-${String(i).padStart(3, '0')}` }))
524
+ const doc = await genPDF(barcodeSheetLayout(), { items })
525
+
526
+ expect(doc.getNumberOfPages()).toBe(2)
527
+ expect(barcodeMarksOnPage(doc, 1)).toEqual(items.slice(0, 12).map((item) => item.barcode))
528
+ expect(barcodeMarksOnPage(doc, 2)).toEqual(items.slice(12).map((item) => item.barcode))
529
+
530
+ const pdfText = Buffer.from(doc.output('arraybuffer')).toString('latin1')
531
+ for (const item of items) {
532
+ const matches = pdfText.match(new RegExp(`\\(${item.barcode}\\)`, 'g'))
533
+ expect(matches, `${item.barcode} should appear exactly once`).toHaveLength(1)
534
+ }
535
+ })
458
536
  })