@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.
Files changed (60) hide show
  1. package/package.json +61 -0
  2. package/src/constants/schedule.ts +549 -0
  3. package/src/css.d.ts +7 -0
  4. package/src/libs/gantt-geometry.ts +771 -0
  5. package/src/libs/gantt-histogram.ts +124 -0
  6. package/src/libs/gantt-keyboard.ts +113 -0
  7. package/src/libs/gantt-state.ts +57 -0
  8. package/src/libs/gantt-url.ts +63 -0
  9. package/src/modules/Gantt.helpers.ts +138 -0
  10. package/src/modules/Gantt.tsx +719 -0
  11. package/src/types/schedule.d.ts +1149 -0
  12. package/src/ui/ActivityFormUI.tsx +133 -0
  13. package/src/ui/GanttEditorsUI.tsx +102 -0
  14. package/src/ui/GanttHistogramUI.tsx +236 -0
  15. package/src/ui/GanttUI.tsx +792 -0
  16. package/src/ui/ProjectFormUI.tsx +273 -0
  17. package/src/ui/ProjectMobileListUI.tsx +80 -0
  18. package/src/ui/ProjectToolbarUI.tsx +54 -0
  19. package/src/ui/RelationshipListUI.tsx +176 -0
  20. package/src/ui/ScheduleRunUI.tsx +173 -0
  21. package/src/ui/ScheduleSettingsUI.tsx +420 -0
  22. package/src/utils/coverage.helpers.ts +679 -0
  23. package/src/utils/coverage.ts +630 -0
  24. package/src/utils/cpm.helpers.ts +674 -0
  25. package/src/utils/cpm.ts +907 -0
  26. package/src/utils/cpmLeveling.helpers.ts +564 -0
  27. package/src/utils/cpmLeveling.ts +367 -0
  28. package/src/utils/defaults.ts +8 -0
  29. package/src/utils/eligibility.ts +457 -0
  30. package/src/utils/planCsv.ts +344 -0
  31. package/src/utils/predecessorText.ts +96 -0
  32. package/src/utils/recurrence.ts +616 -0
  33. package/src/utils/request.ts +153 -0
  34. package/src/utils/resource.ts +182 -0
  35. package/src/utils/rule.ts +216 -0
  36. package/src/utils/run.ts +43 -0
  37. package/src/utils/series.ts +161 -0
  38. package/src/utils/slot.ts +208 -0
  39. package/src/utils/workTime.ts +1382 -0
  40. package/tests/coverage.fixtures.ts +111 -0
  41. package/tests/coverage.test.ts +503 -0
  42. package/tests/cpm.bench.test.ts +154 -0
  43. package/tests/cpm.test.ts +354 -0
  44. package/tests/cpmCorrectness.test.ts +327 -0
  45. package/tests/cpmLeveling.test.ts +471 -0
  46. package/tests/eligibility.test.ts +320 -0
  47. package/tests/gantt-geometry.test.ts +367 -0
  48. package/tests/gantt-histogram.test.ts +78 -0
  49. package/tests/gantt-keyboard.test.ts +69 -0
  50. package/tests/helpers/cpmFixtures.ts +101 -0
  51. package/tests/projectInputs.test.ts +165 -0
  52. package/tests/recurrence.test.ts +68 -0
  53. package/tests/request.test.ts +99 -0
  54. package/tests/resource.test.ts +95 -0
  55. package/tests/rule.test.ts +98 -0
  56. package/tests/series.test.ts +120 -0
  57. package/tests/workTime.test.ts +1007 -0
  58. package/tests/workTimeContracts.test.ts +111 -0
  59. package/tsconfig.json +13 -0
  60. package/vitest.config.ts +8 -0
