alert_definition_test.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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_definition');
  20. var model;
  21. describe('App.AlertDefinition', function () {
  22. beforeEach(function () {
  23. model = App.AlertDefinition.createRecord();
  24. });
  25. describe('#status', function () {
  26. Em.A([
  27. {
  28. summary: {OK: {count: 1, maintenanceCount: 0}, UNKNOWN: {count: 1, maintenanceCount: 0}, WARNING: {count: 2, maintenanceCount: 0}, CRITICAL: {count: 0, maintenanceCount: 0}},
  29. m: 'No CRITICAL',
  30. e: '<span class="alert-state-single-host label alert-state-OK">OK (1)</span> ' +
  31. '<span class="alert-state-single-host label alert-state-WARNING">WARN (2)</span> ' +
  32. '<span class="alert-state-single-host label alert-state-UNKNOWN">UNKWN (1)</span>'
  33. },
  34. {
  35. summary: {WARNING: {count: 2, maintenanceCount: 0}, CRITICAL: {count: 3, maintenanceCount: 0}, UNKNOWN: {count: 1, maintenanceCount: 0}, OK: {count: 1, maintenanceCount: 0}},
  36. m: 'All states exists',
  37. e: '<span class="alert-state-single-host label alert-state-OK">OK (1)</span> ' +
  38. '<span class="alert-state-single-host label alert-state-WARNING">WARN (2)</span> ' +
  39. '<span class="alert-state-single-host label alert-state-CRITICAL">CRIT (3)</span> ' +
  40. '<span class="alert-state-single-host label alert-state-UNKNOWN">UNKWN (1)</span>'
  41. },
  42. {
  43. summary: {OK: {count: 1, maintenanceCount: 0}, UNKNOWN: {count: 0, maintenanceCount: 0}, WARNING: {count: 0, maintenanceCount: 0}, CRITICAL: {count: 0, maintenanceCount: 0}},
  44. m: 'Single host',
  45. e: '<span class="alert-state-single-host label alert-state-OK">OK</span>'
  46. },
  47. {
  48. summary: {OK: {count: 0, maintenanceCount: 1}, UNKNOWN: {count: 0, maintenanceCount: 0}, WARNING: {count: 0, maintenanceCount: 0}, CRITICAL: {count: 0, maintenanceCount: 0}},
  49. m: 'Maintenance OK alert',
  50. e: '<span class="alert-state-single-host label alert-state-PENDING"><span class="icon-medkit"></span> OK</span>'
  51. },
  52. {
  53. summary: {},
  54. m: 'Pending',
  55. e: '<span class="alert-state-single-host label alert-state-PENDING">NONE</span>'
  56. }
  57. ]).forEach(function (test) {
  58. it(test.m, function () {
  59. model.set('summary', test.summary);
  60. expect(model.get('status')).to.equal(test.e);
  61. });
  62. });
  63. });
  64. describe('#isCriticalOrWarning', function () {
  65. Em.A([
  66. {summary: {CRITICAL: {count: 1, maintenanceCount: 0}}, e: true},
  67. {summary: {WARNING: {count: 1, maintenanceCount: 0}}, e: true},
  68. {summary: {OK: {count: 1, maintenanceCount: 0}}, e: false},
  69. {summary: {UNKNOWN: {count: 1, maintenanceCount: 0}}, e: false},
  70. {summary: {}, e: false}
  71. ]).forEach(function (test, i) {
  72. it('test ' + (i + 1), function () {
  73. model.set('summary', test.summary);
  74. expect(model.get('isCriticalOrWarning')).to.equal(test.e);
  75. });
  76. });
  77. });
  78. describe('#isCritical', function () {
  79. Em.A([
  80. {summary: {CRITICAL: {count: 1, maintenanceCount: 0}}, e: true},
  81. {summary: {WARNING: {count: 1, maintenanceCount: 0}}, e: false},
  82. {summary: {OK: {count: 1, maintenanceCount: 0}}, e: false},
  83. {summary: {UNKNOWN: {count: 1, maintenanceCount: 0}}, e: false},
  84. {summary: {}, e: false}
  85. ]).forEach(function (test, i) {
  86. it('test ' + (i + 1), function () {
  87. model.set('summary', test.summary);
  88. expect(model.get('isCritical')).to.equal(test.e);
  89. });
  90. });
  91. });
  92. describe('#isWarning', function () {
  93. Em.A([
  94. {summary: {CRITICAL: {count: 1, maintenanceCount: 0}}, e: false},
  95. {summary: {WARNING: {count: 1, maintenanceCount: 0}}, e: true},
  96. {summary: {OK: {count: 1, maintenanceCount: 0}}, e: false},
  97. {summary: {UNKNOWN: {count: 1, maintenanceCount: 0}}, e: false},
  98. {summary: {}, e: false}
  99. ]).forEach(function (test, i) {
  100. it('test ' + (i + 1), function () {
  101. model.set('summary', test.summary);
  102. expect(model.get('isWarning')).to.equal(test.e);
  103. });
  104. });
  105. });
  106. describe('#lastTriggeredAgoFormatted', function () {
  107. it('should be empty', function () {
  108. model.set('lastTriggered', 0);
  109. expect(model.get('lastTriggeredAgoFormatted')).to.equal('');
  110. });
  111. it('should not be empty', function () {
  112. model.set('lastTriggered', new Date().getTime() - 61000);
  113. expect(model.get('lastTriggeredAgoFormatted')).to.equal('about a minute ago');
  114. });
  115. });
  116. describe('#serviceDisplayName', function () {
  117. it('should get name for non-existing service', function () {
  118. model.set('serviceName', 'FOOBAR');
  119. expect(model.get('serviceDisplayName')).to.equal('Foobar');
  120. });
  121. });
  122. describe('#componentNameFormatted', function () {
  123. beforeEach(function () {
  124. sinon.stub(App.format, 'role', function (a) {
  125. return 'role ' + a;
  126. });
  127. });
  128. it('should wrap component name by App.format.role method', function () {
  129. model.set('componentName', 'test');
  130. var result = model.get('componentNameFormatted');
  131. expect(result).to.equal('role test');
  132. });
  133. afterEach(function () {
  134. App.format.role.restore();
  135. });
  136. });
  137. describe('REOPEN', function () {
  138. describe('#getSortDefinitionsByStatus', function () {
  139. Em.A([
  140. {
  141. a: App.AlertDefinition.createRecord({summary: {OK: {count: 1, maintenanceCount: 0}, WARNING: {count: 1, maintenanceCount: 0}}}),
  142. b: App.AlertDefinition.createRecord({summary: {WARNING: {count: 1, maintenanceCount: 0}}}),
  143. order: true,
  144. e: -1
  145. },
  146. {
  147. a: App.AlertDefinition.createRecord({summary: {OK: {count: 1, maintenanceCount: 0}, WARNING: {count: 2, maintenanceCount: 0}}}),
  148. b: App.AlertDefinition.createRecord({summary: {OK: {count: 1, maintenanceCount: 0}, WARNING: {count: 1, maintenanceCount: 0}}}),
  149. order: true,
  150. e: -1
  151. },
  152. {
  153. a: App.AlertDefinition.createRecord({summary: {OK: {count: 1, maintenanceCount: 0}, WARNING: {count: 1, maintenanceCount: 0}}}),
  154. b: App.AlertDefinition.createRecord({summary: {WARNING: {count: 1, maintenanceCount: 0}}}),
  155. order: false,
  156. e: 1
  157. },
  158. {
  159. a: App.AlertDefinition.createRecord({summary: {OK: {count: 1, maintenanceCount: 0}, WARNING: {count: 2, maintenanceCount: 0}}}),
  160. b: App.AlertDefinition.createRecord({summary: {OK: {count: 1, maintenanceCount: 0}, WARNING: {count: 1, maintenanceCount: 0}}}),
  161. order: false,
  162. e: 1
  163. }
  164. ]).forEach(function(test, i) {
  165. it('test #' + (i + 1), function () {
  166. var func = App.AlertDefinition.getSortDefinitionsByStatus(test.order);
  167. expect(func(test.a, test.b)).to.equal(test.e);
  168. });
  169. });
  170. });
  171. });
  172. });