manage_alert_groups_controller_test.js 7.5 KB

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