Skip to content

Commit

Permalink
Add unit tests for cropmark drawing
Browse files Browse the repository at this point in the history
  • Loading branch information
Cocoa committed Feb 14, 2024
1 parent f5322f0 commit c5f851a
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions src/utils/drawing.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

import { expect, describe, it } from 'vitest';

import { drawFoldlines } from './drawing.js';
import { drawFoldlines, drawCropmarks } from './drawing.js';
import { LINE_LEN } from '../constants.js';

const mockPaper = [50, 100];

describe('tests foldline drawing', () => {
const mockPaper = [50, 100];
const folioFoldsRotate = [
{ start: { x: 0, y: 50 }, end: { x: 50, y: 50 }, dashArray: [10, 5], opacity: 0.4 },
];
Expand Down Expand Up @@ -86,3 +88,43 @@ describe('tests foldline drawing', () => {
});
});
});

describe('tests cropmark drawing', () => {
const quartoMarks = [
{ start: { x: 0, y: 50 }, end: { x: LINE_LEN, y: 50 }, opacity: 0.4 },
{ start: { x: 50 - LINE_LEN, y: 50 }, end: { x: 50, y: 50 }, opacity: 0.4 },
];
const octavoMarks = [
{ start: { x: 25, y: 0 }, end: { x: 25, y: LINE_LEN }, opacity: 0.4 },
{ start: { x: 25, y: 100 - LINE_LEN }, end: { x: 25, y: 100 }, opacity: 0.4 },
{ start: { x: 25 - LINE_LEN, y: 50 }, end: { x: 25 + LINE_LEN, y: 50 }, opacity: 0.4 },
{ start: { x: 25, y: 50 - LINE_LEN }, end: { x: 25, y: 50 + LINE_LEN }, opacity: 0.4 },
...quartoMarks,
];
const sextidecimoMarks = [
{ start: { x: 0, y: 75 }, end: { x: LINE_LEN, y: 75 }, opacity: 0.4 },
{ start: { x: 50 - LINE_LEN, y: 75 }, end: { x: 50, y: 75 }, opacity: 0.4 },
{ start: { x: 0, y: 25 }, end: { x: LINE_LEN, y: 25 }, opacity: 0.4 },
{ start: { x: 50 - LINE_LEN, y: 25 }, end: { x: 50, y: 25 }, opacity: 0.4 },
{ start: { x: 25 - LINE_LEN, y: 75 }, end: { x: 25 + LINE_LEN, y: 75 }, opacity: 0.4 },
{ start: { x: 25, y: 75 - LINE_LEN }, end: { x: 25, y: 75 + LINE_LEN }, opacity: 0.4 },
{ start: { x: 25 - LINE_LEN, y: 25 }, end: { x: 25 + LINE_LEN, y: 25 }, opacity: 0.4 },
{ start: { x: 25, y: 25 - LINE_LEN }, end: { x: 25, y: 25 + LINE_LEN }, opacity: 0.4 },
...octavoMarks,
];

const results = {
4: [],
8: quartoMarks,
16: octavoMarks,
32: sextidecimoMarks,
};
Object.keys(results).forEach((key) => {
const expected = results[key];
const intKey = parseInt(key, 10);
it(`produces the correct cropmarks for ${key}-per-sheet layouts`, () => {
const actual = drawCropmarks(mockPaper, intKey);
expect(actual).toEqual(expected);
});
});
});

0 comments on commit c5f851a

Please sign in to comment.