alert_config_test.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. require('models/alert_config');
  20. var model;
  21. describe('App.AlertConfigProperties', function () {
  22. describe('Threshold', function () {
  23. beforeEach(function () {
  24. model = App.AlertConfigProperties.Threshold.create({});
  25. });
  26. describe('#apiFormattedValue', function () {
  27. it('should be based on showInputForValue and showInputForText', function () {
  28. model.setProperties({
  29. value: 'value',
  30. text: 'text',
  31. showInputForValue: false,
  32. showInputForText: false
  33. });
  34. expect(model.get('apiFormattedValue')).to.eql([]);
  35. model.set('showInputForValue', true);
  36. expect(model.get('apiFormattedValue')).to.eql(['value']);
  37. model.set('showInputForText', true);
  38. expect(model.get('apiFormattedValue')).to.eql(['value', 'text']);
  39. });
  40. });
  41. describe('#valueWasChanged', function () {
  42. it('value change should effect displayValue for AGGREGATE type', function () {
  43. model = App.AlertConfigProperties.Threshold.create(App.AlertConfigProperties.Thresholds.PercentageMixin, {
  44. value: '0.4',
  45. valueMetric: '%',
  46. text: 'text',
  47. showInputForValue: false,
  48. showInputForText: false
  49. });
  50. expect(model.get('displayValue')).to.eql('40');
  51. });
  52. it('value change should not effect displayValue for not AGGREGATE type', function () {
  53. model = App.AlertConfigProperties.Threshold.create({
  54. value: '0.4',
  55. valueMetric: '%',
  56. text: 'text',
  57. showInputForValue: false,
  58. showInputForText: false
  59. });
  60. expect(model.get('displayValue')).to.eql('0.4');
  61. });
  62. });
  63. describe('#badgeCssClass', function () {
  64. it ('should be based on badge', function () {
  65. model.set('badge', 'OK');
  66. expect(model.get('badgeCssClass')).to.equal('alert-state-OK');
  67. });
  68. });
  69. describe('#wasChanged', function () {
  70. Em.A([
  71. {
  72. p: {
  73. previousValue: null,
  74. previousText: null,
  75. value: '',
  76. text: ''
  77. },
  78. e: false
  79. },
  80. {
  81. p: {
  82. previousValue: 'not null',
  83. previousText: null,
  84. value: '',
  85. text: ''
  86. },
  87. e: true
  88. },
  89. {
  90. p: {
  91. previousValue: null,
  92. previousText: 'not null',
  93. value: '',
  94. text: ''
  95. },
  96. e: true
  97. },
  98. {
  99. p: {
  100. previousValue: 'not null',
  101. previousText: 'not null',
  102. value: '',
  103. text: ''
  104. },
  105. e: true
  106. }
  107. ]).forEach(function (test, i) {
  108. it('test #' + (i + 1), function () {
  109. model.setProperties(test.p);
  110. expect(model.get('wasChanged')).to.equal(test.e);
  111. });
  112. });
  113. });
  114. describe('#isValid', function () {
  115. it('should be true if showInputForValue is false', function () {
  116. model.set('showInputForValue', false);
  117. expect(model.get('isValid')).to.be.true;
  118. });
  119. it('should be false if displayValue is null', function () {
  120. model.set('displayValue', null);
  121. expect(model.get('isValid')).to.be.false;
  122. model.set('displayValue', undefined);
  123. expect(model.get('isValid')).to.be.false;
  124. });
  125. it('should be false if METRIC displayValue is not valid float', function () {
  126. model.set('displayValue', '$1234.444');
  127. expect(model.get('isValid')).to.be.false;
  128. model.set('displayValue', 'hello-world!');
  129. expect(model.get('isValid')).to.be.false;
  130. });
  131. it('should be true if METRIC displayValue is valid float with at most one decimal', function () {
  132. model.set('displayValue', '123.4');
  133. expect(model.get('isValid')).to.be.true;
  134. model.set('displayValue', '123.0');
  135. expect(model.get('isValid')).to.be.true;
  136. model.set('displayValue', '666');
  137. expect(model.get('isValid')).to.be.true;
  138. });
  139. it('should be false if METRIC displayValue is valid float with more than one decimal', function () {
  140. model.set('displayValue', '123.48');
  141. expect(model.get('isValid')).to.be.false;
  142. });
  143. it('should be true for AGGREGATE percentage with precision of 1', function () {
  144. model = Em.Object.create(App.AlertConfigProperties.Thresholds.PercentageMixin, {
  145. displayValue: '1',
  146. showInputForValue: true
  147. });
  148. expect(model.get('isValid')).to.be.true;
  149. model.set('displayValue', '88');
  150. expect(model.get('isValid')).to.be.true;
  151. });
  152. it('should be false for AGGREGATE percentage values with precision smaller than 1', function () {
  153. model = Em.Object.create(App.AlertConfigProperties.Thresholds.PercentageMixin, {
  154. displayValue: '70.01',
  155. showInputForValue: true
  156. });
  157. expect(model.get('isValid')).to.be.false;
  158. model.set('displayValue', '70.0');
  159. expect(model.get('isValid')).to.be.false;
  160. model.set('displayValue', '80.000');
  161. expect(model.get('isValid')).to.be.false;
  162. });
  163. it('should be true for PORT percentage values with precision of 1/10th', function () {
  164. model = App.AlertConfigProperties.Threshold.create({
  165. value: '0.4',
  166. showInputForValue: true
  167. })
  168. expect(model.get('isValid')).to.be.true;
  169. model.set('value', '3');
  170. expect(model.get('isValid')).to.be.true;
  171. model.set('value', '33.0');
  172. expect(model.get('isValid')).to.be.true;
  173. });
  174. it('should be false for PORT percentage values with precision greater than 1/10th', function() {
  175. model = App.AlertConfigProperties.Threshold.create({
  176. value: '4.234',
  177. showInputForValue: true
  178. });
  179. expect(model.get('isValid')).to.be.false;
  180. model.set('value', '44.001');
  181. expect(model.get('isValid')).to.be.false;
  182. model.set('value', '112.01');
  183. expect(model.get('isValid')).to.be.false;
  184. });
  185. });
  186. });
  187. describe('App.AlertConfigProperties.Thresholds', function () {
  188. describe('OkThreshold', function () {
  189. beforeEach(function () {
  190. model = App.AlertConfigProperties.Thresholds.OkThreshold.create();
  191. });
  192. describe('#apiProperty', function () {
  193. it('should be based on showInputForValue and showInputForText', function () {
  194. model.setProperties({
  195. showInputForValue: false,
  196. showInputForText: false
  197. });
  198. expect(model.get('apiProperty')).to.eql([]);
  199. model.set('showInputForValue', true);
  200. expect(model.get('apiProperty')).to.eql(['source.reporting.ok.value']);
  201. model.set('showInputForText', true);
  202. expect(model.get('apiProperty')).to.eql(['source.reporting.ok.value', 'source.reporting.ok.text']);
  203. });
  204. });
  205. });
  206. describe('WarningThreshold', function () {
  207. beforeEach(function () {
  208. model = App.AlertConfigProperties.Thresholds.WarningThreshold.create();
  209. });
  210. describe('#apiProperty', function () {
  211. it('should be based on showInputForValue and showInputForText', function () {
  212. model.setProperties({
  213. showInputForValue: false,
  214. showInputForText: false
  215. });
  216. expect(model.get('apiProperty')).to.eql([]);
  217. model.set('showInputForValue', true);
  218. expect(model.get('apiProperty')).to.eql(['source.reporting.warning.value']);
  219. model.set('showInputForText', true);
  220. expect(model.get('apiProperty')).to.eql(['source.reporting.warning.value', 'source.reporting.warning.text']);
  221. });
  222. });
  223. });
  224. describe('CriticalThreshold', function () {
  225. beforeEach(function () {
  226. model = App.AlertConfigProperties.Thresholds.CriticalThreshold.create();
  227. });
  228. describe('#apiProperty', function () {
  229. it('should be based on showInputForValue and showInputForText', function () {
  230. model.setProperties({
  231. showInputForValue: false,
  232. showInputForText: false
  233. });
  234. expect(model.get('apiProperty')).to.eql([]);
  235. model.set('showInputForValue', true);
  236. expect(model.get('apiProperty')).to.eql(['source.reporting.critical.value']);
  237. model.set('showInputForText', true);
  238. expect(model.get('apiProperty')).to.eql(['source.reporting.critical.value', 'source.reporting.critical.text']);
  239. });
  240. });
  241. });
  242. });
  243. });