@umituz/web-dashboard 11.6.1 → 11.8.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/README.md +12 -0
- package/package.json +3 -3
- package/src/domains/calendar/calendar.css +0 -649
- package/src/domains/calendar/components/index.ts +12 -10
- package/src/domains/calendar/types/view.types.ts +8 -51
- package/src/domains/calendar/utils/index.ts +30 -49
- package/src/domains/calendar/utils/layout.ts +31 -221
- package/src/domains/calendar/components/Calendar.test.tsx +0 -106
- package/src/domains/calendar/components/Calendar.tsx +0 -211
- package/src/domains/calendar/components/CalendarAgenda.test.tsx +0 -73
- package/src/domains/calendar/components/CalendarAgenda.tsx +0 -105
- package/src/domains/calendar/components/CalendarMonth.test.tsx +0 -59
- package/src/domains/calendar/components/CalendarMonth.tsx +0 -109
- package/src/domains/calendar/components/CalendarResourceTimeline.test.tsx +0 -93
- package/src/domains/calendar/components/CalendarResourceTimeline.tsx +0 -164
- package/src/domains/calendar/components/CalendarTimeGrid.test.tsx +0 -99
- package/src/domains/calendar/components/CalendarTimeGrid.tsx +0 -182
- package/src/domains/calendar/utils/layout.test.ts +0 -144
|
@@ -1,51 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
payload?: unknown;
|
|
19
|
-
resourceId?: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface CalendarLegendEntry {
|
|
23
|
-
tone: CalendarTone;
|
|
24
|
-
label: string;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface CalendarLabels {
|
|
28
|
-
today: string;
|
|
29
|
-
previous: string;
|
|
30
|
-
next: string;
|
|
31
|
-
month: string;
|
|
32
|
-
week: string;
|
|
33
|
-
day: string;
|
|
34
|
-
agenda: string;
|
|
35
|
-
allDay: string;
|
|
36
|
-
more: string;
|
|
37
|
-
emptyDay: string;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export const DEFAULT_CALENDAR_LABELS: CalendarLabels = {
|
|
41
|
-
today: 'Today',
|
|
42
|
-
previous: 'Previous',
|
|
43
|
-
next: 'Next',
|
|
44
|
-
month: 'Month',
|
|
45
|
-
week: 'Week',
|
|
46
|
-
day: 'Day',
|
|
47
|
-
agenda: 'Agenda',
|
|
48
|
-
allDay: 'All day',
|
|
49
|
-
more: '+{count} more',
|
|
50
|
-
emptyDay: 'Nothing scheduled',
|
|
51
|
-
};
|
|
1
|
+
export type {
|
|
2
|
+
CalendarTone,
|
|
3
|
+
CalendarScreenView,
|
|
4
|
+
CalendarItem,
|
|
5
|
+
CalendarLegendEntry,
|
|
6
|
+
CalendarLabels,
|
|
7
|
+
} from '@umituz/web-design-system/organisms';
|
|
8
|
+
export { DEFAULT_CALENDAR_LABELS } from '@umituz/web-design-system/organisms';
|
|
@@ -1,40 +1,39 @@
|
|
|
1
|
+
import {
|
|
2
|
+
addDays,
|
|
3
|
+
eachDayOfInterval,
|
|
4
|
+
endOfMonth,
|
|
5
|
+
endOfWeek,
|
|
6
|
+
formatDate as formatDateWithStyle,
|
|
7
|
+
formatTime,
|
|
8
|
+
startOfMonth,
|
|
9
|
+
startOfWeek,
|
|
10
|
+
type WeekStartsOn,
|
|
11
|
+
} from '@umituz/web-design-system';
|
|
1
12
|
import type { CalendarConfig } from '../types/calendar.types';
|
|
2
13
|
|
|
3
14
|
export { mapCalendarDocument, mapPostDocument } from './contentItemMapper';
|
|
4
15
|
export * from './layout';
|
|
5
16
|
export type { FirestoreDocument } from './contentItemMapper';
|
|
17
|
+
export { isSameDay } from '@umituz/web-design-system';
|
|
6
18
|
|
|
7
19
|
export function getWeekDates(
|
|
8
20
|
date: Date,
|
|
9
|
-
|
|
21
|
+
weekStartsOn: number = 0,
|
|
10
22
|
): [Date, Date, Date, Date, Date, Date, Date] {
|
|
11
|
-
const anchor =
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
};
|
|
22
|
-
return [at(0), at(1), at(2), at(3), at(4), at(5), at(6)];
|
|
23
|
+
const anchor = startOfWeek(date, weekStartsOn as WeekStartsOn);
|
|
24
|
+
return [
|
|
25
|
+
addDays(anchor, 0),
|
|
26
|
+
addDays(anchor, 1),
|
|
27
|
+
addDays(anchor, 2),
|
|
28
|
+
addDays(anchor, 3),
|
|
29
|
+
addDays(anchor, 4),
|
|
30
|
+
addDays(anchor, 5),
|
|
31
|
+
addDays(anchor, 6),
|
|
32
|
+
];
|
|
23
33
|
}
|
|
24
34
|
|
|
25
35
|
export function getMonthDays(date: Date): Date[] {
|
|
26
|
-
|
|
27
|
-
const month = date.getMonth();
|
|
28
|
-
const days: Date[] = [];
|
|
29
|
-
|
|
30
|
-
const firstDay = new Date(year, month, 1);
|
|
31
|
-
const lastDay = new Date(year, month + 1, 0);
|
|
32
|
-
|
|
33
|
-
for (let d = new Date(firstDay); d <= lastDay; d.setDate(d.getDate() + 1)) {
|
|
34
|
-
days.push(new Date(d));
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return days;
|
|
36
|
+
return eachDayOfInterval({ start: startOfMonth(date), end: endOfMonth(date) });
|
|
38
37
|
}
|
|
39
38
|
|
|
40
39
|
export function isDateInRange(date: Date, range: { start: Date; end: Date }): boolean {
|
|
@@ -47,43 +46,25 @@ export function formatDate(
|
|
|
47
46
|
locale: string = 'en-US',
|
|
48
47
|
): string {
|
|
49
48
|
if (format === 'time') {
|
|
50
|
-
return date
|
|
51
|
-
hour: '2-digit',
|
|
52
|
-
minute: '2-digit',
|
|
53
|
-
});
|
|
49
|
+
return formatTime(date, { locale });
|
|
54
50
|
}
|
|
55
51
|
|
|
56
|
-
return date
|
|
52
|
+
return formatDateWithStyle(date, 'long', {
|
|
53
|
+
weekday: 'none',
|
|
57
54
|
month: format === 'long' ? 'long' : 'short',
|
|
58
|
-
|
|
59
|
-
year: 'numeric',
|
|
55
|
+
locale,
|
|
60
56
|
});
|
|
61
57
|
}
|
|
62
58
|
|
|
63
|
-
export function isSameDay(date1: Date, date2: Date): boolean {
|
|
64
|
-
return (
|
|
65
|
-
date1.getFullYear() === date2.getFullYear() &&
|
|
66
|
-
date1.getMonth() === date2.getMonth() &&
|
|
67
|
-
date1.getDate() === date2.getDate()
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
59
|
export function getViewRange(
|
|
72
60
|
view: 'month' | 'week',
|
|
73
61
|
date: Date,
|
|
74
62
|
): { start: Date; end: Date } {
|
|
75
63
|
if (view === 'month') {
|
|
76
|
-
|
|
77
|
-
const end = new Date(date.getFullYear(), date.getMonth() + 1, 0);
|
|
78
|
-
return { start, end };
|
|
64
|
+
return { start: startOfMonth(date), end: endOfMonth(date) };
|
|
79
65
|
}
|
|
80
66
|
|
|
81
|
-
|
|
82
|
-
const firstDay = new Date(week[0]);
|
|
83
|
-
firstDay.setHours(0, 0, 0, 0);
|
|
84
|
-
const lastDay = new Date(week[6]);
|
|
85
|
-
lastDay.setHours(23, 59, 59, 999);
|
|
86
|
-
return { start: firstDay, end: lastDay };
|
|
67
|
+
return { start: startOfWeek(date), end: endOfWeek(date) };
|
|
87
68
|
}
|
|
88
69
|
|
|
89
70
|
export function generateTimeSlots(
|
|
@@ -1,221 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function addMonthsKey(dayKey: string, months: number): string {
|
|
33
|
-
const date = parseDayKey(dayKey);
|
|
34
|
-
const dayOfMonth = date.getDate();
|
|
35
|
-
date.setDate(1);
|
|
36
|
-
date.setMonth(date.getMonth() + months);
|
|
37
|
-
const lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate();
|
|
38
|
-
date.setDate(Math.min(dayOfMonth, lastDay));
|
|
39
|
-
return toDayKey(date);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function startOfWeekKey(dayKey: string, weekStartsOn: 0 | 1 = 1): string {
|
|
43
|
-
const back = (parseDayKey(dayKey).getDay() + 7 - weekStartsOn) % 7;
|
|
44
|
-
return addDaysKey(dayKey, -back);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export function weekDays(anchorKey: string, weekStartsOn: 0 | 1 = 1): string[] {
|
|
48
|
-
const start = startOfWeekKey(anchorKey, weekStartsOn);
|
|
49
|
-
return Array.from({ length: 7 }, (_, index) => addDaysKey(start, index));
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function monthMatrix(anchorKey: string, weekStartsOn: 0 | 1 = 1): string[] {
|
|
53
|
-
const firstOfMonth = `${anchorKey.slice(0, 7)}-01`;
|
|
54
|
-
const start = startOfWeekKey(firstOfMonth, weekStartsOn);
|
|
55
|
-
return Array.from({ length: 42 }, (_, index) => addDaysKey(start, index));
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export function sameMonth(firstKey: string, secondKey: string): boolean {
|
|
59
|
-
return firstKey.slice(0, 7) === secondKey.slice(0, 7);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export function formatWeekdayShort(dayKey: string, locale = 'en-US'): string {
|
|
63
|
-
return parseDayKey(dayKey).toLocaleDateString(locale, { weekday: 'short' });
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export function formatDayNumber(dayKey: string): string {
|
|
67
|
-
return String(Number(dayKey.slice(8)));
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export function formatMonthTitle(anchorKey: string, locale = 'en-US'): string {
|
|
71
|
-
return parseDayKey(anchorKey).toLocaleDateString(locale, { month: 'long', year: 'numeric' });
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export function formatWeekTitle(anchorKey: string, locale = 'en-US'): string {
|
|
75
|
-
const days = weekDays(anchorKey);
|
|
76
|
-
const first = parseDayKey(days[0] ?? anchorKey);
|
|
77
|
-
const last = parseDayKey(days[6] ?? anchorKey);
|
|
78
|
-
const left = first.toLocaleDateString(locale, { month: 'short', day: 'numeric' });
|
|
79
|
-
const rightOptions: Intl.DateTimeFormatOptions =
|
|
80
|
-
first.getMonth() === last.getMonth()
|
|
81
|
-
? { day: 'numeric', year: 'numeric' }
|
|
82
|
-
: { month: 'short', day: 'numeric', year: 'numeric' };
|
|
83
|
-
return `${left} – ${last.toLocaleDateString(locale, rightOptions)}`;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export function formatDayTitle(dayKey: string, locale = 'en-US'): string {
|
|
87
|
-
return parseDayKey(dayKey).toLocaleDateString(locale, {
|
|
88
|
-
weekday: 'long',
|
|
89
|
-
month: 'long',
|
|
90
|
-
day: 'numeric',
|
|
91
|
-
year: 'numeric',
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export function formatAgendaTitle(anchorKey: string, days: number, locale = 'en-US'): string {
|
|
96
|
-
const span = Math.max(days - 1, 0);
|
|
97
|
-
const from = parseDayKey(anchorKey).toLocaleDateString(locale, { month: 'short', day: 'numeric' });
|
|
98
|
-
const to = parseDayKey(addDaysKey(anchorKey, span)).toLocaleDateString(locale, {
|
|
99
|
-
month: 'short',
|
|
100
|
-
day: 'numeric',
|
|
101
|
-
year: 'numeric',
|
|
102
|
-
});
|
|
103
|
-
return `${from} – ${to}`;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export function minutesToLabel(minutes: number): string {
|
|
107
|
-
const normalized = ((Math.round(minutes) % DAY_MINUTES) + DAY_MINUTES) % DAY_MINUTES;
|
|
108
|
-
return `${pad(Math.floor(normalized / 60))}:${pad(normalized % 60)}`;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export interface CalendarSpan {
|
|
112
|
-
startMin: number;
|
|
113
|
-
endMin: number;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export function itemSpan(item: CalendarItem): CalendarSpan {
|
|
117
|
-
const startMin = item.startMin ?? 0;
|
|
118
|
-
const endMin = item.endMin ?? Math.min(startMin + 60, DAY_MINUTES);
|
|
119
|
-
return { startMin, endMin: Math.max(endMin, startMin) };
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export function spansOverlap(first: CalendarSpan, second: CalendarSpan): boolean {
|
|
123
|
-
return first.startMin < second.endMin && second.startMin < first.endMin;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export function findConflicts<T extends CalendarItem>(items: readonly T[]): T[] {
|
|
127
|
-
const sorted = [...items]
|
|
128
|
-
.map((item) => ({ item, span: itemSpan(item) }))
|
|
129
|
-
.sort((first, second) => first.span.startMin - second.span.startMin);
|
|
130
|
-
const conflicted = new Set<string>();
|
|
131
|
-
for (let index = 0; index < sorted.length; index += 1) {
|
|
132
|
-
for (let other = index + 1; other < sorted.length; other += 1) {
|
|
133
|
-
if (sorted[other]!.span.startMin >= sorted[index]!.span.endMin) break;
|
|
134
|
-
conflicted.add(sorted[index]!.item.id);
|
|
135
|
-
conflicted.add(sorted[other]!.item.id);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
return items.filter((item) => conflicted.has(item.id));
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
export interface PositionedItem<T extends CalendarItem> {
|
|
142
|
-
item: T;
|
|
143
|
-
column: number;
|
|
144
|
-
columns: number;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export function layoutColumns<T extends CalendarItem>(items: readonly T[]): PositionedItem<T>[] {
|
|
148
|
-
const sorted = [...items].sort((first, second) => {
|
|
149
|
-
const firstSpan = itemSpan(first);
|
|
150
|
-
const secondSpan = itemSpan(second);
|
|
151
|
-
return firstSpan.startMin === secondSpan.startMin
|
|
152
|
-
? secondSpan.endMin - firstSpan.endMin
|
|
153
|
-
: firstSpan.startMin - secondSpan.startMin;
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
const placed: PositionedItem<T>[] = [];
|
|
157
|
-
let cluster: PositionedItem<T>[] = [];
|
|
158
|
-
let clusterEnd = -1;
|
|
159
|
-
|
|
160
|
-
const flush = () => {
|
|
161
|
-
for (const entry of cluster) entry.columns = cluster.length;
|
|
162
|
-
placed.push(...cluster);
|
|
163
|
-
cluster = [];
|
|
164
|
-
clusterEnd = -1;
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
for (const item of sorted) {
|
|
168
|
-
const span = itemSpan(item);
|
|
169
|
-
if (cluster.length > 0 && span.startMin >= clusterEnd) flush();
|
|
170
|
-
clusterEnd = Math.max(clusterEnd, span.endMin);
|
|
171
|
-
const column = cluster.findIndex((entry) => itemSpan(entry.item).endMin <= span.startMin);
|
|
172
|
-
cluster.push({ item, column: column === -1 ? cluster.length : column, columns: 1 });
|
|
173
|
-
}
|
|
174
|
-
flush();
|
|
175
|
-
return placed;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
export function eventGeometry(
|
|
179
|
-
item: CalendarItem,
|
|
180
|
-
dayStartMin: number,
|
|
181
|
-
dayEndMin: number,
|
|
182
|
-
): { top: number; height: number } {
|
|
183
|
-
const span = itemSpan(item);
|
|
184
|
-
const total = Math.max(dayEndMin - dayStartMin, 1);
|
|
185
|
-
const start = (span.startMin - dayStartMin) / total;
|
|
186
|
-
const end = Math.min((span.endMin - dayStartMin) / total, 1);
|
|
187
|
-
const clampedStart = Math.max(start, 0);
|
|
188
|
-
return { top: clampedStart * 100, height: Math.max(end - clampedStart, 0.012) * 100 };
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
export interface DaySlot {
|
|
192
|
-
startMin: number;
|
|
193
|
-
endMin: number;
|
|
194
|
-
taken: boolean;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
export function generateDaySlots(
|
|
198
|
-
options: { startMin: number; endMin: number; durationMin: number; stepMin?: number },
|
|
199
|
-
booked: readonly CalendarSpan[] = [],
|
|
200
|
-
): DaySlot[] {
|
|
201
|
-
const step = options.stepMin ?? options.durationMin;
|
|
202
|
-
const slots: DaySlot[] = [];
|
|
203
|
-
for (let start = options.startMin; start + options.durationMin <= options.endMin; start += step) {
|
|
204
|
-
const slot = { startMin: start, endMin: start + options.durationMin };
|
|
205
|
-
slots.push({ ...slot, taken: booked.some((span) => spansOverlap(slot, span)) });
|
|
206
|
-
}
|
|
207
|
-
return slots;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
export function groupByDayKey<T extends CalendarItem>(items: readonly T[]): Map<string, T[]> {
|
|
211
|
-
const map = new Map<string, T[]>();
|
|
212
|
-
for (const item of items) {
|
|
213
|
-
const bucket = map.get(item.dayKey);
|
|
214
|
-
if (bucket) bucket.push(item);
|
|
215
|
-
else map.set(item.dayKey, [item]);
|
|
216
|
-
}
|
|
217
|
-
for (const bucket of map.values()) {
|
|
218
|
-
bucket.sort((first, second) => itemSpan(first).startMin - itemSpan(second).startMin);
|
|
219
|
-
}
|
|
220
|
-
return map;
|
|
221
|
-
}
|
|
1
|
+
export {
|
|
2
|
+
DAY_MINUTES,
|
|
3
|
+
DEFAULT_DAY_START_MIN,
|
|
4
|
+
DEFAULT_DAY_END_MIN,
|
|
5
|
+
DEFAULT_MAX_PER_DAY,
|
|
6
|
+
SLOT_QUANTUM_MIN,
|
|
7
|
+
parseDayKey,
|
|
8
|
+
toDayKey,
|
|
9
|
+
todayKey,
|
|
10
|
+
addDaysKey,
|
|
11
|
+
addMonthsKey,
|
|
12
|
+
startOfWeekKey,
|
|
13
|
+
weekDays,
|
|
14
|
+
monthMatrix,
|
|
15
|
+
sameMonth,
|
|
16
|
+
formatWeekdayShort,
|
|
17
|
+
formatDayNumber,
|
|
18
|
+
formatMonthTitle,
|
|
19
|
+
formatWeekTitle,
|
|
20
|
+
formatDayTitle,
|
|
21
|
+
formatAgendaTitle,
|
|
22
|
+
minutesToLabel,
|
|
23
|
+
itemSpan,
|
|
24
|
+
spansOverlap,
|
|
25
|
+
findConflicts,
|
|
26
|
+
layoutColumns,
|
|
27
|
+
eventGeometry,
|
|
28
|
+
generateDaySlots,
|
|
29
|
+
groupByDayKey,
|
|
30
|
+
} from '@umituz/web-design-system/organisms';
|
|
31
|
+
export type { CalendarSpan, DaySlot, PositionedItem } from '@umituz/web-design-system/organisms';
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import { fireEvent, render, screen } from '@testing-library/react';
|
|
3
|
-
import { Calendar } from './Calendar';
|
|
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 Calendar>[0]> = {}) =>
|
|
15
|
-
render(
|
|
16
|
-
<Calendar
|
|
17
|
-
items={[item('Kickoff', '2026-03-15', 600, 660)]}
|
|
18
|
-
cursor="2026-03-10"
|
|
19
|
-
{...props}
|
|
20
|
-
/>,
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
describe('Calendar', () => {
|
|
24
|
-
it('renders the month grid with a localized title by default', () => {
|
|
25
|
-
const { container } = mount();
|
|
26
|
-
expect(screen.getByText('March 2026')).toBeTruthy();
|
|
27
|
-
expect(container.querySelectorAll('[role="gridcell"]')).toHaveLength(42);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('switches to a seven-lane week grid and a single day grid', () => {
|
|
31
|
-
mount();
|
|
32
|
-
fireEvent.click(screen.getByText('Week'));
|
|
33
|
-
expect(screen.getByRole('region', { name: '2026-03-15' })).toBeTruthy();
|
|
34
|
-
fireEvent.click(screen.getByText('Day'));
|
|
35
|
-
expect(screen.getByText('Tuesday, March 10, 2026')).toBeTruthy();
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('drills from a month cell into the day view', () => {
|
|
39
|
-
const onSelectDay = vi.fn();
|
|
40
|
-
render(
|
|
41
|
-
<Calendar
|
|
42
|
-
items={[item('Kickoff', '2026-03-15', 600, 660)]}
|
|
43
|
-
initialCursor="2026-03-10"
|
|
44
|
-
onSelectDay={onSelectDay}
|
|
45
|
-
/>,
|
|
46
|
-
);
|
|
47
|
-
fireEvent.click(screen.getByRole('button', { name: '2026-03-15' }));
|
|
48
|
-
expect(onSelectDay).toHaveBeenCalledWith('2026-03-15');
|
|
49
|
-
expect(screen.getByText('Sunday, March 15, 2026')).toBeTruthy();
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('stays in the month view when the day view is not offered', () => {
|
|
53
|
-
render(
|
|
54
|
-
<Calendar
|
|
55
|
-
items={[{ id: 'Expiry', dayKey: '2026-03-15', title: 'Expiry' }]}
|
|
56
|
-
initialCursor="2026-03-10"
|
|
57
|
-
views={['month', 'agenda']}
|
|
58
|
-
/>,
|
|
59
|
-
);
|
|
60
|
-
fireEvent.click(screen.getByRole('button', { name: '2026-03-15' }));
|
|
61
|
-
expect(screen.getByText('March 2026')).toBeTruthy();
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('respects a controlled view', () => {
|
|
65
|
-
mount({ view: 'day' });
|
|
66
|
-
expect(screen.getByText('Tuesday, March 10, 2026')).toBeTruthy();
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('reports view changes', () => {
|
|
70
|
-
const onViewChange = vi.fn();
|
|
71
|
-
mount({ onViewChange });
|
|
72
|
-
fireEvent.click(screen.getByText('Week'));
|
|
73
|
-
expect(onViewChange).toHaveBeenCalledWith('week');
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('renders the legend', () => {
|
|
77
|
-
mount({ legend: [{ tone: 'success', label: 'Confirmed' }] });
|
|
78
|
-
expect(screen.getByText('Confirmed')).toBeTruthy();
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('renders toolbar extras inside the toolbar', () => {
|
|
82
|
-
mount({ toolbarExtra: <span className="calendar-count">4 appointments</span> });
|
|
83
|
-
const extra = screen.getByText('4 appointments').closest('.udb-cal-extra');
|
|
84
|
-
expect(extra).toBeTruthy();
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it('switches to the agenda view with a window title', () => {
|
|
88
|
-
mount({ views: ['month', 'agenda'] });
|
|
89
|
-
fireEvent.click(screen.getByText('Agenda'));
|
|
90
|
-
expect(screen.getByText('Mar 10 – Apr 8, 2026')).toBeTruthy();
|
|
91
|
-
expect(screen.getByRole('button', { name: /Kickoff/ })).toBeTruthy();
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it('shifts the agenda window by agendaDays', () => {
|
|
95
|
-
render(
|
|
96
|
-
<Calendar
|
|
97
|
-
items={[item('Kickoff', '2026-03-15', 600, 660)]}
|
|
98
|
-
initialCursor="2026-03-10"
|
|
99
|
-
views={['agenda']}
|
|
100
|
-
agendaDays={30}
|
|
101
|
-
/>,
|
|
102
|
-
);
|
|
103
|
-
fireEvent.click(screen.getByRole('button', { name: 'Next' }));
|
|
104
|
-
expect(screen.getByText('Apr 9 – May 8, 2026')).toBeTruthy();
|
|
105
|
-
});
|
|
106
|
-
});
|