alert_config_test.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. });
  115. describe('App.AlertConfigProperties.Thresholds', function () {
  116. describe('OkThreshold', function () {
  117. beforeEach(function () {
  118. model = App.AlertConfigProperties.Thresholds.OkThreshold.create();
  119. });
  120. describe('#apiProperty', function () {
  121. it('should be based on showInputForValue and showInputForText', function () {
  122. model.setProperties({
  123. showInputForValue: false,
  124. showInputForText: false
  125. });
  126. expect(model.get('apiProperty')).to.eql([]);
  127. model.set('showInputForValue', true);
  128. expect(model.get('apiProperty')).to.eql(['source.reporting.ok.value']);
  129. model.set('showInputForText', true);
  130. expect(model.get('apiProperty')).to.eql(['source.reporting.ok.value', 'source.reporting.ok.text']);
  131. });
  132. });
  133. });
  134. describe('WarningThreshold', function () {
  135. beforeEach(function () {
  136. model = App.AlertConfigProperties.Thresholds.WarningThreshold.create();
  137. });
  138. describe('#apiProperty', function () {
  139. it('should be based on showInputForValue and showInputForText', function () {
  140. model.setProperties({
  141. showInputForValue: false,
  142. showInputForText: false
  143. });
  144. expect(model.get('apiProperty')).to.eql([]);
  145. model.set('showInputForValue', true);
  146. expect(model.get('apiProperty')).to.eql(['source.reporting.warning.value']);
  147. model.set('showInputForText', true);
  148. expect(model.get('apiProperty')).to.eql(['source.reporting.warning.value', 'source.reporting.warning.text']);
  149. });
  150. });
  151. });
  152. describe('CriticalThreshold', function () {
  153. beforeEach(function () {
  154. model = App.AlertConfigProperties.Thresholds.CriticalThreshold.create();
  155. });
  156. describe('#apiProperty', function () {
  157. it('should be based on showInputForValue and showInputForText', function () {
  158. model.setProperties({
  159. showInputForValue: false,
  160. showInputForText: false
  161. });
  162. expect(model.get('apiProperty')).to.eql([]);
  163. model.set('showInputForValue', true);
  164. expect(model.get('apiProperty')).to.eql(['source.reporting.critical.value']);
  165. model.set('showInputForText', true);
  166. expect(model.get('apiProperty')).to.eql(['source.reporting.critical.value', 'source.reporting.critical.text']);
  167. });
  168. });
  169. });
  170. });
  171. });