fix: polish pass for traffic, nav, icons, contact email reveal and dashcam robustness
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
coverCrop,
|
||||
drawPostcard,
|
||||
postcardLayout,
|
||||
postcardSize,
|
||||
type DashcamTelemetry,
|
||||
type PostcardContext,
|
||||
} from '@/lib/dashcam-postcard';
|
||||
@@ -15,7 +16,7 @@ const telemetry: DashcamTelemetry = {
|
||||
sectionLabel: 'Infrastructure',
|
||||
chapter: 'pre-dawn',
|
||||
exit: '04',
|
||||
routePercent: 47,
|
||||
routePercent: 45,
|
||||
clock: '03:51',
|
||||
name: 'Luca Pîslaru',
|
||||
city: 'Bucharest',
|
||||
@@ -53,6 +54,19 @@ function stubContext() {
|
||||
|
||||
const source = (width: number, height: number) => ({ width, height }) as unknown as HTMLCanvasElement;
|
||||
|
||||
describe('postcardSize', () => {
|
||||
it('keeps the buffer\'s own pixels: a 16:9 crop, never upscaled', () => {
|
||||
expect(postcardSize(1440, 900)).toEqual({ w: 1440, h: 810 });
|
||||
expect(postcardSize(1920, 1080)).toEqual({ w: 1920, h: 1080 });
|
||||
expect(postcardSize(1024, 1366)).toEqual({ w: 1024, h: 576 });
|
||||
});
|
||||
|
||||
it('downsamples only past the cap, and survives an empty buffer', () => {
|
||||
expect(postcardSize(2880, 1800)).toEqual({ w: 2560, h: 1440 });
|
||||
expect(postcardSize(0, 0)).toEqual({ w: POSTCARD_WIDTH, h: POSTCARD_HEIGHT });
|
||||
});
|
||||
});
|
||||
|
||||
describe('coverCrop', () => {
|
||||
it('crops a wider source to the 16:9 centre', () => {
|
||||
expect(coverCrop(2400, 900, 1600, 900)).toEqual({ sx: 400, sy: 0, sw: 1600, sh: 900 });
|
||||
@@ -99,15 +113,15 @@ describe('drawPostcard', () => {
|
||||
|
||||
expect(images).toEqual([[0, 90, 2880, 1620, 0, 0, POSTCARD_WIDTH, POSTCARD_HEIGHT]]);
|
||||
expect(texts.map((call) => call.text)).toEqual([
|
||||
'REC DASHCAM · PRE DAWN · EXIT 04',
|
||||
'ROUTE 47% · INFRASTRUCTURE',
|
||||
'REC DASHCAM · EXIT 04',
|
||||
'ROUTE 45% · INFRASTRUCTURE',
|
||||
'03:51',
|
||||
'LUCA PÎSLARU',
|
||||
DASHCAM_COORDINATES,
|
||||
'NIGHT SHIFT · LUCA PÎSLARU · BUCHAREST',
|
||||
]);
|
||||
const byText = Object.fromEntries(texts.map((call) => [call.text, call]));
|
||||
expect(byText['ROUTE 47% · INFRASTRUCTURE']).toMatchObject({ x: l.left, y: l.bottom, align: 'left' });
|
||||
expect(byText['ROUTE 45% · INFRASTRUCTURE']).toMatchObject({ x: l.left, y: l.bottom, align: 'left' });
|
||||
expect(byText['03:51']).toMatchObject({ x: l.right, y: l.top, align: 'right' });
|
||||
expect(byText[DASHCAM_COORDINATES]).toMatchObject({ x: l.right, y: l.bottom - l.lineGap, align: 'right' });
|
||||
expect(byText['NIGHT SHIFT · LUCA PÎSLARU · BUCHAREST']).toMatchObject({ x: 800, y: l.credit, align: 'center' });
|
||||
|
||||
Reference in New Issue
Block a user