mermaid/src/mermaidAPI.spec.js

74 lines
2.0 KiB
JavaScript
Raw Normal View History

2017-04-11 22:57:57 +08:00
/* eslint-env jasmine */
/**
* Created by knut on 14-11-26.
*/
/**
* Created by knut on 14-11-23.
*/
2017-04-11 22:14:25 +08:00
var api = require('./mermaidAPI.js')
2017-09-10 00:47:09 +08:00
const validateDefinition = (text, valid) => {
const foo = {
onError: () => {
}
}
spyOn(foo, 'onError')
global.mermaidAPI.eventEmitter.on('parseError', (err, hash) => {
foo.onError(err)
})
var res = api.parse(text)
if (valid) {
expect(res).toBe(true)
expect(foo.onError).not.toHaveBeenCalled()
} else {
expect(res).toBe(false)
expect(foo.onError).toHaveBeenCalled()
}
}
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 = ''
})
2017-04-11 22:14:25 +08:00
it('should copy a literal into the configuration', function () {
var orgConfig = api.getConfig()
expect(orgConfig.testLiteral).toBe(undefined)
2017-04-16 23:24:47 +08:00
api.initialize({ 'testLiteral': true })
2017-04-11 22:14:25 +08:00
var config = api.getConfig()
2017-04-11 22:14:25 +08:00
expect(config.testLiteral).toBe(true)
})
it('should copy a an object into the configuration', function () {
var orgConfig = api.getConfig()
expect(orgConfig.testObject).toBe(undefined)
2017-04-11 22:14:25 +08:00
var object = {
test1: 1,
test2: false
}
2017-04-16 23:24:47 +08:00
api.initialize({ 'testObject': object })
api.initialize({ 'testObject': { 'test3': true } })
2017-04-11 22:14:25 +08:00
var config = api.getConfig()
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)
expect(config.cloneCssStyles).toBe(orgConfig.cloneCssStyles)
})
})
describe('checking validity of input ', function () {
it('it should return false for an invalid definiton', function () {
2017-09-10 00:47:09 +08:00
validateDefinition('this is not a mermaid diagram definition', false)
2017-04-11 22:14:25 +08:00
})
it('it should return true for a valid definiton', function () {
2017-09-10 00:47:09 +08:00
validateDefinition('graph TD;A--x|text including URL space|B;', true)
2017-04-11 22:14:25 +08:00
})
})
})