Skip to content

Commit

Permalink
Changes to timeline.spec.js
Browse files Browse the repository at this point in the history
1. Re-organized the new TL-6 test to not use a for-loop with a switch case.
2. Imported the commonDb module to ensure titles are be tested.
3. Use indices to retrieve elements that need to be tested.
  • Loading branch information
FutzMonitor committed Mar 19, 2024
1 parent e433b95 commit cf88f06
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions packages/mermaid/src/diagrams/timeline/timeline.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { parser as timeline } from './parser/timeline.jison';
import * as timelineDB from './timelineDb.js';
import * as commonDb from '../common/commonDb.js';
import { setLogLevel } from '../../diagram-api/diagramAPI.js';

describe('when parsing a timeline ', function () {
Expand Down Expand Up @@ -99,29 +100,19 @@ describe('when parsing a timeline ', function () {
});
});

it('TL-6 should handle a section, and task and its multi line events with semicolons', function () {
it('TL-6 should handle a title, section, task, and events with semicolons', function () {
let str = `timeline
section ;a;bc-123;
;ta;sk1;: ;ev;ent1;
;tas;k2;: ;eve;nt2;: ;event;3;
: ;eve;nt4: ;even;t5;
title ;my;title;
section ;a;bc-123;
;ta;sk1;: ;ev;ent1; : ;ev;ent2; : ;ev;ent3;
`;
timeline.parse(str);
expect(timelineDB.getSections()[0]).to.deep.equal(';a;bc-123;');
timelineDB.getTasks().forEach((t) => {
switch (t.task.trim()) {
case ';ta;sk1;':
expect(t.events).to.deep.equal([';ev;ent1;']);
break;

case ';tas;k2;':
expect(t.events).to.deep.equal([';eve;nt2;', ';event;3;', ';eve;nt4', ';even;t5;']);
break;

default:
break;
}
});
expect(commonDb.getDiagramTitle()).equal(';my;title;');
expect(timelineDB.getSections()).to.deep.equal([';a;bc-123;']);
expect(timelineDB.getTasks()[0].task).equal(';ta;sk1;');
expect(timelineDB.getTasks()[0].events[0]).equal(';ev;ent1; ');
expect(timelineDB.getTasks()[0].events[1]).equal(';ev;ent2; ');
expect(timelineDB.getTasks()[0].events[2]).equal(';ev;ent3;');
});
});
});

0 comments on commit cf88f06

Please sign in to comment.