Skip to content

Commit

Permalink
fix text-decoration for abstract attibutes
Browse files Browse the repository at this point in the history
  • Loading branch information
SteffenLm committed Nov 3, 2023
1 parent f5bd1e0 commit b5fd8fb
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 b5fd8fb

Please sign in to comment.