definitions_details_controller_test.js 4.8 KB

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