@jsb188/schedule 1.1.11
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 +61 -0
- package/src/constants/schedule.ts +549 -0
- package/src/css.d.ts +7 -0
- package/src/libs/gantt-geometry.ts +771 -0
- package/src/libs/gantt-histogram.ts +124 -0
- package/src/libs/gantt-keyboard.ts +113 -0
- package/src/libs/gantt-state.ts +57 -0
- package/src/libs/gantt-url.ts +63 -0
- package/src/modules/Gantt.helpers.ts +138 -0
- package/src/modules/Gantt.tsx +719 -0
- package/src/types/schedule.d.ts +1149 -0
- package/src/ui/ActivityFormUI.tsx +133 -0
- package/src/ui/GanttEditorsUI.tsx +102 -0
- package/src/ui/GanttHistogramUI.tsx +236 -0
- package/src/ui/GanttUI.tsx +792 -0
- package/src/ui/ProjectFormUI.tsx +273 -0
- package/src/ui/ProjectMobileListUI.tsx +80 -0
- package/src/ui/ProjectToolbarUI.tsx +54 -0
- package/src/ui/RelationshipListUI.tsx +176 -0
- package/src/ui/ScheduleRunUI.tsx +173 -0
- package/src/ui/ScheduleSettingsUI.tsx +420 -0
- package/src/utils/coverage.helpers.ts +679 -0
- package/src/utils/coverage.ts +630 -0
- package/src/utils/cpm.helpers.ts +674 -0
- package/src/utils/cpm.ts +907 -0
- package/src/utils/cpmLeveling.helpers.ts +564 -0
- package/src/utils/cpmLeveling.ts +367 -0
- package/src/utils/defaults.ts +8 -0
- package/src/utils/eligibility.ts +457 -0
- package/src/utils/planCsv.ts +344 -0
- package/src/utils/predecessorText.ts +96 -0
- package/src/utils/recurrence.ts +616 -0
- package/src/utils/request.ts +153 -0
- package/src/utils/resource.ts +182 -0
- package/src/utils/rule.ts +216 -0
- package/src/utils/run.ts +43 -0
- package/src/utils/series.ts +161 -0
- package/src/utils/slot.ts +208 -0
- package/src/utils/workTime.ts +1382 -0
- package/tests/coverage.fixtures.ts +111 -0
- package/tests/coverage.test.ts +503 -0
- package/tests/cpm.bench.test.ts +154 -0
- package/tests/cpm.test.ts +354 -0
- package/tests/cpmCorrectness.test.ts +327 -0
- package/tests/cpmLeveling.test.ts +471 -0
- package/tests/eligibility.test.ts +320 -0
- package/tests/gantt-geometry.test.ts +367 -0
- package/tests/gantt-histogram.test.ts +78 -0
- package/tests/gantt-keyboard.test.ts +69 -0
- package/tests/helpers/cpmFixtures.ts +101 -0
- package/tests/projectInputs.test.ts +165 -0
- package/tests/recurrence.test.ts +68 -0
- package/tests/request.test.ts +99 -0
- package/tests/resource.test.ts +95 -0
- package/tests/rule.test.ts +98 -0
- package/tests/series.test.ts +120 -0
- package/tests/workTime.test.ts +1007 -0
- package/tests/workTimeContracts.test.ts +111 -0
- package/tsconfig.json +13 -0
- package/vitest.config.ts +8 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
getEffectiveRule,
|
|
4
|
+
getMaxActorWindowDays,
|
|
5
|
+
resolveEffectiveScheduleRules,
|
|
6
|
+
validateScheduleRuleConfig,
|
|
7
|
+
} from '../src/utils/rule.ts';
|
|
8
|
+
import { person, rule } from './coverage.fixtures.ts';
|
|
9
|
+
|
|
10
|
+
describe('closed coverage rules', () => {
|
|
11
|
+
it.each([
|
|
12
|
+
['REQUIRED_COUNT', { ratioDivisor: 2 }],
|
|
13
|
+
['ELIGIBILITY', { predicate: {} }],
|
|
14
|
+
['DERIVED_COUNT', { ratios: {} }],
|
|
15
|
+
['DERIVED_COUNT', { ratios: { INFANT: 0 } }],
|
|
16
|
+
['DERIVED_COUNT', { ratios: { INFANT: 51 } }],
|
|
17
|
+
['OPERATING_HOURS', { minAdults: 100 }],
|
|
18
|
+
['ACTOR_WINDOW_AGGREGATE', { windowDays: 32, maxMinutes: 10 }],
|
|
19
|
+
['ACTOR_WINDOW_AGGREGATE', { maxMinutes: 60 }],
|
|
20
|
+
['ACTOR_WINDOW_AGGREGATE', {}],
|
|
21
|
+
] as const)('rejects invalid %s config %j', (kind, config) => {
|
|
22
|
+
expect(validateScheduleRuleConfig(kind, config).error).toBeTruthy();
|
|
23
|
+
});
|
|
24
|
+
it('normalizes ratios and rejects trimmed duplicates', () => {
|
|
25
|
+
expect(
|
|
26
|
+
validateScheduleRuleConfig('DERIVED_COUNT', { ratios: { ' INFANT ': 4 } })
|
|
27
|
+
.config,
|
|
28
|
+
).toEqual({ ratios: { INFANT: 4 }, predicate: null });
|
|
29
|
+
expect(
|
|
30
|
+
validateScheduleRuleConfig('DERIVED_COUNT', {
|
|
31
|
+
ratios: { ' INFANT': 4, INFANT: 5 },
|
|
32
|
+
}).error,
|
|
33
|
+
).toBeTruthy();
|
|
34
|
+
});
|
|
35
|
+
it('resolves resource scope over calendar over organization, with numeric id ties', () => {
|
|
36
|
+
const resources = new Map([['room', person('room', { kind: 'SPACE' })]]);
|
|
37
|
+
const rules = [
|
|
38
|
+
rule('REQUIRED_COUNT', {}, { id: '1', severity: 'WARN' }),
|
|
39
|
+
rule('REQUIRED_COUNT', {}, { id: '2', calendarId: 'cal' }),
|
|
40
|
+
rule('REQUIRED_COUNT', {}, { id: '10', resourceId: 'room' }),
|
|
41
|
+
rule(
|
|
42
|
+
'REQUIRED_COUNT',
|
|
43
|
+
{},
|
|
44
|
+
{ id: '9', resourceId: 'room', severity: 'WARN' },
|
|
45
|
+
),
|
|
46
|
+
];
|
|
47
|
+
const { index } = resolveEffectiveScheduleRules(rules, 'cal', resources);
|
|
48
|
+
expect(getEffectiveRule(index, 'REQUIRED_COUNT', 'room')?.ruleId).toBe('9');
|
|
49
|
+
expect(getEffectiveRule(index, 'REQUIRED_COUNT', null)?.ruleId).toBe('2');
|
|
50
|
+
});
|
|
51
|
+
it('keeps the operating center rule independent of room rules', () => {
|
|
52
|
+
const { index } = resolveEffectiveScheduleRules(
|
|
53
|
+
[rule('OPERATING_HOURS', { minAdults: 2, predicate: null })],
|
|
54
|
+
'cal',
|
|
55
|
+
new Map(),
|
|
56
|
+
);
|
|
57
|
+
expect(getEffectiveRule(index, 'OPERATING_HOURS', null)).not.toBeNull();
|
|
58
|
+
expect(getEffectiveRule(index, 'OPERATING_HOURS', 'room')).toBeNull();
|
|
59
|
+
});
|
|
60
|
+
it('diagnoses wrong subjects and missing resources', () => {
|
|
61
|
+
const result = resolveEffectiveScheduleRules(
|
|
62
|
+
[
|
|
63
|
+
rule('ELIGIBILITY', {}, { resourceId: 'room' }),
|
|
64
|
+
rule(
|
|
65
|
+
'DERIVED_COUNT',
|
|
66
|
+
{ ratios: { X: 4 }, predicate: null },
|
|
67
|
+
{ resourceId: 'missing' },
|
|
68
|
+
),
|
|
69
|
+
],
|
|
70
|
+
'cal',
|
|
71
|
+
new Map([['room', person('room', { kind: 'SPACE' })]]),
|
|
72
|
+
);
|
|
73
|
+
expect(result.diagnostics.map((d) => d.code).sort()).toEqual([
|
|
74
|
+
'RULE_SUBJECT_KIND_MISMATCH',
|
|
75
|
+
'UNKNOWN_RESOURCE',
|
|
76
|
+
]);
|
|
77
|
+
});
|
|
78
|
+
it('bounds history using the largest valid actor rule', () => {
|
|
79
|
+
expect(
|
|
80
|
+
getMaxActorWindowDays([
|
|
81
|
+
rule('ACTOR_WINDOW_AGGREGATE', {
|
|
82
|
+
windowDays: 31,
|
|
83
|
+
maxMinutes: 100,
|
|
84
|
+
minRestMinutes: null,
|
|
85
|
+
}),
|
|
86
|
+
]),
|
|
87
|
+
).toBe(31);
|
|
88
|
+
expect(
|
|
89
|
+
getMaxActorWindowDays([
|
|
90
|
+
rule('ACTOR_WINDOW_AGGREGATE', {
|
|
91
|
+
windowDays: null,
|
|
92
|
+
maxMinutes: null,
|
|
93
|
+
minRestMinutes: 60,
|
|
94
|
+
}),
|
|
95
|
+
]),
|
|
96
|
+
).toBe(1);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { expandScheduleSeriesInstances } from '../src/utils/recurrence.ts';
|
|
3
|
+
import {
|
|
4
|
+
getLocalDateKey,
|
|
5
|
+
planScheduleSeriesRegeneration,
|
|
6
|
+
type SeriesExistingInstance,
|
|
7
|
+
} from '../src/utils/series.ts';
|
|
8
|
+
|
|
9
|
+
/* Build a small daily series spanning a daylight-saving boundary. */
|
|
10
|
+
function series() {
|
|
11
|
+
return {
|
|
12
|
+
title: 'Morning',
|
|
13
|
+
timeZone: 'America/New_York',
|
|
14
|
+
recurrence: { freq: 'DAILY' as const, count: 3 },
|
|
15
|
+
startsAt: '2026-03-07T13:00:00Z',
|
|
16
|
+
durationMinutes: 240,
|
|
17
|
+
active: true,
|
|
18
|
+
slotTemplate: [],
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/* Materialize existing identities as a server loader would return them. */
|
|
23
|
+
function existing(): SeriesExistingInstance[] {
|
|
24
|
+
return expandScheduleSeriesInstances(series()).map((row, i) => ({
|
|
25
|
+
...row,
|
|
26
|
+
id: String(i),
|
|
27
|
+
detached: false,
|
|
28
|
+
hasLiveAssignments: i === 2,
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/* Plan one deterministic edit with convenient overridable inputs. */
|
|
33
|
+
function plan(
|
|
34
|
+
extra: Partial<Parameters<typeof planScheduleSeriesRegeneration>[0]> = {},
|
|
35
|
+
) {
|
|
36
|
+
return planScheduleSeriesRegeneration({
|
|
37
|
+
series: series(),
|
|
38
|
+
existing: existing(),
|
|
39
|
+
fromDate: '2026-03-07',
|
|
40
|
+
now: new Date('2026-03-07T12:00:00Z'),
|
|
41
|
+
horizon: new Date('2026-03-12T00:00:00Z'),
|
|
42
|
+
labelsChanged: false,
|
|
43
|
+
slotTemplateChanged: false,
|
|
44
|
+
...extra,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
describe('safe series regeneration', () => {
|
|
49
|
+
it('keys local dates across DST independently of UTC offset', () => {
|
|
50
|
+
const rows = expandScheduleSeriesInstances(series());
|
|
51
|
+
expect(rows.map((row) => row.recurrenceDate)).toEqual([
|
|
52
|
+
'2026-03-07',
|
|
53
|
+
'2026-03-08',
|
|
54
|
+
'2026-03-09',
|
|
55
|
+
]);
|
|
56
|
+
expect(rows[1].startAt.toISOString()).toBe('2026-03-08T12:00:00.000Z');
|
|
57
|
+
expect(getLocalDateKey(rows[1].startAt, series().timeZone)).toBe(
|
|
58
|
+
'2026-03-08',
|
|
59
|
+
);
|
|
60
|
+
});
|
|
61
|
+
it('preserves matched ids and assignments when time changes', () => {
|
|
62
|
+
const result = plan({
|
|
63
|
+
series: { ...series(), startsAt: '2026-03-07T12:30:00Z' },
|
|
64
|
+
});
|
|
65
|
+
expect(result.update.map((row) => row.id)).toEqual(['0', '1', '2']);
|
|
66
|
+
expect(result.create).toEqual([]);
|
|
67
|
+
expect(result.detach).toEqual([]);
|
|
68
|
+
});
|
|
69
|
+
it('propagates label-only edits to matched rows', () => {
|
|
70
|
+
const result = plan({
|
|
71
|
+
labelsChanged: true,
|
|
72
|
+
series: { ...series(), title: 'Renamed' },
|
|
73
|
+
});
|
|
74
|
+
expect(result.labels?.title).toBe('Renamed');
|
|
75
|
+
expect(result.update).toEqual([{ id: '0' }, { id: '1' }, { id: '2' }]);
|
|
76
|
+
});
|
|
77
|
+
it('detaches staffed removed dates and deletes unstaffed dates', () => {
|
|
78
|
+
const result = plan({
|
|
79
|
+
series: { ...series(), recurrence: { freq: 'DAILY', count: 1 } },
|
|
80
|
+
});
|
|
81
|
+
expect(result.detach).toEqual([{ id: '2', reason: 'DATE_REMOVED' }]);
|
|
82
|
+
expect(result.delete).toEqual(['1']);
|
|
83
|
+
});
|
|
84
|
+
it('preserves detached dates without duplicate creation', () => {
|
|
85
|
+
const rows = existing();
|
|
86
|
+
rows[1].detached = true;
|
|
87
|
+
const result = plan({ existing: rows });
|
|
88
|
+
expect(result.skipped).toEqual([
|
|
89
|
+
{ recurrenceDate: '2026-03-08', reason: 'DETACHED_EXISTS' },
|
|
90
|
+
]);
|
|
91
|
+
expect(result.create).toEqual([]);
|
|
92
|
+
expect(result.update.map((row) => row.id)).toEqual(['0', '2']);
|
|
93
|
+
});
|
|
94
|
+
it('never edits, deletes or detaches an already-started instance', () => {
|
|
95
|
+
const result = plan({
|
|
96
|
+
now: new Date('2026-03-07T14:00:00Z'),
|
|
97
|
+
series: { ...series(), active: false },
|
|
98
|
+
});
|
|
99
|
+
expect(result.skipped).toEqual([
|
|
100
|
+
{ recurrenceDate: '2026-03-07', reason: 'ALREADY_STARTED' },
|
|
101
|
+
]);
|
|
102
|
+
expect(result.delete).toEqual(['1']);
|
|
103
|
+
expect(result.detach).toEqual([{ id: '2', reason: 'SERIES_DELETED' }]);
|
|
104
|
+
});
|
|
105
|
+
it('freezes a date if its edited time would move into the past', () => {
|
|
106
|
+
const result = plan({
|
|
107
|
+
series: { ...series(), startsAt: '2026-03-07T11:00:00Z' },
|
|
108
|
+
});
|
|
109
|
+
expect(result.skipped).toEqual([
|
|
110
|
+
{ recurrenceDate: '2026-03-07', reason: 'ALREADY_STARTED' },
|
|
111
|
+
]);
|
|
112
|
+
expect(result.delete).toEqual([]);
|
|
113
|
+
});
|
|
114
|
+
it('keeps count relative to the series origin for later materialization', () => {
|
|
115
|
+
const rows = expandScheduleSeriesInstances(series(), {
|
|
116
|
+
from: new Date('2026-03-09T00:00:00Z'),
|
|
117
|
+
});
|
|
118
|
+
expect(rows.map((row) => row.recurrenceDate)).toEqual(['2026-03-09']);
|
|
119
|
+
});
|
|
120
|
+
});
|