mermaid/src/utils.spec.js

45 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-04-11 22:57:57 +08:00
/* eslint-env jasmine */
2017-09-10 19:41:34 +08:00
import utils from './utils'
describe('when detecting chart type ', function () {
2017-04-11 22:14:25 +08:00
var str
it('should handle a graph defintion', function () {
str = 'graph TB\nbfs1:queue'
2017-04-11 22:14:25 +08:00
var type = utils.detectType(str)
expect(type).toBe('graph')
})
it('should handle a graph defintion with leading spaces', function () {
str = ' graph TB\nbfs1:queue'
2017-04-11 22:14:25 +08:00
var type = utils.detectType(str)
expect(type).toBe('graph')
})
2017-04-11 22:14:25 +08:00
it('should handle a graph defintion with leading spaces and newline', function () {
str = ' \n graph TB\nbfs1:queue'
2017-04-11 22:14:25 +08:00
var type = utils.detectType(str)
expect(type).toBe('graph')
})
it('should handle a graph defintion for gitGraph', function () {
str = ' \n gitGraph TB:\nbfs1:queue'
2016-03-29 08:33:38 +05:30
2017-04-11 22:14:25 +08:00
var type = utils.detectType(str)
expect(type).toBe('gitGraph')
})
})
describe('when finding substring in array ', function () {
2017-04-11 22:14:25 +08:00
it('should return the array index that contains the substring', function () {
var arr = ['stroke:val1', 'fill:val2']
var result = utils.isSubstringInArray('fill', arr)
expect(result).toEqual(1)
})
it('should return -1 if the substring is not found in the array', function () {
var arr = ['stroke:val1', 'stroke-width:val2']
var result = utils.isSubstringInArray('fill', arr)
expect(result).toEqual(-1)
})
})