@umituz/web-dashboard 8.3.0 → 8.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -2
- package/src/domains/calendar/calendar.css +335 -0
- package/src/domains/calendar/components/Calendar.test.tsx +68 -0
- package/src/domains/calendar/components/Calendar.tsx +185 -0
- package/src/domains/calendar/components/CalendarMonth.test.tsx +59 -0
- package/src/domains/calendar/components/CalendarMonth.tsx +109 -0
- package/src/domains/calendar/components/CalendarTimeGrid.test.tsx +72 -0
- package/src/domains/calendar/components/CalendarTimeGrid.tsx +143 -0
- package/src/domains/calendar/components/index.ts +6 -0
- package/src/domains/calendar/index.ts +2 -1
- package/src/domains/calendar/types/index.ts +2 -0
- package/src/domains/calendar/types/view.types.ts +45 -0
- package/src/domains/calendar/utils/index.ts +1 -0
- package/src/domains/calendar/utils/layout.test.ts +144 -0
- package/src/domains/calendar/utils/layout.ts +210 -0
- package/src/domains/charts/components.tsx +3 -2
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
DEFAULT_CALENDAR_LABELS,
|
|
4
|
+
type CalendarItem,
|
|
5
|
+
type CalendarLabels,
|
|
6
|
+
} from '../types/view.types';
|
|
7
|
+
import {
|
|
8
|
+
formatDayNumber,
|
|
9
|
+
formatWeekdayShort,
|
|
10
|
+
groupByDayKey,
|
|
11
|
+
minutesToLabel,
|
|
12
|
+
monthMatrix,
|
|
13
|
+
sameMonth,
|
|
14
|
+
todayKey,
|
|
15
|
+
weekDays,
|
|
16
|
+
} from '../utils/layout';
|
|
17
|
+
|
|
18
|
+
export interface CalendarMonthProps {
|
|
19
|
+
items: readonly CalendarItem[];
|
|
20
|
+
anchorKey: string;
|
|
21
|
+
weekStartsOn?: 0 | 1;
|
|
22
|
+
locale?: string;
|
|
23
|
+
maxPerDay?: number;
|
|
24
|
+
labels?: Partial<CalendarLabels>;
|
|
25
|
+
onSelectDay?: (dayKey: string) => void;
|
|
26
|
+
onSelectItem?: (item: CalendarItem) => void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const CalendarMonth = ({
|
|
30
|
+
items,
|
|
31
|
+
anchorKey,
|
|
32
|
+
weekStartsOn = 1,
|
|
33
|
+
locale = 'en-US',
|
|
34
|
+
maxPerDay = 3,
|
|
35
|
+
labels,
|
|
36
|
+
onSelectDay,
|
|
37
|
+
onSelectItem,
|
|
38
|
+
}: CalendarMonthProps) => {
|
|
39
|
+
const text = { ...DEFAULT_CALENDAR_LABELS, ...labels };
|
|
40
|
+
const today = todayKey();
|
|
41
|
+
const cells = useMemo(() => monthMatrix(anchorKey, weekStartsOn), [anchorKey, weekStartsOn]);
|
|
42
|
+
const byDay = useMemo(() => groupByDayKey(items), [items]);
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<div className="udb-cal-month" role="grid">
|
|
46
|
+
<div className="udb-cal-month-head" role="row">
|
|
47
|
+
{weekDays(anchorKey, weekStartsOn).map((dayKey) => (
|
|
48
|
+
<div className="udb-cal-month-weekday" role="columnheader" key={dayKey}>
|
|
49
|
+
{formatWeekdayShort(dayKey, locale)}
|
|
50
|
+
</div>
|
|
51
|
+
))}
|
|
52
|
+
</div>
|
|
53
|
+
<div className="udb-cal-month-body">
|
|
54
|
+
{cells.map((dayKey) => {
|
|
55
|
+
const dayItems = byDay.get(dayKey) ?? [];
|
|
56
|
+
const visible = dayItems.slice(0, maxPerDay);
|
|
57
|
+
const overflow = dayItems.length - visible.length;
|
|
58
|
+
return (
|
|
59
|
+
<div
|
|
60
|
+
className={
|
|
61
|
+
sameMonth(dayKey, anchorKey) ? 'udb-cal-month-cell' : 'udb-cal-month-cell is-outside'
|
|
62
|
+
}
|
|
63
|
+
role="gridcell"
|
|
64
|
+
key={dayKey}
|
|
65
|
+
>
|
|
66
|
+
<button
|
|
67
|
+
type="button"
|
|
68
|
+
className={dayKey === today ? 'udb-cal-month-daynum is-today' : 'udb-cal-month-daynum'}
|
|
69
|
+
onClick={() => onSelectDay?.(dayKey)}
|
|
70
|
+
aria-label={dayKey}
|
|
71
|
+
>
|
|
72
|
+
{formatDayNumber(dayKey)}
|
|
73
|
+
</button>
|
|
74
|
+
<div className="udb-cal-month-chips">
|
|
75
|
+
{visible.map((item) => (
|
|
76
|
+
<button
|
|
77
|
+
type="button"
|
|
78
|
+
key={item.id}
|
|
79
|
+
className={
|
|
80
|
+
item.muted
|
|
81
|
+
? `udb-cal-chip udb-cal-chip--${item.tone ?? 'primary'} is-muted`
|
|
82
|
+
: `udb-cal-chip udb-cal-chip--${item.tone ?? 'primary'}`
|
|
83
|
+
}
|
|
84
|
+
onClick={() => onSelectItem?.(item)}
|
|
85
|
+
>
|
|
86
|
+
{item.icon}
|
|
87
|
+
{item.startMin !== undefined && (
|
|
88
|
+
<span className="udb-cal-chip-time">{minutesToLabel(item.startMin)}</span>
|
|
89
|
+
)}
|
|
90
|
+
<span className="udb-cal-chip-title">{item.title}</span>
|
|
91
|
+
</button>
|
|
92
|
+
))}
|
|
93
|
+
{overflow > 0 && (
|
|
94
|
+
<button
|
|
95
|
+
type="button"
|
|
96
|
+
className="udb-cal-chip-more"
|
|
97
|
+
onClick={() => onSelectDay?.(dayKey)}
|
|
98
|
+
>
|
|
99
|
+
{text.more.replace('{count}', String(overflow))}
|
|
100
|
+
</button>
|
|
101
|
+
)}
|
|
102
|
+
</div>
|
|
103
|
+
</div>
|
|
104
|
+
);
|
|
105
|
+
})}
|
|
106
|
+
</div>
|
|
107
|
+
</div>
|
|
108
|
+
);
|
|
109
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { fireEvent, render, screen } from '@testing-library/react';
|
|
3
|
+
import { CalendarTimeGrid } from './CalendarTimeGrid';
|
|
4
|
+
import type { CalendarItem } from '../types/view.types';
|
|
5
|
+
|
|
6
|
+
const item = (id: string, dayKey: string, startMin: number, endMin: number): CalendarItem => ({
|
|
7
|
+
id,
|
|
8
|
+
dayKey,
|
|
9
|
+
startMin,
|
|
10
|
+
endMin,
|
|
11
|
+
title: id,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const mount = (props: Partial<Parameters<typeof CalendarTimeGrid>[0]> = {}) =>
|
|
15
|
+
render(<CalendarTimeGrid items={[]} days={['2026-03-15']} {...props} />);
|
|
16
|
+
|
|
17
|
+
afterEach(() => {
|
|
18
|
+
vi.restoreAllMocks();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe('CalendarTimeGrid', () => {
|
|
22
|
+
it('positions timed events inside their day lane', () => {
|
|
23
|
+
mount({ items: [item('Consult', '2026-03-15', 600, 660)] });
|
|
24
|
+
const block = screen.getByText('Consult').closest('button') as HTMLElement;
|
|
25
|
+
expect(block.className).toContain('udb-cal-event');
|
|
26
|
+
expect(parseFloat(block.style.top)).toBeCloseTo(21.4286, 3);
|
|
27
|
+
expect(parseFloat(block.style.height)).toBeCloseTo(7.1429, 3);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('splits overlapping events into columns', () => {
|
|
31
|
+
mount({
|
|
32
|
+
items: [item('first', '2026-03-15', 600, 660), item('second', '2026-03-15', 630, 690)],
|
|
33
|
+
});
|
|
34
|
+
const first = screen.getByText('first').closest('button') as HTMLElement;
|
|
35
|
+
const second = screen.getByText('second').closest('button') as HTMLElement;
|
|
36
|
+
expect(first.style.width).toBe('calc(50% - 4px)');
|
|
37
|
+
expect(second.style.width).toBe('calc(50% - 4px)');
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('reports empty single days', () => {
|
|
41
|
+
mount();
|
|
42
|
+
expect(screen.getByText('Nothing scheduled')).toBeTruthy();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('quantizes empty-lane clicks to slot boundaries', () => {
|
|
46
|
+
const onSlotClick = vi.fn();
|
|
47
|
+
const { container } = mount({ onSlotClick });
|
|
48
|
+
vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockReturnValue({
|
|
49
|
+
top: 0,
|
|
50
|
+
height: 400,
|
|
51
|
+
bottom: 400,
|
|
52
|
+
left: 0,
|
|
53
|
+
right: 100,
|
|
54
|
+
width: 100,
|
|
55
|
+
x: 0,
|
|
56
|
+
y: 0,
|
|
57
|
+
toJSON: () => ({}),
|
|
58
|
+
} as DOMRect);
|
|
59
|
+
const lane = container.querySelector('.udb-cal-lane') as HTMLElement;
|
|
60
|
+
fireEvent.click(lane, { clientY: 100 });
|
|
61
|
+
expect(onSlotClick).toHaveBeenCalledWith('2026-03-15', 630);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('reports item selection from an event block', () => {
|
|
65
|
+
const onSelectItem = vi.fn();
|
|
66
|
+
mount({ items: [item('Consult', '2026-03-15', 600, 660)], onSelectItem });
|
|
67
|
+
fireEvent.click(screen.getByText('Consult'));
|
|
68
|
+
expect(onSelectItem).toHaveBeenCalledWith(
|
|
69
|
+
expect.objectContaining({ id: 'Consult' }),
|
|
70
|
+
);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import type { CSSProperties, MouseEvent } from 'react';
|
|
3
|
+
import {
|
|
4
|
+
DEFAULT_CALENDAR_LABELS,
|
|
5
|
+
type CalendarItem,
|
|
6
|
+
type CalendarLabels,
|
|
7
|
+
} from '../types/view.types';
|
|
8
|
+
import {
|
|
9
|
+
DEFAULT_DAY_END_MIN,
|
|
10
|
+
DEFAULT_DAY_START_MIN,
|
|
11
|
+
SLOT_QUANTUM_MIN,
|
|
12
|
+
eventGeometry,
|
|
13
|
+
formatDayNumber,
|
|
14
|
+
formatWeekdayShort,
|
|
15
|
+
groupByDayKey,
|
|
16
|
+
itemSpan,
|
|
17
|
+
layoutColumns,
|
|
18
|
+
minutesToLabel,
|
|
19
|
+
todayKey,
|
|
20
|
+
} from '../utils/layout';
|
|
21
|
+
|
|
22
|
+
export interface CalendarTimeGridProps {
|
|
23
|
+
items: readonly CalendarItem[];
|
|
24
|
+
days: readonly string[];
|
|
25
|
+
dayStartMin?: number;
|
|
26
|
+
dayEndMin?: number;
|
|
27
|
+
locale?: string;
|
|
28
|
+
labels?: Partial<CalendarLabels>;
|
|
29
|
+
onSelectItem?: (item: CalendarItem) => void;
|
|
30
|
+
onSlotClick?: (dayKey: string, minutes: number) => void;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const CalendarTimeGrid = ({
|
|
34
|
+
items,
|
|
35
|
+
days,
|
|
36
|
+
dayStartMin = DEFAULT_DAY_START_MIN,
|
|
37
|
+
dayEndMin = DEFAULT_DAY_END_MIN,
|
|
38
|
+
locale = 'en-US',
|
|
39
|
+
labels,
|
|
40
|
+
onSelectItem,
|
|
41
|
+
onSlotClick,
|
|
42
|
+
}: CalendarTimeGridProps) => {
|
|
43
|
+
const text = { ...DEFAULT_CALENDAR_LABELS, ...labels };
|
|
44
|
+
const today = todayKey();
|
|
45
|
+
const total = Math.max(dayEndMin - dayStartMin, 60);
|
|
46
|
+
|
|
47
|
+
const hours = useMemo(() => {
|
|
48
|
+
const first = Math.ceil(dayStartMin / 60) * 60;
|
|
49
|
+
const list: number[] = [];
|
|
50
|
+
for (let minute = first; minute < dayEndMin; minute += 60) list.push(minute);
|
|
51
|
+
return list;
|
|
52
|
+
}, [dayStartMin, dayEndMin]);
|
|
53
|
+
|
|
54
|
+
const timed = useMemo(() => items.filter((item) => item.startMin !== undefined), [items]);
|
|
55
|
+
const byDay = useMemo(() => groupByDayKey(timed), [timed]);
|
|
56
|
+
|
|
57
|
+
const positionOf = (minute: number): string =>
|
|
58
|
+
`${((minute - dayStartMin) / total) * 100}%`;
|
|
59
|
+
|
|
60
|
+
const handleLaneClick = (dayKey: string, event: MouseEvent<HTMLDivElement>) => {
|
|
61
|
+
if (!onSlotClick) return;
|
|
62
|
+
const bounds = event.currentTarget.getBoundingClientRect();
|
|
63
|
+
if (bounds.height <= 0) return;
|
|
64
|
+
const ratio = (event.clientY - bounds.top) / bounds.height;
|
|
65
|
+
const raw = dayStartMin + ratio * total;
|
|
66
|
+
const quantized = Math.floor(raw / SLOT_QUANTUM_MIN) * SLOT_QUANTUM_MIN;
|
|
67
|
+
if (quantized >= dayStartMin && quantized < dayEndMin) onSlotClick(dayKey, quantized);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<div
|
|
72
|
+
className="udb-cal-grid"
|
|
73
|
+
style={{ ['--udb-cal-days' as string]: days.length } as CSSProperties}
|
|
74
|
+
>
|
|
75
|
+
<div className="udb-cal-gutter" aria-hidden="true">
|
|
76
|
+
{hours.map((minute) => (
|
|
77
|
+
<div className="udb-cal-hour-label" style={{ top: positionOf(minute) }} key={minute}>
|
|
78
|
+
{minutesToLabel(minute)}
|
|
79
|
+
</div>
|
|
80
|
+
))}
|
|
81
|
+
</div>
|
|
82
|
+
|
|
83
|
+
{days.map((dayKey) => {
|
|
84
|
+
const dayItems = byDay.get(dayKey) ?? [];
|
|
85
|
+
return (
|
|
86
|
+
<section className="udb-cal-day" aria-label={dayKey} key={dayKey}>
|
|
87
|
+
<header className={dayKey === today ? 'udb-cal-day-head is-today' : 'udb-cal-day-head'}>
|
|
88
|
+
<span className="udb-cal-weekday">{formatWeekdayShort(dayKey, locale)}</span>
|
|
89
|
+
<span className="udb-cal-daynum">{formatDayNumber(dayKey)}</span>
|
|
90
|
+
</header>
|
|
91
|
+
<div
|
|
92
|
+
className="udb-cal-lane"
|
|
93
|
+
role="grid"
|
|
94
|
+
aria-label={dayKey}
|
|
95
|
+
onClick={(event) => handleLaneClick(dayKey, event)}
|
|
96
|
+
>
|
|
97
|
+
{hours.map((minute) => (
|
|
98
|
+
<div
|
|
99
|
+
className="udb-cal-hour-line"
|
|
100
|
+
style={{ top: positionOf(minute) }}
|
|
101
|
+
key={minute}
|
|
102
|
+
/>
|
|
103
|
+
))}
|
|
104
|
+
{layoutColumns(dayItems).map(({ item, column, columns }) => {
|
|
105
|
+
const geometry = eventGeometry(item, dayStartMin, dayEndMin);
|
|
106
|
+
return (
|
|
107
|
+
<button
|
|
108
|
+
type="button"
|
|
109
|
+
key={item.id}
|
|
110
|
+
className={
|
|
111
|
+
item.muted
|
|
112
|
+
? `udb-cal-event udb-cal-event--${item.tone ?? 'primary'} is-muted`
|
|
113
|
+
: `udb-cal-event udb-cal-event--${item.tone ?? 'primary'}`
|
|
114
|
+
}
|
|
115
|
+
style={{
|
|
116
|
+
top: `${geometry.top}%`,
|
|
117
|
+
height: `${geometry.height}%`,
|
|
118
|
+
left: `calc(${(column / columns) * 100}% + 2px)`,
|
|
119
|
+
width: `calc(${100 / columns}% - 4px)`,
|
|
120
|
+
}}
|
|
121
|
+
onClick={(click) => {
|
|
122
|
+
click.stopPropagation();
|
|
123
|
+
onSelectItem?.(item);
|
|
124
|
+
}}
|
|
125
|
+
>
|
|
126
|
+
<span className="udb-cal-event-time">
|
|
127
|
+
{minutesToLabel(itemSpan(item).startMin)}
|
|
128
|
+
</span>
|
|
129
|
+
<span className="udb-cal-event-title">{item.title}</span>
|
|
130
|
+
{item.meta}
|
|
131
|
+
</button>
|
|
132
|
+
);
|
|
133
|
+
})}
|
|
134
|
+
{days.length === 1 && dayItems.length === 0 && (
|
|
135
|
+
<p className="udb-cal-empty">{text.emptyDay}</p>
|
|
136
|
+
)}
|
|
137
|
+
</div>
|
|
138
|
+
</section>
|
|
139
|
+
);
|
|
140
|
+
})}
|
|
141
|
+
</div>
|
|
142
|
+
);
|
|
143
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { Calendar } from './Calendar';
|
|
2
|
+
export type { CalendarProps } from './Calendar';
|
|
3
|
+
export { CalendarMonth } from './CalendarMonth';
|
|
4
|
+
export type { CalendarMonthProps } from './CalendarMonth';
|
|
5
|
+
export { CalendarTimeGrid } from './CalendarTimeGrid';
|
|
6
|
+
export type { CalendarTimeGridProps } from './CalendarTimeGrid';
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
export type CalendarTone = 'primary' | 'success' | 'warning' | 'danger' | 'info' | 'neutral' | 'accent';
|
|
4
|
+
|
|
5
|
+
export type CalendarScreenView = 'month' | 'week' | 'day';
|
|
6
|
+
|
|
7
|
+
export interface CalendarItem {
|
|
8
|
+
id: string;
|
|
9
|
+
dayKey: string;
|
|
10
|
+
startMin?: number;
|
|
11
|
+
endMin?: number;
|
|
12
|
+
title: ReactNode;
|
|
13
|
+
tone?: CalendarTone;
|
|
14
|
+
icon?: ReactNode;
|
|
15
|
+
meta?: ReactNode;
|
|
16
|
+
kind?: string;
|
|
17
|
+
muted?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface CalendarLegendEntry {
|
|
21
|
+
tone: CalendarTone;
|
|
22
|
+
label: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface CalendarLabels {
|
|
26
|
+
today: string;
|
|
27
|
+
previous: string;
|
|
28
|
+
next: string;
|
|
29
|
+
month: string;
|
|
30
|
+
week: string;
|
|
31
|
+
day: string;
|
|
32
|
+
more: string;
|
|
33
|
+
emptyDay: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const DEFAULT_CALENDAR_LABELS: CalendarLabels = {
|
|
37
|
+
today: 'Today',
|
|
38
|
+
previous: 'Previous',
|
|
39
|
+
next: 'Next',
|
|
40
|
+
month: 'Month',
|
|
41
|
+
week: 'Week',
|
|
42
|
+
day: 'Day',
|
|
43
|
+
more: '+{count} more',
|
|
44
|
+
emptyDay: 'Nothing scheduled',
|
|
45
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { CalendarConfig } from '../types/calendar.types';
|
|
2
2
|
|
|
3
3
|
export { mapCalendarDocument, mapPostDocument } from './contentItemMapper';
|
|
4
|
+
export * from './layout';
|
|
4
5
|
export type { FirestoreDocument } from './contentItemMapper';
|
|
5
6
|
|
|
6
7
|
export function getWeekDates(date: Date, startOfWeek: number = 0): Date[] {
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
addDaysKey,
|
|
4
|
+
addMonthsKey,
|
|
5
|
+
eventGeometry,
|
|
6
|
+
findConflicts,
|
|
7
|
+
generateDaySlots,
|
|
8
|
+
groupByDayKey,
|
|
9
|
+
itemSpan,
|
|
10
|
+
layoutColumns,
|
|
11
|
+
minutesToLabel,
|
|
12
|
+
monthMatrix,
|
|
13
|
+
spansOverlap,
|
|
14
|
+
startOfWeekKey,
|
|
15
|
+
weekDays,
|
|
16
|
+
} from './layout';
|
|
17
|
+
import type { CalendarItem } from '../types/view.types';
|
|
18
|
+
|
|
19
|
+
const item = (id: string, dayKey: string, startMin?: number, endMin?: number): CalendarItem => ({
|
|
20
|
+
id,
|
|
21
|
+
dayKey,
|
|
22
|
+
startMin,
|
|
23
|
+
endMin,
|
|
24
|
+
title: id,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe('day keys', () => {
|
|
28
|
+
it('builds monday-based weeks', () => {
|
|
29
|
+
expect(weekDays('2026-03-10')).toEqual([
|
|
30
|
+
'2026-03-09',
|
|
31
|
+
'2026-03-10',
|
|
32
|
+
'2026-03-11',
|
|
33
|
+
'2026-03-12',
|
|
34
|
+
'2026-03-13',
|
|
35
|
+
'2026-03-14',
|
|
36
|
+
'2026-03-15',
|
|
37
|
+
]);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('honors sunday-based weeks', () => {
|
|
41
|
+
expect(startOfWeekKey('2026-03-10', 0)).toBe('2026-03-08');
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('builds a six-row month matrix', () => {
|
|
45
|
+
const matrix = monthMatrix('2026-03-10');
|
|
46
|
+
expect(matrix).toHaveLength(42);
|
|
47
|
+
expect(matrix[0]).toBe('2026-02-23');
|
|
48
|
+
expect(matrix[41]).toBe('2026-04-05');
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('clamps month shifts to month ends', () => {
|
|
52
|
+
expect(addMonthsKey('2026-03-31', -1)).toBe('2026-02-28');
|
|
53
|
+
expect(addDaysKey('2026-03-01', -1)).toBe('2026-02-28');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('formats minute-of-day labels', () => {
|
|
57
|
+
expect(minutesToLabel(630)).toBe('10:30');
|
|
58
|
+
expect(minutesToLabel(25 * 60 + 15)).toBe('01:15');
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe('spans', () => {
|
|
63
|
+
it('treats touching edges as non-overlapping', () => {
|
|
64
|
+
expect(spansOverlap({ startMin: 60, endMin: 120 }, { startMin: 120, endMin: 180 })).toBe(false);
|
|
65
|
+
expect(spansOverlap({ startMin: 60, endMin: 121 }, { startMin: 120, endMin: 180 })).toBe(true);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('defaults open spans to one hour', () => {
|
|
69
|
+
expect(itemSpan(item('a', '2026-03-10', 600))).toEqual({ startMin: 600, endMin: 660 });
|
|
70
|
+
expect(itemSpan(item('b', '2026-03-10'))).toEqual({ startMin: 0, endMin: 60 });
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('flags only items overlapping another', () => {
|
|
74
|
+
const items = [
|
|
75
|
+
item('a', '2026-03-10', 60, 120),
|
|
76
|
+
item('b', '2026-03-10', 90, 150),
|
|
77
|
+
item('c', '2026-03-10', 200, 260),
|
|
78
|
+
];
|
|
79
|
+
expect(findConflicts(items).map((entry) => entry.id).sort()).toEqual(['a', 'b']);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe('layoutColumns', () => {
|
|
84
|
+
it('gives overlapping events side-by-side columns', () => {
|
|
85
|
+
const placed = layoutColumns([
|
|
86
|
+
item('x', '2026-03-10', 60, 120),
|
|
87
|
+
item('y', '2026-03-10', 90, 150),
|
|
88
|
+
]);
|
|
89
|
+
const byId = new Map(placed.map((entry) => [entry.item.id, entry]));
|
|
90
|
+
expect(byId.get('x')?.columns).toBe(2);
|
|
91
|
+
expect(byId.get('y')?.columns).toBe(2);
|
|
92
|
+
expect(new Set(placed.map((entry) => entry.column))).toEqual(new Set([0, 1]));
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('splits clusters when events only touch', () => {
|
|
96
|
+
const placed = layoutColumns([
|
|
97
|
+
item('x', '2026-03-10', 60, 120),
|
|
98
|
+
item('z', '2026-03-10', 120, 180),
|
|
99
|
+
]);
|
|
100
|
+
expect(placed.every((entry) => entry.columns === 1)).toBe(true);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
describe('eventGeometry', () => {
|
|
105
|
+
it('positions events as percentages of the day range', () => {
|
|
106
|
+
const geometry = eventGeometry(item('a', '2026-03-10', 600, 660), 420, 1260);
|
|
107
|
+
expect(geometry.top).toBeCloseTo(21.43, 1);
|
|
108
|
+
expect(geometry.height).toBeCloseTo(7.14, 1);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('clamps events spilling outside the range', () => {
|
|
112
|
+
const geometry = eventGeometry(item('a', '2026-03-10', 300, 1300), 420, 1260);
|
|
113
|
+
expect(geometry.top).toBe(0);
|
|
114
|
+
expect(geometry.height).toBe(100);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
describe('generateDaySlots', () => {
|
|
119
|
+
it('marks slots intersecting booked spans as taken', () => {
|
|
120
|
+
const slots = generateDaySlots(
|
|
121
|
+
{ startMin: 420, endMin: 720, durationMin: 60 },
|
|
122
|
+
[{ startMin: 480, endMin: 540 }],
|
|
123
|
+
);
|
|
124
|
+
expect(slots.map((slot) => slot.startMin)).toEqual([420, 480, 540, 600, 660]);
|
|
125
|
+
expect(slots.map((slot) => slot.taken)).toEqual([false, true, false, false, false]);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('supports a step smaller than the duration', () => {
|
|
129
|
+
const slots = generateDaySlots({ startMin: 420, endMin: 540, durationMin: 60, stepMin: 30 });
|
|
130
|
+
expect(slots.map((slot) => slot.startMin)).toEqual([420, 450, 480]);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
describe('groupByDayKey', () => {
|
|
135
|
+
it('buckets by day and sorts by start minute', () => {
|
|
136
|
+
const grouped = groupByDayKey([
|
|
137
|
+
item('late', '2026-03-10', 900, 960),
|
|
138
|
+
item('early', '2026-03-10', 540, 600),
|
|
139
|
+
item('other-day', '2026-03-11', 600, 660),
|
|
140
|
+
]);
|
|
141
|
+
expect(grouped.get('2026-03-10')?.map((entry) => entry.id)).toEqual(['early', 'late']);
|
|
142
|
+
expect(grouped.get('2026-03-11')?.map((entry) => entry.id)).toEqual(['other-day']);
|
|
143
|
+
});
|
|
144
|
+
});
|