@@ -0,0 +1,320 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { evaluateScheduleCoverage } from '../src/utils/coverage.ts';
3
+ import {
4
+ diffCoverageViolations,
5
+ evaluateDropImpact,
6
+ evaluateShiftEligibility,
7
+ evaluateSwapEligibility,
8
+ simulateAssignmentChange,
9
+ type ShiftEligibilityContext,
10
+ } from '../src/utils/eligibility.ts';
11
+ import {
12
+ at,
13
+ person,
14
+ rule,
15
+ shift,
16
+ slot,
17
+ snapshot,
18
+ } from './coverage.fixtures.ts';
19
+
20
+ /* Provide complete assignee resources and the caller's deterministic current time. */
21
+ function context(
22
+ extra: Partial<ShiftEligibilityContext> = {},
23
+ ): ShiftEligibilityContext {
24
+ return {
25
+ calendarId: 'calendar',
26
+ now: new Date(at(7)),
27
+ resources: snapshot().resources,
28
+ assignmentsOfResource: [],
29
+ timeOff: [],
30
+ rules: [],
31
+ ...extra,
32
+ };
33
+ }
34
+
35
+ describe('shift eligibility', () => {
36
+ it('resolves an open seat and refuses a full seat on claims', () => {
37
+ expect(
38
+ evaluateShiftEligibility({
39
+ occurrence: shift(),
40
+ resource: person('1'),
41
+ slotKey: null,
42
+ context: context({ requireOpenSlot: true }),
43
+ }),
44
+ ).toMatchObject({ eligible: true, slotKey: 'teacher', reasons: [] });
45
+ expect(
46
+ evaluateShiftEligibility({
47
+ occurrence: shift('10', ['2']),
48
+ resource: person('1'),
49
+ slotKey: null,
50
+ context: context({ requireOpenSlot: true }),
51
+ }),
52
+ ).toMatchObject({ eligible: false, reasons: [{ code: 'SLOT_FULL' }] });
53
+ });
54
+ it('allows managers to add surplus staff with a warning', () => {
55
+ expect(
56
+ evaluateShiftEligibility({
57
+ occurrence: shift('10', ['2']),
58
+ resource: person('1'),
59
+ slotKey: null,
60
+ context: context(),
61
+ }),
62
+ ).toMatchObject({
63
+ eligible: true,
64
+ reasons: [{ code: 'SLOT_FULL', severity: 'WARN' }],
65
+ });
66
+ });
67
+ it('fails closed when the current assignee context is incomplete', () => {
68
+ expect(() =>
69
+ evaluateShiftEligibility({
70
+ occurrence: shift('10', ['2']),
71
+ resource: person('1'),
72
+ slotKey: null,
73
+ context: context({ resources: [person('1')] }),
74
+ }),
75
+ ).toThrow('SCHEDULE_ELIGIBILITY_CONTEXT_INCOMPLETE');
76
+ });
77
+ it.each([
78
+ 'NOT_LABOR',
79
+ 'RESOURCE_RETIRED',
80
+ 'OCCURRENCE_ENDED',
81
+ 'OCCURRENCE_NOT_SHIFT',
82
+ 'ALREADY_ASSIGNED',
83
+ 'SLOT_UNKNOWN',
84
+ ] as const)('refuses the structural reason %s', (code) => {
85
+ const target = shift(
86
+ '10',
87
+ code === 'ALREADY_ASSIGNED' ? ['1'] : [],
88
+ code === 'OCCURRENCE_NOT_SHIFT' ? { kind: 'EVENT' } : {},
89
+ );
90
+ const resource = person(
91
+ '1',
92
+ code === 'NOT_LABOR'
93
+ ? { kind: 'EQUIPMENT' }
94
+ : code === 'RESOURCE_RETIRED'
95
+ ? { retiredAt: at(10) }
96
+ : {},
97
+ );
98
+ const result = evaluateShiftEligibility({
99
+ occurrence: target,
100
+ resource,
101
+ slotKey: code === 'SLOT_UNKNOWN' ? 'bad' : null,
102
+ context: context(
103
+ code === 'OCCURRENCE_ENDED' ? { now: new Date(at(13)) } : {},
104
+ ),
105
+ });
106
+ expect(result.eligible).toBe(false);
107
+ expect(result.reasons.some((reason) => reason.code === code)).toBe(true);
108
+ });
109
+ it('does not count an expired current assignee as a filled seat', () => {
110
+ const current = person('2');
111
+ current.config.qualifications = [{ key: 'CPR', expiresAt: at(7) }];
112
+ const candidate = person('1');
113
+ candidate.config.qualifications = [{ key: 'CPR', expiresAt: null }];
114
+ const result = evaluateShiftEligibility({
115
+ occurrence: shift('10', ['2'], {
116
+ slots: [slot('teacher', { predicate: { qualifications: ['CPR'] } })],
117
+ }),
118
+ resource: candidate,
119
+ slotKey: 'teacher',
120
+ context: context({
121
+ resources: [candidate, current],
122
+ requireOpenSlot: true,
123
+ }),
124
+ });
125
+ expect(result.eligible).toBe(true);
126
+ });
127
+ it('explains qualifications that expire during the target shift', () => {
128
+ const candidate = person('1');
129
+ candidate.config.qualifications = [{ key: 'CPR', expiresAt: at(10) }];
130
+ const result = evaluateShiftEligibility({
131
+ occurrence: shift('10', [], {
132
+ slots: [slot('teacher', { predicate: { qualifications: ['CPR'] } })],
133
+ }),
134
+ resource: candidate,
135
+ slotKey: null,
136
+ context: context(),
137
+ });
138
+ expect(result).toMatchObject({
139
+ eligible: false,
140
+ reasons: [
141
+ {
142
+ code: 'QUALIFICATION_EXPIRES_DURING_SHIFT',
143
+ startAt: new Date(at(10)),
144
+ },
145
+ ],
146
+ });
147
+ });
148
+ it('blocks an explicitly pinned predicate mismatch', () => {
149
+ const result = evaluateShiftEligibility({
150
+ occurrence: shift('10', [], {
151
+ slots: [slot('teacher', { predicate: { roles: ['TEACHER'] } })],
152
+ }),
153
+ resource: person('1'),
154
+ slotKey: 'teacher',
155
+ context: context(),
156
+ });
157
+ expect(result.reasons.map((reason) => reason.code)).toEqual([
158
+ 'PREDICATE_MISMATCH',
159
+ ]);
160
+ });
161
+ it('respects warning severity on policy reasons', () => {
162
+ const result = evaluateShiftEligibility({
163
+ occurrence: shift(),
164
+ resource: person('1'),
165
+ slotKey: null,
166
+ context: context({
167
+ rules: [rule('ELIGIBILITY', {}, { severity: 'WARN' })],
168
+ timeOff: [
169
+ { id: 'off', resourceId: '1', startAt: at(9), endAt: at(10) },
170
+ ],
171
+ }),
172
+ });
173
+ expect(result).toMatchObject({
174
+ eligible: true,
175
+ reasons: [{ code: 'TIME_OFF', severity: 'WARN' }],
176
+ });
177
+ });
178
+ it('catches cross-calendar overlap with exact boundaries', () => {
179
+ const result = evaluateShiftEligibility({
180
+ occurrence: shift(),
181
+ resource: person('1'),
182
+ slotKey: null,
183
+ context: context({
184
+ assignmentsOfResource: [
185
+ {
186
+ occurrenceId: '20',
187
+ calendarId: 'other',
188
+ resourceId: '1',
189
+ kind: 'EVENT',
190
+ startAt: at(9),
191
+ endAt: at(10),
192
+ },
193
+ ],
194
+ }),
195
+ });
196
+ expect(result).toMatchObject({
197
+ eligible: false,
198
+ reasons: [
199
+ { code: 'OVERLAP', startAt: new Date(at(9)), endAt: new Date(at(10)) },
200
+ ],
201
+ });
202
+ });
203
+ it('detects a later external shift pushed over a 31-day cap', () => {
204
+ const result = evaluateShiftEligibility({
205
+ occurrence: shift(),
206
+ resource: person('1'),
207
+ slotKey: null,
208
+ context: context({
209
+ rules: [
210
+ rule('ACTOR_WINDOW_AGGREGATE', {
211
+ windowDays: 31,
212
+ maxMinutes: 360,
213
+ minRestMinutes: null,
214
+ }),
215
+ ],
216
+ assignmentsOfResource: [
217
+ {
218
+ occurrenceId: 'later',
219
+ calendarId: 'other',
220
+ resourceId: '1',
221
+ kind: 'SHIFT',
222
+ startAt: at(8, 8),
223
+ endAt: at(12, 8),
224
+ },
225
+ ],
226
+ }),
227
+ });
228
+ expect(result.eligible).toBe(false);
229
+ expect(result.reasons).toMatchObject([
230
+ { code: 'WINDOW_HOURS_EXCEEDED', detail: { occurrenceId: 'later' } },
231
+ ]);
232
+ });
233
+ it('keeps insufficient rest before the target visible when the gap precedes the evaluation window', () => {
234
+ const result = evaluateShiftEligibility({
235
+ occurrence: shift(),
236
+ resource: person('1'),
237
+ slotKey: null,
238
+ context: context({
239
+ rules: [
240
+ rule('ACTOR_WINDOW_AGGREGATE', {
241
+ windowDays: null,
242
+ maxMinutes: null,
243
+ minRestMinutes: 120,
244
+ }),
245
+ ],
246
+ assignmentsOfResource: [
247
+ {
248
+ occurrenceId: 'previous',
249
+ calendarId: 'other',
250
+ resourceId: '1',
251
+ kind: 'SHIFT',
252
+ startAt: at(2),
253
+ endAt: at(7),
254
+ },
255
+ ],
256
+ }),
257
+ });
258
+ expect(result.eligible).toBe(false);
259
+ expect(result.reasons.map((reason) => reason.code)).toEqual(['MIN_REST']);
260
+ });
261
+
262
+ it('keeps swaps free of their outgoing assignment evidence', () => {
263
+ const a = shift('10', ['1']);
264
+ const b = shift('11', ['2']);
265
+ const result = evaluateSwapEligibility({
266
+ a: { occurrence: a, resource: person('1'), context: context() },
267
+ b: { occurrence: b, resource: person('2'), context: context() },
268
+ });
269
+ expect(result).toMatchObject({
270
+ eligible: true,
271
+ slotKeys: { a: 'teacher', b: 'teacher' },
272
+ reasons: { a: [], b: [] },
273
+ });
274
+ });
275
+ it('preserves the exchanged surplus seat instead of resolving a new slot', () => {
276
+ const a = shift('10', ['1']);
277
+ const b = shift('11', ['2']);
278
+ b.assignments[0].slotKey = null;
279
+ const result = evaluateSwapEligibility({
280
+ a: { occurrence: a, resource: person('1'), context: context() },
281
+ b: { occurrence: b, resource: person('2'), context: context() },
282
+ });
283
+ expect(result.slotKeys).toEqual({ a: null, b: 'teacher' });
284
+ expect(result.eligible).toBe(true);
285
+ });
286
+ it('reports worsening drop shortfalls using the same identity', () => {
287
+ const occurrence = shift('10', ['1'], {
288
+ slots: [slot('teacher', { requiredCount: 3 })],
289
+ });
290
+ const result = evaluateDropImpact({
291
+ occurrence,
292
+ resourceId: '1',
293
+ context: { ...snapshot(), roomOccurrences: [occurrence] },
294
+ });
295
+ expect(result.introduced).toEqual([]);
296
+ expect(result.worsened).toHaveLength(1);
297
+ expect(result.worsened[0].degree).toBe(3);
298
+ });
299
+ it('simulation leaves input untouched and diff ignores a moved improving stretch', () => {
300
+ const input = snapshot({ occurrences: [shift()] });
301
+ const original = JSON.stringify(input);
302
+ const after = simulateAssignmentChange(input, {
303
+ add: [{ occurrenceId: '10', resourceId: '1', slotKey: 'teacher' }],
304
+ remove: [],
305
+ });
306
+ expect(JSON.stringify(input)).toBe(original);
307
+ expect(evaluateScheduleCoverage(after).violations).toEqual([]);
308
+ const before = evaluateScheduleCoverage(input).violations;
309
+ const moved = before.map((v) => ({
310
+ ...v,
311
+ startAt: new Date(at(9)),
312
+ degree: v.degree - 0.5,
313
+ }));
314
+ expect(diffCoverageViolations(before, moved)).toEqual({
315
+ introduced: [],
316
+ worsened: [],
317
+ resolved: [],
318
+ });
319
+ });
320
+ });
@@ -0,0 +1,367 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import {
3
+ buildGanttBars,
4
+ buildGanttLinks,
5
+ buildGanttRows,
6
+ buildGanttScale,
7
+ formatGanttDays,
8
+ GANTT_DAY_WIDTHS,
9
+ GANTT_ROW_HEIGHT,
10
+ getGanttX,
11
+ getGanttDate,
12
+ getGanttNonWorkingColumns,
13
+ type GanttActivityInput,
14
+ type GanttWbsInput,
15
+ } from '../src/libs/gantt-geometry.ts';
16
+ import { buildWorkCalendarTable } from '../src/utils/workTime.ts';
17
+
18
+ const ZONE = 'America/Los_Angeles';
19
+ const NOW = new Date('2026-03-02T17:00:00Z');
20
+
21
+ it('shades a working Saturday correctly and merges holiday closures across daylight saving', () => {
22
+ const scale = buildGanttScale(
23
+ [],
24
+ new Date('2026-03-07T12:00:00Z'),
25
+ 'America/Toronto',
26
+ 'DAY',
27
+ );
28
+ const calendar = {
29
+ id: 'night-calendar',
30
+ timeZone: 'America/Toronto',
31
+ weekHours: {
32
+ '1': [['08:00', '17:00']],
33
+ '2': [['08:00', '17:00']],
34
+ '3': [['08:00', '17:00']],
35
+ '4': [['08:00', '17:00']],
36
+ '5': [['08:00', '17:00']],
37
+ '6': [['08:00', '12:00']],
38
+ },
39
+ exceptions: { '2026-03-09': [] },
40
+ } as const;
41
+ const table = buildWorkCalendarTable(
42
+ calendar as any,
43
+ scale.startAt,
44
+ scale.endAt,
45
+ );
46
+ const columns = getGanttNonWorkingColumns(scale, table);
47
+ const saturday = getGanttX(scale, new Date('2026-03-07T05:00:00Z'));
48
+ const sunday = getGanttX(scale, new Date('2026-03-08T05:00:00Z'));
49
+ expect(
50
+ columns.some(
51
+ (column) => column.x <= saturday && column.x + column.width > saturday,
52
+ ),
53
+ ).toBe(false);
54
+ expect(columns.find((column) => column.x === sunday)).toMatchObject({
55
+ width: scale.dayWidth * 2,
56
+ isException: true,
57
+ });
58
+ });
59
+
60
+ /*
61
+ * Local LA time (PST) to UTC instant.
62
+ */
63
+ function la(date: string, time: string): Date {
64
+ return new Date(`${date}T${time}:00-08:00`);
65
+ }
66
+
67
+ const wbs: GanttWbsInput[] = [
68
+ { id: 'w1', parentId: null, code: '1', name: 'Site', ordinal: 1 },
69
+ { id: 'w2', parentId: 'w1', code: '1.1', name: 'Earthworks', ordinal: 1 },
70
+ { id: 'w3', parentId: null, code: '2', name: 'Structure', ordinal: 2 },
71
+ ];
72
+
73
+ /* Build a drawable activity fixture with effective and analytical dates. */
74
+ function activity(
75
+ over: Partial<GanttActivityInput> & { id: string; code: string },
76
+ ): GanttActivityInput {
77
+ return {
78
+ wbsId: null,
79
+ name: over.code,
80
+ type: 'TASK',
81
+ status: 'NOT_STARTED',
82
+ plannedDurationMinutes: 480 * 2,
83
+ remainingDurationMinutes: 480 * 2,
84
+ startAt: la('2026-03-02', '08:00'),
85
+ finishAt: la('2026-03-03', '17:00'),
86
+ earlyStartAt: la('2026-03-02', '08:00'),
87
+ earlyFinishAt: la('2026-03-03', '17:00'),
88
+ lateStartAt: la('2026-03-02', '08:00'),
89
+ lateFinishAt: la('2026-03-03', '17:00'),
90
+ totalFloatMinutes: 0,
91
+ isCritical: true,
92
+ ordinal: 1,
93
+ ...over,
94
+ };
95
+ }
96
+
97
+ describe('buildGanttRows', () => {
98
+ it('walks the WBS depth-first with activities under their node and collapses subtrees', () => {
99
+ const activities = [
100
+ activity({ id: 'a1', code: 'A1', wbsId: 'w2' }),
101
+ activity({ id: 'a2', code: 'A2', wbsId: 'w3', ordinal: 2 }),
102
+ activity({ id: 'a0', code: 'A0', wbsId: null }),
103
+ ];
104
+
105
+ const rows = buildGanttRows(wbs, activities, [], new Set());
106
+ expect(rows.map((row) => row.id)).toEqual([
107
+ 'a0',
108
+ 'w1',
109
+ 'w2',
110
+ 'a1',
111
+ 'w3',
112
+ 'a2',
113
+ ]);
114
+ expect(rows.map((row) => row.depth)).toEqual([0, 0, 1, 2, 0, 1]);
115
+
116
+ // A WBS row spans its descendants
117
+ const site = rows.find((row) => row.id === 'w1');
118
+ expect(site?.startAt?.toISOString()).toBe(
119
+ la('2026-03-02', '08:00').toISOString(),
120
+ );
121
+ expect(site?.isCritical).toBe(true);
122
+
123
+ const collapsed = buildGanttRows(wbs, activities, [], new Set(['w1']));
124
+ expect(collapsed.map((row) => row.id)).toEqual(['a0', 'w1', 'w3', 'a2']);
125
+ expect(collapsed[1].collapsed).toBe(true);
126
+ });
127
+
128
+ it('attaches baseline dates by activity', () => {
129
+ const rows = buildGanttRows(
130
+ [],
131
+ [activity({ id: 'a1', code: 'A1' })],
132
+ [
133
+ {
134
+ activityId: 'a1',
135
+ plannedStartAt: la('2026-03-01', '08:00'),
136
+ plannedFinishAt: la('2026-03-02', '17:00'),
137
+ },
138
+ ],
139
+ new Set(),
140
+ );
141
+
142
+ expect(rows[0].baselineStartAt?.toISOString()).toBe(
143
+ la('2026-03-01', '08:00').toISOString(),
144
+ );
145
+ });
146
+ });
147
+
148
+ describe('buildGanttScale and bars', () => {
149
+ it('lays days out at the zoom width and positions bars by local day fraction', () => {
150
+ const rows = buildGanttRows(
151
+ [],
152
+ [activity({ id: 'a1', code: 'A1' })],
153
+ [],
154
+ new Set(),
155
+ );
156
+ const scale = buildGanttScale(rows, NOW, ZONE, 'DAY');
157
+
158
+ // Three days of padding before the first start
159
+ expect(scale.startAt.toISOString()).toBe(
160
+ la('2026-02-27', '00:00').toISOString(),
161
+ );
162
+ expect(scale.dayWidth).toBe(GANTT_DAY_WIDTHS.DAY);
163
+ expect(getGanttX(scale, la('2026-03-02', '00:00'))).toBe(
164
+ 3 * GANTT_DAY_WIDTHS.DAY,
165
+ );
166
+ expect(getGanttX(scale, la('2026-03-02', '12:00'))).toBe(
167
+ 3.5 * GANTT_DAY_WIDTHS.DAY,
168
+ );
169
+ expect(scale.minorTicks.length).toBe(
170
+ Math.round(scale.totalWidth / scale.dayWidth),
171
+ );
172
+ expect(scale.minorTicks.find((tick) => tick.label === '1')?.isWeekend).toBe(
173
+ true,
174
+ );
175
+
176
+ const [bar] = buildGanttBars(rows, scale);
177
+ expect(bar.rowIndex).toBe(0);
178
+ expect(bar.x).toBeCloseTo(3 * 40 + (8 / 24) * 40, 5);
179
+ expect(bar.width).toBeCloseTo((33 / 24) * 40, 5);
180
+ expect(bar.isCritical).toBe(true);
181
+ expect(bar.floatX).toBeNull();
182
+ });
183
+
184
+ it('draws milestones as points, progress as a fill, and float as a tail', () => {
185
+ const rows = buildGanttRows(
186
+ [],
187
+ [
188
+ activity({
189
+ id: 'm',
190
+ code: 'M',
191
+ type: 'FINISH_MILESTONE',
192
+ plannedDurationMinutes: 0,
193
+ remainingDurationMinutes: 0,
194
+ finishAt: la('2026-03-02', '08:00'),
195
+ earlyFinishAt: la('2026-03-02', '08:00'),
196
+ }),
197
+ activity({
198
+ id: 'p',
199
+ code: 'P',
200
+ status: 'IN_PROGRESS',
201
+ remainingDurationMinutes: 480,
202
+ totalFloatMinutes: 480,
203
+ isCritical: false,
204
+ lateFinishAt: la('2026-03-04', '17:00'),
205
+ ordinal: 2,
206
+ }),
207
+ ],
208
+ [],
209
+ new Set(),
210
+ );
211
+ const scale = buildGanttScale(rows, NOW, ZONE, 'WEEK');
212
+ const [milestone, task] = buildGanttBars(rows, scale);
213
+
214
+ expect(milestone.isMilestone).toBe(true);
215
+ expect(milestone.width).toBe(0);
216
+ expect(task.progressWidth).toBe(Math.round(task.width * 0.5));
217
+ expect(task.floatX).toBeCloseTo(task.x + task.width, 5);
218
+ expect(task.floatWidth).toBeCloseTo(GANTT_DAY_WIDTHS.WEEK, 5);
219
+ });
220
+ });
221
+
222
+ describe('buildGanttLinks', () => {
223
+ it('routes a finish-to-start link from the predecessor end to the successor start', () => {
224
+ const rows = buildGanttRows(
225
+ [],
226
+ [
227
+ activity({ id: 'a', code: 'A' }),
228
+ activity({
229
+ id: 'b',
230
+ code: 'B',
231
+ earlyStartAt: la('2026-03-04', '08:00'),
232
+ earlyFinishAt: la('2026-03-05', '17:00'),
233
+ ordinal: 2,
234
+ }),
235
+ ],
236
+ [],
237
+ new Set(),
238
+ );
239
+ const scale = buildGanttScale(rows, NOW, ZONE, 'DAY');
240
+ const bars = buildGanttBars(rows, scale);
241
+ const [link] = buildGanttLinks(rows, bars, [
242
+ {
243
+ id: 'r1',
244
+ predecessorId: 'a',
245
+ successorId: 'b',
246
+ type: 'FS',
247
+ isDriving: true,
248
+ },
249
+ ]);
250
+
251
+ expect(link.isCritical).toBe(true);
252
+ expect(
253
+ link.path.startsWith(
254
+ `M ${bars[0].x + bars[0].width} ${GANTT_ROW_HEIGHT / 2}`,
255
+ ),
256
+ ).toBe(true);
257
+ expect(
258
+ link.path.endsWith(`V ${GANTT_ROW_HEIGHT * 1.5} H ${bars[1].x}`),
259
+ ).toBe(true);
260
+
261
+ // A link to a hidden row is dropped
262
+ expect(
263
+ buildGanttLinks(rows.slice(0, 1), bars.slice(0, 1), [
264
+ {
265
+ id: 'r1',
266
+ predecessorId: 'a',
267
+ successorId: 'b',
268
+ type: 'FS',
269
+ isDriving: true,
270
+ },
271
+ ]),
272
+ ).toEqual([]);
273
+ });
274
+ });
275
+
276
+ describe('formatGanttDays', () => {
277
+ it('formats minutes as working days', () => {
278
+ expect(formatGanttDays(960, 480)).toBe('2');
279
+ expect(formatGanttDays(720, 480)).toBe('1.5');
280
+ expect(formatGanttDays(null, 480)).toBe('');
281
+ });
282
+ });
283
+
284
+ /* Effective dates and driving links are independent of analytical CPM values. */
285
+ describe('schedule rewrite Gantt contracts', () => {
286
+ it('uses effective dates for activities and WBS, without resurrecting unscheduled analytics', () => {
287
+ const effective = la('2026-03-09', '08:00');
288
+ const rows = buildGanttRows(
289
+ wbs,
290
+ [
291
+ activity({
292
+ id: 'leveled',
293
+ code: 'L',
294
+ wbsId: 'w2',
295
+ startAt: effective,
296
+ finishAt: la('2026-03-10', '17:00'),
297
+ }),
298
+ activity({ id: 'missing', code: 'M', startAt: null, finishAt: null }),
299
+ ],
300
+ [],
301
+ new Set(),
302
+ );
303
+ expect(rows.find((row) => row.id === 'leveled')!.startAt).toEqual(
304
+ effective,
305
+ );
306
+ expect(rows.find((row) => row.id === 'w1')!.startAt).toEqual(effective);
307
+ expect(rows.find((row) => row.id === 'missing')!.startAt).toBeNull();
308
+ });
309
+ it('does not highlight a non-driving link between critical activities', () => {
310
+ const rows = buildGanttRows(
311
+ [],
312
+ [activity({ id: 'a', code: 'A' }), activity({ id: 'b', code: 'B' })],
313
+ [],
314
+ new Set(),
315
+ );
316
+ const bars = buildGanttBars(rows, buildGanttScale(rows, NOW, ZONE, 'WEEK'));
317
+ expect(
318
+ buildGanttLinks(rows, bars, [
319
+ {
320
+ id: 'r',
321
+ predecessorId: 'a',
322
+ successorId: 'b',
323
+ type: 'FS',
324
+ isDriving: false,
325
+ },
326
+ ])[0].isCritical,
327
+ ).toBe(false);
328
+ });
329
+ it('builds 15,000 dependency paths for 5,000 rows within the interaction budget', () => {
330
+ const activities = Array.from({ length: 5000 }, (_, i) =>
331
+ activity({ id: String(i + 1), code: String(i + 1), ordinal: i }),
332
+ );
333
+ const rows = buildGanttRows([], activities, [], new Set());
334
+ const bars = buildGanttBars(rows, buildGanttScale(rows, NOW, ZONE, 'WEEK'));
335
+ const relationships = Array.from({ length: 15000 }, (_, i) => ({
336
+ id: String(i),
337
+ predecessorId: String((i % 4997) + 1),
338
+ successorId: String((i % 4997) + 2 + (i % 3)),
339
+ type: 'FS' as const,
340
+ }));
341
+ const before = performance.now();
342
+ const links = buildGanttLinks(rows, bars, relationships);
343
+ expect(links).toHaveLength(15000);
344
+ expect(performance.now() - before).toBeLessThan(250);
345
+ });
346
+ });
347
+
348
+ it.each([
349
+ '2026-03-08T08:00:00-04:00',
350
+ '2026-11-01T08:00:00-05:00',
351
+ '2026-11-01T01:30:00-04:00',
352
+ '2026-11-01T01:30:00-05:00',
353
+ ])(
354
+ 'preserves the exact instant when converting DST day geometry: %s',
355
+ (value) => {
356
+ const at = new Date(value);
357
+ for (const offset of [-7, 7]) {
358
+ const scale = buildGanttScale(
359
+ [],
360
+ new Date(at.getTime() + offset * 86_400_000),
361
+ 'America/New_York',
362
+ 'DAY',
363
+ );
364
+ expect(getGanttDate(scale, getGanttX(scale, at))).toEqual(at);
365
+ }
366
+ },
367
+ );