Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/salty-wombats-sin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'mermaid': patch
---

fix: Allow multiple interactions between the same components in C4 Dynamic diagrams
7 changes: 1 addition & 6 deletions packages/mermaid/src/diagrams/c4/c4Db.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,7 @@ export const addRel = function (type, from, to, label, techn, descr, sprite, tag
}

let rel = {};
const old = rels.find((rel) => rel.from === from && rel.to === to);
if (old) {
rel = old;
} else {
rels.push(rel);
}
rels.push(rel);

rel.type = type;
rel.from = from;
Expand Down
30 changes: 30 additions & 0 deletions packages/mermaid/src/diagrams/c4/parser/c4Dynamic.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import c4Db from '../c4Db.js';
import c4 from './c4Diagram.jison';
import { setConfig } from '../../../config.js';

setConfig({
securityLevel: 'strict',
});

describe('parsing a C4 dynamic diagram', function () {
beforeEach(function () {
c4.parser.yy = c4Db;
c4.parser.yy.clear();
});

it('should allow multiple interactions between components', function () {
c4.parser.parse(`C4Dynamic
System(a, "A")
System(b, "B")
Rel(a, b, "Interaction 1")
Rel(a, b, "Interaction 2")`);

const yy = c4.parser.yy;

expect(yy.getC4Type()).toBe('C4Dynamic');
const rels = yy.getRels();
expect(rels.length).toBe(2);
expect(rels[0].label.text).toBe('Interaction 1');
expect(rels[1].label.text).toBe('Interaction 2');
});
});
Loading