From 14c4bb6f876f048cccd7a3e995b2f7844a1f9af0 Mon Sep 17 00:00:00 2001 From: Dominik Prokop Date: Thu, 1 Aug 2024 09:38:15 +0200 Subject: [PATCH] TemplateSrv: Add test case for SafeSerializableSceneObject (#90808) * TemplateSrv: Add test case for SafeSerializableSceneObject * Update dashboard data source to use scoped vars scene object valueOf --- public/app/features/templating/template_srv.test.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/public/app/features/templating/template_srv.test.ts b/public/app/features/templating/template_srv.test.ts index e96fce7f5d3..640143a289e 100644 --- a/public/app/features/templating/template_srv.test.ts +++ b/public/app/features/templating/template_srv.test.ts @@ -7,6 +7,7 @@ import { EmbeddedScene, IntervalVariable, QueryVariable, + SafeSerializableSceneObject, SceneCanvasText, SceneVariableSet, TestVariable, @@ -844,6 +845,16 @@ describe('templateSrv', () => { expect(interpolateMock.mock.calls[0][1]).toEqual('test ${test}'); }); + it('should use scene interpolator when scoped var provided via SafeSerializableSceneObject', () => { + const variable = new TestVariable({}); + const serializable = new SafeSerializableSceneObject(variable); + _templateSrv.replace('test ${test}', { __sceneObject: serializable }); + + expect(interpolateMock).toHaveBeenCalledTimes(1); + expect(interpolateMock.mock.calls[0][0]).toEqual(variable); + expect(interpolateMock.mock.calls[0][1]).toEqual('test ${test}'); + }); + it('should use scene interpolator global __grafanaSceneContext is active', () => { window.__grafanaSceneContext = new EmbeddedScene({ $variables: new SceneVariableSet({