2022-10-20 15:49:40 -05:00
|
|
|
import gfunc, { FuncInstance } from './gfunc';
|
2021-04-09 16:21:53 -05:00
|
|
|
|
|
|
|
describe('gfunc', () => {
|
|
|
|
const INDEX = {
|
|
|
|
foo: {
|
|
|
|
name: 'foo',
|
|
|
|
params: [],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
it('returns function from the index', () => {
|
|
|
|
expect(gfunc.getFuncDef('foo', INDEX)).toEqual(INDEX.foo);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('marks function as unknown when it is not available in the index', () => {
|
2021-07-21 13:09:00 -05:00
|
|
|
expect(gfunc.getFuncDef('bar', INDEX)).toEqual({
|
|
|
|
name: 'bar',
|
|
|
|
params: [{ name: '', type: '', multiple: true }],
|
|
|
|
defaultParams: [''],
|
|
|
|
unknown: true,
|
|
|
|
});
|
2021-04-09 16:21:53 -05:00
|
|
|
});
|
2022-10-20 15:49:40 -05:00
|
|
|
|
|
|
|
it('renders the version < .9 asPercent function parameters by not escaping them as a string', () => {
|
|
|
|
// this function is returned from the graphite functions endpoint
|
|
|
|
const asPercentDef = {
|
|
|
|
name: 'asPercent',
|
|
|
|
description: 'Calculates a percentage.',
|
|
|
|
category: 'Combine',
|
|
|
|
params: [
|
|
|
|
{
|
|
|
|
name: 'total',
|
|
|
|
type: 'string',
|
|
|
|
optional: true,
|
|
|
|
multiple: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'nodes',
|
|
|
|
type: 'node_or_tag',
|
|
|
|
optional: true,
|
|
|
|
multiple: true,
|
|
|
|
options: [],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
defaultParams: [],
|
|
|
|
};
|
|
|
|
|
|
|
|
const asPercent = new FuncInstance(asPercentDef);
|
|
|
|
|
|
|
|
const asPercentRendered = asPercent.render('#A', () => '#A');
|
|
|
|
|
|
|
|
expect(asPercentRendered).toEqual('asPercent(#A)');
|
|
|
|
});
|
2021-04-09 16:21:53 -05:00
|
|
|
});
|