Skip to content

Commit ad3ef8f

Browse files
committed
u
1 parent 83636e5 commit ad3ef8f

File tree

4 files changed

+22
-15
lines changed

4 files changed

+22
-15
lines changed

spec/global_class.test.ts

+9-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import { $GF, GFDrawioTools, GFTimer, GFVariables } from '../src/globals_class';
22

3+
const $scope = require('$scope');
4+
const templateSrv = {};
5+
const dashboard = {};
6+
const ctrl = {
7+
notify: jest.fn(),
8+
clearNotify: jest.fn(),
9+
};
10+
const $gf = $GF.create($scope, templateSrv, dashboard, ctrl);
311

412
const xmlGraph =
513
'<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>';
@@ -34,24 +42,13 @@ describe('Test Global $GF utils', () => {
3442

3543
// Test if eval javascript works
3644
describe('Secure Eval', () => {
37-
let $gf: $GF;
38-
const $scope = jest.fn();
39-
const templateSrv = jest.fn();
40-
const dashboard = jest.fn();
41-
const ctrl = jest.fn();
42-
beforeAll(()=>{
43-
$gf = $GF.create($scope, templateSrv, dashboard, ctrl);
44-
});
45-
afterAll(()=>{
46-
$gf = $GF.create($scope, templateSrv, dashboard, ctrl);
47-
});
4845
//TODO : Fix eval
4946
// it('should be enable to understand Math Lib', () => {
5047
// expect($gf.eval('Math.random()')).toBeGreaterThan(0);
5148
// expect($gf.utils.evalIt_deprecated('Math.random() * 100')).toBeLessThanOrEqual(101);
5249
// });
5350
test('should be eval simple operation 2+2', () => {
54-
expect($GF.utils.evalIt_deprecated('2+2')).toBe(4);
51+
expect($gf.utils.evalIt_deprecated('2+2')).toBe(4);
5552
});
5653
});
5754

spec/rule.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44

55
import { $GF, GFCONSTANT } from '../src/globals_class';
66
import { Rule } from '../src/rule_class';
7+
78
const $scope = require('$scope');
89
const templateSrv = {};
910
const dashboard = {};
1011
const ctrl = {
1112
notify: jest.fn(),
1213
clearNotify: jest.fn(),
1314
};
15+
1416
const $gf = $GF.create($scope, templateSrv, dashboard, ctrl);
1517

1618
describe('Rule', () => {

spec/setup-jest.js

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ global.angular = angular;
1111
import grafana from '../src/grafana_func';
1212
global.grafana = grafana;
1313

14-
1514
jest.mock('grafana/app/core/utils/kbn');
1615
jest.mock('grafana/app/core/time_series2');
1716
jest.mock('grafana/app/plugins/sdk');

spec/threshold.test.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ import { Rule } from '../src/rule_class';
33
import { $GF, GFCONSTANT } from '../src/globals_class';
44
import { default as dayjs } from 'dayjs';
55

6+
const $scope = require('$scope');
7+
const templateSrv = {};
8+
const dashboard = {};
9+
const ctrl = {
10+
notify: jest.fn(),
11+
clearNotify: jest.fn(),
12+
};
13+
const $gf = $GF.create($scope, templateSrv, dashboard, ctrl);
14+
615
describe("Test thresholds", () =>{
716
describe('Threshold init', () => {
817
describe('on NumberTH', () => {
@@ -139,7 +148,7 @@ describe("Test thresholds", () =>{
139148

140149
describe('Thresholds Handler', () => {
141150
describe('on NumberTHs', () => {
142-
const rule = new Rule('/.*/', Rule.getDefaultData());
151+
const rule = new Rule($gf,'/.*/', Rule.getDefaultData());
143152
let th1 = rule.addThreshold(undefined, '#111111', 10);
144153
let th2 = rule.addThreshold(undefined, '#222222', 20);
145154
let th3 = rule.addThreshold(undefined, '#333333', 30);
@@ -201,7 +210,7 @@ describe("Test thresholds", () =>{
201210
});
202211
});
203212
describe('on StringTHs', () => {
204-
const rule = new Rule('/.*/', Rule.getDefaultData());
213+
const rule = new Rule($gf, '/.*/', Rule.getDefaultData());
205214
rule.data.type = 'string';
206215
let th1 = rule.addThreshold(undefined, '#111111', 'Error');
207216
let th2 = rule.addThreshold(undefined, '#222222', '/.*warning.*/');

0 commit comments

Comments
 (0)