Skip to content

Commit 6f10cb9

Browse files
committed
test(gantt): cover end date fallback branches
1 parent bb0868c commit 6f10cb9

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

packages/mermaid/src/diagrams/gantt/ganttDb.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,6 @@ const getEndDate = function (prevTime, dateFormat, str, inclusive = false) {
420420
// without a time when the dateFormat includes one.
421421
const d = new Date(str);
422422
if (
423-
d !== undefined &&
424423
!isNaN(d.getTime()) &&
425424
// WebKit browsers can mis-parse invalid dates to be ridiculously
426425
// huge numbers, e.g. new Date('202304') gets parsed as January 1, 202304.

packages/mermaid/src/diagrams/gantt/ganttDb.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,25 @@ describe('when using the ganttDb', function () {
500500
expect(tasks[0].endTime).toEqual(new Date('2026-01-03 23:30'));
501501
});
502502

503+
it('should fall back to duration when the end date is invalid', function () {
504+
ganttDb.setDateFormat('YYYY-MM-DD HH:mm');
505+
ganttDb.addSection('Tasks with invalid end dates');
506+
ganttDb.addTask('test1', 'id1,2026-01-02,2d');
507+
const tasks = ganttDb.getTasks();
508+
509+
expect(tasks[0].endTime).toEqual(dayjs(new Date('2026-01-02')).add(2, 'd').toDate());
510+
});
511+
512+
it('should apply inclusiveEndDates to a non-strict end date', function () {
513+
ganttDb.setDateFormat('YYYY-MM-DD HH:mm');
514+
ganttDb.enableInclusiveEndDates();
515+
ganttDb.addSection('Tasks with inclusive end dates');
516+
ganttDb.addTask('test1', 'id1,2026-01-03,2026-01-05');
517+
const tasks = ganttDb.getTasks();
518+
519+
expect(tasks[0].endTime).toEqual(dayjs(new Date('2026-01-05')).add(1, 'd').toDate());
520+
});
521+
503522
/**
504523
* Unfortunately, Vitest has no way of modifying the timezone at runtime, so
505524
* in order to test this, please run this test with

0 commit comments

Comments
 (0)