Skip to content

Commit

Permalink
Merge pull request mermaid-js#5013 from SteffenLm/bug/5009_static_cla…
Browse files Browse the repository at this point in the history
…ss_attribute_not_rendered

Fix - static class attributes are not rendered underlined
  • Loading branch information
aloisklink authored Nov 14, 2023
2 parents 0c0f7a7 + b5fd8fb commit c56025e
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 1 deletion.
79 changes: 79 additions & 0 deletions packages/mermaid/src/diagrams/class/classTypes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/class/classTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class ClassMember {
this.visibility = firstChar as Visibility;
}

if (lastChar.match(/[*?]/)) {
if (lastChar.match(/[$*]/)) {
potentialClassifier = lastChar;
}

Expand Down

0 comments on commit c56025e

Please sign in to comment.