Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix - static class attributes are not rendered underlined #5013

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(/[$*]/)) {
knsv marked this conversation as resolved.
Show resolved Hide resolved
potentialClassifier = lastChar;
}

Expand Down
Loading