alert_definition_test.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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: 1, UNKNOWN: 1, WARNING: 2},
  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: 2, CRITICAL: 3, UNKNOWN: 1, OK: 1},
  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: 1},
  44. m: 'Single host',
  45. e: '<span class="alert-state-single-host label alert-state-OK">OK</span>'
  46. },
  47. {
  48. summary: {},
  49. m: 'Pending',
  50. e: '<span class="alert-state-single-host label alert-state-PENDING">NONE</span>'
  51. }
  52. ]).forEach(function (test) {
  53. it(test.m, function () {
  54. model.set('summary', test.summary);
  55. expect(model.get('status')).to.equal(test.e);
  56. });
  57. });
  58. });
  59. describe('#isCriticalOrWarning', function () {
  60. Em.A([
  61. {summary: {CRITICAL: 1}, e: true},
  62. {summary: {WARNING: 1}, e: true},
  63. {summary: {OK: 1}, e: false},
  64. {summary: {UNKNOWN: 1}, 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('isCriticalOrWarning')).to.equal(test.e);
  70. });
  71. });
  72. });
  73. describe('#isCritical', function () {
  74. Em.A([
  75. {summary: {CRITICAL: 1}, e: true},
  76. {summary: {WARNING: 1}, e: false},
  77. {summary: {OK: 1}, e: false},
  78. {summary: {UNKNOWN: 1}, 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('isCritical')).to.equal(test.e);
  84. });
  85. });
  86. });
  87. describe('#isWarning', function () {
  88. Em.A([
  89. {summary: {CRITICAL: 1}, e: false},
  90. {summary: {WARNING: 1}, e: true},
  91. {summary: {OK: 1}, e: false},
  92. {summary: {UNKNOWN: 1}, e: false},
  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('isWarning')).to.equal(test.e);
  98. });
  99. });
  100. });
  101. describe('#lastTriggeredAgoFormatted', function () {
  102. it('should be empty', function () {
  103. model.set('lastTriggered', 0);
  104. expect(model.get('lastTriggeredAgoFormatted')).to.equal('');
  105. });
  106. it('should not be empty', function () {
  107. model.set('lastTriggered', 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. });