1 |
|
2 | import utils from './utils'
|
3 |
|
4 | describe('when detecting chart type ', function () {
|
5 | it('should handle a graph defintion', function () {
|
6 | const str = 'graph TB\nbfs1:queue'
|
7 | const type = utils.detectType(str)
|
8 | expect(type).toBe('flowchart')
|
9 | })
|
10 | it('should handle a graph defintion with leading spaces', function () {
|
11 | const str = ' graph TB\nbfs1:queue'
|
12 | const type = utils.detectType(str)
|
13 | expect(type).toBe('flowchart')
|
14 | })
|
15 |
|
16 | it('should handle a graph defintion with leading spaces and newline', function () {
|
17 | const str = ' \n graph TB\nbfs1:queue'
|
18 | const type = utils.detectType(str)
|
19 | expect(type).toBe('flowchart')
|
20 | })
|
21 | it('should handle a graph defintion for gitGraph', function () {
|
22 | const str = ' \n gitGraph TB:\nbfs1:queue'
|
23 | const type = utils.detectType(str)
|
24 | expect(type).toBe('git')
|
25 | })
|
26 | })
|
27 |
|
28 | describe('when finding substring in array ', function () {
|
29 | it('should return the array index that contains the substring', function () {
|
30 | const arr = ['stroke:val1', 'fill:val2']
|
31 | const result = utils.isSubstringInArray('fill', arr)
|
32 | expect(result).toEqual(1)
|
33 | })
|
34 | it('should return -1 if the substring is not found in the array', function () {
|
35 | const arr = ['stroke:val1', 'stroke-width:val2']
|
36 | const result = utils.isSubstringInArray('fill', arr)
|
37 | expect(result).toEqual(-1)
|
38 | })
|
39 | })
|