2019-09-11 18:53:05 +02:00
|
|
|
/* eslint-env jest */
|
2020-08-23 15:45:23 +02:00
|
|
|
import { imgSnapshotTest, renderGraph } from '../../helpers/util';
|
2019-09-11 18:53:05 +02:00
|
|
|
|
2019-10-04 23:58:06 +02:00
|
|
|
describe('Class diagram', () => {
|
2019-11-26 11:18:32 -08:00
|
|
|
it('1: should render a simple class diagram', () => {
|
2019-09-18 18:25:06 +02:00
|
|
|
imgSnapshotTest(
|
|
|
|
`
|
2019-09-11 18:53:05 +02:00
|
|
|
classDiagram
|
|
|
|
Class01 <|-- AveryLongClass : Cool
|
2019-10-05 00:46:56 +02:00
|
|
|
<<interface>> Class01
|
2019-09-11 18:53:05 +02:00
|
|
|
Class03 *-- Class04
|
|
|
|
Class05 o-- Class06
|
|
|
|
Class07 .. Class08
|
|
|
|
Class09 --> C2 : Where am i?
|
|
|
|
Class09 --* C3
|
|
|
|
Class09 --|> Class07
|
2020-01-02 19:57:11 +01:00
|
|
|
Class12 <|.. Class08
|
|
|
|
Class11 ..>Class12
|
2019-09-11 18:53:05 +02:00
|
|
|
Class07 : equals()
|
|
|
|
Class07 : Object[] elementData
|
|
|
|
Class01 : size()
|
|
|
|
Class01 : int chimp
|
|
|
|
Class01 : int gorilla
|
2019-11-19 12:18:41 -08:00
|
|
|
Class01 : -int privateChimp
|
|
|
|
Class01 : +int publicGorilla
|
|
|
|
Class01 : #int protectedMarmoset
|
2019-09-11 18:53:05 +02:00
|
|
|
Class08 <--> C2: Cool label
|
2019-10-05 00:05:47 +02:00
|
|
|
class Class10 {
|
2019-10-05 00:46:56 +02:00
|
|
|
<<service>>
|
2019-10-04 23:58:06 +02:00
|
|
|
int id
|
|
|
|
test()
|
|
|
|
}
|
2019-09-11 18:53:05 +02:00
|
|
|
`,
|
2020-01-02 19:57:11 +01:00
|
|
|
{logLevel : 1}
|
2019-09-18 18:25:06 +02:00
|
|
|
);
|
|
|
|
cy.get('svg');
|
|
|
|
});
|
2019-11-26 11:18:32 -08:00
|
|
|
|
|
|
|
it('2: should render a simple class diagrams with cardinality', () => {
|
2019-10-08 21:46:03 +02:00
|
|
|
imgSnapshotTest(
|
|
|
|
`
|
|
|
|
classDiagram
|
|
|
|
Class01 "1" <|--|> "*" AveryLongClass : Cool
|
|
|
|
<<interface>> Class01
|
|
|
|
Class03 "1" *-- "*" Class04
|
|
|
|
Class05 "1" o-- "many" Class06
|
|
|
|
Class07 "1" .. "*" Class08
|
|
|
|
Class09 "1" --> "*" C2 : Where am i?
|
|
|
|
Class09 "*" --* "*" C3
|
|
|
|
Class09 "1" --|> "1" Class07
|
|
|
|
Class07 : equals()
|
|
|
|
Class07 : Object[] elementData
|
|
|
|
Class01 : size()
|
|
|
|
Class01 : int chimp
|
|
|
|
Class01 : int gorilla
|
|
|
|
Class08 "1" <--> "*" C2: Cool label
|
|
|
|
class Class10 {
|
|
|
|
<<service>>
|
|
|
|
int id
|
|
|
|
test()
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
cy.get('svg');
|
|
|
|
});
|
2019-11-21 11:17:53 -08:00
|
|
|
|
2020-08-23 15:45:23 +02:00
|
|
|
it('3: should render a simple class diagram with different visibilities', () => {
|
2019-11-21 11:17:53 -08:00
|
|
|
imgSnapshotTest(
|
|
|
|
`
|
|
|
|
classDiagram
|
|
|
|
Class01 <|-- AveryLongClass : Cool
|
|
|
|
<<interface>> Class01
|
2020-06-08 19:21:33 -07:00
|
|
|
Class01 : -privateMethod()
|
|
|
|
Class01 : +publicMethod()
|
|
|
|
Class01 : #protectedMethod()
|
2019-11-21 11:17:53 -08:00
|
|
|
Class01 : -int privateChimp
|
|
|
|
Class01 : +int publicGorilla
|
|
|
|
Class01 : #int protectedMarmoset
|
|
|
|
`,
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
cy.get('svg');
|
|
|
|
});
|
|
|
|
|
2019-11-26 11:18:32 -08:00
|
|
|
it('4: should render a simple class diagram with comments', () => {
|
|
|
|
imgSnapshotTest(
|
|
|
|
`
|
|
|
|
classDiagram
|
|
|
|
%% this is a comment
|
|
|
|
Class01 <|-- AveryLongClass : Cool
|
|
|
|
<<interface>> Class01
|
|
|
|
Class03 *-- Class04
|
|
|
|
Class05 o-- Class06
|
|
|
|
Class07 .. Class08
|
|
|
|
Class09 --> C2 : Where am i?
|
|
|
|
Class09 --* C3
|
|
|
|
Class09 --|> Class07
|
|
|
|
Class07 : equals()
|
|
|
|
Class07 : Object[] elementData
|
|
|
|
Class01 : size()
|
|
|
|
Class01 : int chimp
|
|
|
|
Class01 : int gorilla
|
|
|
|
Class08 <--> C2: Cool label
|
|
|
|
class Class10 {
|
|
|
|
<<service>>
|
|
|
|
int id
|
|
|
|
test()
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
cy.get('svg');
|
|
|
|
});
|
2019-12-09 17:41:26 -08:00
|
|
|
|
|
|
|
it('5: should render a simple class diagram with abstract method', () => {
|
|
|
|
imgSnapshotTest(
|
|
|
|
`
|
|
|
|
classDiagram
|
|
|
|
Class01 <|-- AveryLongClass : Cool
|
2019-12-09 18:13:06 -08:00
|
|
|
Class01 : someMethod()*
|
2019-12-09 17:41:26 -08:00
|
|
|
`,
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
cy.get('svg');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('6: should render a simple class diagram with static method', () => {
|
|
|
|
imgSnapshotTest(
|
|
|
|
`
|
|
|
|
classDiagram
|
|
|
|
Class01 <|-- AveryLongClass : Cool
|
2019-12-09 18:13:06 -08:00
|
|
|
Class01 : someMethod()$
|
2019-12-09 17:41:26 -08:00
|
|
|
`,
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
cy.get('svg');
|
|
|
|
});
|
2019-12-11 10:31:27 -08:00
|
|
|
|
2019-12-11 10:34:51 -08:00
|
|
|
it('7: should render a simple class diagram with Generic class', () => {
|
2019-12-05 12:55:46 -08:00
|
|
|
imgSnapshotTest(
|
|
|
|
`
|
|
|
|
classDiagram
|
|
|
|
class Class01~T~
|
|
|
|
Class01 : size()
|
|
|
|
Class01 : int chimp
|
|
|
|
Class01 : int gorilla
|
|
|
|
Class08 <--> C2: Cool label
|
|
|
|
class Class10~T~ {
|
|
|
|
<<service>>
|
|
|
|
int id
|
|
|
|
test()
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
cy.get('svg');
|
|
|
|
});
|
|
|
|
|
2019-12-11 10:34:51 -08:00
|
|
|
it('8: should render a simple class diagram with Generic class and relations', () => {
|
2019-12-05 12:55:46 -08:00
|
|
|
imgSnapshotTest(
|
|
|
|
`
|
|
|
|
classDiagram
|
|
|
|
Class01~T~ <|-- AveryLongClass : Cool
|
|
|
|
Class03~T~ *-- Class04~T~
|
|
|
|
Class01 : size()
|
|
|
|
Class01 : int chimp
|
|
|
|
Class01 : int gorilla
|
|
|
|
Class08 <--> C2: Cool label
|
|
|
|
class Class10~T~ {
|
|
|
|
<<service>>
|
|
|
|
int id
|
|
|
|
test()
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
cy.get('svg');
|
|
|
|
});
|
2019-12-30 17:24:19 -08:00
|
|
|
|
|
|
|
it('9: should render a simple class diagram with clickable link', () => {
|
|
|
|
imgSnapshotTest(
|
|
|
|
`
|
|
|
|
classDiagram
|
|
|
|
Class01~T~ <|-- AveryLongClass : Cool
|
|
|
|
Class03~T~ *-- Class04~T~
|
|
|
|
Class01 : size()
|
|
|
|
Class01 : int chimp
|
|
|
|
Class01 : int gorilla
|
|
|
|
Class08 <--> C2: Cool label
|
|
|
|
class Class10~T~ {
|
|
|
|
<<service>>
|
|
|
|
int id
|
|
|
|
test()
|
|
|
|
}
|
2020-09-16 18:59:53 +02:00
|
|
|
link Class01 "google.com" "A Tooltip"
|
2019-12-30 17:24:19 -08:00
|
|
|
`,
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
cy.get('svg');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('10: should render a simple class diagram with clickable callback', () => {
|
|
|
|
imgSnapshotTest(
|
|
|
|
`
|
|
|
|
classDiagram
|
|
|
|
Class01~T~ <|-- AveryLongClass : Cool
|
|
|
|
Class03~T~ *-- Class04~T~
|
|
|
|
Class01 : size()
|
|
|
|
Class01 : int chimp
|
|
|
|
Class01 : int gorilla
|
|
|
|
Class08 <--> C2: Cool label
|
|
|
|
class Class10~T~ {
|
|
|
|
<<service>>
|
|
|
|
int id
|
|
|
|
test()
|
|
|
|
}
|
2020-09-16 18:59:53 +02:00
|
|
|
callback Class01 "functionCall" "A Tooltip"
|
2019-12-30 17:24:19 -08:00
|
|
|
`,
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
cy.get('svg');
|
|
|
|
});
|
2020-01-06 16:21:11 -08:00
|
|
|
|
|
|
|
it('11: should render a simple class diagram with return type on method', () => {
|
|
|
|
imgSnapshotTest(
|
|
|
|
`
|
|
|
|
classDiagram
|
|
|
|
class Class10~T~ {
|
|
|
|
int[] id
|
|
|
|
test(int[] ids) bool
|
|
|
|
testArray() bool[]
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
cy.get('svg');
|
|
|
|
});
|
2020-01-13 16:04:26 -08:00
|
|
|
|
|
|
|
it('12: should render a simple class diagram with generic types', () => {
|
|
|
|
imgSnapshotTest(
|
|
|
|
`
|
|
|
|
classDiagram
|
|
|
|
class Class10~T~ {
|
|
|
|
int[] id
|
|
|
|
List~int~ ids
|
|
|
|
test(List~int~ ids) List~bool~
|
|
|
|
testArray() bool[]
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
cy.get('svg');
|
|
|
|
});
|
2020-08-03 12:41:10 -07:00
|
|
|
|
|
|
|
it('13: should render a simple class diagram with css classes applied', () => {
|
|
|
|
imgSnapshotTest(
|
|
|
|
`
|
|
|
|
classDiagram
|
|
|
|
class Class10 {
|
|
|
|
int[] id
|
|
|
|
List~int~ ids
|
|
|
|
test(List~int~ ids) List~bool~
|
|
|
|
testArray() bool[]
|
|
|
|
}
|
|
|
|
|
|
|
|
cssClass "Class10" exClass
|
|
|
|
`,
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
cy.get('svg');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('14: should render a simple class diagram with css classes applied directly', () => {
|
|
|
|
imgSnapshotTest(
|
|
|
|
`
|
|
|
|
classDiagram
|
|
|
|
class Class10:::exClass {
|
|
|
|
int[] id
|
|
|
|
List~int~ ids
|
|
|
|
test(List~int~ ids) List~bool~
|
|
|
|
testArray() bool[]
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
cy.get('svg');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('15: should render a simple class diagram with css classes applied two multiple classes', () => {
|
|
|
|
imgSnapshotTest(
|
|
|
|
`
|
|
|
|
classDiagram
|
|
|
|
class Class10
|
|
|
|
class Class20
|
|
|
|
|
|
|
|
cssClass "Class10, class20" exClass
|
|
|
|
`,
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
cy.get('svg');
|
|
|
|
});
|
2020-08-23 15:45:23 +02:00
|
|
|
|
|
|
|
it('16: should render multiple class diagrams', () => {
|
|
|
|
imgSnapshotTest(
|
|
|
|
[
|
|
|
|
`
|
|
|
|
classDiagram
|
|
|
|
Class01 "1" <|--|> "*" AveryLongClass : Cool
|
|
|
|
<<interface>> Class01
|
|
|
|
Class03 "1" *-- "*" Class04
|
|
|
|
Class05 "1" o-- "many" Class06
|
|
|
|
Class07 "1" .. "*" Class08
|
|
|
|
Class09 "1" --> "*" C2 : Where am i?
|
|
|
|
Class09 "*" --* "*" C3
|
|
|
|
Class09 "1" --|> "1" Class07
|
|
|
|
Class07 : equals()
|
|
|
|
Class07 : Object[] elementData
|
|
|
|
Class01 : size()
|
|
|
|
Class01 : int chimp
|
|
|
|
Class01 : int gorilla
|
|
|
|
Class08 "1" <--> "*" C2: Cool label
|
|
|
|
class Class10 {
|
|
|
|
<<service>>
|
|
|
|
int id
|
|
|
|
test()
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
`
|
|
|
|
classDiagram
|
|
|
|
Class01 "1" <|--|> "*" AveryLongClass : Cool
|
|
|
|
<<interface>> Class01
|
|
|
|
Class03 "1" *-- "*" Class04
|
|
|
|
Class05 "1" o-- "many" Class06
|
|
|
|
Class07 "1" .. "*" Class08
|
|
|
|
Class09 "1" --> "*" C2 : Where am i?
|
|
|
|
Class09 "*" --* "*" C3
|
|
|
|
Class09 "1" --|> "1" Class07
|
|
|
|
Class07 : equals()
|
|
|
|
Class07 : Object[] elementData
|
|
|
|
Class01 : size()
|
|
|
|
Class01 : int chimp
|
|
|
|
Class01 : int gorilla
|
|
|
|
Class08 "1" <--> "*" C2: Cool label
|
|
|
|
class Class10 {
|
|
|
|
<<service>>
|
|
|
|
int id
|
|
|
|
test()
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
],
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
cy.get('svg');
|
|
|
|
});
|
|
|
|
|
2020-08-25 17:05:01 +02:00
|
|
|
it('17: should render a class diagram when useMaxWidth is true (default)', () => {
|
2020-08-23 15:45:23 +02:00
|
|
|
renderGraph(
|
|
|
|
`
|
|
|
|
classDiagram
|
|
|
|
Class01 <|-- AveryLongClass : Cool
|
|
|
|
Class01 : size()
|
|
|
|
Class01 : int chimp
|
|
|
|
Class01 : int gorilla
|
|
|
|
Class01 : -int privateChimp
|
|
|
|
Class01 : +int publicGorilla
|
|
|
|
Class01 : #int protectedMarmoset
|
|
|
|
`,
|
|
|
|
{ class: { useMaxWidth: true } }
|
|
|
|
);
|
|
|
|
cy.get('svg')
|
2020-08-25 17:05:01 +02:00
|
|
|
.should((svg) => {
|
|
|
|
expect(svg).to.have.attr('width', '100%');
|
|
|
|
expect(svg).to.have.attr('height', '218');
|
|
|
|
const style = svg.attr('style');
|
|
|
|
expect(style).to.match(/^max-width: [\d.]+px;$/);
|
|
|
|
const maxWidthValue = parseInt(style.match(/[\d.]+/g).join(''));
|
|
|
|
// use within because the absolute value can be slightly different depending on the environment ±5%
|
|
|
|
expect(maxWidthValue).to.be.within(160 * .95, 160 * 1.05);
|
|
|
|
});
|
2020-08-23 15:45:23 +02:00
|
|
|
});
|
|
|
|
|
2020-08-25 17:05:01 +02:00
|
|
|
it('18: should render a class diagram when useMaxWidth is false', () => {
|
2020-08-23 15:45:23 +02:00
|
|
|
renderGraph(
|
|
|
|
`
|
|
|
|
classDiagram
|
|
|
|
Class01 <|-- AveryLongClass : Cool
|
|
|
|
Class01 : size()
|
|
|
|
Class01 : int chimp
|
|
|
|
Class01 : int gorilla
|
|
|
|
Class01 : -int privateChimp
|
|
|
|
Class01 : +int publicGorilla
|
|
|
|
Class01 : #int protectedMarmoset
|
|
|
|
`,
|
|
|
|
{ class: { useMaxWidth: false } }
|
|
|
|
);
|
|
|
|
cy.get('svg')
|
2020-08-25 17:05:01 +02:00
|
|
|
.should((svg) => {
|
|
|
|
const width = parseFloat(svg.attr('width'));
|
|
|
|
// use within because the absolute value can be slightly different depending on the environment ±5%
|
|
|
|
expect(width).to.be.within(160 * .95, 160 * 1.05);
|
|
|
|
expect(svg).to.have.attr('height', '218');
|
|
|
|
expect(svg).to.not.have.attr('style');
|
|
|
|
});
|
2020-08-23 15:45:23 +02:00
|
|
|
});
|
2019-09-18 18:25:06 +02:00
|
|
|
});
|