From 2414435641a1c9b45e677cd3469dd73813e35715 Mon Sep 17 00:00:00 2001 From: Daniel Bartholomae Date: Sat, 27 Aug 2022 15:51:49 +0200 Subject: [PATCH] Add tests for C4 System --- src/diagrams/c4/parser/c4System.spec.js | 116 ++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 src/diagrams/c4/parser/c4System.spec.js diff --git a/src/diagrams/c4/parser/c4System.spec.js b/src/diagrams/c4/parser/c4System.spec.js new file mode 100644 index 000000000..fb8a2aaa4 --- /dev/null +++ b/src/diagrams/c4/parser/c4System.spec.js @@ -0,0 +1,116 @@ +import c4Db from '../c4Db'; +import c4 from './c4Diagram.jison'; +import { setConfig } from '../../../config'; + +setConfig({ + securityLevel: 'strict', +}); + +describe('parsing a C4 System', function () { + beforeEach(function () { + c4.parser.yy = c4Db; + c4.parser.yy.clear(); + }); + + it('should parse a C4 diagram with one System correctly', function () { + c4.parser.parse(`C4Context +title System Context diagram for Internet Banking System +System(SystemAA, "Internet Banking System", "Allows customers to view information about their bank accounts, and make payments.")`); + + const yy = c4.parser.yy; + + const shapes = yy.getC4ShapeArray(); + expect(shapes.length).toBe(1); + const onlyShape = shapes[0]; + + expect(onlyShape).toEqual({ + alias: 'SystemAA', + descr: { + text: 'Allows customers to view information about their bank accounts, and make payments.', + }, + label: { + text: 'Internet Banking System', + }, + // TODO: Why are link, sprite, and tags undefined instead of not appearing at all? + // Compare to Person where they don't show up. + link: undefined, + sprite: undefined, + tags: undefined, + parentBoundary: 'global', + typeC4Shape: { + text: 'system', + }, + wrap: false, + }); + }); + + it('should parse the alias', function () { + c4.parser.parse(`C4Context +System(SystemAA, "Internet Banking System")`); + + expect(c4.parser.yy.getC4ShapeArray()[0]).toMatchObject({ + alias: 'SystemAA', + }); + }); + + it('should parse the label', function () { + c4.parser.parse(`C4Context +System(SystemAA, "Internet Banking System")`); + + expect(c4.parser.yy.getC4ShapeArray()[0]).toMatchObject({ + label: { + text: 'Internet Banking System', + }, + }); + }); + + it('should parse the description', function () { + c4.parser.parse(`C4Context +System(SystemAA, "", "Allows customers to view information about their bank accounts, and make payments.")`); + + expect(c4.parser.yy.getC4ShapeArray()[0]).toMatchObject({ + descr: { + text: 'Allows customers to view information about their bank accounts, and make payments.', + }, + }); + }); + + it('should parse a sprite', function () { + c4.parser.parse(`C4Context +System(SystemAA, $sprite="users")`); + + expect(c4.parser.yy.getC4ShapeArray()[0]).toMatchObject({ + label: { + text: { + sprite: 'users', + }, + }, + }); + }); + + it('should parse a link', function () { + c4.parser.parse(`C4Context +System(SystemAA, $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 +System(SystemAA, $tags="tag1,tag2")`); + + expect(c4.parser.yy.getC4ShapeArray()[0]).toMatchObject({ + label: { + text: { + tags: 'tag1,tag2', + }, + }, + }); + }); +});