From b5fd8fb7c1276f004ebbdab62fddc5ecc1e97e0b Mon Sep 17 00:00:00 2001 From: SteffenLm <33038091+SteffenLm@users.noreply.github.com> Date: Fri, 3 Nov 2023 20:55:42 +0100 Subject: [PATCH] fix text-decoration for abstract attibutes --- .../src/diagrams/class/classTypes.spec.ts | 79 +++++++++++++++++++ .../mermaid/src/diagrams/class/classTypes.ts | 2 +- 2 files changed, 80 insertions(+), 1 deletion(-) diff --git a/packages/mermaid/src/diagrams/class/classTypes.spec.ts b/packages/mermaid/src/diagrams/class/classTypes.spec.ts index 2b360d4473..5a5ffa4dbd 100644 --- a/packages/mermaid/src/diagrams/class/classTypes.spec.ts +++ b/packages/mermaid/src/diagrams/class/classTypes.spec.ts @@ -681,3 +681,82 @@ describe('given text representing a method, ', function () { }); }); }); + +describe('given text representing an attribute', () => { + describe('when the attribute has no modifiers', () => { + it('should parse the display text correctly', () => { + const str = 'name String'; + + const displayDetails = new ClassMember(str, 'attribute').getDisplayDetails(); + + expect(displayDetails.displayText).toBe('name String'); + expect(displayDetails.cssStyle).toBe(''); + }); + }); + + describe('when the attribute has public "+" modifier', () => { + it('should parse the display text correctly', () => { + const str = '+name String'; + + const displayDetails = new ClassMember(str, 'attribute').getDisplayDetails(); + + expect(displayDetails.displayText).toBe('+name String'); + expect(displayDetails.cssStyle).toBe(''); + }); + }); + + describe('when the attribute has protected "#" modifier', () => { + it('should parse the display text correctly', () => { + const str = '#name String'; + + const displayDetails = new ClassMember(str, 'attribute').getDisplayDetails(); + + expect(displayDetails.displayText).toBe('#name String'); + expect(displayDetails.cssStyle).toBe(''); + }); + }); + + describe('when the attribute has private "-" modifier', () => { + it('should parse the display text correctly', () => { + const str = '-name String'; + + const displayDetails = new ClassMember(str, 'attribute').getDisplayDetails(); + + expect(displayDetails.displayText).toBe('-name String'); + expect(displayDetails.cssStyle).toBe(''); + }); + }); + + describe('when the attribute has internal "~" modifier', () => { + it('should parse the display text correctly', () => { + const str = '~name String'; + + const displayDetails = new ClassMember(str, 'attribute').getDisplayDetails(); + + expect(displayDetails.displayText).toBe('~name String'); + expect(displayDetails.cssStyle).toBe(''); + }); + }); + + describe('when the attribute has static "$" modifier', () => { + it('should parse the display text correctly and apply static css style', () => { + const str = 'name String$'; + + const displayDetails = new ClassMember(str, 'attribute').getDisplayDetails(); + + expect(displayDetails.displayText).toBe('name String'); + expect(displayDetails.cssStyle).toBe(staticCssStyle); + }); + }); + + describe('when the attribute has abstract "*" modifier', () => { + it('should parse the display text correctly and apply abstract css style', () => { + const str = 'name String*'; + + const displayDetails = new ClassMember(str, 'attribute').getDisplayDetails(); + + expect(displayDetails.displayText).toBe('name String'); + expect(displayDetails.cssStyle).toBe(abstractCssStyle); + }); + }); +}); diff --git a/packages/mermaid/src/diagrams/class/classTypes.ts b/packages/mermaid/src/diagrams/class/classTypes.ts index e288eefde8..f112dd4dde 100644 --- a/packages/mermaid/src/diagrams/class/classTypes.ts +++ b/packages/mermaid/src/diagrams/class/classTypes.ts @@ -106,7 +106,7 @@ export class ClassMember { this.visibility = firstChar as Visibility; } - if (lastChar.match(/[*?]/)) { + if (lastChar.match(/[$*]/)) { potentialClassifier = lastChar; }