manage_alert_groups_controller_test.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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 manageAlertGroupsController;
  20. function getController() {
  21. return App.ManageAlertGroupsController.create({});
  22. }
  23. describe('App.ManageAlertGroupsController', function () {
  24. beforeEach(function () {
  25. manageAlertGroupsController = getController();
  26. });
  27. App.TestAliases.testAsComputedFilterBy(getController(), 'alertGlobalNotifications', 'alertNotifications', 'global', true);
  28. describe('#duplicateAlertGroup', function () {
  29. beforeEach(function () {
  30. var group = Ember.Object.create({
  31. name: 'test'
  32. });
  33. manageAlertGroupsController.set('selectedAlertGroup', group);
  34. manageAlertGroupsController.duplicateAlertGroup();
  35. });
  36. describe("#validate", function () {
  37. it("should display no warning if user duplicate an existed group", function () {
  38. manageAlertGroupsController.addGroupPopup.set('alertGroupName', 'test Copy');
  39. expect(manageAlertGroupsController.addGroupPopup.warningMessage).to.be.empty;
  40. });
  41. });
  42. });
  43. describe('#deleteDefinitions', function () {
  44. var definitions = [
  45. Em.Object.create({
  46. name: 'def1',
  47. serviceName: 'HDFS',
  48. label: "Alert Definition 1",
  49. id: 1
  50. }),
  51. Em.Object.create({
  52. name: 'def2',
  53. serviceName: 'HDFS',
  54. label: "Alert Definition 2",
  55. id: 2
  56. }),
  57. Em.Object.create({
  58. name: 'def3',
  59. serviceName: 'HDFS',
  60. label: "Alert Definition 3",
  61. id: 3
  62. })
  63. ];
  64. beforeEach(function () {
  65. manageAlertGroupsController = App.ManageAlertGroupsController.create({});
  66. });
  67. var createAlertGroupMock = function (groupDefs) {
  68. return Em.Object.create({
  69. definitions: groupDefs,
  70. name: 'group'
  71. });
  72. };
  73. var tests = [
  74. {
  75. selectedDefinitions: definitions.slice(0, 1),
  76. selectedAlertGroup: createAlertGroupMock(definitions),
  77. e: definitions.slice(1)
  78. },
  79. {
  80. selectedDefinitions: definitions.slice(0, 2),
  81. selectedAlertGroup: createAlertGroupMock(definitions),
  82. e: definitions.slice(2)
  83. },
  84. {
  85. selectedDefinitions: definitions,
  86. selectedAlertGroup: createAlertGroupMock(definitions),
  87. e: []
  88. }
  89. ];
  90. tests.forEach(function (test) {
  91. it('delete definitions length {0} definitions'.format(test.selectedDefinitions.slice(0).length), function () {
  92. manageAlertGroupsController.reopen({
  93. selectedDefinitions: test.selectedDefinitions,
  94. selectedAlertGroup: test.selectedAlertGroup
  95. });
  96. manageAlertGroupsController.deleteDefinitions();
  97. expect(manageAlertGroupsController.get('selectedAlertGroup.definitions').toArray()).to.eql(test.e);
  98. });
  99. });
  100. });
  101. describe('#addDefinitionsCallback', function () {
  102. var definitions = [
  103. Em.Object.create({
  104. name: 'def1',
  105. serviceName: 'HDFS',
  106. label: "Alert Definition 1",
  107. id: 1
  108. }),
  109. Em.Object.create({
  110. name: 'def2',
  111. serviceName: 'HDFS',
  112. label: "Alert Definition 2",
  113. id: 2
  114. }),
  115. Em.Object.create({
  116. name: 'def3',
  117. serviceName: 'HDFS',
  118. label: "Alert Definition 3",
  119. id: 3
  120. })
  121. ];
  122. var definitionsToAdd = [
  123. Em.Object.create({
  124. name: 'def4',
  125. serviceName: 'HDFS',
  126. label: "Alert Definition 4",
  127. id: 4
  128. }),
  129. Em.Object.create({
  130. name: 'def5',
  131. serviceName: 'HDFS',
  132. label: "Alert Definition 5",
  133. id: 5
  134. }),
  135. Em.Object.create({
  136. name: 'def6',
  137. serviceName: 'HDFS',
  138. label: "Alert Definition 6",
  139. id: 6
  140. })
  141. ];
  142. beforeEach(function () {
  143. manageAlertGroupsController = App.ManageAlertGroupsController.create({});
  144. });
  145. var createAlertGroupMock = function (groupDefs) {
  146. return Em.Object.create({
  147. definitions: groupDefs,
  148. name: 'group'
  149. });
  150. };
  151. var result = function (originalDefs, addedDefs) {
  152. return originalDefs.concat(addedDefs);
  153. };
  154. var tests = [
  155. {
  156. selectedDefinitions: definitionsToAdd.slice(0, 1),
  157. selectedAlertGroup: createAlertGroupMock(definitions.slice(0, 1)),
  158. e: result(definitions.slice(0, 1), definitionsToAdd.slice(0, 1))
  159. },
  160. {
  161. selectedDefinitions: definitionsToAdd.slice(0, 2),
  162. selectedAlertGroup: createAlertGroupMock(definitions.slice(0, 2)),
  163. e: result(definitions.slice(0, 2), definitionsToAdd.slice(0, 2))
  164. },
  165. {
  166. selectedDefinitions: definitionsToAdd,
  167. selectedAlertGroup: createAlertGroupMock(definitions),
  168. e: result(definitions, definitionsToAdd)
  169. }
  170. ];
  171. tests.forEach(function (test) {
  172. it('add Definitions length {0} definitions'.format(test.selectedDefinitions.slice(0).length), function () {
  173. manageAlertGroupsController.set('selectedAlertGroup', test.selectedAlertGroup);
  174. manageAlertGroupsController.addDefinitionsCallback(test.selectedDefinitions);
  175. expect(manageAlertGroupsController.get('selectedAlertGroup.definitions').toArray()).to.eql(test.e);
  176. });
  177. });
  178. });
  179. });