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