@jsb188/calendar 1.1.12 → 1.1.13
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/LICENSE +21 -0
- package/package.json +18 -12
- package/src/constants/calendar.ts +3 -7
- package/src/libs/calendar-range.ts +2 -3
- package/src/libs/calendar-url.ts +18 -41
- package/src/libs/roster-layout.ts +357 -288
- package/src/ui/CalendarToolbarUI.tsx +16 -12
- package/src/ui/RosterUI.tsx +135 -169
- package/src/types/shift-form.d.ts +0 -19
- package/src/ui/ShiftFormUI.tsx +0 -333
- package/tests/calendar-geometry.test.ts +0 -549
- package/tests/calendar-gesture.test.ts +0 -340
- package/tests/calendar-range.test.ts +0 -358
- package/tests/calendar-url.test.ts +0 -189
- package/tests/roster-layout.test.ts +0 -210
- package/tsconfig.json +0 -13
- package/vitest.config.ts +0 -11
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { getCalendarDateKey } from '../src/libs/calendar-range.ts';
|
|
3
|
-
import {
|
|
4
|
-
getCalendarViewSlug,
|
|
5
|
-
parseCalendarViewSlug,
|
|
6
|
-
readCalendarUrlState,
|
|
7
|
-
writeCalendarUrlState,
|
|
8
|
-
} from '../src/libs/calendar-url.ts';
|
|
9
|
-
|
|
10
|
-
const LA = 'America/Los_Angeles';
|
|
11
|
-
// A Wednesday
|
|
12
|
-
const NOW = new Date('2026-07-22T19:00:00Z');
|
|
13
|
-
|
|
14
|
-
/*
|
|
15
|
-
* Render the query string a write produces, for readable assertions.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
function write(
|
|
19
|
-
current: string,
|
|
20
|
-
next: Parameters<typeof writeCalendarUrlState>[1],
|
|
21
|
-
) {
|
|
22
|
-
return writeCalendarUrlState(
|
|
23
|
-
new URLSearchParams(current),
|
|
24
|
-
next,
|
|
25
|
-
NOW,
|
|
26
|
-
LA,
|
|
27
|
-
).toString();
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
describe('view slugs', () => {
|
|
31
|
-
it('spells views the way a person would read them', () => {
|
|
32
|
-
expect(getCalendarViewSlug('FOUR_DAYS')).toBe('4day');
|
|
33
|
-
expect(getCalendarViewSlug('WEEK')).toBe('week');
|
|
34
|
-
expect(getCalendarViewSlug('AGENDA')).toBe('agenda');
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('round-trips every slug', () => {
|
|
38
|
-
for (const view of [
|
|
39
|
-
'ROSTER',
|
|
40
|
-
'DAY',
|
|
41
|
-
'FOUR_DAYS',
|
|
42
|
-
'WEEK',
|
|
43
|
-
'MONTH',
|
|
44
|
-
'YEAR',
|
|
45
|
-
'AGENDA',
|
|
46
|
-
] as const) {
|
|
47
|
-
expect(parseCalendarViewSlug(getCalendarViewSlug(view))).toBe(view);
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('still accepts the enum spelling from an older link', () => {
|
|
52
|
-
expect(parseCalendarViewSlug('FOUR_DAYS')).toBe('FOUR_DAYS');
|
|
53
|
-
expect(parseCalendarViewSlug('month')).toBe('MONTH');
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('falls back to the week rather than throwing', () => {
|
|
57
|
-
expect(parseCalendarViewSlug('nonsense')).toBe('WEEK');
|
|
58
|
-
expect(parseCalendarViewSlug(null)).toBe('WEEK');
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
describe('readCalendarUrlState', () => {
|
|
63
|
-
it('reads a bare URL as this week, everything', () => {
|
|
64
|
-
const state = readCalendarUrlState(new URLSearchParams(''), NOW, LA);
|
|
65
|
-
|
|
66
|
-
expect(state.view).toBe('WEEK');
|
|
67
|
-
expect(getCalendarDateKey(state.anchorDate, LA)).toBe('2026-07-22');
|
|
68
|
-
expect(state.mineOnly).toBe(false);
|
|
69
|
-
expect(state.hiddenCalendarIds).toEqual([]);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('reads a full URL', () => {
|
|
73
|
-
const state = readCalendarUrlState(
|
|
74
|
-
new URLSearchParams('v=month&d=2026-03-01&me=1&hide=a,b'),
|
|
75
|
-
NOW,
|
|
76
|
-
LA,
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
expect(state.view).toBe('MONTH');
|
|
80
|
-
expect(getCalendarDateKey(state.anchorDate, LA)).toBe('2026-03-01');
|
|
81
|
-
expect(state.mineOnly).toBe(true);
|
|
82
|
-
expect(state.hiddenCalendarIds).toEqual(['a', 'b']);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('ignores blank entries in the calendar list', () => {
|
|
86
|
-
const state = readCalendarUrlState(
|
|
87
|
-
new URLSearchParams('hide=a,,b,'),
|
|
88
|
-
NOW,
|
|
89
|
-
LA,
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
expect(state.hiddenCalendarIds).toEqual(['a', 'b']);
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
describe('writeCalendarUrlState', () => {
|
|
97
|
-
it('writes nothing at all for the defaults', () => {
|
|
98
|
-
// The whole point: an untouched calendar has a clean URL
|
|
99
|
-
expect(
|
|
100
|
-
write('', {
|
|
101
|
-
view: 'WEEK',
|
|
102
|
-
anchorDate: NOW,
|
|
103
|
-
mineOnly: false,
|
|
104
|
-
hiddenCalendarIds: [],
|
|
105
|
-
}),
|
|
106
|
-
).toBe('');
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it('writes only what differs from the default', () => {
|
|
110
|
-
expect(write('', { view: 'MONTH' })).toBe('v=month');
|
|
111
|
-
expect(write('', { mineOnly: true })).toBe('me=1');
|
|
112
|
-
expect(write('', { hiddenCalendarIds: ['a', 'b'] })).toBe('hide=a%2Cb');
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('omits the date when it is today', () => {
|
|
116
|
-
expect(write('', { anchorDate: new Date('2026-07-22T23:00:00Z') })).toBe(
|
|
117
|
-
'',
|
|
118
|
-
);
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it('writes the date when it is not today', () => {
|
|
122
|
-
expect(write('', { anchorDate: new Date('2026-08-01T12:00:00Z') })).toBe(
|
|
123
|
-
'd=2026-08-01',
|
|
124
|
-
);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it('resolves "today" in the calendar zone, not in UTC', () => {
|
|
128
|
-
// 2026-07-23T02:00Z is still the 22nd in Los Angeles, so it is today
|
|
129
|
-
// and should produce no parameter at all
|
|
130
|
-
expect(write('', { anchorDate: new Date('2026-07-23T02:00:00Z') })).toBe(
|
|
131
|
-
'',
|
|
132
|
-
);
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it('clears a parameter when it returns to the default', () => {
|
|
136
|
-
expect(write('v=month', { view: 'WEEK' })).toBe('');
|
|
137
|
-
expect(write('me=1', { mineOnly: false })).toBe('');
|
|
138
|
-
expect(write('hide=a', { hiddenCalendarIds: [] })).toBe('');
|
|
139
|
-
expect(write('d=2026-08-01', { anchorDate: NOW })).toBe('');
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it('leaves untouched keys alone', () => {
|
|
143
|
-
// The calendar does not own the whole query string
|
|
144
|
-
expect(write('v=month', { mineOnly: true })).toBe('v=month&me=1');
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it('preserves an unrelated parameter somebody else put there', () => {
|
|
148
|
-
const result = write('ref=email&v=month', { view: 'WEEK' });
|
|
149
|
-
|
|
150
|
-
expect(result).toBe('ref=email');
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it('changes nothing for keys it was not asked about', () => {
|
|
154
|
-
expect(write('v=month&me=1&d=2026-08-01', {})).toBe(
|
|
155
|
-
'v=month&me=1&d=2026-08-01',
|
|
156
|
-
);
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it('produces a readable full URL', () => {
|
|
160
|
-
expect(
|
|
161
|
-
write('', {
|
|
162
|
-
view: 'MONTH',
|
|
163
|
-
anchorDate: new Date('2026-08-01T12:00:00Z'),
|
|
164
|
-
mineOnly: true,
|
|
165
|
-
}),
|
|
166
|
-
).toBe('v=month&d=2026-08-01&me=1');
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
it('round-trips active calendar, room, panel and deep-linked occurrence without losing unrelated params', () => {
|
|
171
|
-
const query = write('external=1', {
|
|
172
|
-
view: 'ROSTER',
|
|
173
|
-
calendarId: 'cal',
|
|
174
|
-
roomId: 'room',
|
|
175
|
-
groupByRoom: true,
|
|
176
|
-
panel: 'requests',
|
|
177
|
-
openId: 'row',
|
|
178
|
-
});
|
|
179
|
-
const state = readCalendarUrlState(new URLSearchParams(query), NOW, LA);
|
|
180
|
-
expect(state).toMatchObject({
|
|
181
|
-
view: 'ROSTER',
|
|
182
|
-
calendarId: 'cal',
|
|
183
|
-
roomId: 'room',
|
|
184
|
-
groupByRoom: true,
|
|
185
|
-
panel: 'requests',
|
|
186
|
-
openId: 'row',
|
|
187
|
-
});
|
|
188
|
-
expect(query).toContain('external=1');
|
|
189
|
-
});
|
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { buildRosterLayout } from '../src/libs/roster-layout.ts';
|
|
3
|
-
import { getCalendarRange } from '../src/libs/calendar-range.ts';
|
|
4
|
-
import type {
|
|
5
|
-
ScheduleOccurrenceGQL,
|
|
6
|
-
ScheduleResourceGQL,
|
|
7
|
-
ScheduleViolationGQL,
|
|
8
|
-
ScheduleTimeOffGQL,
|
|
9
|
-
} from '@jsb188/graphql/schedule.d';
|
|
10
|
-
|
|
11
|
-
/* Build the smallest realistic resource used by roster placement assertions. */
|
|
12
|
-
function resource(
|
|
13
|
-
id: string,
|
|
14
|
-
kind: 'LABOR' | 'SPACE' = 'LABOR',
|
|
15
|
-
ordinal = 0,
|
|
16
|
-
): ScheduleResourceGQL {
|
|
17
|
-
return {
|
|
18
|
-
id,
|
|
19
|
-
kind,
|
|
20
|
-
name: id,
|
|
21
|
-
key: id,
|
|
22
|
-
ordinal,
|
|
23
|
-
accountId: kind === 'LABOR' ? `account:${id}` : null,
|
|
24
|
-
retiredAt: null,
|
|
25
|
-
config: { roles: [], qualifications: [], tags: [] },
|
|
26
|
-
} as ScheduleResourceGQL;
|
|
27
|
-
}
|
|
28
|
-
/* Build an overnight shift whose assignee account identity differs from the resource identity. */
|
|
29
|
-
function occurrence(
|
|
30
|
-
id: string,
|
|
31
|
-
roomId: string,
|
|
32
|
-
personId: string,
|
|
33
|
-
start = '2026-07-20T22:00:00Z',
|
|
34
|
-
end = '2026-07-21T06:00:00Z',
|
|
35
|
-
): ScheduleOccurrenceGQL {
|
|
36
|
-
return {
|
|
37
|
-
id,
|
|
38
|
-
calendarId: 'cal',
|
|
39
|
-
resourceId: roomId,
|
|
40
|
-
title: id,
|
|
41
|
-
kind: 'SHIFT',
|
|
42
|
-
startAt: start,
|
|
43
|
-
endAt: end,
|
|
44
|
-
status: 'DRAFT',
|
|
45
|
-
version: '1',
|
|
46
|
-
openCount: 1,
|
|
47
|
-
slots: [],
|
|
48
|
-
assignments: [
|
|
49
|
-
{
|
|
50
|
-
id: `a:${id}`,
|
|
51
|
-
resourceId: personId,
|
|
52
|
-
accountId: `account:${personId}`,
|
|
53
|
-
slotKey: 'S1',
|
|
54
|
-
status: 'ASSIGNED',
|
|
55
|
-
},
|
|
56
|
-
],
|
|
57
|
-
} as ScheduleOccurrenceGQL;
|
|
58
|
-
}
|
|
59
|
-
/* Supply a stable UTC week so tests isolate placement from browser locale. */
|
|
60
|
-
function input(): Parameters<typeof buildRosterLayout>[0] {
|
|
61
|
-
return {
|
|
62
|
-
days: getCalendarRange({
|
|
63
|
-
view: 'ROSTER',
|
|
64
|
-
anchorDate: new Date('2026-07-20T12:00Z'),
|
|
65
|
-
now: new Date('2026-07-20T12:00Z'),
|
|
66
|
-
timeZone: 'UTC',
|
|
67
|
-
weekStartsOn: 1,
|
|
68
|
-
}).days,
|
|
69
|
-
timeZone: 'UTC',
|
|
70
|
-
locale: 'en',
|
|
71
|
-
resources: [resource('one'), resource('two')],
|
|
72
|
-
rooms: [resource('A', 'SPACE', 0), resource('B', 'SPACE', 1)],
|
|
73
|
-
occurrences: [],
|
|
74
|
-
timeOff: [],
|
|
75
|
-
violations: [],
|
|
76
|
-
groupByRoom: false,
|
|
77
|
-
roomFilterId: null,
|
|
78
|
-
mineOnly: false,
|
|
79
|
-
viewerAccountId: 'account:one',
|
|
80
|
-
viewerResourceId: null,
|
|
81
|
-
formatTime: (at) => at.toISOString().slice(11, 16),
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
describe('roster placement', () => {
|
|
86
|
-
it('draws an overnight assignment once, retains real hours and matches the viewer account', () => {
|
|
87
|
-
const p = input();
|
|
88
|
-
p.occurrences = [occurrence('night', 'A', 'one')];
|
|
89
|
-
const result = buildRosterLayout(p),
|
|
90
|
-
person = result.rows.find((row) => row.resourceId === 'one')!;
|
|
91
|
-
expect(person.cells.flatMap((cell) => cell.chips)).toHaveLength(1);
|
|
92
|
-
expect(person.cells[0].chips[0]).toMatchObject({
|
|
93
|
-
overnight: true,
|
|
94
|
-
isMine: true,
|
|
95
|
-
roomName: 'A',
|
|
96
|
-
});
|
|
97
|
-
expect(person.cells[1].chips).toHaveLength(0);
|
|
98
|
-
expect(person.weekMinutes).toBe(480);
|
|
99
|
-
expect(result.openTotal).toBe(1);
|
|
100
|
-
});
|
|
101
|
-
it('groups a person once by most assigned minutes and preserves chips from other rooms', () => {
|
|
102
|
-
const p = input();
|
|
103
|
-
p.groupByRoom = true;
|
|
104
|
-
p.occurrences = [
|
|
105
|
-
occurrence('long', 'B', 'one'),
|
|
106
|
-
occurrence('short', 'A', 'one', '2026-07-22T09:00Z', '2026-07-22T10:00Z'),
|
|
107
|
-
];
|
|
108
|
-
const result = buildRosterLayout(p);
|
|
109
|
-
const people = result.rows.filter((row) => row.resourceId === 'one');
|
|
110
|
-
expect(people).toHaveLength(1);
|
|
111
|
-
expect(people[0].roomId).toBe('B');
|
|
112
|
-
expect(people[0].weekMinutes).toBe(540);
|
|
113
|
-
expect(
|
|
114
|
-
people[0].cells
|
|
115
|
-
.flatMap((cell) => cell.chips)
|
|
116
|
-
.map((chip) => chip.roomName),
|
|
117
|
-
).toEqual(['B', 'A']);
|
|
118
|
-
});
|
|
119
|
-
it('breaks primary-room ties by room ordinal', () => {
|
|
120
|
-
const p = input();
|
|
121
|
-
p.groupByRoom = true;
|
|
122
|
-
p.occurrences = [
|
|
123
|
-
occurrence('first', 'B', 'one'),
|
|
124
|
-
occurrence(
|
|
125
|
-
'second',
|
|
126
|
-
'A',
|
|
127
|
-
'one',
|
|
128
|
-
'2026-07-22T22:00Z',
|
|
129
|
-
'2026-07-23T06:00Z',
|
|
130
|
-
),
|
|
131
|
-
];
|
|
132
|
-
expect(
|
|
133
|
-
buildRosterLayout(p).rows.find((row) => row.resourceId === 'one')?.roomId,
|
|
134
|
-
).toBe('A');
|
|
135
|
-
});
|
|
136
|
-
it('keeps retired people with assignments and marks time off and person-only breaches', () => {
|
|
137
|
-
const p = input();
|
|
138
|
-
p.resources[0].retiredAt = '2026-07-01';
|
|
139
|
-
p.resources[1].retiredAt = '2026-07-01';
|
|
140
|
-
p.occurrences = [occurrence('night', 'A', 'one')];
|
|
141
|
-
p.timeOff = [
|
|
142
|
-
{
|
|
143
|
-
id: 't',
|
|
144
|
-
resourceId: 'one',
|
|
145
|
-
status: 'APPROVED',
|
|
146
|
-
startAt: '2026-07-21T00:00Z',
|
|
147
|
-
endAt: '2026-07-22T00:00Z',
|
|
148
|
-
} as ScheduleTimeOffGQL,
|
|
149
|
-
];
|
|
150
|
-
p.violations = [
|
|
151
|
-
{
|
|
152
|
-
id: 'v',
|
|
153
|
-
resourceId: 'one',
|
|
154
|
-
occurrenceId: null,
|
|
155
|
-
severity: 'BLOCK',
|
|
156
|
-
startAt: '2026-07-20T22:00Z',
|
|
157
|
-
endAt: '2026-07-21T06:00Z',
|
|
158
|
-
} as ScheduleViolationGQL,
|
|
159
|
-
];
|
|
160
|
-
const result = buildRosterLayout(p);
|
|
161
|
-
expect(result.rows.some((row) => row.resourceId === 'two')).toBe(false);
|
|
162
|
-
const person = result.rows.find((row) => row.resourceId === 'one')!;
|
|
163
|
-
expect(person.breach).toBe('BLOCK');
|
|
164
|
-
expect(person.cells[1].timeOff?.id).toBe('t');
|
|
165
|
-
});
|
|
166
|
-
it('builds a 150-person week without duplicating grouped workers', () => {
|
|
167
|
-
const p = input();
|
|
168
|
-
p.resources = Array.from({ length: 150 }, (_, i) => resource(String(i)));
|
|
169
|
-
p.occurrences = p.resources.flatMap((r, i) =>
|
|
170
|
-
Array.from({ length: 7 }, (_, day) =>
|
|
171
|
-
occurrence(
|
|
172
|
-
`${i}:${day}`,
|
|
173
|
-
i % 2 ? 'A' : 'B',
|
|
174
|
-
r.id,
|
|
175
|
-
`2026-07-${20 + day}T09:00Z`,
|
|
176
|
-
`2026-07-${20 + day}T17:00Z`,
|
|
177
|
-
),
|
|
178
|
-
),
|
|
179
|
-
);
|
|
180
|
-
p.groupByRoom = true;
|
|
181
|
-
const result = buildRosterLayout(p);
|
|
182
|
-
expect(result.rows.filter((row) => row.kind === 'PERSON')).toHaveLength(
|
|
183
|
-
150,
|
|
184
|
-
);
|
|
185
|
-
expect(
|
|
186
|
-
result.rows.reduce(
|
|
187
|
-
(n, row) =>
|
|
188
|
-
n +
|
|
189
|
-
row.cells.reduce(
|
|
190
|
-
(n, cell) =>
|
|
191
|
-
n + cell.chips.filter((chip) => chip.assignmentId).length,
|
|
192
|
-
0,
|
|
193
|
-
),
|
|
194
|
-
0,
|
|
195
|
-
),
|
|
196
|
-
).toBe(1050);
|
|
197
|
-
});
|
|
198
|
-
it('shows assigned people from a shared calendar without requiring their resource catalog', () => {
|
|
199
|
-
const p = input();
|
|
200
|
-
p.resources = [];
|
|
201
|
-
const shift = occurrence('shared', 'A', 'foreign');
|
|
202
|
-
shift.assignments[0].resourceName = 'Shared worker';
|
|
203
|
-
p.occurrences = [shift];
|
|
204
|
-
const person = buildRosterLayout(p).rows.find(
|
|
205
|
-
(row) => row.resourceId === 'foreign',
|
|
206
|
-
);
|
|
207
|
-
expect(person?.name).toBe('Shared worker');
|
|
208
|
-
expect(person?.weekMinutes).toBe(480);
|
|
209
|
-
});
|
|
210
|
-
});
|
package/tsconfig.json
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ESNext",
|
|
4
|
-
"module": "ESNext",
|
|
5
|
-
"moduleResolution": "Bundler",
|
|
6
|
-
"allowImportingTsExtensions": true,
|
|
7
|
-
"jsx": "react-jsx",
|
|
8
|
-
"noEmit": true,
|
|
9
|
-
"strict": true,
|
|
10
|
-
"esModuleInterop": true
|
|
11
|
-
},
|
|
12
|
-
"include": ["src/**/*"]
|
|
13
|
-
}
|
package/vitest.config.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from 'vitest/config';
|
|
2
|
-
|
|
3
|
-
export default defineConfig({
|
|
4
|
-
test: {
|
|
5
|
-
environment: 'node',
|
|
6
|
-
// Rendering tests live in apps/marketday/tests instead: vitest's jsdom
|
|
7
|
-
// environment cannot resolve modules from a directory whose name
|
|
8
|
-
// contains a colon, and this package is "@jsb188:calendar"
|
|
9
|
-
include: ['tests/**/*.test.ts?(x)'],
|
|
10
|
-
},
|
|
11
|
-
});
|