2017-04-11 16:57:57 +02:00
|
|
|
/* eslint-env jasmine */
|
2019-02-01 10:04:43 +01:00
|
|
|
/* eslint-disable no-eval */
|
2019-09-12 21:57:36 +02:00
|
|
|
import { parser } from './gantt';
|
|
|
|
import ganttDb from '../ganttDb';
|
2017-09-10 15:23:04 +02:00
|
|
|
|
2019-09-12 21:57:36 +02:00
|
|
|
const parserFnConstructor = str => {
|
2019-07-07 21:41:07 +02:00
|
|
|
return () => {
|
2019-09-12 21:57:36 +02:00
|
|
|
parser.parse(str);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('when parsing a gantt diagram it', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
parser.yy = ganttDb;
|
|
|
|
parser.yy.clear();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle a dateFormat definition', function() {
|
|
|
|
const str = 'gantt\ndateFormat yyyy-mm-dd';
|
|
|
|
|
|
|
|
expect(parserFnConstructor(str)).not.toThrow();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle a inclusive end date definition', function() {
|
|
|
|
const str = 'gantt\ndateFormat yyyy-mm-dd\ninclusiveEndDates';
|
|
|
|
|
|
|
|
expect(parserFnConstructor(str)).not.toThrow();
|
|
|
|
});
|
|
|
|
it('should handle a title definition', function() {
|
|
|
|
const str = 'gantt\ndateFormat yyyy-mm-dd\ntitle Adding gantt diagram functionality to mermaid';
|
|
|
|
|
|
|
|
expect(parserFnConstructor(str)).not.toThrow();
|
|
|
|
});
|
|
|
|
it('should handle an excludes definition', function() {
|
|
|
|
const str =
|
|
|
|
'gantt\ndateFormat yyyy-mm-dd\ntitle Adding gantt diagram functionality to mermaid\nexcludes weekdays 2019-02-01';
|
|
|
|
|
|
|
|
expect(parserFnConstructor(str)).not.toThrow();
|
|
|
|
});
|
|
|
|
it('should handle a section definition', function() {
|
|
|
|
const str =
|
|
|
|
'gantt\n' +
|
2017-11-18 16:22:49 +01:00
|
|
|
'dateFormat yyyy-mm-dd\n' +
|
|
|
|
'title Adding gantt diagram functionality to mermaid\n' +
|
2019-02-06 19:54:09 +01:00
|
|
|
'excludes weekdays 2019-02-01\n' +
|
2019-09-12 21:57:36 +02:00
|
|
|
'section Documentation';
|
2017-04-11 16:14:25 +02:00
|
|
|
|
2019-09-12 21:57:36 +02:00
|
|
|
expect(parserFnConstructor(str)).not.toThrow();
|
|
|
|
});
|
2020-01-08 13:50:58 +01:00
|
|
|
it('should handle multiline section titles with different line breaks', function() {
|
|
|
|
const str =
|
|
|
|
'gantt\n' +
|
|
|
|
'dateFormat yyyy-mm-dd\n' +
|
|
|
|
'title Adding gantt diagram functionality to mermaid\n' +
|
|
|
|
'excludes weekdays 2019-02-01\n' +
|
|
|
|
'section Line1<br>Line2<br/>Line3</br />Line4<br\t/>Line5';
|
|
|
|
|
|
|
|
expect(parserFnConstructor(str)).not.toThrow();
|
|
|
|
});
|
2017-04-16 17:48:36 +02:00
|
|
|
/**
|
|
|
|
* Beslutsflöde inligt nedan. Obs bla bla bla
|
|
|
|
* ```
|
|
|
|
* graph TD
|
|
|
|
* A[Hard pledge] -- text on link -->B(Round edge)
|
|
|
|
* B --> C{to do or not to do}
|
|
|
|
* C -->|Too| D[Result one]
|
|
|
|
* C -->|Doo| E[Result two]
|
|
|
|
```
|
|
|
|
* params bapa - a unique bapap
|
|
|
|
*/
|
2019-09-12 21:57:36 +02:00
|
|
|
it('should handle a task definition', function() {
|
|
|
|
const str =
|
|
|
|
'gantt\n' +
|
2019-02-01 09:16:28 +01:00
|
|
|
'dateFormat YYYY-MM-DD\n' +
|
2017-04-16 17:48:36 +02:00
|
|
|
'title Adding gantt diagram functionality to mermaid\n' +
|
|
|
|
'section Documentation\n' +
|
2019-09-12 21:57:36 +02:00
|
|
|
'Design jison grammar:des1, 2014-01-01, 2014-01-04';
|
2015-02-08 20:07:15 +01:00
|
|
|
|
2019-09-12 21:57:36 +02:00
|
|
|
expect(parserFnConstructor(str)).not.toThrow();
|
2019-02-01 09:16:28 +01:00
|
|
|
|
2019-09-12 21:57:36 +02:00
|
|
|
const tasks = parser.yy.getTasks();
|
2019-02-01 09:16:28 +01:00
|
|
|
|
2019-09-12 21:57:36 +02:00
|
|
|
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');
|
|
|
|
});
|
2019-02-01 10:04:43 +01:00
|
|
|
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}
|
2019-09-12 21:57:36 +02:00
|
|
|
`('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'];
|
|
|
|
|
|
|
|
expect(parserFnConstructor(str)).not.toThrow();
|
|
|
|
|
|
|
|
const tasks = parser.yy.getTasks();
|
|
|
|
|
|
|
|
allowedTags.forEach(function(t) {
|
|
|
|
if (eval(t)) {
|
|
|
|
expect(tasks[0][t]).toBeTruthy();
|
|
|
|
} else {
|
|
|
|
expect(tasks[0][t]).toBeFalsy();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2019-12-11 00:27:06 +01:00
|
|
|
it('should parse callback specifier with no args', function() {
|
|
|
|
spyOn(ganttDb, 'setClickEvent');
|
|
|
|
const str =
|
|
|
|
'gantt\n' +
|
|
|
|
'dateFormat YYYY-MM-DD\n' +
|
|
|
|
'section Clickable\n' +
|
|
|
|
'Visit mermaidjs :active, cl1, 2014-01-07, 3d\n' +
|
|
|
|
'Calling a callback :cl2, after cl1, 3d\n\n' +
|
|
|
|
'click cl1 href "https://mermaidjs.github.io/"\n' +
|
|
|
|
'click cl2 call ganttTestClick()\n';
|
|
|
|
|
|
|
|
expect(parserFnConstructor(str)).not.toThrow();
|
|
|
|
expect(ganttDb.setClickEvent).toHaveBeenCalledWith('cl2', 'ganttTestClick', null);
|
|
|
|
});
|
|
|
|
it('should parse callback specifier with arbitrary number of args', function() {
|
|
|
|
spyOn(ganttDb, 'setClickEvent');
|
|
|
|
const str =
|
|
|
|
'gantt\n' +
|
|
|
|
'dateFormat YYYY-MM-DD\n' +
|
|
|
|
'section Clickable\n' +
|
|
|
|
'Visit mermaidjs :active, cl1, 2014-01-07, 3d\n' +
|
|
|
|
'Calling a callback :cl2, after cl1, 3d\n\n' +
|
|
|
|
'click cl1 href "https://mermaidjs.github.io/"\n' +
|
|
|
|
'click cl2 call ganttTestClick("test0", test1, test2)\n';
|
|
|
|
|
|
|
|
expect(parserFnConstructor(str)).not.toThrow();
|
|
|
|
const args = '"test1", "test2", "test3"';
|
|
|
|
expect(ganttDb.setClickEvent).toHaveBeenCalledWith('cl2', 'ganttTestClick', '"test0", test1, test2');
|
|
|
|
});
|
|
|
|
|
2019-09-12 21:57:36 +02:00
|
|
|
});
|