manage_alert_groups_controller_test.js 7.7 KB

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