User journey handler

This commit is contained in:
Russell Geraghty
2020-04-04 16:38:30 +01:00
parent 9f8a0234aa
commit f081527731
12 changed files with 1307 additions and 1 deletions

View File

@@ -0,0 +1,52 @@
/** mermaid
* https://mermaidjs.github.io/
* (c) 2015 Knut Sveidqvist
* MIT license.
*/
%lex
%options case-insensitive
%%
[\n]+ return 'NL';
\s+ /* skip whitespace */
\#[^\n]* /* skip comments */
\%%[^\n]* /* skip comments */
"journey" return 'journey';
"title"\s[^#\n;]+ return 'title';
"section"\s[^#:\n;]+ return 'section';
[^#:\n;]+ return 'taskName';
":"[^#\n;]+ return 'taskData';
":" return ':';
<<EOF>> return 'EOF';
. return 'INVALID';
/lex
%left '^'
%start start
%% /* language grammar */
start
: journey document 'EOF' { return $2; }
;
document
: /* empty */ { $$ = [] }
| document line {$1.push($2);$$ = $1}
;
line
: SPACE statement { $$ = $2 }
| statement { $$ = $1 }
| NL { $$=[];}
| EOF { $$=[];}
;
statement
: title {yy.setTitle($1.substr(6));$$=$1.substr(6);}
| section {yy.addSection($1.substr(8));$$=$1.substr(8);}
| taskName taskData {yy.addTask($1, $2);$$='task';}
;

View File

@@ -0,0 +1,117 @@
/* eslint-env jasmine */
/* eslint-disable no-eval */
import { parser } from './journey';
import journeyDb from '../journeyDb';
const parserFnConstructor = str => {
return () => {
parser.parse(str);
};
};
describe('when parsing a journey diagram it', function() {
beforeEach(function() {
parser.yy = journeyDb;
parser.yy.clear();
});
it('should handle a title definition', function() {
const str = 'journey\ntitle Adding journey diagram functionality to mermaid';
expect(parserFnConstructor(str)).not.toThrow();
});
it('should handle a section definition', function() {
const str =
'journey\n' +
'title Adding journey diagram functionality to mermaid\n' +
'section Order from website';
expect(parserFnConstructor(str)).not.toThrow();
});
it('should handle multiline section titles with different line breaks', function() {
const str =
'journey\n' +
'title Adding gantt diagram functionality to mermaid\n' +
'section Line1<br>Line2<br/>Line3</br />Line4<br\t/>Line5';
expect(parserFnConstructor(str)).not.toThrow();
});
it('should handle a task definition', function() {
const str =
'journey\n' +
'title Adding journey diagram functionality to mermaid\n' +
'section Documentation\n' +
'A task: 5: Alice, Bob, Charlie\n' +
'B task: 3:Bob, Charlie\n' +
'C task: 5\n' +
'D task: 5: Charlie, Alice\n' +
'E task: 5:\n' +
'section Another section\n' +
'P task: 5:\n' +
'Q task: 5:\n' +
'R task: 5:';
expect(parserFnConstructor(str)).not.toThrow();
const tasks = parser.yy.getTasks();
expect(tasks.length).toEqual(8);
expect(tasks[0]).toEqual({
score: 5,
people: ['Alice', 'Bob', 'Charlie'],
section: 'Documentation',
task: 'A task',
type: 'Documentation'
});
expect(tasks[1]).toEqual({
score: 3,
people: ['Bob', 'Charlie'],
section: 'Documentation',
type: 'Documentation',
task: 'B task'
});
expect(tasks[2]).toEqual({
score: 5,
people: [],
section: 'Documentation',
type: 'Documentation',
task: 'C task'
});
expect(tasks[3]).toEqual({
score: 5,
people: ['Charlie', 'Alice'],
section: 'Documentation',
task: 'D task',
type: 'Documentation'
});
expect(tasks[4]).toEqual({
score: 5,
people: [''],
section: 'Documentation',
type: 'Documentation',
task: 'E task'
});
expect(tasks[5]).toEqual({
score: 5,
people: [''],
section: 'Another section',
type: 'Another section',
task: 'P task'
});
expect(tasks[6]).toEqual({
score: 5,
people: [''],
section: 'Another section',
type: 'Another section',
task: 'Q task'
});
expect(tasks[7]).toEqual({
score: 5,
people: [''],
section: 'Another section',
type: 'Another section',
task: 'R task'
});
});
});