24 lines
1.2 KiB
TypeScript
24 lines
1.2 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { movePlacement, normalizePlacement, overlaps, resizePlacement } from '../../src/dashboardSpatial';
|
|
|
|
describe('dashboard spatial layout', () => {
|
|
it('clamps placements to the active column budget', () => {
|
|
expect(normalizePlacement({ x: 17, y: -3, w: 6, h: 0 }, 'desktop')).toEqual({ x: 12, y: 0, w: 6, h: 1, visible: true });
|
|
expect(normalizePlacement({ x: 4, y: 3, w: 4, h: 5 }, 'mobile')).toEqual({ x: 0, y: 3, w: 1, h: 5, visible: true });
|
|
});
|
|
|
|
it('detects overlap and pushes a moved widget below collisions', () => {
|
|
const occupied = [{ id: 'a', placement: { x: 0, y: 0, w: 6, h: 4, visible: true } }];
|
|
expect(overlaps({ x: 0, y: 0, w: 2, h: 2 }, occupied[0].placement)).toBe(true);
|
|
expect(movePlacement({ x: 6, y: 0, w: 6, h: 4 }, -6, 0, occupied, 'desktop')).toMatchObject({ x: 0, y: 4, w: 6, h: 4 });
|
|
});
|
|
|
|
it('keeps resize within the viewport and resolves collisions', () => {
|
|
const occupied = [{ id: 'a', placement: { x: 8, y: 0, w: 4, h: 4, visible: true } }];
|
|
const resized = resizePlacement({ x: 0, y: 0, w: 6, h: 4 }, 6, 2, occupied, 'desktop');
|
|
expect(resized.w).toBe(12);
|
|
expect(resized.y).toBe(4);
|
|
expect(resized.h).toBe(6);
|
|
});
|
|
});
|