From 234a2cc819c656aba67888024949b50d912476eb Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Sun, 24 Mar 2024 12:29:40 +0530 Subject: [PATCH] chore: Revert changes to existing tests, add new tests --- .cspell/contributors.txt | 1 + .../rendering/classDiagram-v2.spec.js | 142 +++++++++++++++-- .../rendering/classDiagram.spec.js | 143 ++++++++++++++++-- 3 files changed, 262 insertions(+), 24 deletions(-) diff --git a/.cspell/contributors.txt b/.cspell/contributors.txt index bd3ad9da24..f90c064998 100644 --- a/.cspell/contributors.txt +++ b/.cspell/contributors.txt @@ -2,6 +2,7 @@ Ashish Jain cpettitt Dong Cai +jgreywolf Nikolay Rozhkov Peng Xiao subhash-halder diff --git a/cypress/integration/rendering/classDiagram-v2.spec.js b/cypress/integration/rendering/classDiagram-v2.spec.js index 919d7ad5b0..8da82f98c6 100644 --- a/cypress/integration/rendering/classDiagram-v2.spec.js +++ b/cypress/integration/rendering/classDiagram-v2.spec.js @@ -201,9 +201,9 @@ describe('Class diagram V2', () => { ` classDiagram-v2 class Class01~T~ - Class01-T : size() - Class01-T : int chimp - Class01-T : int gorilla + Class01 : size() + Class01 : int chimp + Class01 : int gorilla Class08 <--> C2: Cool label class Class10~T~ { <<service>> @@ -221,9 +221,9 @@ describe('Class diagram V2', () => { classDiagram-v2 Class01~T~ <|-- AveryLongClass : Cool Class03~T~ *-- Class04~T~ - Class01-T : size() - Class01-T : int chimp - Class01-T : int gorilla + Class01 : size() + Class01 : int chimp + Class01 : int gorilla Class08 <--> C2: Cool label class Class10~T~ { <<service>> @@ -241,9 +241,9 @@ describe('Class diagram V2', () => { classDiagram-v2 Class01~T~ <|-- AveryLongClass : Cool Class03~T~ *-- Class04~T~ - Class01-T : size() - Class01-T : int chimp - Class01-T : int gorilla + Class01 : size() + Class01 : int chimp + Class01 : int gorilla Class08 <--> C2: Cool label class Class10~T~ { <<service>> @@ -262,9 +262,9 @@ describe('Class diagram V2', () => { classDiagram-v2 Class01~T~ <|-- AveryLongClass : Cool Class03~T~ *-- Class04~T~ - Class01-T : size() - Class01-T : int chimp - Class01-T : int gorilla + Class01 : size() + Class01 : int chimp + Class01 : int gorilla Class08 <--> C2: Cool label class Class10~T~ { <<service>> @@ -581,4 +581,122 @@ class C13["With Città foreign language"] { logLevel: 1, flowchart: { htmlLabels: false } } ); }); + + describe('when adding generic types', () => { + it('should add properties when type is mentioned in classID', () => { + imgSnapshotTest( + ` + classDiagram-v2 + class Class01~T~ + Class01-T : size() + Class01-T : int chimp + Class01-T : int gorilla + ` + ); + }); + + it('should fallback to matching class name when type is not mentioned in property', () => { + imgSnapshotTest( + ` + classDiagram-v2 + class Class01~T~ + Class01-T : size() + Class01-T : int chimp + Class01 : int gorilla + ` + ); + }); + + it('should fallback to the first matching class name when type is not mentioned in property', () => { + imgSnapshotTest( + ` + classDiagram-v2 + class Class01~T~ + class Class01~X~ + Class01-T : int inClassT + Class01-X : int inClassX + Class01 : int alsoInClassT + ` + ); + }); + + it('should detect generic classes correctly when using different classIDs', () => { + imgSnapshotTest( + ` + classDiagram-v2 + class Class01~T~ + Class01-T : size() + Class01-T : int chimp + Class01 : int gorillaInClassT + class Class01~X~ + Class01-X : size() + Class01-X : int chimp + Class01-X : int gorilla + ` + ); + }); + + it('should render with Generic class and relations', () => { + imgSnapshotTest( + ` + classDiagram-v2 + Class01~T~ <|-- AveryLongClass : Cool + Class03~T~ *-- Class04~T~ + Class01-T : size() + Class01-T : int chimp + Class01-T : int gorilla + Class08 <--> C2: Cool label + class Class10~T~ { + <<service>> + int id + test() + } + ` + ); + }); + + it('should render with clickable link when type is not mentioned', () => { + imgSnapshotTest( + ` + classDiagram-v2 + Class01~T~ <|-- AveryLongClass : Cool + Class01-T : size() + link Class01 "google.com" "A Tooltip" + ` + ); + }); + + it('should render with clickable callback when type is not mentioned', () => { + imgSnapshotTest( + ` + classDiagram-v2 + Class01~T~ <|-- AveryLongClass : Cool + Class01-T : size() + callback Class01 "functionCall" "A Tooltip" + ` + ); + }); + + it('should render with clickable link when type is mentioned', () => { + imgSnapshotTest( + ` + classDiagram-v2 + Class01~T~ <|-- AveryLongClass : Cool + Class01-T : size() + link Class01-T "google.com" "A Tooltip" + ` + ); + }); + + it('should render with clickable callback when type is mentioned', () => { + imgSnapshotTest( + ` + classDiagram-v2 + Class01~T~ <|-- AveryLongClass : Cool + Class01-T : size() + callback Class01-T "functionCall" "A Tooltip" + ` + ); + }); + }); }); diff --git a/cypress/integration/rendering/classDiagram.spec.js b/cypress/integration/rendering/classDiagram.spec.js index 6c0b5846d2..95f7d9723a 100644 --- a/cypress/integration/rendering/classDiagram.spec.js +++ b/cypress/integration/rendering/classDiagram.spec.js @@ -141,9 +141,9 @@ describe('Class diagram', () => { ` classDiagram class Class01~T~ - Class01-T : size() - Class01-T : int chimp - Class01~T~ : int gorilla + Class01 : size() + Class01 : int chimp + Class01 : int gorilla Class08 <--> C2: Cool label class Class10~T~ { <<service>> @@ -162,9 +162,9 @@ describe('Class diagram', () => { classDiagram Class01~T~ <|-- AveryLongClass : Cool Class03~T~ *-- Class04~T~ - Class01-T : size() - Class01-T : int chimp - Class01-T : int gorilla + Class01 : size() + Class01 : int chimp + Class01 : int gorilla Class08 <--> C2: Cool label class Class10~T~ { <<service>> @@ -183,9 +183,9 @@ describe('Class diagram', () => { classDiagram Class01~T~ <|-- AveryLongClass : Cool Class03~T~ *-- Class04~T~ - Class01-T : size() - Class01-T : int chimp - Class01-T : int gorilla + Class01 : size() + Class01 : int chimp + Class01 : int gorilla Class08 <--> C2: Cool label class Class10~T~ { <<service>> @@ -205,9 +205,9 @@ describe('Class diagram', () => { classDiagram Class01~T~ <|-- AveryLongClass : Cool Class03~T~ *-- Class04~T~ - Class01-T : size() - Class01-T : int chimp - Class01-T : int gorilla + Class01 : size() + Class01 : int chimp + Class01 : int gorilla Class08 <--> C2: Cool label class Class10~T~ { <<service>> @@ -513,4 +513,123 @@ describe('Class diagram', () => { cy.get('a').should('have.attr', 'target', '_blank').should('have.attr', 'rel', 'noopener'); }); }); + + describe('when adding generic types', () => { + it('should add properties when type is mentioned in classID', () => { + imgSnapshotTest( + ` + classDiagram + class Class01~T~ + Class01-T : size() + Class01-T : int chimp + Class01-T : int gorilla + ` + ); + }); + + it('should fallback to matching class name when type is not mentioned in property', () => { + imgSnapshotTest( + ` + classDiagram + class Class01~T~ + Class01-T : size() + Class01-T : int chimp + Class01 : int gorilla + ` + ); + }); + + it('should fallback to the first matching class name when type is not mentioned in property', () => { + imgSnapshotTest( + ` + classDiagram + class Class01~T~ + class Class01~X~ + Class01-T : int inClassT + Class01-X : int inClassX + Class01 : int alsoInClassT + ` + ); + }); + + it('should detect generic classes correctly when using different classIDs', () => { + imgSnapshotTest( + ` + classDiagram + class Class01~T~ + Class01-T : size() + Class01-T : int chimp + Class01 : int gorillaInClassT + class Class01~X~ + Class01-X : size() + Class01-X : int chimp + Class01-X : int gorilla + ` + ); + }); + + it('should render with Generic class and relations', () => { + imgSnapshotTest( + ` + classDiagram + Class01~T~ <|-- AveryLongClass : Cool + Class03~T~ *-- Class04~T~ + Class01-T : size() + Class01-T : int chimp + Class01-T : int gorilla + Class08 <--> C2: Cool label + class Class10~T~ { + <<service>> + int id + test() + } + ` + ); + }); + + // TODO: @jgreywolf These tests should ideally be unit tests, as links cannot be verified visually. + it('should render with clickable link when type is not mentioned', () => { + imgSnapshotTest( + ` + classDiagram + Class01~T~ <|-- AveryLongClass : Cool + Class01-T : size() + link Class01 "google.com" "A Tooltip" + ` + ); + }); + + it('should render with clickable callback when type is not mentioned', () => { + imgSnapshotTest( + ` + classDiagram + Class01~T~ <|-- AveryLongClass : Cool + Class01-T : size() + callback Class01 "functionCall" "A Tooltip" + ` + ); + }); + + it('should render with clickable link when type is mentioned', () => { + imgSnapshotTest( + ` + classDiagram + Class01~T~ <|-- AveryLongClass : Cool + Class01-T : size() + link Class01-T "google.com" "A Tooltip" + ` + ); + }); + + it('should render with clickable callback when type is mentioned', () => { + imgSnapshotTest( + ` + classDiagram + Class01~T~ <|-- AveryLongClass : Cool + Class01-T : size() + callback Class01-T "functionCall" "A Tooltip" + ` + ); + }); + }); });