definitions_details_controller_test.js 4.6 KB

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