From a3eef7298e900675645ad5c6538678dbec58a800 Mon Sep 17 00:00:00 2001 From: Gijs van Dam Date: Thu, 31 Jan 2019 15:33:35 +0800 Subject: [PATCH 01/10] Add milestone to ganttDb --- src/diagrams/gantt/ganttDb.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/diagrams/gantt/ganttDb.js b/src/diagrams/gantt/ganttDb.js index b4e4fda763..3f4328c1cc 100644 --- a/src/diagrams/gantt/ganttDb.js +++ b/src/diagrams/gantt/ganttDb.js @@ -157,7 +157,7 @@ const compileData = function (prevTask, dataStr) { const task = {} - // Get tags like active, done cand crit + // Get tags like active, done, crit and milestone let matchFound = true while (matchFound) { matchFound = false @@ -176,6 +176,11 @@ const compileData = function (prevTask, dataStr) { data.shift(1) matchFound = true } + if (data[0].match(/^\s*milestone\s*$/)) { + task.milestone = true + data.shift(1) + matchFound = true + } } for (let i = 0; i < data.length; i++) { data[i] = data[i].trim() @@ -215,7 +220,7 @@ const parseData = function (prevTaskId, dataStr) { const task = {} - // Get tags like active, done cand crit + // Get tags like active, done, crit and milestone let matchFound = true while (matchFound) { matchFound = false @@ -234,6 +239,11 @@ const parseData = function (prevTaskId, dataStr) { data.shift(1) matchFound = true } + if (data[0].match(/^\s*milestone\s*$/)) { + task.milestone = true + data.shift(1) + matchFound = true + } } for (let i = 0; i < data.length; i++) { data[i] = data[i].trim() @@ -281,6 +291,7 @@ export const addTask = function (descr, data) { rawTask.active = taskInfo.active rawTask.done = taskInfo.done rawTask.crit = taskInfo.crit + rawTask.milestone = taskInfo.milestone const pos = rawTasks.push(rawTask) @@ -308,6 +319,7 @@ export const addTaskOrg = function (descr, data) { newTask.active = taskInfo.active newTask.done = taskInfo.done newTask.crit = taskInfo.crit + newTask.milestone = taskInfo.milestone lastTask = newTask tasks.push(newTask) } From 48f8c3f85a7c162990eeeb1ec7d18ee3c0bc5b93 Mon Sep 17 00:00:00 2001 From: Gijs van Dam Date: Fri, 1 Feb 2019 12:34:55 +0800 Subject: [PATCH 02/10] Add custom rendering of milestone tasks If a task is a milestone, the rect shape will be square in the center of the original width of the rectangular calculated if it weren't a milestone. The placement of the label text is adjusted accordingly. Both the rect and the text get a 'milestone' and 'milestoneText' class accordingly. The scss rotates the square and scales it a bit down, so that it's a diamond, which appears to be the defacto standard for milestone icons. The label text is put in italics. The rotational transform is done in the scss, so that it's easy for users to create their own milestone icon-style. --- src/diagrams/gantt/ganttRenderer.js | 52 +++++++++++++++++++++++------ src/themes/gantt.scss | 7 ++++ 2 files changed, 48 insertions(+), 11 deletions(-) diff --git a/src/diagrams/gantt/ganttRenderer.js b/src/diagrams/gantt/ganttRenderer.js index 7d24df2a4c..176550d2f8 100644 --- a/src/diagrams/gantt/ganttRenderer.js +++ b/src/diagrams/gantt/ganttRenderer.js @@ -98,6 +98,7 @@ export const draw = function (text, id) { } function drawRects (theArray, theGap, theTopPad, theSidePad, theBarHeight, theColorScale, w, h) { + //draw background rects covering the entire width of the graph, these form the section rows. svg.append('g') .selectAll('rect') .data(theArray) @@ -120,6 +121,7 @@ export const draw = function (text, id) { return 'section section0' }) + //draw the rects representing the tasks const rectangles = svg.append('g') .selectAll('rect') .data(theArray) @@ -129,17 +131,26 @@ export const draw = function (text, id) { .attr('rx', 3) .attr('ry', 3) .attr('x', function (d) { + if (d.milestone) { + return timeScale(d.startTime) + theSidePad + (0.5 * (timeScale(d.endTime) - timeScale(d.startTime))) - (0.5* theBarHeight) + } return timeScale(d.startTime) + theSidePad }) .attr('y', function (d, i) { return i * theGap + theTopPad }) .attr('width', function (d) { + if (d.milestone) { + return theBarHeight + } return (timeScale(d.endTime) - timeScale(d.startTime)) }) .attr('height', theBarHeight) + .attr('transform-origin', function(d, i) { + return (timeScale(d.startTime) + theSidePad + 0.5 * (timeScale(d.endTime) - timeScale(d.startTime))).toString() + 'px ' + (i * theGap + theTopPad + 0.5* theBarHeight).toString() + 'px' + } ) .attr('class', function (d) { - const res = 'task ' + const res = 'task' let secNum = 0 for (let i = 0; i < categories.length; i++) { @@ -148,37 +159,49 @@ export const draw = function (text, id) { } } + let milestone = '' + if (d.milestone) { + milestone = ' milestone' + } + if (d.active) { if (d.crit) { - return res + ' activeCrit' + secNum + return res + milestone + ' activeCrit' + secNum } else { - return res + ' active' + secNum + return res + milestone + ' active' + secNum } } if (d.done) { if (d.crit) { - return res + ' doneCrit' + secNum + return res + milestone + ' doneCrit' + secNum } else { - return res + ' done' + secNum + return res + milestone + ' done' + secNum } } if (d.crit) { - return res + ' crit' + secNum + return res + milestone + ' crit' + secNum } - return res + ' task' + secNum + return res + milestone + ' task' + secNum }) - + + //Append task labels rectangles.append('text') .text(function (d) { return d.task }) .attr('font-size', conf.fontSize) .attr('x', function (d) { - const startX = timeScale(d.startTime) - const endX = timeScale(d.endTime) + let startX = timeScale(d.startTime) + let endX = timeScale(d.endTime) + if (d.milestone) { + startX += (0.5 * (timeScale(d.endTime) - timeScale(d.startTime))) - (0.5* theBarHeight) + } + if (d.milestone) { + endX = startX + theBarHeight + } const textWidth = this.getBBox().width // Check id text width > width of rectangle @@ -198,7 +221,10 @@ export const draw = function (text, id) { .attr('text-height', theBarHeight) .attr('class', function (d) { const startX = timeScale(d.startTime) - const endX = timeScale(d.endTime) + let endX = timeScale(d.endTime) + if (d.milestone) { + endX = startX + theBarHeight + } const textWidth = this.getBBox().width let secNum = 0 for (let i = 0; i < categories.length; i++) { @@ -228,6 +254,10 @@ export const draw = function (text, id) { } } + if (d.milestone) { + taskType += ' milestoneText' + } + // Check id text width > width of rectangle if (textWidth > (endX - startX)) { if (endX + textWidth + 1.5 * conf.leftPadding > w) { diff --git a/src/themes/gantt.scss b/src/themes/gantt.scss index 6793135ec8..2d1182cc51 100644 --- a/src/themes/gantt.scss +++ b/src/themes/gantt.scss @@ -188,6 +188,13 @@ shape-rendering: crispEdges; } +.milestone { + transform: rotate(45deg) scale(0.8,0.8); +} + +.milestoneText { + font-style: italic; +} .doneCritText0, .doneCritText1, .doneCritText2, From 5565d36ef25c1a06773247abc9af3b5c9af2aea0 Mon Sep 17 00:00:00 2001 From: Gijs van Dam Date: Fri, 1 Feb 2019 12:41:03 +0800 Subject: [PATCH 03/10] Fix lint issues --- src/diagrams/gantt/ganttRenderer.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/diagrams/gantt/ganttRenderer.js b/src/diagrams/gantt/ganttRenderer.js index 176550d2f8..0529e3b06f 100644 --- a/src/diagrams/gantt/ganttRenderer.js +++ b/src/diagrams/gantt/ganttRenderer.js @@ -98,7 +98,7 @@ export const draw = function (text, id) { } function drawRects (theArray, theGap, theTopPad, theSidePad, theBarHeight, theColorScale, w, h) { - //draw background rects covering the entire width of the graph, these form the section rows. + // Draw background rects covering the entire width of the graph, these form the section rows. svg.append('g') .selectAll('rect') .data(theArray) @@ -121,7 +121,7 @@ export const draw = function (text, id) { return 'section section0' }) - //draw the rects representing the tasks + // Draw the rects representing the tasks const rectangles = svg.append('g') .selectAll('rect') .data(theArray) @@ -132,7 +132,7 @@ export const draw = function (text, id) { .attr('ry', 3) .attr('x', function (d) { if (d.milestone) { - return timeScale(d.startTime) + theSidePad + (0.5 * (timeScale(d.endTime) - timeScale(d.startTime))) - (0.5* theBarHeight) + return timeScale(d.startTime) + theSidePad + (0.5 * (timeScale(d.endTime) - timeScale(d.startTime))) - (0.5 * theBarHeight) } return timeScale(d.startTime) + theSidePad }) @@ -146,9 +146,9 @@ export const draw = function (text, id) { return (timeScale(d.endTime) - timeScale(d.startTime)) }) .attr('height', theBarHeight) - .attr('transform-origin', function(d, i) { - return (timeScale(d.startTime) + theSidePad + 0.5 * (timeScale(d.endTime) - timeScale(d.startTime))).toString() + 'px ' + (i * theGap + theTopPad + 0.5* theBarHeight).toString() + 'px' - } ) + .attr('transform-origin', function (d, i) { + return (timeScale(d.startTime) + theSidePad + 0.5 * (timeScale(d.endTime) - timeScale(d.startTime))).toString() + 'px ' + (i * theGap + theTopPad + 0.5 * theBarHeight).toString() + 'px' + }) .attr('class', function (d) { const res = 'task' @@ -186,8 +186,8 @@ export const draw = function (text, id) { return res + milestone + ' task' + secNum }) - - //Append task labels + + // Append task labels rectangles.append('text') .text(function (d) { return d.task @@ -197,7 +197,7 @@ export const draw = function (text, id) { let startX = timeScale(d.startTime) let endX = timeScale(d.endTime) if (d.milestone) { - startX += (0.5 * (timeScale(d.endTime) - timeScale(d.startTime))) - (0.5* theBarHeight) + startX += (0.5 * (timeScale(d.endTime) - timeScale(d.startTime))) - (0.5 * theBarHeight) } if (d.milestone) { endX = startX + theBarHeight From 9dbb3767e28cd45fcd5c9ad2227ff0cbdb3ee313 Mon Sep 17 00:00:00 2001 From: Gijs van Dam Date: Fri, 1 Feb 2019 13:27:42 +0800 Subject: [PATCH 04/10] Extract tag parsing in separate function --- src/diagrams/gantt/ganttDb.js | 79 ++++++++++++++--------------------- 1 file changed, 31 insertions(+), 48 deletions(-) diff --git a/src/diagrams/gantt/ganttDb.js b/src/diagrams/gantt/ganttDb.js index 3f4328c1cc..adf8304a66 100644 --- a/src/diagrams/gantt/ganttDb.js +++ b/src/diagrams/gantt/ganttDb.js @@ -158,30 +158,8 @@ const compileData = function (prevTask, dataStr) { const task = {} // Get tags like active, done, crit and milestone - let matchFound = true - while (matchFound) { - matchFound = false - if (data[0].match(/^\s*active\s*$/)) { - task.active = true - data.shift(1) - matchFound = true - } - if (data[0].match(/^\s*done\s*$/)) { - task.done = true - data.shift(1) - matchFound = true - } - if (data[0].match(/^\s*crit\s*$/)) { - task.crit = true - data.shift(1) - matchFound = true - } - if (data[0].match(/^\s*milestone\s*$/)) { - task.milestone = true - data.shift(1) - matchFound = true - } - } + getTaskTags(data, task) + for (let i = 0; i < data.length; i++) { data[i] = data[i].trim() } @@ -221,30 +199,8 @@ const parseData = function (prevTaskId, dataStr) { const task = {} // Get tags like active, done, crit and milestone - let matchFound = true - while (matchFound) { - matchFound = false - if (data[0].match(/^\s*active\s*$/)) { - task.active = true - data.shift(1) - matchFound = true - } - if (data[0].match(/^\s*done\s*$/)) { - task.done = true - data.shift(1) - matchFound = true - } - if (data[0].match(/^\s*crit\s*$/)) { - task.crit = true - data.shift(1) - matchFound = true - } - if (data[0].match(/^\s*milestone\s*$/)) { - task.milestone = true - data.shift(1) - matchFound = true - } - } + getTaskTags(data, task) + for (let i = 0; i < data.length; i++) { data[i] = data[i].trim() } @@ -373,3 +329,30 @@ export default { findTaskById, addTaskOrg } + +function getTaskTags (data, task) { + let matchFound = true + while (matchFound) { + matchFound = false + if (data[0].match(/^\s*active\s*$/)) { + task.active = true + data.shift(1) + matchFound = true + } + if (data[0].match(/^\s*done\s*$/)) { + task.done = true + data.shift(1) + matchFound = true + } + if (data[0].match(/^\s*crit\s*$/)) { + task.crit = true + data.shift(1) + matchFound = true + } + if (data[0].match(/^\s*milestone\s*$/)) { + task.milestone = true + data.shift(1) + matchFound = true + } + } +} From 901df242b78a69bf104c97b154695dd902c7a1e1 Mon Sep 17 00:00:00 2001 From: Gijs van Dam Date: Fri, 1 Feb 2019 13:28:12 +0800 Subject: [PATCH 05/10] Replace multiple returns with single return --- src/diagrams/gantt/ganttRenderer.js | 33 ++++++++++++++--------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/diagrams/gantt/ganttRenderer.js b/src/diagrams/gantt/ganttRenderer.js index 0529e3b06f..c25724b702 100644 --- a/src/diagrams/gantt/ganttRenderer.js +++ b/src/diagrams/gantt/ganttRenderer.js @@ -159,32 +159,31 @@ export const draw = function (text, id) { } } - let milestone = '' - if (d.milestone) { - milestone = ' milestone' - } - + let taskClass = '' if (d.active) { - if (d.crit) { - return res + milestone + ' activeCrit' + secNum + taskClass = ' active' + } else if (d.done) { + taskClass = ' done' + } + if (d.crit) { + if (taskClass.length > 0) { + taskClass += 'Crit' } else { - return res + milestone + ' active' + secNum + taskClass = ' crit' } } - if (d.done) { - if (d.crit) { - return res + milestone + ' doneCrit' + secNum - } else { - return res + milestone + ' done' + secNum - } + if (taskClass.length === 0) { + taskClass = ' task' } - if (d.crit) { - return res + milestone + ' crit' + secNum + if (d.milestone) { + taskClass = ' milestone' + taskClass } - return res + milestone + ' task' + secNum + taskClass += secNum + + return res + taskClass }) // Append task labels From f903090e0f7ae8f082a4ce851f9d78a19c29d143 Mon Sep 17 00:00:00 2001 From: Gijs van Dam Date: Fri, 1 Feb 2019 14:21:25 +0800 Subject: [PATCH 06/10] Refactor tag parsing of tags The allowed tags are now a const at the top of the code. Adding a tag there, automatically assigns the property to the javascript object, if the tag is present in the data. --- src/diagrams/gantt/ganttDb.js | 36 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/src/diagrams/gantt/ganttDb.js b/src/diagrams/gantt/ganttDb.js index adf8304a66..96b93cb892 100644 --- a/src/diagrams/gantt/ganttDb.js +++ b/src/diagrams/gantt/ganttDb.js @@ -7,6 +7,7 @@ let title = '' let sections = [] let tasks = [] let currentSection = '' +const tags = ['active', 'done', 'crit', 'milestone'] export const clear = function () { sections = [] @@ -158,7 +159,7 @@ const compileData = function (prevTask, dataStr) { const task = {} // Get tags like active, done, crit and milestone - getTaskTags(data, task) + getTaskTags(data, task, tags) for (let i = 0; i < data.length; i++) { data[i] = data[i].trim() @@ -199,7 +200,7 @@ const parseData = function (prevTaskId, dataStr) { const task = {} // Get tags like active, done, crit and milestone - getTaskTags(data, task) + getTaskTags(data, task, tags) for (let i = 0; i < data.length; i++) { data[i] = data[i].trim() @@ -330,29 +331,18 @@ export default { addTaskOrg } -function getTaskTags (data, task) { +function getTaskTags (data, task, tags) { let matchFound = true while (matchFound) { matchFound = false - if (data[0].match(/^\s*active\s*$/)) { - task.active = true - data.shift(1) - matchFound = true - } - if (data[0].match(/^\s*done\s*$/)) { - task.done = true - data.shift(1) - matchFound = true - } - if (data[0].match(/^\s*crit\s*$/)) { - task.crit = true - data.shift(1) - matchFound = true - } - if (data[0].match(/^\s*milestone\s*$/)) { - task.milestone = true - data.shift(1) - matchFound = true - } + tags.forEach(function (t) { + const pattern = '^\\s*' + t + '\\s*$' + const regex = new RegExp(pattern) + if (data[0].match(regex)) { + task[t] = true + data.shift(1) + matchFound = true + } + }) } } From c84c1546032f5c6867f50a8d344ee31aea5dd29b Mon Sep 17 00:00:00 2001 From: Gijs van Dam Date: Fri, 1 Feb 2019 16:16:28 +0800 Subject: [PATCH 07/10] Add tests for all possible task tags --- src/diagrams/gantt/gantt.spec.js | 86 +++++++++++++++++++++++++++++++- 1 file changed, 85 insertions(+), 1 deletion(-) diff --git a/src/diagrams/gantt/gantt.spec.js b/src/diagrams/gantt/gantt.spec.js index a170be6e1f..d8f5b7038b 100644 --- a/src/diagrams/gantt/gantt.spec.js +++ b/src/diagrams/gantt/gantt.spec.js @@ -1,10 +1,12 @@ /* eslint-env jasmine */ import { parser } from './parser/gantt' import ganttDb from './ganttDb' +import moment from 'moment' describe('when parsing a gantt diagram it', function () { beforeEach(function () { parser.yy = ganttDb + parser.yy.clear() }) it('should handle a dateFormat definition', function () { @@ -38,11 +40,93 @@ describe('when parsing a gantt diagram it', function () { */ it('should handle a task definition', function () { const str = 'gantt\n' + - 'dateFormat yyyy-mm-dd\n' + + 'dateFormat YYYY-MM-DD\n' + 'title Adding gantt diagram functionality to mermaid\n' + 'section Documentation\n' + 'Design jison grammar:des1, 2014-01-01, 2014-01-04' parser.parse(str) + + const tasks = parser.yy.getTasks() + + expect(tasks[0].startTime).toEqual(moment('2014-01-01', 'YYYY-MM-DD').toDate()) + expect(tasks[0].endTime).toEqual(moment('2014-01-04', 'YYYY-MM-DD').toDate()) + expect(tasks[0].id).toEqual('des1') + expect(tasks[0].task).toEqual('Design jison grammar') + }) + it('should handle a milestone task', function () { + const str = 'gantt\n' + + 'dateFormat YYYY-MM-DD\n' + + 'title Adding gantt diagram functionality to mermaid\n' + + 'section Documentation\n' + + 'test task:milestone, 2014-01-01, 2014-01-04' + + parser.parse(str) + + const tasks = parser.yy.getTasks() + expect(tasks[0].milestone).toBeTruthy() + expect(tasks[0].done).toBeFalsy() + expect(tasks[0].crit).toBeFalsy() + expect(tasks[0].active).toBeFalsy() + }) + it('should handle a done task', function () { + const str = 'gantt\n' + + 'dateFormat YYYY-MM-DD\n' + + 'title Adding gantt diagram functionality to mermaid\n' + + 'section Documentation\n' + + 'test task:done, 2014-01-01, 2014-01-04' + + parser.parse(str) + + const tasks = parser.yy.getTasks() + expect(tasks[0].milestone).toBeFalsy() + expect(tasks[0].done).toBeTruthy() + expect(tasks[0].crit).toBeFalsy() + expect(tasks[0].active).toBeFalsy() + }) + it('should handle a critical task', function () { + const str = 'gantt\n' + + 'dateFormat YYYY-MM-DD\n' + + 'title Adding gantt diagram functionality to mermaid\n' + + 'section Documentation\n' + + 'test task:crit, 2014-01-01, 2014-01-04' + + parser.parse(str) + + const tasks = parser.yy.getTasks() + expect(tasks[0].milestone).toBeFalsy() + expect(tasks[0].done).toBeFalsy() + expect(tasks[0].crit).toBeTruthy() + expect(tasks[0].active).toBeFalsy() + }) + it('should handle an active task', function () { + const str = 'gantt\n' + + 'dateFormat YYYY-MM-DD\n' + + 'title Adding gantt diagram functionality to mermaid\n' + + 'section Documentation\n' + + 'test task:active, 2014-01-01, 2014-01-04' + + parser.parse(str) + + const tasks = parser.yy.getTasks() + expect(tasks[0].milestone).toBeFalsy() + expect(tasks[0].done).toBeFalsy() + expect(tasks[0].crit).toBeFalsy() + expect(tasks[0].active).toBeTruthy() + }) + it('should handle task with multiple tags', function () { + const str = 'gantt\n' + + 'dateFormat YYYY-MM-DD\n' + + 'title Adding gantt diagram functionality to mermaid\n' + + 'section Documentation\n' + + 'test task:crit,milestone,done, 2014-01-01, 2014-01-04' + + parser.parse(str) + + const tasks = parser.yy.getTasks() + expect(tasks[0].milestone).toBeTruthy() + expect(tasks[0].done).toBeTruthy() + expect(tasks[0].crit).toBeTruthy() + expect(tasks[0].active).toBeFalsy() }) }) From a211b6d55d0d29ada18a5a13119866f172fc7aa8 Mon Sep 17 00:00:00 2001 From: Gijs van Dam Date: Fri, 1 Feb 2019 17:04:43 +0800 Subject: [PATCH 08/10] Use it.each in test cases to prevent code repetition --- src/diagrams/gantt/gantt.spec.js | 102 +++++++++---------------------- 1 file changed, 28 insertions(+), 74 deletions(-) diff --git a/src/diagrams/gantt/gantt.spec.js b/src/diagrams/gantt/gantt.spec.js index d8f5b7038b..694128f14f 100644 --- a/src/diagrams/gantt/gantt.spec.js +++ b/src/diagrams/gantt/gantt.spec.js @@ -1,4 +1,5 @@ /* eslint-env jasmine */ +/* eslint-disable no-eval */ import { parser } from './parser/gantt' import ganttDb from './ganttDb' import moment from 'moment' @@ -54,79 +55,32 @@ describe('when parsing a gantt diagram it', function () { expect(tasks[0].id).toEqual('des1') expect(tasks[0].task).toEqual('Design jison grammar') }) - it('should handle a milestone task', function () { - const str = 'gantt\n' + - 'dateFormat YYYY-MM-DD\n' + - 'title Adding gantt diagram functionality to mermaid\n' + - 'section Documentation\n' + - 'test task:milestone, 2014-01-01, 2014-01-04' - - parser.parse(str) - - const tasks = parser.yy.getTasks() - expect(tasks[0].milestone).toBeTruthy() - expect(tasks[0].done).toBeFalsy() - expect(tasks[0].crit).toBeFalsy() - expect(tasks[0].active).toBeFalsy() - }) - it('should handle a done task', function () { - const str = 'gantt\n' + - 'dateFormat YYYY-MM-DD\n' + - 'title Adding gantt diagram functionality to mermaid\n' + - 'section Documentation\n' + - 'test task:done, 2014-01-01, 2014-01-04' - - parser.parse(str) - - const tasks = parser.yy.getTasks() - expect(tasks[0].milestone).toBeFalsy() - expect(tasks[0].done).toBeTruthy() - expect(tasks[0].crit).toBeFalsy() - expect(tasks[0].active).toBeFalsy() - }) - it('should handle a critical task', function () { - const str = 'gantt\n' + - 'dateFormat YYYY-MM-DD\n' + - 'title Adding gantt diagram functionality to mermaid\n' + - 'section Documentation\n' + - 'test task:crit, 2014-01-01, 2014-01-04' - - parser.parse(str) - - const tasks = parser.yy.getTasks() - expect(tasks[0].milestone).toBeFalsy() - expect(tasks[0].done).toBeFalsy() - expect(tasks[0].crit).toBeTruthy() - expect(tasks[0].active).toBeFalsy() - }) - it('should handle an active task', function () { - const str = 'gantt\n' + - 'dateFormat YYYY-MM-DD\n' + - 'title Adding gantt diagram functionality to mermaid\n' + - 'section Documentation\n' + - 'test task:active, 2014-01-01, 2014-01-04' - - parser.parse(str) - - const tasks = parser.yy.getTasks() - expect(tasks[0].milestone).toBeFalsy() - expect(tasks[0].done).toBeFalsy() - expect(tasks[0].crit).toBeFalsy() - expect(tasks[0].active).toBeTruthy() - }) - it('should handle task with multiple tags', function () { - const str = 'gantt\n' + - 'dateFormat YYYY-MM-DD\n' + - 'title Adding gantt diagram functionality to mermaid\n' + - 'section Documentation\n' + - 'test task:crit,milestone,done, 2014-01-01, 2014-01-04' - - parser.parse(str) - - const tasks = parser.yy.getTasks() - expect(tasks[0].milestone).toBeTruthy() - expect(tasks[0].done).toBeTruthy() - expect(tasks[0].crit).toBeTruthy() - expect(tasks[0].active).toBeFalsy() + it.each` + tags | milestone | done | crit | active + ${'milestone'} | ${true} | ${false} | ${false} | ${false} + ${'done'} | ${false} | ${true} | ${false} | ${false} + ${'crit'} | ${false} | ${false} | ${true} | ${false} + ${'active'} | ${false} | ${false} | ${false} | ${true} + ${'crit,milestone,done'} | ${true} | ${true} | ${true} | ${false} + `('should handle a task with tags $tags', ({ tags, milestone, done, crit, active }) => { + const str = 'gantt\n' + + 'dateFormat YYYY-MM-DD\n' + + 'title Adding gantt diagram functionality to mermaid\n' + + 'section Documentation\n' + + 'test task:' + tags + ', 2014-01-01, 2014-01-04' + + const allowedTags = ['active', 'done', 'crit', 'milestone'] + + parser.parse(str) + + const tasks = parser.yy.getTasks() + + allowedTags.forEach(function (t) { + if (eval(t)) { + expect(tasks[0][t]).toBeTruthy() + } else { + expect(tasks[0][t]).toBeFalsy() + } }) }) +}) From f912f8582d03c89b868e49e96491ebe460fbfb84 Mon Sep 17 00:00:00 2001 From: Gijs van Dam Date: Mon, 4 Feb 2019 10:21:58 +0800 Subject: [PATCH 09/10] Remove MomentJS dependency from Gantt Jest test cases To reduce the dependencies of the Jest test cases, the moment dates in both Jest test files are replaced with native javascript. Also the physical file gantt.spec.js is moved to be in the same folder as gantt.js --- src/diagrams/gantt/ganttDb.spec.js | 53 +++++++++---------- src/diagrams/gantt/{ => parser}/gantt.spec.js | 9 ++-- 2 files changed, 30 insertions(+), 32 deletions(-) rename src/diagrams/gantt/{ => parser}/gantt.spec.js (90%) diff --git a/src/diagrams/gantt/ganttDb.spec.js b/src/diagrams/gantt/ganttDb.spec.js index a956e36053..8b7775a2c8 100644 --- a/src/diagrams/gantt/ganttDb.spec.js +++ b/src/diagrams/gantt/ganttDb.spec.js @@ -1,5 +1,4 @@ /* eslint-env jasmine */ -import moment from 'moment' import ganttDb from './ganttDb' describe('when using the ganttDb', function () { @@ -12,8 +11,8 @@ describe('when using the ganttDb', function () { ganttDb.addSection('testa1') ganttDb.addTask('test1', 'id1,2013-01-01,2013-01-12') const tasks = ganttDb.getTasks() - expect(tasks[0].startTime).toEqual(moment('2013-01-01', 'YYYY-MM-DD').toDate()) - expect(tasks[0].endTime).toEqual(moment('2013-01-12', 'YYYY-MM-DD').toDate()) + expect(tasks[0].startTime).toEqual(new Date(2013, 0, 1)) + expect(tasks[0].endTime).toEqual(new Date(2013, 0, 12)) expect(tasks[0].id).toEqual('id1') expect(tasks[0].task).toEqual('test1') }) @@ -22,8 +21,8 @@ describe('when using the ganttDb', function () { ganttDb.addSection('testa1') ganttDb.addTask('test1', 'id1,2013-01-01,2d') const tasks = ganttDb.getTasks() - expect(tasks[0].startTime).toEqual(moment('2013-01-01', 'YYYY-MM-DD').toDate()) - expect(tasks[0].endTime).toEqual(moment('2013-01-03', 'YYYY-MM-DD').toDate()) + expect(tasks[0].startTime).toEqual(new Date(2013, 0, 1)) + expect(tasks[0].endTime).toEqual(new Date(2013, 0, 3)) expect(tasks[0].id).toEqual('id1') expect(tasks[0].task).toEqual('test1') }) @@ -32,8 +31,8 @@ describe('when using the ganttDb', function () { ganttDb.addSection('testa1') ganttDb.addTask('test1', 'id1,2013-01-01,2h') const tasks = ganttDb.getTasks() - expect(tasks[0].startTime).toEqual(moment('2013-01-01', 'YYYY-MM-DD').toDate()) - expect(tasks[0].endTime).toEqual(moment('2013-01-01 2:00', 'YYYY-MM-DD hh:mm').toDate()) + expect(tasks[0].startTime).toEqual(new Date(2013, 0, 1)) + expect(tasks[0].endTime).toEqual(new Date(2013, 0, 1, 2)) expect(tasks[0].id).toEqual('id1') expect(tasks[0].task).toEqual('test1') }) @@ -42,8 +41,8 @@ describe('when using the ganttDb', function () { ganttDb.addSection('testa1') ganttDb.addTask('test1', 'id1,2013-01-01,2m') const tasks = ganttDb.getTasks() - expect(tasks[0].startTime).toEqual(moment('2013-01-01', 'YYYY-MM-DD').toDate()) - expect(tasks[0].endTime).toEqual(moment('2013-01-01 00:02', 'YYYY-MM-DD hh:mm').toDate()) + expect(tasks[0].startTime).toEqual(new Date(2013, 0, 1)) + expect(tasks[0].endTime).toEqual(new Date(2013, 0, 1, 0, 2)) expect(tasks[0].id).toEqual('id1') expect(tasks[0].task).toEqual('test1') }) @@ -52,8 +51,8 @@ describe('when using the ganttDb', function () { ganttDb.addSection('testa1') ganttDb.addTask('test1', 'id1,2013-01-01,2s') const tasks = ganttDb.getTasks() - expect(tasks[0].startTime).toEqual(moment('2013-01-01', 'YYYY-MM-DD').toDate()) - expect(tasks[0].endTime).toEqual(moment('2013-01-01 00:00:02', 'YYYY-MM-DD hh:mm:ss').toDate()) + expect(tasks[0].startTime).toEqual(new Date(2013, 0, 1)) + expect(tasks[0].endTime).toEqual(new Date(2013, 0, 1, 0, 0, 2)) expect(tasks[0].id).toEqual('id1') expect(tasks[0].task).toEqual('test1') }) @@ -62,8 +61,8 @@ describe('when using the ganttDb', function () { ganttDb.addSection('testa1') ganttDb.addTask('test1', 'id1,2013-01-01,2w') const tasks = ganttDb.getTasks() - expect(tasks[0].startTime).toEqual(moment('2013-01-01', 'YYYY-MM-DD').toDate()) - expect(tasks[0].endTime).toEqual(moment('2013-01-15', 'YYYY-MM-DD').toDate()) + expect(tasks[0].startTime).toEqual(new Date(2013, 0, 1)) + expect(tasks[0].endTime).toEqual(new Date(2013, 0, 15)) expect(tasks[0].id).toEqual('id1') expect(tasks[0].task).toEqual('test1') }) @@ -76,7 +75,7 @@ describe('when using the ganttDb', function () { const tasks = ganttDb.getTasks() - expect(tasks[1].startTime).toEqual(moment('2013-01-15', 'YYYY-MM-DD').toDate()) + expect(tasks[1].startTime).toEqual(new Date(2013, 0, 15)) expect(tasks[1].id).toEqual('id2') expect(tasks[1].task).toEqual('test2') }) @@ -97,8 +96,8 @@ describe('when using the ganttDb', function () { ganttDb.addSection('testa1') ganttDb.addTask('test1', '2013-01-01,2013-01-12') const tasks = ganttDb.getTasks() - expect(tasks[0].startTime).toEqual(moment('2013-01-01', 'YYYY-MM-DD').toDate()) - expect(tasks[0].endTime).toEqual(moment('2013-01-12', 'YYYY-MM-DD').toDate()) + expect(tasks[0].startTime).toEqual(new Date(2013, 0, 1)) + expect(tasks[0].endTime).toEqual(new Date(2013, 0, 12)) expect(tasks[0].id).toEqual('task1') expect(tasks[0].task).toEqual('test1') }) @@ -108,8 +107,8 @@ describe('when using the ganttDb', function () { ganttDb.addSection('testa1') ganttDb.addTask('test1', '2013-01-01,4d') const tasks = ganttDb.getTasks() - expect(tasks[0].startTime).toEqual(moment('2013-01-01', 'YYYY-MM-DD').toDate()) - expect(tasks[0].endTime).toEqual(moment('2013-01-05', 'YYYY-MM-DD').toDate()) + expect(tasks[0].startTime).toEqual(new Date(2013, 0, 1)) + expect(tasks[0].endTime).toEqual(new Date(2013, 0, 5)) expect(tasks[0].id).toEqual('task1') expect(tasks[0].task).toEqual('test1') }) @@ -122,7 +121,7 @@ describe('when using the ganttDb', function () { const tasks = ganttDb.getTasks() - expect(tasks[1].startTime).toEqual(moment('2013-01-15', 'YYYY-MM-DD').toDate()) + expect(tasks[1].startTime).toEqual(new Date(2013, 0, 15)) expect(tasks[1].id).toEqual('task1') expect(tasks[1].task).toEqual('test2') }) @@ -134,8 +133,8 @@ describe('when using the ganttDb', function () { const tasks = ganttDb.getTasks() - expect(tasks[1].startTime).toEqual(moment('2013-01-15', 'YYYY-MM-DD').toDate()) - expect(tasks[1].endTime).toEqual(moment('2013-01-26', 'YYYY-MM-DD').toDate()) + expect(tasks[1].startTime).toEqual(new Date(2013, 0, 15)) + expect(tasks[1].endTime).toEqual(new Date(2013, 0, 26)) expect(tasks[1].id).toEqual('task1') expect(tasks[1].task).toEqual('test2') }) @@ -147,8 +146,8 @@ describe('when using the ganttDb', function () { const tasks = ganttDb.getTasks() - expect(tasks[1].startTime).toEqual(moment('2013-01-15', 'YYYY-MM-DD').toDate()) - expect(tasks[1].endTime).toEqual(moment('2013-01-17', 'YYYY-MM-DD').toDate()) + expect(tasks[1].startTime).toEqual(new Date(2013, 0, 15)) + expect(tasks[1].endTime).toEqual(new Date(2013, 0, 17)) expect(tasks[1].id).toEqual('task1') expect(tasks[1].task).toEqual('test2') }) @@ -162,14 +161,14 @@ describe('when using the ganttDb', function () { const tasks = ganttDb.getTasks() - expect(tasks[1].startTime).toEqual(moment('2013-01-17', 'YYYY-MM-DD').toDate()) - expect(tasks[1].endTime).toEqual(moment('2013-01-18', 'YYYY-MM-DD').toDate()) + expect(tasks[1].startTime).toEqual(new Date(2013, 0, 17)) + expect(tasks[1].endTime).toEqual(new Date(2013, 0, 18)) expect(tasks[1].id).toEqual('id2') expect(tasks[1].task).toEqual('test2') expect(tasks[2].id).toEqual('id3') expect(tasks[2].task).toEqual('test3') - expect(tasks[2].startTime).toEqual(moment('2013-01-15', 'YYYY-MM-DD').toDate()) - expect(tasks[2].endTime).toEqual(moment('2013-01-17', 'YYYY-MM-DD').toDate()) + expect(tasks[2].startTime).toEqual(new Date(2013, 0, 15)) + expect(tasks[2].endTime).toEqual(new Date(2013, 0, 17)) }) }) diff --git a/src/diagrams/gantt/gantt.spec.js b/src/diagrams/gantt/parser/gantt.spec.js similarity index 90% rename from src/diagrams/gantt/gantt.spec.js rename to src/diagrams/gantt/parser/gantt.spec.js index 694128f14f..80bb8fd609 100644 --- a/src/diagrams/gantt/gantt.spec.js +++ b/src/diagrams/gantt/parser/gantt.spec.js @@ -1,8 +1,7 @@ /* eslint-env jasmine */ /* eslint-disable no-eval */ -import { parser } from './parser/gantt' -import ganttDb from './ganttDb' -import moment from 'moment' +import { parser } from './gantt' +import ganttDb from '../ganttDb' describe('when parsing a gantt diagram it', function () { beforeEach(function () { @@ -50,8 +49,8 @@ describe('when parsing a gantt diagram it', function () { const tasks = parser.yy.getTasks() - expect(tasks[0].startTime).toEqual(moment('2014-01-01', 'YYYY-MM-DD').toDate()) - expect(tasks[0].endTime).toEqual(moment('2014-01-04', 'YYYY-MM-DD').toDate()) + expect(tasks[0].startTime).toEqual(new Date(2014, 0, 1)) + expect(tasks[0].endTime).toEqual(new Date(2014, 0, 4)) expect(tasks[0].id).toEqual('des1') expect(tasks[0].task).toEqual('Design jison grammar') }) From 7ca9df9357c2d8e62da8d67fdec8a896e4483e0b Mon Sep 17 00:00:00 2001 From: Gijs van Dam Date: Mon, 4 Feb 2019 11:33:24 +0800 Subject: [PATCH 10/10] Refactor ganttDb tests --- src/diagrams/gantt/ganttDb.spec.js | 183 +++++++---------------------- 1 file changed, 40 insertions(+), 143 deletions(-) diff --git a/src/diagrams/gantt/ganttDb.spec.js b/src/diagrams/gantt/ganttDb.spec.js index 8b7775a2c8..18b83699aa 100644 --- a/src/diagrams/gantt/ganttDb.spec.js +++ b/src/diagrams/gantt/ganttDb.spec.js @@ -6,151 +6,48 @@ describe('when using the ganttDb', function () { ganttDb.clear() }) - it('should handle an fixed dates', function () { - ganttDb.setDateFormat('YYYY-MM-DD') - ganttDb.addSection('testa1') - ganttDb.addTask('test1', 'id1,2013-01-01,2013-01-12') - const tasks = ganttDb.getTasks() - expect(tasks[0].startTime).toEqual(new Date(2013, 0, 1)) - expect(tasks[0].endTime).toEqual(new Date(2013, 0, 12)) - expect(tasks[0].id).toEqual('id1') - expect(tasks[0].task).toEqual('test1') - }) - it('should handle duration (days) instead of fixed date to determine end date', function () { - ganttDb.setDateFormat('YYYY-MM-DD') - ganttDb.addSection('testa1') - ganttDb.addTask('test1', 'id1,2013-01-01,2d') - const tasks = ganttDb.getTasks() - expect(tasks[0].startTime).toEqual(new Date(2013, 0, 1)) - expect(tasks[0].endTime).toEqual(new Date(2013, 0, 3)) - expect(tasks[0].id).toEqual('id1') - expect(tasks[0].task).toEqual('test1') - }) - it('should handle duration (hours) instead of fixed date to determine end date', function () { - ganttDb.setDateFormat('YYYY-MM-DD') - ganttDb.addSection('testa1') - ganttDb.addTask('test1', 'id1,2013-01-01,2h') - const tasks = ganttDb.getTasks() - expect(tasks[0].startTime).toEqual(new Date(2013, 0, 1)) - expect(tasks[0].endTime).toEqual(new Date(2013, 0, 1, 2)) - expect(tasks[0].id).toEqual('id1') - expect(tasks[0].task).toEqual('test1') - }) - it('should handle duration (minutes) instead of fixed date to determine end date', function () { - ganttDb.setDateFormat('YYYY-MM-DD') - ganttDb.addSection('testa1') - ganttDb.addTask('test1', 'id1,2013-01-01,2m') - const tasks = ganttDb.getTasks() - expect(tasks[0].startTime).toEqual(new Date(2013, 0, 1)) - expect(tasks[0].endTime).toEqual(new Date(2013, 0, 1, 0, 2)) - expect(tasks[0].id).toEqual('id1') - expect(tasks[0].task).toEqual('test1') - }) - it('should handle duration (seconds) instead of fixed date to determine end date', function () { - ganttDb.setDateFormat('YYYY-MM-DD') - ganttDb.addSection('testa1') - ganttDb.addTask('test1', 'id1,2013-01-01,2s') - const tasks = ganttDb.getTasks() - expect(tasks[0].startTime).toEqual(new Date(2013, 0, 1)) - expect(tasks[0].endTime).toEqual(new Date(2013, 0, 1, 0, 0, 2)) - expect(tasks[0].id).toEqual('id1') - expect(tasks[0].task).toEqual('test1') - }) - it('should handle duration (weeks) instead of fixed date to determine end date', function () { - ganttDb.setDateFormat('YYYY-MM-DD') - ganttDb.addSection('testa1') - ganttDb.addTask('test1', 'id1,2013-01-01,2w') - const tasks = ganttDb.getTasks() - expect(tasks[0].startTime).toEqual(new Date(2013, 0, 1)) - expect(tasks[0].endTime).toEqual(new Date(2013, 0, 15)) - expect(tasks[0].id).toEqual('id1') - expect(tasks[0].task).toEqual('test1') - }) - - it('should handle relative start date based on id', function () { - ganttDb.setDateFormat('YYYY-MM-DD') - ganttDb.addSection('testa1') - ganttDb.addTask('test1', 'id1,2013-01-01,2w') - ganttDb.addTask('test2', 'id2,after id1,1d') - - const tasks = ganttDb.getTasks() - - expect(tasks[1].startTime).toEqual(new Date(2013, 0, 15)) - expect(tasks[1].id).toEqual('id2') - expect(tasks[1].task).toEqual('test2') - }) - - it('should handle relative start date based on id when id is invalid', function () { - ganttDb.setDateFormat('YYYY-MM-DD') - ganttDb.addSection('testa1') - ganttDb.addTask('test1', 'id1,2013-01-01,2w') - ganttDb.addTask('test2', 'id2,after id3,1d') - const tasks = ganttDb.getTasks() - expect(tasks[1].startTime).toEqual(new Date((new Date()).setHours(0, 0, 0, 0))) - expect(tasks[1].id).toEqual('id2') - expect(tasks[1].task).toEqual('test2') - }) - - it('should handle fixed dates without id', function () { - ganttDb.setDateFormat('YYYY-MM-DD') - ganttDb.addSection('testa1') - ganttDb.addTask('test1', '2013-01-01,2013-01-12') - const tasks = ganttDb.getTasks() - expect(tasks[0].startTime).toEqual(new Date(2013, 0, 1)) - expect(tasks[0].endTime).toEqual(new Date(2013, 0, 12)) - expect(tasks[0].id).toEqual('task1') - expect(tasks[0].task).toEqual('test1') - }) - - it('should handle duration instead of a fixed date to determine end date without id', function () { - ganttDb.setDateFormat('YYYY-MM-DD') - ganttDb.addSection('testa1') - ganttDb.addTask('test1', '2013-01-01,4d') - const tasks = ganttDb.getTasks() - expect(tasks[0].startTime).toEqual(new Date(2013, 0, 1)) - expect(tasks[0].endTime).toEqual(new Date(2013, 0, 5)) - expect(tasks[0].id).toEqual('task1') - expect(tasks[0].task).toEqual('test1') - }) - - it('should handle relative start date of a fixed date to determine end date without id', function () { - ganttDb.setDateFormat('YYYY-MM-DD') - ganttDb.addSection('testa1') - ganttDb.addTask('test1', 'id1,2013-01-01,2w') - ganttDb.addTask('test2', 'after id1,1d') - - const tasks = ganttDb.getTasks() - - expect(tasks[1].startTime).toEqual(new Date(2013, 0, 15)) - expect(tasks[1].id).toEqual('task1') - expect(tasks[1].task).toEqual('test2') - }) - it('should handle a new task with only an end date as definition', function () { - ganttDb.setDateFormat('YYYY-MM-DD') - ganttDb.addSection('testa1') - ganttDb.addTask('test1', 'id1,2013-01-01,2w') - ganttDb.addTask('test2', '2013-01-26') - - const tasks = ganttDb.getTasks() - - expect(tasks[1].startTime).toEqual(new Date(2013, 0, 15)) - expect(tasks[1].endTime).toEqual(new Date(2013, 0, 26)) - expect(tasks[1].id).toEqual('task1') - expect(tasks[1].task).toEqual('test2') - }) - it('should handle a new task with only an end date as definition', function () { - ganttDb.setDateFormat('YYYY-MM-DD') - ganttDb.addSection('testa1') - ganttDb.addTask('test1', 'id1,2013-01-01,2w') - ganttDb.addTask('test2', '2d') + it.each` + testName | section | taskName | taskData | expStartDate | expEndDate | expId | expTask + ${'should handle fixed dates'} | ${'testa1'} | ${'test1'} | ${'id1,2013-01-01,2013-01-12'} | ${new Date(2013, 0, 1)} | ${new Date(2013, 0, 12)} | ${'id1'} | ${'test1'} + ${'should handle duration (days) instead of fixed date to determine end date'} | ${'testa1'} | ${'test1'} | ${'id1,2013-01-01,2d'} | ${new Date(2013, 0, 1)} | ${new Date(2013, 0, 3)} | ${'id1'} | ${'test1'} + ${'should handle duration (hours) instead of fixed date to determine end date'} | ${'testa1'} | ${'test1'} | ${'id1,2013-01-01,2h'} | ${new Date(2013, 0, 1)} | ${new Date(2013, 0, 1, 2)} | ${'id1'} | ${'test1'} + ${'should handle duration (minutes) instead of fixed date to determine end date'} | ${'testa1'} | ${'test1'} | ${'id1,2013-01-01,2m'} | ${new Date(2013, 0, 1)} | ${new Date(2013, 0, 1, 0, 2)} | ${'id1'} | ${'test1'} + ${'should handle duration (seconds) instead of fixed date to determine end date'} | ${'testa1'} | ${'test1'} | ${'id1,2013-01-01,2s'} | ${new Date(2013, 0, 1)} | ${new Date(2013, 0, 1, 0, 0, 2)} | ${'id1'} | ${'test1'} + ${'should handle duration (weeks) instead of fixed date to determine end date'} | ${'testa1'} | ${'test1'} | ${'id1,2013-01-01,2w'} | ${new Date(2013, 0, 1)} | ${new Date(2013, 0, 15)} | ${'id1'} | ${'test1'} + ${'should handle fixed dates without id'} | ${'testa1'} | ${'test1'} | ${'2013-01-01,2013-01-12'} | ${new Date(2013, 0, 1)} | ${new Date(2013, 0, 12)} | ${'task1'} | ${'test1'} + ${'should handle duration instead of a fixed date to determine end date without id'} | ${'testa1'} | ${'test1'} | ${'2013-01-01,4d'} | ${new Date(2013, 0, 1)} | ${new Date(2013, 0, 5)} | ${'task1'} | ${'test1'} +`('$testName', ({ section, taskName, taskData, expStartDate, expEndDate, expId, expTask }) => { + ganttDb.setDateFormat('YYYY-MM-DD') + ganttDb.addSection(section) + ganttDb.addTask(taskName, taskData) + const tasks = ganttDb.getTasks() + expect(tasks[0].startTime).toEqual(expStartDate) + expect(tasks[0].endTime).toEqual(expEndDate) + expect(tasks[0].id).toEqual(expId) + expect(tasks[0].task).toEqual(expTask) +}) - const tasks = ganttDb.getTasks() + it.each` + section | taskName1 | taskName2 | taskData1 | taskData2 | expStartDate2 | expEndDate2 | expId2 | expTask2 + ${'testa1'} | ${'test1'} | ${'test2'} | ${'id1,2013-01-01,2w'} | ${'id2,after id1,1d'} | ${new Date(2013, 0, 15)} | ${undefined} | ${'id2'} | ${'test2'} + ${'testa1'} | ${'test1'} | ${'test2'} | ${'id1,2013-01-01,2w'} | ${'id2,after id3,1d'} | ${new Date((new Date()).setHours(0, 0, 0, 0))} | ${undefined} | ${'id2'} | ${'test2'} + ${'testa1'} | ${'test1'} | ${'test2'} | ${'id1,2013-01-01,2w'} | ${'after id1,1d'} | ${new Date(2013, 0, 15)} | ${undefined} | ${'task1'} | ${'test2'} + ${'testa1'} | ${'test1'} | ${'test2'} | ${'id1,2013-01-01,2w'} | ${'2013-01-26'} | ${new Date(2013, 0, 15)} | ${new Date(2013, 0, 26)} | ${'task1'} | ${'test2'} + ${'testa1'} | ${'test1'} | ${'test2'} | ${'id1,2013-01-01,2w'} | ${'2d'} | ${new Date(2013, 0, 15)} | ${new Date(2013, 0, 17)} | ${'task1'} | ${'test2'} +`('$testName', ({ section, taskName1, taskName2, taskData1, taskData2, expStartDate2, expEndDate2, expId2, expTask2 }) => { + ganttDb.setDateFormat('YYYY-MM-DD') + ganttDb.addSection(section) + ganttDb.addTask(taskName1, taskData1) + ganttDb.addTask(taskName2, taskData2) + const tasks = ganttDb.getTasks() + expect(tasks[1].startTime).toEqual(expStartDate2) + if (!expEndDate2 === undefined) { + expect(tasks[1].endTime).toEqual(expEndDate2) + } + expect(tasks[1].id).toEqual(expId2) + expect(tasks[1].task).toEqual(expTask2) +}) - expect(tasks[1].startTime).toEqual(new Date(2013, 0, 15)) - expect(tasks[1].endTime).toEqual(new Date(2013, 0, 17)) - expect(tasks[1].id).toEqual('task1') - expect(tasks[1].task).toEqual('test2') - }) it('should handle relative start date based on id regardless of sections', function () { ganttDb.setDateFormat('YYYY-MM-DD') ganttDb.addSection('testa1')