From c84c1546032f5c6867f50a8d344ee31aea5dd29b Mon Sep 17 00:00:00 2001 From: Gijs van Dam Date: Fri, 1 Feb 2019 16:16:28 +0800 Subject: [PATCH] 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 a170be6e1..d8f5b7038 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() }) })