mermaid/src/utils.spec.js

40 lines
1.4 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
it('should handle a graph defintion', function () {
2017-09-14 19:32:35 +08:00
const str = 'graph TB\nbfs1:queue'
const type = utils.detectType(str)
2018-03-12 21:06:49 +08:00
expect(type).toBe('flowchart')
2017-04-11 22:14:25 +08:00
})
it('should handle a graph defintion with leading spaces', function () {
2017-09-14 19:32:35 +08:00
const str = ' graph TB\nbfs1:queue'
const type = utils.detectType(str)
2018-03-12 21:06:49 +08:00
expect(type).toBe('flowchart')
2017-04-11 22:14:25 +08:00
})
2017-04-11 22:14:25 +08:00
it('should handle a graph defintion with leading spaces and newline', function () {
2017-09-14 19:32:35 +08:00
const str = ' \n graph TB\nbfs1:queue'
const type = utils.detectType(str)
2018-03-12 21:06:49 +08:00
expect(type).toBe('flowchart')
2017-04-11 22:14:25 +08:00
})
it('should handle a graph defintion for gitGraph', function () {
2017-09-14 19:32:35 +08:00
const str = ' \n gitGraph TB:\nbfs1:queue'
const type = utils.detectType(str)
2018-03-12 21:16:22 +08:00
expect(type).toBe('git')
2017-04-11 22:14:25 +08:00
})
})
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 () {
2017-09-14 19:32:35 +08:00
const arr = ['stroke:val1', 'fill:val2']
const result = utils.isSubstringInArray('fill', arr)
2017-04-11 22:14:25 +08:00
expect(result).toEqual(1)
})
it('should return -1 if the substring is not found in the array', function () {
2017-09-14 19:32:35 +08:00
const arr = ['stroke:val1', 'stroke-width:val2']
const result = utils.isSubstringInArray('fill', arr)
2017-04-11 22:14:25 +08:00
expect(result).toEqual(-1)
})
})