The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/features/scenes/variables/SceneVariableSet.test.ts

43 lines
1.3 KiB

import { SceneObjectBase } from '../core/SceneObjectBase';
import { SceneObjectStatePlain } from '../core/types';
import { sceneTemplateInterpolator, SceneVariableSet, TextBoxSceneVariable } from './SceneVariableSet';
interface TestSceneState extends SceneObjectStatePlain {
nested?: TestScene;
}
class TestScene extends SceneObjectBase<TestSceneState> {}
describe('SceneObject with variables', () => {
it('Should be interpolate and use closest variable', () => {
const scene = new TestScene({
$variables: new SceneVariableSet({
variables: [
new TextBoxSceneVariable({
name: 'test',
current: { value: 'hello' },
}),
new TextBoxSceneVariable({
name: 'atRootOnly',
current: { value: 'RootValue' },
}),
],
}),
nested: new TestScene({
$variables: new SceneVariableSet({
variables: [
new TextBoxSceneVariable({
name: 'test',
current: { value: 'nestedValue' },
}),
],
}),
}),
});
expect(sceneTemplateInterpolator('${test}', scene)).toBe('hello');
expect(sceneTemplateInterpolator('${test}', scene.state.nested!)).toBe('nestedValue');
expect(sceneTemplateInterpolator('${atRootOnly}', scene.state.nested!)).toBe('RootValue');
});
});