Commit 560b6bfd authored by Sascha Herzinger's avatar Sascha Herzinger
Browse files

Fixed bugs of parameter API (all tests pass now)

parent d6c441a0
Pipeline #6705 failed with stages
in 6 minutes and 49 seconds
......@@ -24,13 +24,7 @@ module.exports = function (config) {
colors: true,
logLevel: config.LOG_INFO,
autoWatch: false,
browsers: ['NoSandboxHeadlessChrome'],
customLaunchers: {
NoSandboxHeadlessChrome: {
base: 'ChromeHeadless',
flags: ['--no-sandbox']
}
},
browsers: ['FirefoxHeadless'],
singleRun: true,
concurrency: Infinity
})
......
......@@ -48,7 +48,7 @@ export default class {
}
getChartParamDescr (vm, callback) {
if (typeof vm._parameterChangedCallback === 'undefined') {
if (vm.$data._paramPath == null) {
throw new Error('Cannot get parameters for this chart. It does not implement the parameter-interface mixin.')
}
vm._setParameterChangedCallback(callback)
......
......@@ -12,7 +12,7 @@ export default {
},
methods: {
registerParameterObjectInterface (path) {
this.$data.paramPath = path
this.$data._paramPath = path
this.$watch(path, newParams => {
const paramCopy = _.cloneDeep(newParams)
this.$data._parameterChangedCallback(paramCopy)
......@@ -20,10 +20,12 @@ export default {
},
_setParameterChangedCallback (callback) {
this.$data._parameterChangedCallback = callback
const paramCopy = _.cloneDeep(_.get(this, this.$data._paramPath))
callback(paramCopy)
},
_setParameters (params) {
Object.keys(params).forEach(key => {
_.set(this, [this.$data._paramPath, key], params[key])
_.set(this, [this.$data._paramPath, key, 'value'], params[key])
})
}
}
......
import Vue from 'vue'
import ChartManager from '../src/services/chart-manager'
describe('Chart manager', () => {
......@@ -5,26 +6,56 @@ describe('Chart manager', () => {
beforeEach(() => {
const el = document.createElement('div')
el.className = 'placeholder'
el.id = 'placeholder'
document.body.appendChild(el)
})
afterEach(() => {
const el = document.querySelector('.placeholder')
const el = document.querySelector('#placeholder')
el.parentNode.removeChild(el)
})
it('fails to set non existing charts', () => {
const f = () => cm.setChart('foo', '.placeholder')
const f = () => cm.setChart('foo', '#placeholder')
expect(f).toThrowError(/.+not available.+/)
})
it('sets chart if it exists', () => {
cm.setChart('scatterplot', '.placeholder')
cm.setChart('scatterplot', '#placeholder')
expect(document.querySelector('.fjs-chart')).toBeDefined()
})
afterAll(() => {
document.body.innerHTML = ''
})
describe('parameter interface', () => {
function testParameterInterface (chartName) {
it(' is implemented correctly by ' + chartName, done => {
const vm = cm.setChart('scatterplot', '#placeholder')
const callback = {f: () => {}}
spyOn(callback, 'f')
cm.getChartParamDescr(vm, callback.f)
expect(callback.f).toHaveBeenCalledTimes(1)
let params = callback.f.calls.allArgs()[0][0]
expect(Object.keys(params).length).toBeGreaterThan(0)
Object.keys(params).forEach(key => {
expect(Object.keys(params[key]).indexOf('label')).not.toBe(-1)
expect(Object.keys(params[key]).indexOf('value')).not.toBe(-1)
})
const randomKey = Object.keys(params)[0]
const randomValue = 'foo'
vm._setParameters({[randomKey]: randomValue})
Vue.nextTick(() => {
expect(callback.f).toHaveBeenCalledTimes(2)
params = callback.f.calls.allArgs()[1][0]
expect(params[randomKey].value).toEqual(randomValue)
done()
})
})
}
cm.getAvailableCharts().forEach(chartName => {
testParameterInterface(chartName)
})
})
})
......@@ -93,7 +93,7 @@
const fjs = fractalis.init({
handler: 'demo_tcga_coad',
dataSource: location.protocol + '//' + window.location.host,
fractalisNode: 'http://localhost:5000',
fractalisNode: 'https://192.168.99.100/',
getAuth () {
return {token: ''}
},
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment