Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3367 from dbartholomae/add_tests_for_C4_system_co…
…ntext_macros Add tests for C4 system context macros
- Loading branch information
Showing
5 changed files
with
470 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import c4Db from '../c4Db'; | ||
import c4 from './c4Diagram.jison'; | ||
import { setConfig } from '../../../config'; | ||
|
||
setConfig({ | ||
securityLevel: 'strict', | ||
}); | ||
|
||
describe.each(['Boundary'])('parsing a C4 %s', function (macroName) { | ||
beforeEach(function () { | ||
c4.parser.yy = c4Db; | ||
c4.parser.yy.clear(); | ||
}); | ||
|
||
it('should parse a C4 diagram with one Boundary correctly', function () { | ||
c4.parser.parse(`C4Context | ||
title System Context diagram for Internet Banking System | ||
${macroName}(b1, "BankBoundary") { | ||
System(SystemAA, "Internet Banking System") | ||
}`); | ||
|
||
const yy = c4.parser.yy; | ||
|
||
const boundaries = yy.getBoundarys(); | ||
expect(boundaries.length).toBe(2); | ||
const boundary = boundaries[1]; | ||
|
||
expect(boundary).toEqual({ | ||
alias: 'b1', | ||
label: { | ||
text: 'BankBoundary', | ||
}, | ||
// TODO: Why are link, and tags undefined instead of not appearing at all? | ||
// Compare to Person where they don't show up. | ||
link: undefined, | ||
tags: undefined, | ||
parentBoundary: 'global', | ||
type: { | ||
// TODO: Why is this `system` instead of `boundary`? | ||
text: 'system', | ||
}, | ||
wrap: false, | ||
}); | ||
}); | ||
|
||
it('should parse the alias', function () { | ||
c4.parser.parse(`C4Context | ||
${macroName}(b1, "BankBoundary") { | ||
System(SystemAA, "Internet Banking System") | ||
}`); | ||
|
||
expect(c4.parser.yy.getBoundarys()[1]).toMatchObject({ | ||
alias: 'b1', | ||
}); | ||
}); | ||
|
||
it('should parse the label', function () { | ||
c4.parser.parse(`C4Context | ||
${macroName}(b1, "BankBoundary") { | ||
System(SystemAA, "Internet Banking System") | ||
}`); | ||
|
||
expect(c4.parser.yy.getBoundarys()[1]).toMatchObject({ | ||
label: { | ||
text: 'BankBoundary', | ||
}, | ||
}); | ||
}); | ||
|
||
it('should parse the type', function () { | ||
c4.parser.parse(`C4Context | ||
${macroName}(b1, "", "company") { | ||
System(SystemAA, "Internet Banking System") | ||
}`); | ||
|
||
expect(c4.parser.yy.getBoundarys()[1]).toMatchObject({ | ||
type: { text: 'company' }, | ||
}); | ||
}); | ||
|
||
it('should parse a link', function () { | ||
c4.parser.parse(`C4Context | ||
${macroName}(b1, $link="https://github.com/mermaidjs") { | ||
System(SystemAA, "Internet Banking System") | ||
}`); | ||
|
||
expect(c4.parser.yy.getBoundarys()[1]).toMatchObject({ | ||
label: { | ||
text: { | ||
link: 'https://github.com/mermaidjs', | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should parse tags', function () { | ||
c4.parser.parse(`C4Context | ||
${macroName}(b1, $tags="tag1,tag2") { | ||
System(SystemAA, "Internet Banking System") | ||
}`); | ||
|
||
expect(c4.parser.yy.getBoundarys()[1]).toMatchObject({ | ||
label: { | ||
text: { | ||
tags: 'tag1,tag2', | ||
}, | ||
}, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import c4Db from '../c4Db'; | ||
import c4 from './c4Diagram.jison'; | ||
import { setConfig } from '../../../config'; | ||
|
||
setConfig({ | ||
securityLevel: 'strict', | ||
}); | ||
|
||
describe('parsing a C4 Person', function () { | ||
beforeEach(function () { | ||
c4.parser.yy = c4Db; | ||
c4.parser.yy.clear(); | ||
}); | ||
|
||
it('should parse a C4 diagram with one Person correctly', function () { | ||
c4.parser.parse(`C4Context | ||
title System Context diagram for Internet Banking System | ||
Person(customerA, "Banking Customer A", "A customer of the bank, with personal bank accounts.")`); | ||
|
||
const yy = c4.parser.yy; | ||
|
||
const shapes = yy.getC4ShapeArray(); | ||
expect(shapes.length).toBe(1); | ||
const onlyShape = shapes[0]; | ||
|
||
expect(onlyShape).toEqual({ | ||
alias: 'customerA', | ||
descr: { | ||
text: 'A customer of the bank, with personal bank accounts.', | ||
}, | ||
label: { | ||
text: 'Banking Customer A', | ||
}, | ||
parentBoundary: 'global', | ||
typeC4Shape: { | ||
text: 'person', | ||
}, | ||
wrap: false, | ||
}); | ||
}); | ||
|
||
it('should parse the alias', function () { | ||
c4.parser.parse(`C4Context | ||
Person(customerA, "Banking Customer A")`); | ||
|
||
expect(c4.parser.yy.getC4ShapeArray()[0]).toMatchObject({ | ||
alias: 'customerA', | ||
}); | ||
}); | ||
|
||
it('should parse the label', function () { | ||
c4.parser.parse(`C4Context | ||
Person(customerA, "Banking Customer A")`); | ||
|
||
expect(c4.parser.yy.getC4ShapeArray()[0]).toMatchObject({ | ||
label: { | ||
text: 'Banking Customer A', | ||
}, | ||
}); | ||
}); | ||
|
||
it('should parse the description', function () { | ||
c4.parser.parse(`C4Context | ||
Person(customerA, "", "A customer of the bank, with personal bank accounts.")`); | ||
|
||
expect(c4.parser.yy.getC4ShapeArray()[0]).toMatchObject({ | ||
descr: { | ||
text: 'A customer of the bank, with personal bank accounts.', | ||
}, | ||
}); | ||
}); | ||
|
||
it('should parse a sprite', function () { | ||
c4.parser.parse(`C4Context | ||
Person(customerA, $sprite="users")`); | ||
|
||
expect(c4.parser.yy.getC4ShapeArray()[0]).toMatchObject({ | ||
label: { | ||
text: { | ||
sprite: 'users', | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should parse a link', function () { | ||
c4.parser.parse(`C4Context | ||
Person(customerA, $link="https://github.com/mermaidjs")`); | ||
|
||
expect(c4.parser.yy.getC4ShapeArray()[0]).toMatchObject({ | ||
label: { | ||
text: { | ||
link: 'https://github.com/mermaidjs', | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should parse tags', function () { | ||
c4.parser.parse(`C4Context | ||
Person(customerA, $tags="tag1,tag2")`); | ||
|
||
expect(c4.parser.yy.getC4ShapeArray()[0]).toMatchObject({ | ||
label: { | ||
text: { | ||
tags: 'tag1,tag2', | ||
}, | ||
}, | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.