@@ -3,12 +3,8 @@ import { $GF, GFDrawioTools, GFTimer, GFVariables } from '../src/globals_class';
3
3
const $scope = require ( '$scope' ) ;
4
4
const templateSrv = { } ;
5
5
const dashboard = { } ;
6
- const ctrl = {
7
- notify : jest . fn ( ) ,
8
- clearNotify : jest . fn ( ) ,
9
- } ;
6
+ const ctrl = require ( 'ctrl' ) ;
10
7
const $gf = $GF . create ( $scope , templateSrv , dashboard , ctrl ) ;
11
-
12
8
const xmlGraph =
13
9
'<mxGraphModel dx="1073" dy="521" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="0" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0"><root><mxCell id="0"/><mxCell id="1" parent="0"/><mxCell id="arrow-1" style="edgeStyle=orthogonalEdgeStyle;rounded=0;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;jettySize=auto;orthogonalLoop=1;strokeWidth=4;shadow=1;" parent="1" source="shape-grafana" target="shape-love" edge="1"><mxGeometry relative="1" as="geometry"/></mxCell><object label="Grafana" href="www.google.fr" id="shape-grafana"><mxCell style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffe6cc;strokeColor=#d79b00;shadow=1;" parent="1" vertex="1"><mxGeometry x="10" y="10" width="120" height="60" as="geometry"/></mxCell></object><mxCell id="arrow-2" style="edgeStyle=orthogonalEdgeStyle;rounded=0;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;jettySize=auto;orthogonalLoop=1;strokeWidth=4;shadow=1;" parent="1" source="shape-love" target="shape-mxgraph" edge="1"><mxGeometry relative="1" as="geometry"/></mxCell><mxCell id="shape-love" value="loves" style="triangle;whiteSpace=wrap;html=1;fillColor=#e1d5e7;strokeColor=#9673a6;shadow=1;" parent="1" vertex="1"><mxGeometry x="210" width="60" height="80" as="geometry"/></mxCell><mxCell id="shape-mxgraph" value="mxGraph" style="ellipse;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;shadow=1;" parent="1" vertex="1"><mxGeometry x="340" width="120" height="80" as="geometry"/></mxCell><mxCell id="text-grafana" value="MyText : TextVal" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1"><mxGeometry x="9" y="50" width="120" height="20" as="geometry"/></mxCell><mxCell id="text-arrow1" value="Text 2" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1"><mxGeometry x="150" y="20" width="40" height="20" as="geometry"/></mxCell><mxCell id="text-arrow2" value="Text 3" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1"><mxGeometry x="280" y="20" width="40" height="20" as="geometry"/></mxCell><mxCell id="text-mxgraph" value="Text 4" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1"><mxGeometry x="380" y="50" width="40" height="20" as="geometry"/></mxCell></root></mxGraphModel>' ;
14
10
const compGraph =
@@ -42,65 +38,67 @@ describe('Test Global $GF utils', () => {
42
38
43
39
// Test if eval javascript works
44
40
describe ( 'Secure Eval' , ( ) => {
45
- //TODO : Fix eval
46
- // it('should be enable to understand Math Lib', () => {
47
- // expect($gf.eval('Math.random()')).toBeGreaterThan(0);
48
- // expect($gf.utils.evalIt_deprecated('Math.random() * 100')).toBeLessThanOrEqual(101);
49
- // });
50
- test ( 'should be eval simple operation 2+2' , ( ) => {
51
- expect ( $gf . utils . evalIt_deprecated ( '2+2' ) ) . toBe ( 4 ) ;
41
+ let variables ;
42
+ beforeAll ( ( ) => {
43
+ variables = GFVariables . create ( ) ;
44
+ } )
45
+ afterAll ( ( ) => {
46
+ variables = GFVariables . create ( ) ;
47
+ } )
48
+ it ( 'should be enable to understand Math Lib' , ( ) => {
49
+ expect ( variables . eval ( 'Math.random()' ) ) . toBeGreaterThan ( 0 ) ;
50
+ expect ( variables . eval ( 'Math.random() * 100' ) ) . toBeLessThanOrEqual ( 101 ) ;
51
+ } ) ;
52
+ it ( 'should be eval simple operation 2+2' , ( ) => {
53
+ expect ( variables . eval ( '2+2' ) ) . toBe ( 4 ) ;
52
54
} ) ;
53
55
} ) ;
54
56
55
57
// Test if globalvariables
56
58
describe ( 'Variables' , ( ) => {
57
- // let $gf: $GF;
58
- // const $scope = jest.fn();
59
- // const templateSrv = jest.fn();
60
- // const dashboard = jest.fn();
61
- // const ctrl = jest.fn();
62
- const key = '_value' ;
63
- const value = 12345 ;
64
- const text_entry = 'My text is ${_value} at this time' ;
65
- const text_result = 'My text is 12345 at this time' ;
66
- let variable : GFVariables ;
59
+ let variables , key , value , text_entry , text_result ;
67
60
beforeEach ( ( ) => {
68
- // $gf = $GF.create($scope, templateSrv, dashboard, ctrl)
69
- variable = GFVariables . create ( ) ;
61
+ key = '_value' ;
62
+ value = 12345 ;
63
+ text_entry = 'My text is ${_value} at this time' ;
64
+ text_result = 'My text is 12345 at this time' ;
65
+ variables = GFVariables . create ( ) ;
70
66
} ) ;
71
67
beforeEach ( ( ) => {
72
- // $gf = $GF.create($scope, templateSrv, dashboard, ctrl)
73
- variable . clear ( ) ;
68
+ variables . clear ( ) ;
74
69
} ) ;
75
70
test ( 'Should be not null' , ( ) => {
76
- expect ( variable ) . not . toBe ( undefined ) ;
77
- expect ( variable ) . toMatchSnapshot ( ) ;
78
- expect ( variable . get ( key ) ) . toBe ( undefined ) ;
71
+ expect ( variables ) . not . toBe ( undefined ) ;
72
+ expect ( variables ) . toMatchSnapshot ( ) ;
73
+ expect ( variables . get ( key ) ) . toBe ( undefined ) ;
79
74
} ) ;
80
75
81
76
test ( 'Should be null for key ' + key , ( ) => {
82
- expect ( variable . get ( key ) ) . toBe ( undefined ) ;
77
+ expect ( variables . get ( key ) ) . toBe ( undefined ) ;
83
78
} ) ;
84
79
test ( 'Should be not null for key ' + key , ( ) => {
85
- variable . set ( key , value ) ;
86
- expect ( variable . get ( key ) ) . not . toBe ( undefined ) ;
87
- expect ( variable . get ( key ) ) . toBe ( value ) ;
80
+ variables . set ( key , value ) ;
81
+ expect ( variables . get ( key ) ) . not . toBe ( undefined ) ;
82
+ expect ( variables . get ( key ) ) . toBe ( value ) ;
88
83
} ) ;
89
84
90
85
test ( 'should be a list' , ( ) => {
91
- expect ( variable . keys ( ) ) . toStrictEqual ( [ '_value' ] ) ;
86
+ variables . set ( key , value ) ;
87
+ expect ( variables . keys ( ) ) . toStrictEqual ( [ '_value' ] ) ;
92
88
} ) ;
93
89
94
90
test ( 'should be a list ${}' , ( ) => {
95
- expect ( variable . getVarsNames ( ) ) . toStrictEqual ( [ '${_value}' ] ) ;
91
+ variables . set ( key , value ) ;
92
+ expect ( variables . getVarsNames ( ) ) . toStrictEqual ( [ '${_value}' ] ) ;
96
93
} ) ;
97
94
98
95
test ( 'Remplace text with variable' , ( ) => {
99
- expect ( variable . replaceText ( text_entry ) ) . toBe ( text_result ) ;
96
+ variables . set ( key , value ) ;
97
+ expect ( variables . replaceText ( text_entry ) ) . toBe ( text_result ) ;
100
98
} ) ;
101
99
102
100
test ( 'should be evaluate' , ( ) => {
103
- expect ( variable . eval ( '${_value}*2' ) ) . toBe ( 24690 ) ;
101
+ expect ( variables . eval ( '${_value}*2' ) ) . toBe ( 24690 ) ;
104
102
} ) ;
105
103
106
104
test ( 'Should be null after remove key ' + key , ( ) => {
0 commit comments