@cryptotaxi247 / netdata-1 / commits / 50e7100ad

updated test cases

BrainDoctor committed Jul 25, 2017 at 00:26 UTC 50e7100add6a6c3cd4c0dca85a3c79290d015be7
1 file changed +44 -1
tests/web/easypiechart.percentage.spec.js
+44 -1
@@ -19,14 +19,30 @@ describe("percentage calculations for easy pie charts with dynamic range", funct
19 expect(result).toBe(-60);
20 });
21
22 - it("should return 0.1 if value is zero and min/max undefined", function () {
22 + it("should return 0 if value is zero and min negative, max positive", function () {
23 var state = createState(null, null);
24
25 var result = NETDATA.easypiechartPercentFromValueMinMax(state, 0, -1, 2);
26
27 + expect(result).toBe(0);
28 + });
29 +
30 + it("should return 0.1 if value and min are zero and max positive", function () {
31 + var state = createState(null, null);
32 +
33 + var result = NETDATA.easypiechartPercentFromValueMinMax(state, 0, 0, 2);
34 +
35 expect(result).toBe(0.1);
36 });
37
38 + it("should return -0.1 if value is zero, max and min negative", function () {
39 + var state = createState(null, null);
40 +
41 + var result = NETDATA.easypiechartPercentFromValueMinMax(state, 0, -2, -1);
42 +
43 + expect(result).toBe(-0.1);
44 + });
45 +
46 it("should return positive value, if max is user-defined", function () {
47 var state = createState(null, 50);
48
@@ -88,6 +104,33 @@ describe("percentage calculations for easy pie charts with fixed range", functio
104 });
105 });
106
107 +describe("percentage calculations for easy pie charts with invalid input", function () {
108 +
109 + it("should return 0.1 if value undefined", function () {
110 + var state = createState(null, null);
111 +
112 + var result = NETDATA.easypiechartPercentFromValueMinMax(state, null, 40, 50);
113 +
114 + expect(result).toBe(0.1);
115 + });
116 +
117 + it("should return positive value if min is undefined", function () {
118 + var state = createState(null, null);
119 +
120 + var result = NETDATA.easypiechartPercentFromValueMinMax(state, 1, null, 2);
121 +
122 + expect(result).toBe(50);
123 + });
124 +
125 + it("should return positive if max is undefined", function () {
126 + var state = createState(null, null);
127 +
128 + var result = NETDATA.easypiechartPercentFromValueMinMax(state, 21, 42, null);
129 +
130 + expect(result).toBe(50);
131 + });
132 +});
133 +
134 function createState(min, max) {
135 // create a fake state with only the needed properties.
136 return {