-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving out tests from mermaid.spec.js
- Loading branch information
Showing
3 changed files
with
156 additions
and
150 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
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,154 @@ | ||
import flowDb from './flowDb'; | ||
import flowParser from './parser/flow'; | ||
import flowRenderer from './flowRenderer'; | ||
import Diagram from '../../Diagram'; | ||
import { addDiagrams } from '../../diagram-api/diagram-orchestration'; | ||
addDiagrams(); | ||
afterEach(() => { | ||
jest.restoreAllMocks(); | ||
}); | ||
|
||
describe('when using mermaid and ', function () { | ||
describe('when calling addEdges ', function () { | ||
beforeEach(function () { | ||
flowParser.parser.yy = flowDb; | ||
flowDb.clear(); | ||
flowDb.setGen('gen-2'); | ||
}); | ||
it('should handle edges with text', function () { | ||
const diag = new Diagram('graph TD;A-->|text ex|B;'); | ||
diag.db.getVertices(); | ||
const edges = diag.db.getEdges(); | ||
|
||
const mockG = { | ||
setEdge: function (start, end, options) { | ||
expect(start).toContain('flowchart-A-'); | ||
expect(end).toContain('flowchart-B-'); | ||
expect(options.arrowhead).toBe('normal'); | ||
expect(options.label.match('text ex')).toBeTruthy(); | ||
}, | ||
}; | ||
|
||
flowRenderer.addEdges(edges, mockG, diag); | ||
}); | ||
|
||
it('should handle edges without text', function () { | ||
const diag = new Diagram('graph TD;A-->B;'); | ||
diag.db.getVertices(); | ||
const edges = diag.db.getEdges(); | ||
|
||
const mockG = { | ||
setEdge: function (start, end, options) { | ||
expect(start).toContain('flowchart-A-'); | ||
expect(end).toContain('flowchart-B-'); | ||
expect(options.arrowhead).toBe('normal'); | ||
}, | ||
}; | ||
|
||
flowRenderer.addEdges(edges, mockG, diag); | ||
}); | ||
|
||
it('should handle open-ended edges', function () { | ||
const diag = new Diagram('graph TD;A---B;'); | ||
diag.db.getVertices(); | ||
const edges = diag.db.getEdges(); | ||
|
||
const mockG = { | ||
setEdge: function (start, end, options) { | ||
expect(start).toContain('flowchart-A-'); | ||
expect(end).toContain('flowchart-B-'); | ||
expect(options.arrowhead).toBe('none'); | ||
}, | ||
}; | ||
|
||
flowRenderer.addEdges(edges, mockG, diag); | ||
}); | ||
|
||
it('should handle edges with styles defined', function () { | ||
const diag = new Diagram('graph TD;A---B; linkStyle 0 stroke:val1,stroke-width:val2;'); | ||
diag.db.getVertices(); | ||
const edges = diag.db.getEdges(); | ||
|
||
const mockG = { | ||
setEdge: function (start, end, options) { | ||
expect(start).toContain('flowchart-A-'); | ||
expect(end).toContain('flowchart-B-'); | ||
expect(options.arrowhead).toBe('none'); | ||
expect(options.style).toBe('stroke:val1;stroke-width:val2;fill:none;'); | ||
}, | ||
}; | ||
|
||
flowRenderer.addEdges(edges, mockG, diag); | ||
}); | ||
it('should handle edges with interpolation defined', function () { | ||
const diag = new Diagram('graph TD;A---B; linkStyle 0 interpolate basis'); | ||
diag.db.getVertices(); | ||
const edges = diag.db.getEdges(); | ||
|
||
const mockG = { | ||
setEdge: function (start, end, options) { | ||
expect(start).toContain('flowchart-A-'); | ||
expect(end).toContain('flowchart-B-'); | ||
expect(options.arrowhead).toBe('none'); | ||
expect(options.curve).toBe('basis'); // mocked as string | ||
}, | ||
}; | ||
|
||
flowRenderer.addEdges(edges, mockG, diag); | ||
}); | ||
it('should handle edges with text and styles defined', function () { | ||
const diag = new Diagram( | ||
'graph TD;A---|the text|B; linkStyle 0 stroke:val1,stroke-width:val2;' | ||
); | ||
diag.db.getVertices(); | ||
const edges = diag.db.getEdges(); | ||
|
||
const mockG = { | ||
setEdge: function (start, end, options) { | ||
expect(start).toContain('flowchart-A-'); | ||
expect(end).toContain('flowchart-B-'); | ||
expect(options.arrowhead).toBe('none'); | ||
expect(options.label.match('the text')).toBeTruthy(); | ||
expect(options.style).toBe('stroke:val1;stroke-width:val2;fill:none;'); | ||
}, | ||
}; | ||
|
||
flowRenderer.addEdges(edges, mockG, diag); | ||
}); | ||
|
||
it('should set fill to "none" by default when handling edges', function () { | ||
const diag = new Diagram('graph TD;A---B; linkStyle 0 stroke:val1,stroke-width:val2;'); | ||
diag.db.getVertices(); | ||
const edges = diag.db.getEdges(); | ||
|
||
const mockG = { | ||
setEdge: function (start, end, options) { | ||
expect(start).toContain('flowchart-A-'); | ||
expect(end).toContain('flowchart-B'); | ||
expect(options.arrowhead).toBe('none'); | ||
expect(options.style).toBe('stroke:val1;stroke-width:val2;fill:none;'); | ||
}, | ||
}; | ||
|
||
flowRenderer.addEdges(edges, mockG, diag); | ||
}); | ||
|
||
it('should not set fill to none if fill is set in linkStyle', function () { | ||
const diag = new Diagram( | ||
'graph TD;A---B; linkStyle 0 stroke:val1,stroke-width:val2,fill:blue;' | ||
); | ||
diag.db.getVertices(); | ||
const edges = diag.db.getEdges(); | ||
const mockG = { | ||
setEdge: function (start, end, options) { | ||
expect(start).toContain('flowchart-A-'); | ||
expect(end).toContain('flowchart-B-'); | ||
expect(options.arrowhead).toBe('none'); | ||
expect(options.style).toBe('stroke:val1;stroke-width:val2;fill:blue;'); | ||
}, | ||
}; | ||
|
||
flowRenderer.addEdges(edges, mockG, diag); | ||
}); | ||
}); | ||
}); |
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