mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-08-15 06:19:24 +02:00
chore: Added unit tests around drawBackgroundRect and drawRect
This commit is contained in:
2
__mocks__/d3.js
vendored
2
__mocks__/d3.js
vendored
@@ -1,4 +1,4 @@
|
||||
|
||||
/* eslint-env jest */
|
||||
let NewD3 = function () {
|
||||
return {
|
||||
append: function () {
|
||||
|
@@ -417,7 +417,7 @@ export const draw = function (text, id) {
|
||||
break
|
||||
case parser.yy.LINETYPE.RECT_END:
|
||||
const rectData = bounds.endLoop()
|
||||
svgDraw.drawBackgroundRect(diagram, rectData);
|
||||
svgDraw.drawBackgroundRect(diagram, rectData)
|
||||
bounds.bumpVerticalPos(conf.boxMargin)
|
||||
break
|
||||
case parser.yy.LINETYPE.OPT_START:
|
||||
|
@@ -168,7 +168,6 @@ export const drawLoop = function (elem, bounds, labelText, conf) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draws a background rectangle
|
||||
* @param color - The fill color for the background
|
||||
@@ -181,8 +180,8 @@ export const drawBackgroundRect = function (elem, bounds) {
|
||||
height: bounds.stopy - bounds.starty,
|
||||
fill: bounds.fill,
|
||||
class: 'rect'
|
||||
});
|
||||
rectElem.lower();
|
||||
})
|
||||
rectElem.lower()
|
||||
}
|
||||
/**
|
||||
* Setup arrow head and define the marker. The result is appended to the svg.
|
||||
|
@@ -1,6 +1,7 @@
|
||||
/* eslint-env jasmine */
|
||||
const svgDraw = require('./svgDraw')
|
||||
const { MockD3 } = require('d3')
|
||||
console.log(MockD3)
|
||||
|
||||
describe('svgDraw', function () {
|
||||
describe('drawRect', function () {
|
||||
it('it should append a rectangle', function () {
|
||||
@@ -14,7 +15,7 @@ describe('svgDraw', function () {
|
||||
height: '20',
|
||||
rx: '10',
|
||||
ry: '10',
|
||||
class: 'unitTestRectangleClass',
|
||||
class: 'unitTestRectangleClass'
|
||||
})
|
||||
expect(svg.__children.length).toBe(1)
|
||||
const rect = svg.__children[0]
|
||||
@@ -39,7 +40,7 @@ describe('svgDraw', function () {
|
||||
width: '20',
|
||||
height: '20',
|
||||
rx: '10',
|
||||
ry: '10',
|
||||
ry: '10'
|
||||
})
|
||||
expect(svg.__children.length).toBe(1)
|
||||
const rect = svg.__children[0]
|
||||
@@ -57,7 +58,7 @@ describe('svgDraw', function () {
|
||||
stopx: 150,
|
||||
stopy: 260,
|
||||
title: undefined,
|
||||
fill: '#ccc',
|
||||
fill: '#ccc'
|
||||
}
|
||||
svgDraw.drawBackgroundRect(svg, boundingRect)
|
||||
expect(svg.__children.length).toBe(1)
|
||||
|
Reference in New Issue
Block a user