manage_alert_groups_controller_test.js 7.5 KB

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