1
This commit is contained in:
@@ -4,6 +4,9 @@ import { afterEach, describe, expect, test, vi } from 'vitest';
|
||||
|
||||
import {
|
||||
PUZZLE_REFERENCE_IMAGE_MAX_DATA_URL_LENGTH,
|
||||
cropPuzzleReferenceImageDataUrl,
|
||||
isPuzzleReferenceImageSquare,
|
||||
readPuzzleReferenceImageForUpload,
|
||||
readPuzzleReferenceImageAsDataUrl,
|
||||
} from './puzzleReferenceImage';
|
||||
|
||||
@@ -115,3 +118,53 @@ describe('readPuzzleReferenceImageAsDataUrl', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('puzzle reference image square crop helpers', () => {
|
||||
test('reports square upload dimensions without opening crop flow', async () => {
|
||||
const sourceDataUrl = 'data:image/png;base64,square';
|
||||
stubFileReader(sourceDataUrl);
|
||||
stubImage(512, 512);
|
||||
|
||||
const file = new File(['x'], 'square.png', { type: 'image/png' });
|
||||
const result = await readPuzzleReferenceImageForUpload(file);
|
||||
|
||||
expect(result).toEqual({
|
||||
dataUrl: sourceDataUrl,
|
||||
width: 512,
|
||||
height: 512,
|
||||
});
|
||||
expect(isPuzzleReferenceImageSquare(result)).toBe(true);
|
||||
});
|
||||
|
||||
test('crops non-square uploads to a centered square data URL', async () => {
|
||||
const sourceDataUrl = 'data:image/png;base64,wide';
|
||||
const croppedDataUrl = 'data:image/jpeg;base64,cropped';
|
||||
stubImage(800, 600);
|
||||
const { drawImage, toDataURL } = stubCanvas([
|
||||
`data:image/jpeg;base64,${'A'.repeat(30)}`,
|
||||
croppedDataUrl,
|
||||
`data:image/jpeg;base64,${'B'.repeat(40)}`,
|
||||
]);
|
||||
|
||||
const dataUrl = await cropPuzzleReferenceImageDataUrl({
|
||||
source: sourceDataUrl,
|
||||
cropX: 100,
|
||||
cropY: 0,
|
||||
cropSize: 600,
|
||||
});
|
||||
|
||||
expect(dataUrl).toBe(croppedDataUrl);
|
||||
expect(drawImage).toHaveBeenCalledWith(
|
||||
expect.anything(),
|
||||
100,
|
||||
0,
|
||||
600,
|
||||
600,
|
||||
0,
|
||||
0,
|
||||
600,
|
||||
600,
|
||||
);
|
||||
expect(toDataURL).toHaveBeenCalledWith('image/jpeg', 0.88);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user