import { describe, expect, it } from 'vitest'; import type { SheetSpec } from './types'; import { labelPositions, labelsPerPage } from './sheet'; function makeSheet(overrides: Partial = {}): SheetSpec { return { id: 'test-sheet', brand: 'Test', code: 'T-1', pageWidthMm: 210, pageHeightMm: 297, pageName: 'A4', shape: 'rectangle', cornerRadiusMm: 0, columns: 3, rows: 4, labelWidthMm: 60, labelHeightMm: 40, marginLeftMm: 10, marginTopMm: 15, pitchXMm: 65, pitchYMm: 45, ...overrides }; } describe('labelsPerPage', () => { it('is columns times rows', () => { expect(labelsPerPage(makeSheet({ columns: 3, rows: 4 }))).toBe(12); }); }); describe('labelPositions', () => { it('enumerates in reading order: left to right, then top to bottom', () => { const sheet = makeSheet({ columns: 2, rows: 2 }); const positions = labelPositions(sheet); expect(positions.map((p) => [p.column, p.row])).toEqual([ [0, 0], [1, 0], [0, 1], [1, 1] ]); expect(positions.map((p) => p.index)).toEqual([0, 1, 2, 3]); }); it('places each label from the page margin plus its pitch offset', () => { const sheet = makeSheet({ columns: 2, rows: 2 }); const positions = labelPositions(sheet); expect(positions[3]).toEqual({ index: 3, column: 1, row: 1, xMm: sheet.marginLeftMm + sheet.pitchXMm, yMm: sheet.marginTopMm + sheet.pitchYMm, widthMm: sheet.labelWidthMm, heightMm: sheet.labelHeightMm }); }); });