..
This commit is contained in:
parent
9689bfcc18
commit
62a385e4c9
33 changed files with 2649 additions and 809 deletions
|
|
@ -4,12 +4,8 @@ import { describe, expect, it } from 'vitest';
|
|||
import { FlooringPreview, SkirtingPreview } from '../src/components/CutPreview';
|
||||
import { CutDialog } from '../src/components/CutDialog';
|
||||
import { defaultProject } from '../src/lib/defaults';
|
||||
import {
|
||||
dimensionedOutline,
|
||||
exactMm,
|
||||
flooringTemplate,
|
||||
skirtingEndBoxes,
|
||||
} from '../src/lib/cut-preview';
|
||||
import { dimensionedOutline, flooringTemplate, skirtingEndBoxes } from '../src/lib/cut-preview';
|
||||
import { cutMm, degree } from '../src/lib/format';
|
||||
import type { FlooringPiece, Point, SkirtingPiece } from '../src/lib/types';
|
||||
|
||||
const floor: FlooringPiece = {
|
||||
|
|
@ -50,7 +46,7 @@ const skirt: SkirtingPiece = {
|
|||
};
|
||||
|
||||
describe('cut shape previews', () => {
|
||||
it('draws rectangular floor cuts too, keeping their precise measured dimensions', () => {
|
||||
it('keeps precise geometry while rounding displayed cuts up to half millimetres', () => {
|
||||
const points = flooringTemplate(floor);
|
||||
expect(points).toEqual([
|
||||
{ x: 0, y: 0 },
|
||||
|
|
@ -61,11 +57,11 @@ describe('cut shape previews', () => {
|
|||
const markup = renderToStaticMarkup(createElement(FlooringPreview, { piece: floor }));
|
||||
expect(markup).toContain('aria-label="Flooring shape F1"');
|
||||
expect(markup).toContain('preserveAspectRatio="xMidYMid meet"');
|
||||
expect(markup).toContain('600.001 × 190 mm');
|
||||
expect(markup).toContain('>600.001</text>');
|
||||
expect(markup).toContain('600.5 × 190 mm');
|
||||
expect(markup).toContain('>600.5</text>');
|
||||
expect(markup).toContain('>190</text>');
|
||||
expect(markup.match(/class="dimension-label"/g)).toHaveLength(2);
|
||||
expect(exactMm(600.001)).toBe('600.001');
|
||||
expect(cutMm(600.001)).toBe('600.5');
|
||||
});
|
||||
|
||||
it('keeps skirting endpoints in original coordinates and gives both ends equal square windows', () => {
|
||||
|
|
@ -166,9 +162,9 @@ describe('cut shape previews', () => {
|
|||
expect(preview.dimensions[1].text).toBe('200');
|
||||
const angle = preview.dimensions[1].angle!;
|
||||
expect(angle).toBeCloseTo(53.130102, 6);
|
||||
const markedAngle = (Number(exactMm(angle)) * Math.PI) / 180;
|
||||
expect(200 * Math.cos(markedAngle)).toBeCloseTo(120, 2);
|
||||
expect(200 * Math.sin(markedAngle)).toBeCloseTo(160, 2);
|
||||
const markedAngle = (Number(degree(angle).replace('°', '')) * Math.PI) / 180;
|
||||
expect(Math.abs(200 * Math.cos(markedAngle) - 120)).toBeLessThan(0.5);
|
||||
expect(Math.abs(200 * Math.sin(markedAngle) - 160)).toBeLessThan(0.5);
|
||||
expect(preview.dimensions[1].start).toEqual({ x: 800, y: 0 });
|
||||
expect(preview.dimensions[1].end).toEqual({ x: 920, y: 160 });
|
||||
const reversed = dimensionedOutline([...points].reverse());
|
||||
|
|
@ -181,7 +177,7 @@ describe('cut shape previews', () => {
|
|||
piece: { ...floor, length: 920, width: 160, shaped: true, template: points },
|
||||
}),
|
||||
);
|
||||
expect(markup).toContain('>53.13°</tspan>');
|
||||
expect(markup).toContain('>53.1°</tspan>');
|
||||
expect(markup).toContain('angles from horizontal');
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue