definitions_details_controller_test.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. var controller;
  20. describe('App.MainAlertDefinitionDetailsController', function () {
  21. beforeEach(function () {
  22. controller = App.MainAlertDefinitionDetailsController.create({
  23. content: Em.Object.create({
  24. description: 'description',
  25. label: 'label'
  26. })
  27. });
  28. });
  29. describe('#labelValidation()', function () {
  30. it('should set editing.label.isError to true', function () {
  31. controller.set('editing.label.value', ' ');
  32. expect(controller.get('editing.label.isError')).to.be.true;
  33. });
  34. });
  35. describe('#descriptionValidation()', function () {
  36. it('should set editing.description.isError to true', function () {
  37. controller.set('editing.description.value', ' ');
  38. expect(controller.get('editing.description.isError')).to.be.true;
  39. });
  40. });
  41. describe('#edit()', function () {
  42. it('should change value of value, originalValue and isEditing properties', function () {
  43. controller.set('editing.label.value', 'test');
  44. controller.set('editing.label.originalValue', 'test');
  45. controller.set('editing.label.isEditing', false);
  46. controller.edit({context: controller.get('editing.label')});
  47. expect(controller.get('editing.label.value')).to.equal('label');
  48. expect(controller.get('editing.label.originalValue')).to.equal('label');
  49. expect(controller.get('editing.label.isEditing')).to.be.true;
  50. });
  51. });
  52. describe('#saveEdit()', function () {
  53. it('should change values of content.label and isEditing properties', function () {
  54. controller.set('editing.label.value', 'test');
  55. controller.set('editing.label.isEditing', true);
  56. controller.saveEdit({context: controller.get('editing.label')});
  57. expect(controller.get('content.label')).to.equal('test');
  58. expect(controller.get('editing.label.isEditing')).to.be.false;
  59. });
  60. });
  61. describe('#toggleDefinitionState()', function () {
  62. beforeEach(function() {
  63. sinon.stub(App.ajax, 'send', Em.K);
  64. controller.reopen({
  65. content: [
  66. App.AlertDefinition.createRecord({id: 1, enabled: true})
  67. ]
  68. });
  69. });
  70. afterEach(function() {
  71. App.ajax.send.restore();
  72. });
  73. it('should call App.ajax.send function', function () {
  74. var alertDefinition = controller.get('content')[0];
  75. controller.toggleDefinitionState(alertDefinition);
  76. expect(App.ajax.send.calledOnce).to.be.true;
  77. });
  78. });
  79. describe("#goToHostAlerts()", function () {
  80. beforeEach(function () {
  81. sinon.stub(App.get('router'), 'transitionTo', Em.K);
  82. });
  83. afterEach(function () {
  84. App.get('router').transitionTo.restore();
  85. });
  86. it("not route to host - no event", function () {
  87. controller.goToHostAlerts(null);
  88. expect(App.get('router').transitionTo.notCalled).to.be.true;
  89. });
  90. it("not route to host - no event context", function () {
  91. controller.goToHostAlerts({});
  92. expect(App.get('router').transitionTo.notCalled).to.be.true;
  93. });
  94. it("routes to host", function () {
  95. controller.goToHostAlerts({"context": "hostname"});
  96. expect(App.get('router').transitionTo.calledOnce).to.be.true;
  97. });
  98. });
  99. describe("#deleteAlertDefinition()", function () {
  100. beforeEach(function () {
  101. sinon.stub(App.get('router'), 'transitionTo', Em.K);
  102. });
  103. afterEach(function () {
  104. App.get('router').transitionTo.restore();
  105. });
  106. it("deleteAlertDefinitionSuccess", function () {
  107. controller.deleteAlertDefinitionSuccess();
  108. expect(App.get('router').transitionTo.calledWith('main.alerts.index')).to.be.true;
  109. });
  110. });
  111. describe("#loadAlertInstancesHistory()", function () {
  112. beforeEach(function () {
  113. sinon.stub(App.ajax, 'send', Em.K);
  114. });
  115. afterEach(function () {
  116. App.ajax.send.restore();
  117. });
  118. it("should load alert instances history", function () {
  119. controller.set('lastDayAlertsCount', 'test');
  120. controller.loadAlertInstancesHistory();
  121. expect(App.ajax.send.calledOnce).to.be.true;
  122. expect(controller.get('lastDayAlertsCount')).to.equal(null);
  123. });
  124. });
  125. describe("#loadAlertInstancesHistorySuccess()", function () {
  126. it("should calculate alerts count in different hosts", function () {
  127. controller.set('lastDayAlertsCount', null);
  128. controller.loadAlertInstancesHistorySuccess({
  129. items: [
  130. {
  131. AlertHistory: {
  132. host_name: 'host1'
  133. }
  134. },
  135. {
  136. AlertHistory: {
  137. host_name: 'host2'
  138. }
  139. },
  140. {
  141. AlertHistory: {
  142. host_name: 'host1'
  143. }
  144. },
  145. {
  146. AlertHistory: {
  147. host_name: 'host3'
  148. }
  149. }
  150. ]
  151. });
  152. expect(controller.get('lastDayAlertsCount')).to.eql({
  153. host1: 2,
  154. host2: 1,
  155. host3: 1
  156. });
  157. });
  158. });
  159. });