mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-19 15:30:03 +02:00
Create new type for member handling
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
// @ts-expect-error Jison doesn't export types
|
||||
import { parser } from './parser/classDiagram.jison';
|
||||
import classDb from './classDb.js';
|
||||
import classParser from './classParser.js';
|
||||
import { vi, describe, it, expect } from 'vitest';
|
||||
const spyOn = vi.spyOn;
|
||||
|
||||
describe('given a basic class diagram, ', function () {
|
||||
describe('when parsing class definition', function () {
|
||||
beforeEach(function () {
|
||||
classDb.clear();
|
||||
parser.yy = classDb;
|
||||
classParser.clear();
|
||||
parser.yy = classParser;
|
||||
});
|
||||
it('should handle accTitle and accDescr', function () {
|
||||
const str = `classDiagram
|
||||
@@ -54,7 +54,7 @@ describe('given a basic class diagram, ', function () {
|
||||
const str = 'classDiagram\n' + 'class Ca-r';
|
||||
|
||||
parser.parse(str);
|
||||
const actual = classDb.getClass('Ca-r');
|
||||
const actual = classParser.getClass('Ca-r');
|
||||
expect(actual.label).toBe('Ca-r');
|
||||
});
|
||||
|
||||
@@ -102,7 +102,7 @@ describe('given a basic class diagram, ', function () {
|
||||
|
||||
parser.parse(str);
|
||||
|
||||
const c1 = classDb.getClass('C1');
|
||||
const c1 = classParser.getClass('C1');
|
||||
expect(c1.label).toBe('Class 1 with text label');
|
||||
});
|
||||
|
||||
@@ -114,9 +114,9 @@ describe('given a basic class diagram, ', function () {
|
||||
|
||||
parser.parse(str);
|
||||
|
||||
const c1 = classDb.getClass('C1');
|
||||
const c1 = classParser.getClass('C1');
|
||||
expect(c1.label).toBe('Class 1 with text label');
|
||||
const c2 = classDb.getClass('C2');
|
||||
const c2 = classParser.getClass('C2');
|
||||
expect(c2.label).toBe('Class 2 with chars @?');
|
||||
});
|
||||
|
||||
@@ -124,7 +124,7 @@ describe('given a basic class diagram, ', function () {
|
||||
const str = 'classDiagram\n' + 'class C1["Class 1 with text label"]\n' + 'C1: member1';
|
||||
|
||||
parser.parse(str);
|
||||
const c1 = classDb.getClass('C1');
|
||||
const c1 = classParser.getClass('C1');
|
||||
expect(c1.label).toBe('Class 1 with text label');
|
||||
expect(c1.members.length).toBe(1);
|
||||
expect(c1.members[0]).toBe('member1');
|
||||
@@ -139,7 +139,7 @@ describe('given a basic class diagram, ', function () {
|
||||
|
||||
parser.parse(str);
|
||||
|
||||
const c1 = classDb.getClass('C1');
|
||||
const c1 = classParser.getClass('C1');
|
||||
expect(c1.label).toBe('Class 1 with text label');
|
||||
expect(c1.members.length).toBe(1);
|
||||
expect(c1.members[0]).toBe('int member1');
|
||||
@@ -152,7 +152,7 @@ describe('given a basic class diagram, ', function () {
|
||||
|
||||
parser.parse(str);
|
||||
|
||||
const c1 = classDb.getClass('C1');
|
||||
const c1 = classParser.getClass('C1');
|
||||
expect(c1.label).toBe('Class 1 with text label');
|
||||
expect(c1.cssClasses[0]).toBe('styleClass');
|
||||
});
|
||||
@@ -166,7 +166,7 @@ describe('given a basic class diagram, ', function () {
|
||||
|
||||
parser.parse(str);
|
||||
|
||||
const c1 = classDb.getClass('C1');
|
||||
const c1 = classParser.getClass('C1');
|
||||
expect(c1.label).toBe('Class 1 with text label');
|
||||
expect(c1.members[0]).toBe('int member1');
|
||||
expect(c1.cssClasses[0]).toBe('styleClass');
|
||||
@@ -182,11 +182,11 @@ describe('given a basic class diagram, ', function () {
|
||||
|
||||
parser.parse(str);
|
||||
|
||||
const c1 = classDb.getClass('C1');
|
||||
const c1 = classParser.getClass('C1');
|
||||
expect(c1.label).toBe('Class 1 with text label');
|
||||
expect(c1.cssClasses[0]).toBe('styleClass');
|
||||
|
||||
const c2 = classDb.getClass('C2');
|
||||
const c2 = classParser.getClass('C2');
|
||||
expect(c2.label).toBe('Long long long long long long long long long long label');
|
||||
expect(c2.cssClasses[0]).toBe('styleClass');
|
||||
});
|
||||
@@ -199,11 +199,11 @@ describe('given a basic class diagram, ', function () {
|
||||
|
||||
parser.parse(str);
|
||||
|
||||
const c1 = classDb.getClass('C1');
|
||||
const c1 = classParser.getClass('C1');
|
||||
expect(c1.label).toBe('Class 1 with text label');
|
||||
expect(c1.cssClasses[0]).toBe('styleClass1');
|
||||
|
||||
const c2 = classDb.getClass('C2');
|
||||
const c2 = classParser.getClass('C2');
|
||||
expect(c2.label).toBe('Class 2 !@#$%^&*() label');
|
||||
expect(c2.cssClasses[0]).toBe('styleClass2');
|
||||
});
|
||||
@@ -214,13 +214,13 @@ class C1["Class with text label"]
|
||||
class C2["Class with text label"]
|
||||
class C3["Class with text label"]`);
|
||||
|
||||
const c1 = classDb.getClass('C1');
|
||||
const c1 = classParser.getClass('C1');
|
||||
expect(c1.label).toBe('Class with text label');
|
||||
|
||||
const c2 = classDb.getClass('C2');
|
||||
const c2 = classParser.getClass('C2');
|
||||
expect(c2.label).toBe('Class with text label');
|
||||
|
||||
const c3 = classDb.getClass('C3');
|
||||
const c3 = classParser.getClass('C3');
|
||||
expect(c3.label).toBe('Class with text label');
|
||||
});
|
||||
|
||||
@@ -240,19 +240,19 @@ class C11["With ' single quote"]
|
||||
class C12["With ~!@#$%^&*()_+=-/?"]
|
||||
class C13["With Città foreign language"]
|
||||
`);
|
||||
expect(classDb.getClass('C1').label).toBe('OneWord');
|
||||
expect(classDb.getClass('C2').label).toBe('With, Comma');
|
||||
expect(classDb.getClass('C3').label).toBe('With (Brackets)');
|
||||
expect(classDb.getClass('C4').label).toBe('With [Brackets]');
|
||||
expect(classDb.getClass('C5').label).toBe('With {Brackets}');
|
||||
expect(classDb.getClass('C6').label).toBe(' ');
|
||||
expect(classDb.getClass('C7').label).toBe('With 1 number');
|
||||
expect(classDb.getClass('C8').label).toBe('With . period...');
|
||||
expect(classDb.getClass('C9').label).toBe('With - dash');
|
||||
expect(classDb.getClass('C10').label).toBe('With _ underscore');
|
||||
expect(classDb.getClass('C11').label).toBe("With ' single quote");
|
||||
expect(classDb.getClass('C12').label).toBe('With ~!@#$%^&*()_+=-/?');
|
||||
expect(classDb.getClass('C13').label).toBe('With Città foreign language');
|
||||
expect(classParser.getClass('C1').label).toBe('OneWord');
|
||||
expect(classParser.getClass('C2').label).toBe('With, Comma');
|
||||
expect(classParser.getClass('C3').label).toBe('With (Brackets)');
|
||||
expect(classParser.getClass('C4').label).toBe('With [Brackets]');
|
||||
expect(classParser.getClass('C5').label).toBe('With {Brackets}');
|
||||
expect(classParser.getClass('C6').label).toBe(' ');
|
||||
expect(classParser.getClass('C7').label).toBe('With 1 number');
|
||||
expect(classParser.getClass('C8').label).toBe('With . period...');
|
||||
expect(classParser.getClass('C9').label).toBe('With - dash');
|
||||
expect(classParser.getClass('C10').label).toBe('With _ underscore');
|
||||
expect(classParser.getClass('C11').label).toBe("With ' single quote");
|
||||
expect(classParser.getClass('C12').label).toBe('With ~!@#$%^&*()_+=-/?');
|
||||
expect(classParser.getClass('C13').label).toBe('With Città foreign language');
|
||||
});
|
||||
|
||||
it('should handle "note for"', function () {
|
||||
@@ -268,8 +268,8 @@ class C13["With Città foreign language"]
|
||||
|
||||
describe('when parsing class defined in brackets', function () {
|
||||
beforeEach(function () {
|
||||
classDb.clear();
|
||||
parser.yy = classDb;
|
||||
classParser.clear();
|
||||
parser.yy = classParser;
|
||||
});
|
||||
|
||||
it('should handle member definitions', function () {
|
||||
@@ -334,7 +334,7 @@ class C13["With Città foreign language"]
|
||||
const str = 'classDiagram\n' + 'class C1["Class 1 with text label"] {\n' + '+member1\n' + '}';
|
||||
|
||||
parser.parse(str);
|
||||
const c1 = classDb.getClass('C1');
|
||||
const c1 = classParser.getClass('C1');
|
||||
expect(c1.label).toBe('Class 1 with text label');
|
||||
expect(c1.members.length).toBe(1);
|
||||
expect(c1.members[0]).toBe('+member1');
|
||||
@@ -349,7 +349,7 @@ class C13["With Città foreign language"]
|
||||
'}';
|
||||
|
||||
parser.parse(str);
|
||||
const c1 = classDb.getClass('C1');
|
||||
const c1 = classParser.getClass('C1');
|
||||
expect(c1.label).toBe('Class 1 with text label');
|
||||
expect(c1.members.length).toBe(1);
|
||||
expect(c1.members[0]).toBe('+member1');
|
||||
@@ -360,8 +360,8 @@ class C13["With Città foreign language"]
|
||||
|
||||
describe('when parsing comments', function () {
|
||||
beforeEach(function () {
|
||||
classDb.clear();
|
||||
parser.yy = classDb;
|
||||
classParser.clear();
|
||||
parser.yy = classParser;
|
||||
});
|
||||
|
||||
it('should handle comments at the start', function () {
|
||||
@@ -450,16 +450,16 @@ foo()
|
||||
|
||||
describe('when parsing click statements', function () {
|
||||
beforeEach(function () {
|
||||
classDb.clear();
|
||||
parser.yy = classDb;
|
||||
classParser.clear();
|
||||
parser.yy = classParser;
|
||||
});
|
||||
it('should handle href link', function () {
|
||||
spyOn(classDb, 'setLink');
|
||||
spyOn(classParser, 'setLink');
|
||||
const str = 'classDiagram\n' + 'class Class1 \n' + 'click Class1 href "google.com" ';
|
||||
|
||||
parser.parse(str);
|
||||
|
||||
expect(classDb.setLink).toHaveBeenCalledWith('Class1', 'google.com');
|
||||
expect(classParser.setLink).toHaveBeenCalledWith('Class1', 'google.com');
|
||||
|
||||
const actual = parser.yy.getClass('Class1');
|
||||
expect(actual.link).toBe('google.com');
|
||||
@@ -467,14 +467,14 @@ foo()
|
||||
});
|
||||
|
||||
it('should handle href link with tooltip', function () {
|
||||
spyOn(classDb, 'setLink');
|
||||
spyOn(classDb, 'setTooltip');
|
||||
spyOn(classParser, 'setLink');
|
||||
spyOn(classParser, 'setTooltip');
|
||||
const str =
|
||||
'classDiagram\n' + 'class Class1 \n' + 'click Class1 href "google.com" "A Tooltip" ';
|
||||
|
||||
parser.parse(str);
|
||||
|
||||
expect(classDb.setLink).toHaveBeenCalledWith('Class1', 'google.com');
|
||||
expect(classParser.setLink).toHaveBeenCalledWith('Class1', 'google.com');
|
||||
|
||||
const actual = parser.yy.getClass('Class1');
|
||||
expect(actual.link).toBe('google.com');
|
||||
@@ -483,8 +483,8 @@ foo()
|
||||
});
|
||||
|
||||
it('should handle href link with tooltip and target', function () {
|
||||
spyOn(classDb, 'setLink');
|
||||
spyOn(classDb, 'setTooltip');
|
||||
spyOn(classParser, 'setLink');
|
||||
spyOn(classParser, 'setTooltip');
|
||||
const str =
|
||||
'classDiagram\n' +
|
||||
'class Class1\n' +
|
||||
@@ -492,8 +492,8 @@ foo()
|
||||
'click Class1 href "google.com" "A tooltip" _self';
|
||||
parser.parse(str);
|
||||
|
||||
expect(classDb.setLink).toHaveBeenCalledWith('Class1', 'google.com', '_self');
|
||||
expect(classDb.setTooltip).toHaveBeenCalledWith('Class1', 'A tooltip');
|
||||
expect(classParser.setLink).toHaveBeenCalledWith('Class1', 'google.com', '_self');
|
||||
expect(classParser.setTooltip).toHaveBeenCalledWith('Class1', 'A tooltip');
|
||||
|
||||
const actual = parser.yy.getClass('Class1');
|
||||
expect(actual.link).toBe('google.com');
|
||||
@@ -502,30 +502,30 @@ foo()
|
||||
});
|
||||
|
||||
it('should handle function call', function () {
|
||||
spyOn(classDb, 'setClickEvent');
|
||||
spyOn(classParser, 'setClickEvent');
|
||||
|
||||
const str = 'classDiagram\n' + 'class Class1 \n' + 'click Class1 call functionCall() ';
|
||||
|
||||
parser.parse(str);
|
||||
|
||||
expect(classDb.setClickEvent).toHaveBeenCalledWith('Class1', 'functionCall');
|
||||
expect(classParser.setClickEvent).toHaveBeenCalledWith('Class1', 'functionCall');
|
||||
});
|
||||
|
||||
it('should handle function call with tooltip', function () {
|
||||
spyOn(classDb, 'setClickEvent');
|
||||
spyOn(classDb, 'setTooltip');
|
||||
spyOn(classParser, 'setClickEvent');
|
||||
spyOn(classParser, 'setTooltip');
|
||||
|
||||
const str =
|
||||
'classDiagram\n' + 'class Class1 \n' + 'click Class1 call functionCall() "A Tooltip" ';
|
||||
|
||||
parser.parse(str);
|
||||
|
||||
expect(classDb.setClickEvent).toHaveBeenCalledWith('Class1', 'functionCall');
|
||||
expect(classDb.setTooltip).toHaveBeenCalledWith('Class1', 'A Tooltip');
|
||||
expect(classParser.setClickEvent).toHaveBeenCalledWith('Class1', 'functionCall');
|
||||
expect(classParser.setTooltip).toHaveBeenCalledWith('Class1', 'A Tooltip');
|
||||
});
|
||||
|
||||
it('should handle function call with an arbitrary number of args', function () {
|
||||
spyOn(classDb, 'setClickEvent');
|
||||
spyOn(classParser, 'setClickEvent');
|
||||
const str =
|
||||
'classDiagram\n' +
|
||||
'class Class1\n' +
|
||||
@@ -533,7 +533,7 @@ foo()
|
||||
'click Class1 call functionCall(test, test1, test2)';
|
||||
parser.parse(str);
|
||||
|
||||
expect(classDb.setClickEvent).toHaveBeenCalledWith(
|
||||
expect(classParser.setClickEvent).toHaveBeenCalledWith(
|
||||
'Class1',
|
||||
'functionCall',
|
||||
'test, test1, test2'
|
||||
@@ -541,8 +541,8 @@ foo()
|
||||
});
|
||||
|
||||
it('should handle function call with an arbitrary number of args and tooltip', function () {
|
||||
spyOn(classDb, 'setClickEvent');
|
||||
spyOn(classDb, 'setTooltip');
|
||||
spyOn(classParser, 'setClickEvent');
|
||||
spyOn(classParser, 'setTooltip');
|
||||
const str =
|
||||
'classDiagram\n' +
|
||||
'class Class1\n' +
|
||||
@@ -550,19 +550,19 @@ foo()
|
||||
'click Class1 call functionCall("test0", test1, test2) "A Tooltip"';
|
||||
parser.parse(str);
|
||||
|
||||
expect(classDb.setClickEvent).toHaveBeenCalledWith(
|
||||
expect(classParser.setClickEvent).toHaveBeenCalledWith(
|
||||
'Class1',
|
||||
'functionCall',
|
||||
'"test0", test1, test2'
|
||||
);
|
||||
expect(classDb.setTooltip).toHaveBeenCalledWith('Class1', 'A Tooltip');
|
||||
expect(classParser.setTooltip).toHaveBeenCalledWith('Class1', 'A Tooltip');
|
||||
});
|
||||
});
|
||||
|
||||
describe('when parsing annotations', function () {
|
||||
beforeEach(function () {
|
||||
classDb.clear();
|
||||
parser.yy = classDb;
|
||||
classParser.clear();
|
||||
parser.yy = classParser;
|
||||
});
|
||||
|
||||
it('should handle class annotations', function () {
|
||||
@@ -625,8 +625,8 @@ foo()
|
||||
describe('given a class diagram with members and methods ', function () {
|
||||
describe('when parsing members', function () {
|
||||
beforeEach(function () {
|
||||
classDb.clear();
|
||||
parser.yy = classDb;
|
||||
classParser.clear();
|
||||
parser.yy = classParser;
|
||||
});
|
||||
|
||||
it('should handle simple member declaration', function () {
|
||||
@@ -670,8 +670,8 @@ describe('given a class diagram with members and methods ', function () {
|
||||
|
||||
describe('when parsing method definition', function () {
|
||||
beforeEach(function () {
|
||||
classDb.clear();
|
||||
parser.yy = classDb;
|
||||
classParser.clear();
|
||||
parser.yy = classParser;
|
||||
});
|
||||
|
||||
it('should handle method definition', function () {
|
||||
@@ -753,8 +753,8 @@ describe('given a class diagram with members and methods ', function () {
|
||||
describe('given a class diagram with generics, ', function () {
|
||||
describe('when parsing valid generic classes', function () {
|
||||
beforeEach(function () {
|
||||
classDb.clear();
|
||||
parser.yy = classDb;
|
||||
classParser.clear();
|
||||
parser.yy = classParser;
|
||||
});
|
||||
|
||||
it('should handle generic class', function () {
|
||||
@@ -851,8 +851,8 @@ foo()
|
||||
|
||||
describe('when parsing invalid generic classes', function () {
|
||||
beforeEach(function () {
|
||||
classDb.clear();
|
||||
parser.yy = classDb;
|
||||
classParser.clear();
|
||||
parser.yy = classParser;
|
||||
});
|
||||
|
||||
it('should break when another `{`is encountered before closing the first one while defining generic class with brackets', function () {
|
||||
@@ -900,8 +900,8 @@ foo()
|
||||
describe('given a class diagram with relationships, ', function () {
|
||||
describe('when parsing basic relationships', function () {
|
||||
beforeEach(function () {
|
||||
classDb.clear();
|
||||
parser.yy = classDb;
|
||||
classParser.clear();
|
||||
parser.yy = classParser;
|
||||
});
|
||||
|
||||
it('should handle all basic relationships', function () {
|
||||
@@ -938,9 +938,9 @@ describe('given a class diagram with relationships, ', function () {
|
||||
expect(parser.yy.getClass('Class1').id).toBe('Class1');
|
||||
expect(parser.yy.getClass('Class1').type).toBe('T');
|
||||
expect(parser.yy.getClass('Class02').id).toBe('Class02');
|
||||
expect(relations[0].relation.type1).toBe(classDb.relationType.EXTENSION);
|
||||
expect(relations[0].relation.type1).toBe(classParser.relationType.EXTENSION);
|
||||
expect(relations[0].relation.type2).toBe('none');
|
||||
expect(relations[0].relation.lineType).toBe(classDb.lineType.LINE);
|
||||
expect(relations[0].relation.lineType).toBe(classParser.lineType.LINE);
|
||||
});
|
||||
|
||||
it('should handle relationships with labels', function () {
|
||||
@@ -963,9 +963,9 @@ describe('given a class diagram with relationships, ', function () {
|
||||
|
||||
expect(parser.yy.getClass('Class1').id).toBe('Class1');
|
||||
expect(parser.yy.getClass('Class02').id).toBe('Class02');
|
||||
expect(relations[0].relation.type1).toBe(classDb.relationType.EXTENSION);
|
||||
expect(relations[0].relation.type1).toBe(classParser.relationType.EXTENSION);
|
||||
expect(relations[0].relation.type2).toBe('none');
|
||||
expect(relations[0].relation.lineType).toBe(classDb.lineType.LINE);
|
||||
expect(relations[0].relation.lineType).toBe(classParser.lineType.LINE);
|
||||
});
|
||||
|
||||
it('should handle relation definition of different types and directions', function () {
|
||||
@@ -1010,9 +1010,9 @@ describe('given a class diagram with relationships, ', function () {
|
||||
|
||||
expect(parser.yy.getClass('Class1').id).toBe('Class1');
|
||||
expect(parser.yy.getClass('Class02').id).toBe('Class02');
|
||||
expect(relations[0].relation.type1).toBe(classDb.relationType.AGGREGATION);
|
||||
expect(relations[0].relation.type1).toBe(classParser.relationType.AGGREGATION);
|
||||
expect(relations[0].relation.type2).toBe('none');
|
||||
expect(relations[0].relation.lineType).toBe(classDb.lineType.DOTTED_LINE);
|
||||
expect(relations[0].relation.lineType).toBe(classParser.lineType.DOTTED_LINE);
|
||||
});
|
||||
|
||||
it('should handle relation definitions COMPOSITION on both sides', function () {
|
||||
@@ -1024,9 +1024,9 @@ describe('given a class diagram with relationships, ', function () {
|
||||
|
||||
expect(parser.yy.getClass('Class1').id).toBe('Class1');
|
||||
expect(parser.yy.getClass('Class02').id).toBe('Class02');
|
||||
expect(relations[0].relation.type1).toBe(classDb.relationType.COMPOSITION);
|
||||
expect(relations[0].relation.type2).toBe(classDb.relationType.COMPOSITION);
|
||||
expect(relations[0].relation.lineType).toBe(classDb.lineType.LINE);
|
||||
expect(relations[0].relation.type1).toBe(classParser.relationType.COMPOSITION);
|
||||
expect(relations[0].relation.type2).toBe(classParser.relationType.COMPOSITION);
|
||||
expect(relations[0].relation.lineType).toBe(classParser.lineType.LINE);
|
||||
});
|
||||
|
||||
it('should handle relation definitions with no types', function () {
|
||||
@@ -1040,7 +1040,7 @@ describe('given a class diagram with relationships, ', function () {
|
||||
expect(parser.yy.getClass('Class02').id).toBe('Class02');
|
||||
expect(relations[0].relation.type1).toBe('none');
|
||||
expect(relations[0].relation.type2).toBe('none');
|
||||
expect(relations[0].relation.lineType).toBe(classDb.lineType.LINE);
|
||||
expect(relations[0].relation.lineType).toBe(classParser.lineType.LINE);
|
||||
});
|
||||
|
||||
it('should handle relation definitions with type only on right side', function () {
|
||||
@@ -1053,8 +1053,8 @@ describe('given a class diagram with relationships, ', function () {
|
||||
expect(parser.yy.getClass('Class1').id).toBe('Class1');
|
||||
expect(parser.yy.getClass('Class02').id).toBe('Class02');
|
||||
expect(relations[0].relation.type1).toBe('none');
|
||||
expect(relations[0].relation.type2).toBe(classDb.relationType.EXTENSION);
|
||||
expect(relations[0].relation.lineType).toBe(classDb.lineType.LINE);
|
||||
expect(relations[0].relation.type2).toBe(classParser.relationType.EXTENSION);
|
||||
expect(relations[0].relation.lineType).toBe(classParser.lineType.LINE);
|
||||
});
|
||||
|
||||
it('should handle multiple classes and relation definitions', function () {
|
||||
@@ -1075,12 +1075,12 @@ describe('given a class diagram with relationships, ', function () {
|
||||
|
||||
expect(relations.length).toBe(5);
|
||||
|
||||
expect(relations[0].relation.type1).toBe(classDb.relationType.EXTENSION);
|
||||
expect(relations[0].relation.type1).toBe(classParser.relationType.EXTENSION);
|
||||
expect(relations[0].relation.type2).toBe('none');
|
||||
expect(relations[0].relation.lineType).toBe(classDb.lineType.LINE);
|
||||
expect(relations[0].relation.lineType).toBe(classParser.lineType.LINE);
|
||||
expect(relations[3].relation.type1).toBe('none');
|
||||
expect(relations[3].relation.type2).toBe('none');
|
||||
expect(relations[3].relation.lineType).toBe(classDb.lineType.DOTTED_LINE);
|
||||
expect(relations[3].relation.lineType).toBe(classParser.lineType.DOTTED_LINE);
|
||||
});
|
||||
|
||||
it('should handle generic class with relation definitions', function () {
|
||||
@@ -1093,9 +1093,9 @@ describe('given a class diagram with relationships, ', function () {
|
||||
expect(parser.yy.getClass('Class01').id).toBe('Class01');
|
||||
expect(parser.yy.getClass('Class01').type).toBe('T');
|
||||
expect(parser.yy.getClass('Class02').id).toBe('Class02');
|
||||
expect(relations[0].relation.type1).toBe(classDb.relationType.EXTENSION);
|
||||
expect(relations[0].relation.type1).toBe(classParser.relationType.EXTENSION);
|
||||
expect(relations[0].relation.type2).toBe('none');
|
||||
expect(relations[0].relation.lineType).toBe(classDb.lineType.LINE);
|
||||
expect(relations[0].relation.lineType).toBe(classParser.lineType.LINE);
|
||||
});
|
||||
|
||||
it('should handle class annotations', function () {
|
||||
@@ -1254,8 +1254,8 @@ describe('given a class diagram with relationships, ', function () {
|
||||
});
|
||||
|
||||
it('should associate click and href link with tooltip and target appropriately', function () {
|
||||
spyOn(classDb, 'setLink');
|
||||
spyOn(classDb, 'setTooltip');
|
||||
spyOn(classParser, 'setLink');
|
||||
spyOn(classParser, 'setTooltip');
|
||||
const str =
|
||||
'classDiagram\n' +
|
||||
'class Class1\n' +
|
||||
@@ -1263,12 +1263,12 @@ describe('given a class diagram with relationships, ', function () {
|
||||
'click Class1 href "google.com" "A tooltip" _self';
|
||||
parser.parse(str);
|
||||
|
||||
expect(classDb.setLink).toHaveBeenCalledWith('Class1', 'google.com', '_self');
|
||||
expect(classDb.setTooltip).toHaveBeenCalledWith('Class1', 'A tooltip');
|
||||
expect(classParser.setLink).toHaveBeenCalledWith('Class1', 'google.com', '_self');
|
||||
expect(classParser.setTooltip).toHaveBeenCalledWith('Class1', 'A tooltip');
|
||||
});
|
||||
|
||||
it('should associate click and href link appropriately', function () {
|
||||
spyOn(classDb, 'setLink');
|
||||
spyOn(classParser, 'setLink');
|
||||
const str =
|
||||
'classDiagram\n' +
|
||||
'class Class1\n' +
|
||||
@@ -1276,11 +1276,11 @@ describe('given a class diagram with relationships, ', function () {
|
||||
'click Class1 href "google.com"';
|
||||
parser.parse(str);
|
||||
|
||||
expect(classDb.setLink).toHaveBeenCalledWith('Class1', 'google.com');
|
||||
expect(classParser.setLink).toHaveBeenCalledWith('Class1', 'google.com');
|
||||
});
|
||||
|
||||
it('should associate click and href link with target appropriately', function () {
|
||||
spyOn(classDb, 'setLink');
|
||||
spyOn(classParser, 'setLink');
|
||||
const str =
|
||||
'classDiagram\n' +
|
||||
'class Class1\n' +
|
||||
@@ -1288,12 +1288,12 @@ describe('given a class diagram with relationships, ', function () {
|
||||
'click Class1 href "google.com" _self';
|
||||
parser.parse(str);
|
||||
|
||||
expect(classDb.setLink).toHaveBeenCalledWith('Class1', 'google.com', '_self');
|
||||
expect(classParser.setLink).toHaveBeenCalledWith('Class1', 'google.com', '_self');
|
||||
});
|
||||
|
||||
it('should associate link appropriately', function () {
|
||||
spyOn(classDb, 'setLink');
|
||||
spyOn(classDb, 'setTooltip');
|
||||
spyOn(classParser, 'setLink');
|
||||
spyOn(classParser, 'setTooltip');
|
||||
const str =
|
||||
'classDiagram\n' +
|
||||
'class Class1\n' +
|
||||
@@ -1301,12 +1301,12 @@ describe('given a class diagram with relationships, ', function () {
|
||||
'link Class1 "google.com" "A tooltip" _self';
|
||||
parser.parse(str);
|
||||
|
||||
expect(classDb.setLink).toHaveBeenCalledWith('Class1', 'google.com', '_self');
|
||||
expect(classDb.setTooltip).toHaveBeenCalledWith('Class1', 'A tooltip');
|
||||
expect(classParser.setLink).toHaveBeenCalledWith('Class1', 'google.com', '_self');
|
||||
expect(classParser.setTooltip).toHaveBeenCalledWith('Class1', 'A tooltip');
|
||||
});
|
||||
|
||||
it('should associate callback appropriately', function () {
|
||||
spyOn(classDb, 'setClickEvent');
|
||||
spyOn(classParser, 'setClickEvent');
|
||||
const str =
|
||||
'classDiagram\n' +
|
||||
'class Class1\n' +
|
||||
@@ -1314,11 +1314,11 @@ describe('given a class diagram with relationships, ', function () {
|
||||
'callback Class1 "functionCall"';
|
||||
parser.parse(str);
|
||||
|
||||
expect(classDb.setClickEvent).toHaveBeenCalledWith('Class1', 'functionCall');
|
||||
expect(classParser.setClickEvent).toHaveBeenCalledWith('Class1', 'functionCall');
|
||||
});
|
||||
|
||||
it('should associate click and call callback appropriately', function () {
|
||||
spyOn(classDb, 'setClickEvent');
|
||||
spyOn(classParser, 'setClickEvent');
|
||||
const str =
|
||||
'classDiagram\n' +
|
||||
'class Class1\n' +
|
||||
@@ -1326,11 +1326,11 @@ describe('given a class diagram with relationships, ', function () {
|
||||
'click Class1 call functionCall()';
|
||||
parser.parse(str);
|
||||
|
||||
expect(classDb.setClickEvent).toHaveBeenCalledWith('Class1', 'functionCall');
|
||||
expect(classParser.setClickEvent).toHaveBeenCalledWith('Class1', 'functionCall');
|
||||
});
|
||||
|
||||
it('should associate callback appropriately with an arbitrary number of args', function () {
|
||||
spyOn(classDb, 'setClickEvent');
|
||||
spyOn(classParser, 'setClickEvent');
|
||||
const str =
|
||||
'classDiagram\n' +
|
||||
'class Class1\n' +
|
||||
@@ -1338,7 +1338,7 @@ describe('given a class diagram with relationships, ', function () {
|
||||
'click Class1 call functionCall("test0", test1, test2)';
|
||||
parser.parse(str);
|
||||
|
||||
expect(classDb.setClickEvent).toHaveBeenCalledWith(
|
||||
expect(classParser.setClickEvent).toHaveBeenCalledWith(
|
||||
'Class1',
|
||||
'functionCall',
|
||||
'"test0", test1, test2'
|
||||
@@ -1346,8 +1346,8 @@ describe('given a class diagram with relationships, ', function () {
|
||||
});
|
||||
|
||||
it('should associate callback with tooltip', function () {
|
||||
spyOn(classDb, 'setClickEvent');
|
||||
spyOn(classDb, 'setTooltip');
|
||||
spyOn(classParser, 'setClickEvent');
|
||||
spyOn(classParser, 'setTooltip');
|
||||
const str =
|
||||
'classDiagram\n' +
|
||||
'class Class1\n' +
|
||||
@@ -1355,8 +1355,8 @@ describe('given a class diagram with relationships, ', function () {
|
||||
'click Class1 call functionCall() "A tooltip"';
|
||||
parser.parse(str);
|
||||
|
||||
expect(classDb.setClickEvent).toHaveBeenCalledWith('Class1', 'functionCall');
|
||||
expect(classDb.setTooltip).toHaveBeenCalledWith('Class1', 'A tooltip');
|
||||
expect(classParser.setClickEvent).toHaveBeenCalledWith('Class1', 'functionCall');
|
||||
expect(classParser.setTooltip).toHaveBeenCalledWith('Class1', 'A tooltip');
|
||||
});
|
||||
|
||||
it('should add classes namespaces', function () {
|
||||
@@ -1381,7 +1381,7 @@ class Class2
|
||||
|
||||
describe('when parsing classDiagram with text labels', () => {
|
||||
beforeEach(function () {
|
||||
parser.yy = classDb;
|
||||
parser.yy = classParser;
|
||||
parser.yy.clear();
|
||||
});
|
||||
|
||||
@@ -1390,9 +1390,9 @@ class Class2
|
||||
class C1["Class 1 with text label"]
|
||||
C1 --> C2
|
||||
`);
|
||||
const c1 = classDb.getClass('C1');
|
||||
const c1 = classParser.getClass('C1');
|
||||
expect(c1.label).toBe('Class 1 with text label');
|
||||
const c2 = classDb.getClass('C2');
|
||||
const c2 = classParser.getClass('C2');
|
||||
expect(c2.label).toBe('C2');
|
||||
});
|
||||
|
||||
@@ -1402,9 +1402,9 @@ class Class2
|
||||
class C2["Class 2 with chars @?"]
|
||||
C1 --> C2
|
||||
`);
|
||||
const c1 = classDb.getClass('C1');
|
||||
const c1 = classParser.getClass('C1');
|
||||
expect(c1.label).toBe('Class 1 with text label');
|
||||
const c2 = classDb.getClass('C2');
|
||||
const c2 = classParser.getClass('C2');
|
||||
expect(c2.label).toBe('Class 2 with chars @?');
|
||||
});
|
||||
|
||||
@@ -1415,12 +1415,12 @@ class Class2
|
||||
}
|
||||
C1 --> C2
|
||||
`);
|
||||
const c1 = classDb.getClass('C1');
|
||||
const c1 = classParser.getClass('C1');
|
||||
expect(c1.label).toBe('Class 1 with text label');
|
||||
expect(c1.members.length).toBe(1);
|
||||
expect(c1.members[0]).toBe('+member1');
|
||||
|
||||
const c2 = classDb.getClass('C2');
|
||||
const c2 = classParser.getClass('C2');
|
||||
expect(c2.label).toBe('C2');
|
||||
});
|
||||
|
||||
@@ -1432,14 +1432,14 @@ class Class2
|
||||
}
|
||||
C1 --> C2
|
||||
`);
|
||||
const c1 = classDb.getClass('C1');
|
||||
const c1 = classParser.getClass('C1');
|
||||
expect(c1.label).toBe('Class 1 with text label');
|
||||
expect(c1.members.length).toBe(1);
|
||||
expect(c1.members[0]).toBe('+member1');
|
||||
expect(c1.annotations.length).toBe(1);
|
||||
expect(c1.annotations[0]).toBe('interface');
|
||||
|
||||
const c2 = classDb.getClass('C2');
|
||||
const c2 = classParser.getClass('C2');
|
||||
expect(c2.label).toBe('C2');
|
||||
});
|
||||
|
||||
@@ -1451,7 +1451,7 @@ class C1["Class 1 with text label"]:::styleClass {
|
||||
C1 --> C2
|
||||
`);
|
||||
|
||||
const c1 = classDb.getClass('C1');
|
||||
const c1 = classParser.getClass('C1');
|
||||
expect(c1.label).toBe('Class 1 with text label');
|
||||
expect(c1.cssClasses.length).toBe(1);
|
||||
expect(c1.members[0]).toBe('+member1');
|
||||
@@ -1467,7 +1467,7 @@ C1 --> C2
|
||||
cssClass "C1" styleClass
|
||||
`);
|
||||
|
||||
const c1 = classDb.getClass('C1');
|
||||
const c1 = classParser.getClass('C1');
|
||||
expect(c1.label).toBe('Class 1 with text label');
|
||||
expect(c1.cssClasses.length).toBe(1);
|
||||
expect(c1.members[0]).toBe('+member1');
|
||||
@@ -1484,12 +1484,12 @@ C1 --> C2
|
||||
cssClass "C1,C2" styleClass
|
||||
`);
|
||||
|
||||
const c1 = classDb.getClass('C1');
|
||||
const c1 = classParser.getClass('C1');
|
||||
expect(c1.label).toBe('Class 1 with text label');
|
||||
expect(c1.cssClasses.length).toBe(1);
|
||||
expect(c1.cssClasses[0]).toBe('styleClass');
|
||||
|
||||
const c2 = classDb.getClass('C2');
|
||||
const c2 = classParser.getClass('C2');
|
||||
expect(c2.label).toBe('Long long long long long long long long long long label');
|
||||
expect(c2.cssClasses.length).toBe(1);
|
||||
expect(c2.cssClasses[0]).toBe('styleClass');
|
||||
@@ -1504,12 +1504,12 @@ class C2["Class 2 !@#$%^&*() label"]:::styleClass2
|
||||
C1 --> C2
|
||||
`);
|
||||
|
||||
const c1 = classDb.getClass('C1');
|
||||
const c1 = classParser.getClass('C1');
|
||||
expect(c1.label).toBe('Class 1 with text label');
|
||||
expect(c1.cssClasses.length).toBe(1);
|
||||
expect(c1.cssClasses[0]).toBe('styleClass1');
|
||||
|
||||
const c2 = classDb.getClass('C2');
|
||||
const c2 = classParser.getClass('C2');
|
||||
expect(c2.label).toBe('Class 2 !@#$%^&*() label');
|
||||
expect(c2.cssClasses.length).toBe(1);
|
||||
expect(c2.cssClasses[0]).toBe('styleClass2');
|
||||
@@ -1524,13 +1524,13 @@ C1 --> C2
|
||||
C3 ..> C2
|
||||
`);
|
||||
|
||||
const c1 = classDb.getClass('C1');
|
||||
const c1 = classParser.getClass('C1');
|
||||
expect(c1.label).toBe('Class with text label');
|
||||
|
||||
const c2 = classDb.getClass('C2');
|
||||
const c2 = classParser.getClass('C2');
|
||||
expect(c2.label).toBe('Class with text label');
|
||||
|
||||
const c3 = classDb.getClass('C3');
|
||||
const c3 = classParser.getClass('C3');
|
||||
expect(c3.label).toBe('Class with text label');
|
||||
});
|
||||
|
||||
@@ -1550,19 +1550,19 @@ class C11["With ' single quote"]
|
||||
class C12["With ~!@#$%^&*()_+=-/?"]
|
||||
class C13["With Città foreign language"]
|
||||
`);
|
||||
expect(classDb.getClass('C1').label).toBe('OneWord');
|
||||
expect(classDb.getClass('C2').label).toBe('With, Comma');
|
||||
expect(classDb.getClass('C3').label).toBe('With (Brackets)');
|
||||
expect(classDb.getClass('C4').label).toBe('With [Brackets]');
|
||||
expect(classDb.getClass('C5').label).toBe('With {Brackets}');
|
||||
expect(classDb.getClass('C6').label).toBe(' ');
|
||||
expect(classDb.getClass('C7').label).toBe('With 1 number');
|
||||
expect(classDb.getClass('C8').label).toBe('With . period...');
|
||||
expect(classDb.getClass('C9').label).toBe('With - dash');
|
||||
expect(classDb.getClass('C10').label).toBe('With _ underscore');
|
||||
expect(classDb.getClass('C11').label).toBe("With ' single quote");
|
||||
expect(classDb.getClass('C12').label).toBe('With ~!@#$%^&*()_+=-/?');
|
||||
expect(classDb.getClass('C13').label).toBe('With Città foreign language');
|
||||
expect(classParser.getClass('C1').label).toBe('OneWord');
|
||||
expect(classParser.getClass('C2').label).toBe('With, Comma');
|
||||
expect(classParser.getClass('C3').label).toBe('With (Brackets)');
|
||||
expect(classParser.getClass('C4').label).toBe('With [Brackets]');
|
||||
expect(classParser.getClass('C5').label).toBe('With {Brackets}');
|
||||
expect(classParser.getClass('C6').label).toBe(' ');
|
||||
expect(classParser.getClass('C7').label).toBe('With 1 number');
|
||||
expect(classParser.getClass('C8').label).toBe('With . period...');
|
||||
expect(classParser.getClass('C9').label).toBe('With - dash');
|
||||
expect(classParser.getClass('C10').label).toBe('With _ underscore');
|
||||
expect(classParser.getClass('C11').label).toBe("With ' single quote");
|
||||
expect(classParser.getClass('C12').label).toBe('With ~!@#$%^&*()_+=-/?');
|
||||
expect(classParser.getClass('C13').label).toBe('With Città foreign language');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user