2017-04-11 22:57:57 +08:00
|
|
|
/* eslint-env jasmine */
|
2017-09-10 10:45:38 +08:00
|
|
|
import mermaidAPI from './mermaidAPI'
|
2015-06-07 09:21:19 +02:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
describe('when using mermaidAPI and ', function () {
|
|
|
|
describe('doing initialize ', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
delete global.mermaid_config
|
|
|
|
document.body.innerHTML = ''
|
|
|
|
})
|
2015-06-07 09:21:19 +02:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
it('should copy a literal into the configuration', function () {
|
2017-09-10 10:45:38 +08:00
|
|
|
var orgConfig = mermaidAPI.getConfig()
|
2017-04-11 22:14:25 +08:00
|
|
|
expect(orgConfig.testLiteral).toBe(undefined)
|
2015-06-07 09:21:19 +02:00
|
|
|
|
2017-09-10 10:45:38 +08:00
|
|
|
mermaidAPI.initialize({ 'testLiteral': true })
|
|
|
|
var config = mermaidAPI.getConfig()
|
2015-06-07 09:21:19 +02:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
expect(config.testLiteral).toBe(true)
|
|
|
|
})
|
|
|
|
it('should copy a an object into the configuration', function () {
|
2017-09-10 10:45:38 +08:00
|
|
|
var orgConfig = mermaidAPI.getConfig()
|
2017-04-11 22:14:25 +08:00
|
|
|
expect(orgConfig.testObject).toBe(undefined)
|
2015-06-07 09:21:19 +02:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
var object = {
|
|
|
|
test1: 1,
|
|
|
|
test2: false
|
|
|
|
}
|
2015-06-07 09:21:19 +02:00
|
|
|
|
2017-09-10 10:45:38 +08:00
|
|
|
mermaidAPI.initialize({ 'testObject': object })
|
|
|
|
mermaidAPI.initialize({ 'testObject': { 'test3': true } })
|
|
|
|
var config = mermaidAPI.getConfig()
|
2015-06-07 09:21:19 +02:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
expect(config.testObject.test1).toBe(1)
|
|
|
|
expect(config.testObject.test2).toBe(false)
|
|
|
|
expect(config.testObject.test3).toBe(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
describe('checking validity of input ', function () {
|
2017-09-10 10:10:36 +08:00
|
|
|
it('it should throw for an invalid definiton', function () {
|
2017-09-10 10:45:38 +08:00
|
|
|
expect(() => mermaidAPI.parse('this is not a mermaid diagram definition')).toThrow()
|
2017-04-11 22:14:25 +08:00
|
|
|
})
|
2017-09-10 10:10:36 +08:00
|
|
|
it('it should not throw for a valid definiton', function () {
|
2017-09-10 10:45:38 +08:00
|
|
|
expect(() => mermaidAPI.parse('graph TD;A--x|text including URL space|B;')).not.toThrow()
|
2017-04-11 22:14:25 +08:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|