grafana/public/app/plugins/datasource/graphite/gfunc.test.ts

55 lines
1.3 KiB
TypeScript
Raw Normal View History

import gfunc, { FuncInstance } from './gfunc';
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', () => {
Graphite: Migrate to React (part 2: migrate smaller AngularJS directives) (#36797) * Add UMLs * Add rendered diagrams * Move QueryCtrl to flux * Remove redundant param in the reducer * Use named imports for lodash and fix typing for GraphiteTagOperator * Add missing async/await * Extract providers to a separate file * Clean up async await * Rename controller functions back to main * Simplify creating actions * Re-order controller functions * Separate helpers from actions * Rename vars * Simplify helpers * Move controller methods to state reducers * Remove docs (they are added in design doc) * Move actions.ts to state folder * Add docs * Add old methods stubs for easier review * Check how state dependencies will be mapped * Rename state to store * Rename state to store * Rewrite spec tests for Graphite Query Controller * Update docs * Update docs * Add GraphiteTextEditor * Add play button * Add AddGraphiteFunction * Use Segment to simplify AddGraphiteFunction * Memoize function defs * Fix useCallback deps * Update public/app/plugins/datasource/graphite/state/helpers.ts Co-authored-by: Giordano Ricci <me@giordanoricci.com> * Update public/app/plugins/datasource/graphite/state/helpers.ts Co-authored-by: Giordano Ricci <me@giordanoricci.com> * Update public/app/plugins/datasource/graphite/state/helpers.ts Co-authored-by: Giordano Ricci <me@giordanoricci.com> * Update public/app/plugins/datasource/graphite/state/providers.ts Co-authored-by: Giordano Ricci <me@giordanoricci.com> * Update public/app/plugins/datasource/graphite/state/providers.ts Co-authored-by: Giordano Ricci <me@giordanoricci.com> * Update public/app/plugins/datasource/graphite/state/providers.ts Co-authored-by: Giordano Ricci <me@giordanoricci.com> * Update public/app/plugins/datasource/graphite/state/providers.ts Co-authored-by: Giordano Ricci <me@giordanoricci.com> * Update public/app/plugins/datasource/graphite/state/providers.ts Co-authored-by: Giordano Ricci <me@giordanoricci.com> * Update public/app/plugins/datasource/graphite/state/providers.ts Co-authored-by: Giordano Ricci <me@giordanoricci.com> * Add more type definitions * Remove submitOnClickAwayOption This behavior is actually needed to remove parameters in functions * Load function definitions before parsing the target on initial load * Add button padding * Fix loading function definitions * Change targetChanged to updateQuery to avoid mutating state directly It's also needed for extra refresh/runQuery execution as handleTargetChanged doesn't handle changing the raw query * Fix updating query after adding a function * Simplify updating function params * Simplify setting Segment Select min width * Extract view logic to a helper and update types definitions * Clean up types * Update FuncDef types and add tests Co-authored-by: Giordano Ricci <me@giordanoricci.com>
2021-07-21 13:09:00 -05:00
expect(gfunc.getFuncDef('bar', INDEX)).toEqual({
name: 'bar',
params: [{ name: '', type: '', multiple: true }],
defaultParams: [''],
unknown: true,
});
});
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)');
});
});