feat: add edutainment drawing and visual package flows
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
import { describe, expect, test } from 'vitest';
|
||||
|
||||
import {
|
||||
appendPointToStroke,
|
||||
BABY_LOVE_DRAWING_BUTTON_HOVER_MS,
|
||||
BABY_LOVE_DRAWING_COLOR_HOVER_MS,
|
||||
createBabyDrawingStroke,
|
||||
hasHoverCompleted,
|
||||
isPointInsideBounds,
|
||||
resolveHoverProgress,
|
||||
toCanvasPoint,
|
||||
} from './babyLoveDrawingModel';
|
||||
|
||||
describe('babyLoveDrawingModel', () => {
|
||||
test('completes color hover after 1.5 seconds', () => {
|
||||
const target = { kind: 'color' as const, id: 'red' };
|
||||
|
||||
expect(
|
||||
hasHoverCompleted(
|
||||
target,
|
||||
1000,
|
||||
1000 + BABY_LOVE_DRAWING_COLOR_HOVER_MS - 1,
|
||||
),
|
||||
).toBe(false);
|
||||
expect(
|
||||
hasHoverCompleted(
|
||||
target,
|
||||
1000,
|
||||
1000 + BABY_LOVE_DRAWING_COLOR_HOVER_MS,
|
||||
),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
test('completes button hover after 2 seconds', () => {
|
||||
const target = { kind: 'button' as const, id: 'finish' };
|
||||
|
||||
expect(
|
||||
hasHoverCompleted(
|
||||
target,
|
||||
1000,
|
||||
1000 + BABY_LOVE_DRAWING_BUTTON_HOVER_MS - 1,
|
||||
),
|
||||
).toBe(false);
|
||||
expect(
|
||||
hasHoverCompleted(
|
||||
target,
|
||||
1000,
|
||||
1000 + BABY_LOVE_DRAWING_BUTTON_HOVER_MS,
|
||||
),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
test('clamps hover progress and canvas point into unit bounds', () => {
|
||||
const bounds = {
|
||||
left: 0.25,
|
||||
top: 0.2,
|
||||
width: 0.5,
|
||||
height: 0.4,
|
||||
};
|
||||
|
||||
expect(resolveHoverProgress(null, null, 1000)).toBe(0);
|
||||
expect(resolveHoverProgress({ kind: 'color', id: 'red' }, 0, 999999)).toBe(
|
||||
1,
|
||||
);
|
||||
expect(isPointInsideBounds({ x: 0.4, y: 0.3 }, bounds)).toBe(true);
|
||||
expect(isPointInsideBounds({ x: 0.1, y: 0.3 }, bounds)).toBe(false);
|
||||
expect(toCanvasPoint({ x: 0.5, y: 0.4 }, bounds)).toMatchObject({
|
||||
x: 0.5,
|
||||
y: 0.5,
|
||||
});
|
||||
expect(toCanvasPoint({ x: 0.9, y: 0.9 }, bounds)).toMatchObject({
|
||||
x: 1,
|
||||
y: 1,
|
||||
});
|
||||
});
|
||||
|
||||
test('creates and extends stroke trace without mutating previous stroke', () => {
|
||||
const stroke = createBabyDrawingStroke('brush', '#ef4444', {
|
||||
x: 0.1,
|
||||
y: 0.2,
|
||||
t: 1,
|
||||
});
|
||||
const nextStroke = appendPointToStroke(stroke, {
|
||||
x: 0.3,
|
||||
y: 0.4,
|
||||
t: 2,
|
||||
});
|
||||
|
||||
expect(stroke.points).toHaveLength(1);
|
||||
expect(nextStroke.points).toHaveLength(2);
|
||||
expect(nextStroke).toMatchObject({
|
||||
tool: 'brush',
|
||||
color: '#ef4444',
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user