alert_config_test.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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', function () {
  43. model = App.AlertConfigProperties.Threshold.create({
  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', function () {
  53. model = App.AlertConfigProperties.Threshold.create({
  54. value: '0.4',
  55. text: 'text',
  56. showInputForValue: false,
  57. showInputForText: false
  58. });
  59. expect(model.get('displayValue')).to.eql('0.4');
  60. });
  61. });
  62. describe('#badgeCssClass', function () {
  63. it ('should be based on badge', function () {
  64. model.set('badge', 'OK');
  65. expect(model.get('badgeCssClass')).to.equal('alert-state-OK');
  66. });
  67. });
  68. describe('#wasChanged', function () {
  69. Em.A([
  70. {
  71. p: {
  72. previousValue: null,
  73. previousText: null,
  74. value: '',
  75. text: ''
  76. },
  77. e: false
  78. },
  79. {
  80. p: {
  81. previousValue: 'not null',
  82. previousText: null,
  83. value: '',
  84. text: ''
  85. },
  86. e: true
  87. },
  88. {
  89. p: {
  90. previousValue: null,
  91. previousText: 'not null',
  92. value: '',
  93. text: ''
  94. },
  95. e: true
  96. },
  97. {
  98. p: {
  99. previousValue: 'not null',
  100. previousText: 'not null',
  101. value: '',
  102. text: ''
  103. },
  104. e: true
  105. }
  106. ]).forEach(function (test, i) {
  107. it('test #' + (i + 1), function () {
  108. model.setProperties(test.p);
  109. expect(model.get('wasChanged')).to.equal(test.e);
  110. });
  111. });
  112. });
  113. });
  114. describe('App.AlertConfigProperties.Thresholds', function () {
  115. describe('OkThreshold', function () {
  116. beforeEach(function () {
  117. model = App.AlertConfigProperties.Thresholds.OkThreshold.create();
  118. });
  119. describe('#apiProperty', function () {
  120. it('should be based on showInputForValue and showInputForText', function () {
  121. model.setProperties({
  122. showInputForValue: false,
  123. showInputForText: false
  124. });
  125. expect(model.get('apiProperty')).to.eql([]);
  126. model.set('showInputForValue', true);
  127. expect(model.get('apiProperty')).to.eql(['source.reporting.ok.value']);
  128. model.set('showInputForText', true);
  129. expect(model.get('apiProperty')).to.eql(['source.reporting.ok.value', 'source.reporting.ok.text']);
  130. });
  131. });
  132. });
  133. describe('WarningThreshold', function () {
  134. beforeEach(function () {
  135. model = App.AlertConfigProperties.Thresholds.WarningThreshold.create();
  136. });
  137. describe('#apiProperty', function () {
  138. it('should be based on showInputForValue and showInputForText', function () {
  139. model.setProperties({
  140. showInputForValue: false,
  141. showInputForText: false
  142. });
  143. expect(model.get('apiProperty')).to.eql([]);
  144. model.set('showInputForValue', true);
  145. expect(model.get('apiProperty')).to.eql(['source.reporting.warning.value']);
  146. model.set('showInputForText', true);
  147. expect(model.get('apiProperty')).to.eql(['source.reporting.warning.value', 'source.reporting.warning.text']);
  148. });
  149. });
  150. });
  151. describe('CriticalThreshold', function () {
  152. beforeEach(function () {
  153. model = App.AlertConfigProperties.Thresholds.CriticalThreshold.create();
  154. });
  155. describe('#apiProperty', function () {
  156. it('should be based on showInputForValue and showInputForText', function () {
  157. model.setProperties({
  158. showInputForValue: false,
  159. showInputForText: false
  160. });
  161. expect(model.get('apiProperty')).to.eql([]);
  162. model.set('showInputForValue', true);
  163. expect(model.get('apiProperty')).to.eql(['source.reporting.critical.value']);
  164. model.set('showInputForText', true);
  165. expect(model.get('apiProperty')).to.eql(['source.reporting.critical.value', 'source.reporting.critical.text']);
  166. });
  167. });
  168. });
  169. });
  170. });