manage_alert_notifications_controller_test.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038
  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. var helpers = require('test/helpers');
  21. function getController() {
  22. return App.ManageAlertNotificationsController.create({});
  23. }
  24. var createEditPopupView = getController().showCreateEditPopup();
  25. describe('App.ManageAlertNotificationsController', function () {
  26. beforeEach(function () {
  27. controller = getController();
  28. sinon.stub($, 'ajax', Em.K);
  29. });
  30. afterEach(function () {
  31. $.ajax.restore();
  32. });
  33. describe('#alertNotifications', function () {
  34. beforeEach(function () {
  35. sinon.stub(App.AlertNotification, 'find', function () {
  36. return [1, 2, 3];
  37. });
  38. });
  39. afterEach(function () {
  40. App.AlertNotification.find.restore();
  41. });
  42. it("should return all alert notifications if controller isLoaded", function () {
  43. controller.set('isLoaded', true);
  44. expect(controller.get('alertNotifications')).to.eql([1, 2, 3]);
  45. });
  46. it("should return [] if controller isLoaded=false", function () {
  47. controller.set('isLoaded', false);
  48. expect(controller.get('alertNotifications')).to.eql([]);
  49. });
  50. });
  51. describe('#loadAlertNotifications()', function () {
  52. it("should send ajax request and set isLoaded to false", function () {
  53. controller.set('isLoaded', true);
  54. controller.loadAlertNotifications();
  55. expect(controller.get('isLoaded')).to.be.false;
  56. });
  57. });
  58. describe('#getAlertNotificationsSuccessCallback()', function () {
  59. beforeEach(function () {
  60. sinon.spy(App.alertNotificationMapper, 'map');
  61. });
  62. afterEach(function () {
  63. App.alertNotificationMapper.map.restore();
  64. });
  65. it("should call mapper and set isLoaded to true", function () {
  66. controller.set('isLoaded', false);
  67. controller.getAlertNotificationsSuccessCallback('test');
  68. expect(controller.get('isLoaded')).to.be.true;
  69. expect(App.alertNotificationMapper.map.calledWith('test')).to.be.true;
  70. });
  71. });
  72. describe('#getAlertNotificationsErrorCallback()', function () {
  73. it("should set isLoaded to true", function () {
  74. controller.set('isLoaded', false);
  75. controller.getAlertNotificationsSuccessCallback('test');
  76. expect(controller.get('isLoaded')).to.be.true;
  77. });
  78. });
  79. describe('#addAlertNotification()', function () {
  80. beforeEach(function () {
  81. sinon.stub(controller, 'showCreateEditPopup');
  82. });
  83. afterEach(function () {
  84. controller.showCreateEditPopup.restore();
  85. });
  86. it("should set value for inputFields and call showCreateEditPopup", function () {
  87. controller.set('inputFields', Em.Object.create({
  88. a: {
  89. value: '',
  90. defaultValue: 'a'
  91. },
  92. b: {
  93. value: '',
  94. defaultValue: 'b'
  95. },
  96. c: {
  97. value: '',
  98. defaultValue: 'c'
  99. },
  100. severityFilter: {
  101. value: [],
  102. defaultValue: ['OK', 'WARNING', 'CRITICAL', 'UNKNOWN']
  103. },
  104. global: {
  105. value: false
  106. },
  107. allGroups: Em.Object.create({
  108. value: 'custom'
  109. })
  110. }));
  111. controller.addAlertNotification();
  112. Em.keys(controller.get('inputFields')).forEach(function (key) {
  113. expect(controller.get('inputFields.' + key + '.value')).to.eql(controller.get('inputFields.' + key + '.defaultValue'));
  114. });
  115. expect(controller.showCreateEditPopup.calledOnce).to.be.true;
  116. });
  117. });
  118. describe('#editAlertNotification()', function () {
  119. beforeEach(function () {
  120. sinon.stub(controller, 'showCreateEditPopup', Em.K);
  121. sinon.stub(controller, 'fillEditCreateInputs', Em.K);
  122. });
  123. afterEach(function () {
  124. controller.showCreateEditPopup.restore();
  125. controller.fillEditCreateInputs.restore();
  126. });
  127. it("should call fillEditCreateInputs and showCreateEditPopup", function () {
  128. controller.editAlertNotification();
  129. expect(controller.fillEditCreateInputs.calledOnce).to.be.true;
  130. expect(controller.showCreateEditPopup.calledWith(true)).to.be.true;
  131. });
  132. });
  133. describe('#fillEditCreateInputs()', function () {
  134. it("should map properties from selectedAlertNotification to inputFields (ambari.dispatch.recipients ignored) - EMAIL", function () {
  135. controller.set('selectedAlertNotification', Em.Object.create({
  136. name: 'test_name',
  137. global: true,
  138. description: 'test_description',
  139. groups: ['test1', 'test2'],
  140. type: 'EMAIL',
  141. alertStates: ['OK', 'UNKNOWN'],
  142. properties: {
  143. 'ambari.dispatch.recipients': [
  144. 'test1@test.test',
  145. 'test2@test.test'
  146. ],
  147. 'customName': 'customValue',
  148. "mail.smtp.from" : "from",
  149. "ambari.dispatch.credential.username" : "user",
  150. "mail.smtp.host" : "s1",
  151. "mail.smtp.port" : "25",
  152. "mail.smtp.auth" : "true",
  153. "ambari.dispatch.credential.password" : "pass",
  154. "mail.smtp.starttls.enable" : "true"
  155. }
  156. }));
  157. controller.set('inputFields', Em.Object.create({
  158. name: {
  159. value: ''
  160. },
  161. groups: {
  162. value: []
  163. },
  164. global: {
  165. value: false
  166. },
  167. allGroups: {
  168. value: false
  169. },
  170. method: {
  171. value: ''
  172. },
  173. email: {
  174. value: ''
  175. },
  176. severityFilter: {
  177. value: []
  178. },
  179. description: {
  180. value: ''
  181. },
  182. SMTPServer: {
  183. value: ''
  184. },
  185. SMTPPort: {
  186. value: ''
  187. },
  188. SMTPUseAuthentication: {
  189. value: ''
  190. },
  191. SMTPUsername: {
  192. value: ''
  193. },
  194. SMTPPassword: {
  195. value: ''
  196. },
  197. retypeSMTPPassword: {
  198. value: ''
  199. },
  200. SMTPSTARTTLS: {
  201. value: ''
  202. },
  203. emailFrom: {
  204. value: ''
  205. },
  206. version: {
  207. value: ''
  208. },
  209. OIDs: {
  210. value: ''
  211. },
  212. community: {
  213. value: ''
  214. },
  215. host: {
  216. value: ''
  217. },
  218. port: {
  219. value: ''
  220. },
  221. customProperties: [
  222. {name: 'customName', value: 'customValue1', defaultValue: 'customValue1'},
  223. {name: 'customName2', value: 'customValue1', defaultValue: 'customValue1'}
  224. ]
  225. }));
  226. controller.fillEditCreateInputs();
  227. expect(JSON.stringify(controller.get('inputFields'))).to.equal(JSON.stringify({
  228. name: {
  229. value: 'test_name'
  230. },
  231. groups: {
  232. value: ['test1', 'test2']
  233. },
  234. global: {
  235. value: true,
  236. disabled: true
  237. },
  238. allGroups: {
  239. value: 'all'
  240. },
  241. method: {
  242. value: 'EMAIL'
  243. },
  244. email: {
  245. value: 'test1@test.test, test2@test.test'
  246. },
  247. severityFilter: {
  248. value: ['OK', 'UNKNOWN']
  249. },
  250. description: {
  251. value: 'test_description'
  252. },
  253. SMTPServer: {
  254. value: 's1'
  255. },
  256. SMTPPort: {
  257. value: '25'
  258. },
  259. SMTPUseAuthentication: {
  260. value: true
  261. },
  262. SMTPUsername: {
  263. value: 'user'
  264. },
  265. SMTPPassword: {
  266. value: 'pass'
  267. },
  268. retypeSMTPPassword: {
  269. value: 'pass'
  270. },
  271. SMTPSTARTTLS: {
  272. value: true
  273. },
  274. emailFrom: {
  275. value: 'from'
  276. },
  277. version: {},
  278. OIDs: {},
  279. community: {},
  280. host: {
  281. value: 'test1@test.test, test2@test.test'
  282. },
  283. port: {},
  284. customProperties: [
  285. {name: 'customName', value: 'customValue', defaultValue: 'customValue'}
  286. ]
  287. }));
  288. });
  289. it("should map properties from selectedAlertNotification to inputFields (ambari.dispatch.recipients ignored) - SNMP", function () {
  290. controller.set('selectedAlertNotification', Em.Object.create({
  291. name: 'test_SNMP_name',
  292. global: true,
  293. description: 'test_description',
  294. groups: ['test1', 'test2'],
  295. type: 'SNMP',
  296. alertStates: ['OK', 'UNKNOWN'],
  297. properties: {
  298. 'ambari.dispatch.recipients': [
  299. 'c6401.ambari.apache.org',
  300. 'c6402.ambari.apache.org'
  301. ],
  302. 'customName': 'customValue',
  303. 'ambari.dispatch.snmp.version': 'SNMPv1',
  304. 'ambari.dispatch.snmp.oids.trap': '1',
  305. 'ambari.dispatch.snmp.community': 'snmp',
  306. 'ambari.dispatch.snmp.port': 161
  307. }
  308. }));
  309. controller.set('inputFields', Em.Object.create({
  310. name: {
  311. value: ''
  312. },
  313. groups: {
  314. value: []
  315. },
  316. global: {
  317. value: false
  318. },
  319. allGroups: {
  320. value: false
  321. },
  322. method: {
  323. value: ''
  324. },
  325. email: {
  326. value: ''
  327. },
  328. severityFilter: {
  329. value: []
  330. },
  331. description: {
  332. value: ''
  333. },
  334. SMTPServer: {
  335. value: ''
  336. },
  337. SMTPPort: {
  338. value: ''
  339. },
  340. SMTPUseAuthentication: {
  341. value: ''
  342. },
  343. SMTPUsername: {
  344. value: ''
  345. },
  346. SMTPPassword: {
  347. value: ''
  348. },
  349. retypeSMTPPassword: {
  350. value: ''
  351. },
  352. SMTPSTARTTLS: {
  353. value: ''
  354. },
  355. emailFrom: {
  356. value: ''
  357. },
  358. version: {
  359. value: ''
  360. },
  361. OIDs: {
  362. value: ''
  363. },
  364. community: {
  365. value: ''
  366. },
  367. host: {
  368. value: ''
  369. },
  370. port: {
  371. value: ''
  372. },
  373. customProperties: [
  374. {name: 'customName', value: 'customValue1', defaultValue: 'customValue1'},
  375. {name: 'customName2', value: 'customValue1', defaultValue: 'customValue1'}
  376. ]
  377. }));
  378. controller.fillEditCreateInputs();
  379. expect(JSON.stringify(controller.get('inputFields'))).to.equal(JSON.stringify({
  380. name: {
  381. value: 'test_SNMP_name'
  382. },
  383. groups: {
  384. value: ['test1', 'test2']
  385. },
  386. global: {
  387. value: true,
  388. disabled: true
  389. },
  390. allGroups: {
  391. value: 'all'
  392. },
  393. method: {
  394. value: 'SNMP'
  395. },
  396. email: {
  397. value: 'c6401.ambari.apache.org, c6402.ambari.apache.org'
  398. },
  399. severityFilter: {
  400. value: ['OK', 'UNKNOWN']
  401. },
  402. description: {
  403. value: 'test_description'
  404. },
  405. SMTPServer: {},
  406. SMTPPort: {},
  407. SMTPUseAuthentication: {
  408. value: true
  409. },
  410. SMTPUsername: {},
  411. SMTPPassword: {},
  412. retypeSMTPPassword: {},
  413. SMTPSTARTTLS: {
  414. value: true
  415. },
  416. emailFrom: {},
  417. version: {
  418. value:'SNMPv1'
  419. },
  420. OIDs: {
  421. value: '1'
  422. },
  423. community: {
  424. value: 'snmp'
  425. },
  426. host: {
  427. value: 'c6401.ambari.apache.org, c6402.ambari.apache.org'
  428. },
  429. port: {
  430. value: 161
  431. },
  432. customProperties: [
  433. {name: 'customName', value: 'customValue', defaultValue: 'customValue'}
  434. ]
  435. }));
  436. })
  437. });
  438. describe("#showCreateEditPopup()", function () {
  439. beforeEach(function () {
  440. sinon.spy(App.ModalPopup, 'show');
  441. });
  442. afterEach(function () {
  443. App.ModalPopup.show.restore();
  444. });
  445. it("should open popup and set popup object to createEditPopup", function () {
  446. controller.showCreateEditPopup();
  447. expect(App.ModalPopup.show.calledOnce).to.be.true;
  448. });
  449. App.TestAliases.testAsComputedOr(getController().showCreateEditPopup(), 'disablePrimary', ['isSaving', 'hasErrors']);
  450. describe('#bodyClass', function () {
  451. function getBodyClass() {
  452. return createEditPopupView.get('bodyClass').create({
  453. controller: Em.Object.create({
  454. inputFields: {
  455. name: {},
  456. global: {},
  457. allGroups: {},
  458. SMTPPassword: {},
  459. retypeSMTPPassword: {},
  460. method: {}
  461. }
  462. }),
  463. groupSelect: Em.Object.create({
  464. selection: [],
  465. content: [{}, {}]
  466. }),
  467. parentView: Em.Object.create({
  468. hasErrors: false
  469. })
  470. });
  471. }
  472. var view;
  473. beforeEach(function () {
  474. view = getBodyClass();
  475. });
  476. App.TestAliases.testAsComputedOr(getBodyClass(), 'someErrorExists', ['nameError', 'emailToError', 'emailFromError', 'smtpPortError', 'hostError', 'portError', 'passwordError']);
  477. describe('#selectAllGroups', function () {
  478. it('should check inputFields.allGroups.value', function () {
  479. view.set('controller.inputFields.allGroups.value', 'all');
  480. view.selectAllGroups();
  481. expect(view.get('groupSelect.selection')).to.eql([]);
  482. view.set('controller.inputFields.allGroups.value', 'custom');
  483. view.selectAllGroups();
  484. expect(view.get('groupSelect.selection')).to.eql([{}, {}]);
  485. });
  486. });
  487. describe('#clearAllGroups', function () {
  488. it('should check inputFields.allGroups.value', function () {
  489. view.set('controller.inputFields.allGroups.value', 'custom');
  490. view.selectAllGroups();
  491. view.set('controller.inputFields.allGroups.value', 'all');
  492. view.clearAllGroups();
  493. expect(view.get('groupSelect.selection')).to.eql([{}, {}]);
  494. view.set('controller.inputFields.allGroups.value', 'custom');
  495. view.clearAllGroups();
  496. expect(view.get('groupSelect.selection')).to.eql([]);
  497. });
  498. });
  499. describe('#nameValidation', function () {
  500. it('should check inputFields.name.value', function () {
  501. view.set('controller.inputFields.name.value', '');
  502. expect(view.get('controller.inputFields.name.errorMsg')).to.equal(Em.I18n.t('alerts.actions.manage_alert_notifications_popup.error.name.empty'));
  503. expect(view.get('parentView.hasErrors')).to.be.true;
  504. });
  505. it('should check inputFields.name.value (2)', function () {
  506. view.set('controller.inputFields.name.errorMsg', 'error');
  507. view.set('controller.inputFields.name.value', 'test');
  508. expect(view.get('controller.inputFields.name.errorMsg')).to.equal('');
  509. });
  510. it('should check inputFields.name.value (3)', function () {
  511. view.set('isEdit', true);
  512. view.set('controller.inputFields.name.value', '');
  513. expect(view.get('controller.inputFields.name.errorMsg')).to.equal(Em.I18n.t('alerts.actions.manage_alert_notifications_popup.error.name.empty'));
  514. expect(view.get('parentView.hasErrors')).to.be.true;
  515. });
  516. it('should check inputFields.name.value (4)', function () {
  517. view.set('isEdit', true);
  518. view.set('controller.inputFields.name.errorMsg', 'error');
  519. view.set('controller.inputFields.name.value', 'test');
  520. expect(view.get('controller.inputFields.name.errorMsg')).to.equal('');
  521. });
  522. });
  523. describe('#retypePasswordValidation', function () {
  524. it('should check inputFields.retypeSMTPPassword.value', function () {
  525. view.set('controller.inputFields.retypeSMTPPassword.errorMsg', null);
  526. view.set('controller.inputFields.SMTPPassword.value', 'pass');
  527. view.set('controller.inputFields.retypeSMTPPassword.value', 'pas');
  528. expect(view.get('controller.inputFields.retypeSMTPPassword.errorMsg')).to.equal(Em.I18n.t('alerts.notifications.error.retypePassword'));
  529. expect(view.get('parentView.hasErrors')).to.be.true;
  530. });
  531. it('should check inputFields.retypeSMTPPassword.value (2)', function () {
  532. view.set('parentView.hasErrors', true);
  533. view.set('controller.inputFields.retypeSMTPPassword.errorMsg', 'error');
  534. view.set('controller.inputFields.SMTPPassword.value', 'pass');
  535. view.set('controller.inputFields.retypeSMTPPassword.value', 'pass');
  536. expect(view.get('controller.inputFields.retypeSMTPPassword.errorMsg')).to.equal(null);
  537. expect(view.get('parentView.hasErrors')).to.be.false;
  538. });
  539. });
  540. describe('#methodObserver', function () {
  541. var cases = [
  542. {
  543. method: 'EMAIL',
  544. errors: ['portError', 'hostError'],
  545. validators: ['emailToValidation', 'emailFromValidation', 'smtpPortValidation', 'retypePasswordValidation']
  546. },
  547. {
  548. method: 'SNMP',
  549. errors: ['emailToError', 'emailFromError', 'smtpPortError', 'passwordError'],
  550. validators: ['portValidation', 'hostsValidation']
  551. }
  552. ],
  553. validators = [];
  554. before(function () {
  555. cases.forEach(function (item) {
  556. validators.pushObjects(item.validators);
  557. });
  558. });
  559. beforeEach(function () {
  560. validators.forEach(function (item) {
  561. sinon.stub(view, item, Em.K);
  562. });
  563. });
  564. afterEach(function () {
  565. validators.forEach(function (item) {
  566. view.get(item).restore();
  567. });
  568. });
  569. cases.forEach(function (item) {
  570. it(item.method, function () {
  571. item.errors.forEach(function (errorName) {
  572. view.set(errorName, true);
  573. });
  574. view.set('controller.inputFields.method.value', item.method);
  575. item.errors.forEach(function (errorName) {
  576. expect(view.get(errorName)).to.be.false;
  577. });
  578. validators.forEach(function (validatorName) {
  579. expect(view.get(validatorName).calledOnce).to.equal(item.validators.contains(validatorName));
  580. });
  581. });
  582. });
  583. });
  584. });
  585. });
  586. describe("#formatNotificationAPIObject()", function () {
  587. var inputFields = Em.Object.create({
  588. name: {
  589. value: 'test_name'
  590. },
  591. groups: {
  592. value: [{id: 1}, {id: 2}, {id: 3}]
  593. },
  594. allGroups: {
  595. value: 'custom'
  596. },
  597. global: {
  598. value: false
  599. },
  600. method: {
  601. value: 'EMAIL'
  602. },
  603. email: {
  604. value: 'test1@test.test, test2@test.test,test3@test.test , test4@test.test'
  605. },
  606. severityFilter: {
  607. value: ['OK', 'CRITICAL']
  608. },
  609. SMTPServer: {
  610. value: 's1'
  611. },
  612. SMTPPort: {
  613. value: '25'
  614. },
  615. SMTPUseAuthentication: {
  616. value: "true"
  617. },
  618. SMTPUsername: {
  619. value: 'user'
  620. },
  621. SMTPPassword: {
  622. value: 'pass'
  623. },
  624. SMTPSTARTTLS: {
  625. value: "true"
  626. },
  627. emailFrom: {
  628. value: 'from'
  629. },
  630. description: {
  631. value: 'test_description'
  632. },
  633. customProperties: [
  634. {name: 'n1', value: 'v1'},
  635. {name: 'n2', value: 'v2'}
  636. ]
  637. });
  638. it("should create object with properties from inputFields values", function () {
  639. controller.set('inputFields', inputFields);
  640. var result = controller.formatNotificationAPIObject();
  641. expect(JSON.stringify(result)).to.eql(JSON.stringify({
  642. AlertTarget: {
  643. name: 'test_name',
  644. description: 'test_description',
  645. global: false,
  646. notification_type: 'EMAIL',
  647. alert_states: ['OK', 'CRITICAL'],
  648. properties: {
  649. 'ambari.dispatch.recipients': [
  650. 'test1@test.test',
  651. 'test2@test.test',
  652. 'test3@test.test',
  653. 'test4@test.test'
  654. ],
  655. "mail.smtp.host" : "s1",
  656. "mail.smtp.port" : "25",
  657. "mail.smtp.from" : "from",
  658. "mail.smtp.auth" : "true",
  659. "ambari.dispatch.credential.username" : "user",
  660. "ambari.dispatch.credential.password" : "pass",
  661. "mail.smtp.starttls.enable" : "true",
  662. 'n1': 'v1',
  663. 'n2': 'v2'
  664. },
  665. groups: [1,2,3]
  666. }
  667. }));
  668. });
  669. it('should ignore groups if global is true', function () {
  670. controller.set('inputFields', inputFields);
  671. controller.set('inputFields.allGroups.value', 'all');
  672. var result = controller.formatNotificationAPIObject();
  673. expect(Em.keys(result.AlertTarget)).to.not.contain('groups');
  674. });
  675. });
  676. describe('#createAlertNotification()', function () {
  677. it("should send ajax request", function () {
  678. controller.createAlertNotification();
  679. expect($.ajax.calledOnce).to.be.true;
  680. expect($.ajax.args[0][0].url.contains('overwrite_existing=true')).to.be.false;
  681. });
  682. });
  683. describe('#createAlertNotificationSuccessCallback()', function () {
  684. beforeEach(function () {
  685. controller.set('createEditPopup', {
  686. hide: Em.K
  687. });
  688. sinon.stub(controller, 'loadAlertNotifications', Em.K);
  689. sinon.spy(controller.createEditPopup, 'hide');
  690. });
  691. afterEach(function () {
  692. controller.loadAlertNotifications.restore();
  693. controller.createEditPopup.hide.restore();
  694. });
  695. it("should call loadAlertNotifications and createEditPopup.hide", function () {
  696. controller.createAlertNotificationSuccessCallback();
  697. expect(controller.loadAlertNotifications.calledOnce).to.be.true;
  698. expect(controller.createEditPopup.hide.calledOnce).to.be.true;
  699. });
  700. });
  701. describe('#updateAlertNotification()', function () {
  702. it("should send ajax request", function () {
  703. controller.updateAlertNotification();
  704. expect($.ajax.calledOnce).to.be.true;
  705. });
  706. });
  707. describe('#updateAlertNotificationSuccessCallback()', function () {
  708. beforeEach(function () {
  709. controller.set('createEditPopup', {
  710. hide: Em.K
  711. });
  712. sinon.stub(controller, 'loadAlertNotifications', Em.K);
  713. sinon.spy(controller.createEditPopup, 'hide');
  714. });
  715. afterEach(function () {
  716. controller.loadAlertNotifications.restore();
  717. controller.createEditPopup.hide.restore();
  718. });
  719. it("should call loadAlertNotifications and createEditPopup.hide", function () {
  720. controller.updateAlertNotificationSuccessCallback();
  721. expect(controller.loadAlertNotifications.calledOnce).to.be.true;
  722. expect(controller.createEditPopup.hide.calledOnce).to.be.true;
  723. });
  724. });
  725. describe('#deleteAlertNotification()', function () {
  726. beforeEach(function () {
  727. sinon.spy(App, 'showConfirmationPopup');
  728. });
  729. afterEach(function () {
  730. App.showConfirmationPopup.restore();
  731. });
  732. it("should show popup and send request on confirmation", function () {
  733. var popup = controller.deleteAlertNotification();
  734. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  735. popup.onPrimary();
  736. expect($.ajax.calledOnce).to.be.true;
  737. });
  738. });
  739. describe('#deleteAlertNotificationSuccessCallback()', function () {
  740. var mockSelectedAlertNotification;
  741. beforeEach(function () {
  742. mockSelectedAlertNotification = {
  743. deleteRecord: Em.K
  744. };
  745. controller.set('selectedAlertNotification', mockSelectedAlertNotification);
  746. sinon.stub(controller, 'loadAlertNotifications', Em.K);
  747. sinon.spy(mockSelectedAlertNotification, 'deleteRecord');
  748. controller.deleteAlertNotificationSuccessCallback();
  749. });
  750. afterEach(function () {
  751. controller.loadAlertNotifications.restore();
  752. mockSelectedAlertNotification.deleteRecord.restore();
  753. });
  754. it("should call loadAlertNotifications", function () {
  755. expect(controller.loadAlertNotifications.calledOnce).to.be.true;
  756. });
  757. it("should call selectedAlertNotification.deleteRecord", function () {
  758. expect(mockSelectedAlertNotification.deleteRecord.calledOnce).to.be.true;
  759. });
  760. it("should set null to selectedAlertNotification", function () {
  761. expect(controller.get('selectedAlertNotification')).to.equal(null);
  762. });
  763. });
  764. describe('#duplicateAlertNotification()', function () {
  765. beforeEach(function () {
  766. sinon.stub(controller, 'fillEditCreateInputs', Em.K);
  767. sinon.stub(controller, 'showCreateEditPopup', Em.K);
  768. });
  769. afterEach(function () {
  770. controller.fillEditCreateInputs.restore();
  771. controller.showCreateEditPopup.restore();
  772. });
  773. it("should call fillEditCreateInputs and showCreateEditPopup", function () {
  774. controller.duplicateAlertNotification();
  775. expect(controller.fillEditCreateInputs.calledWith(true)).to.be.true;
  776. expect(controller.showCreateEditPopup.calledOnce).to.be.true;
  777. });
  778. });
  779. describe('#addCustomProperty', function () {
  780. beforeEach(function () {
  781. controller.set('inputFields.customProperties', []);
  782. });
  783. it('should add custom Property to customProperties', function () {
  784. controller.set('newCustomProperty', {name: 'n1', value: 'v1'});
  785. controller.addCustomProperty();
  786. helpers.nestedExpect([{name: 'n1', value: 'v1', defaultValue: 'v1'}], controller.get('inputFields.customProperties'));
  787. });
  788. });
  789. describe('#removeCustomPropertyHandler', function () {
  790. var c = {name: 'n2', value: 'v2', defaultValue: 'v2'};
  791. beforeEach(function () {
  792. controller.set('inputFields.customProperties', [
  793. {name: 'n1', value: 'v1', defaultValue: 'v1'},
  794. c,
  795. {name: 'n3', value: 'v3', defaultValue: 'v3'}
  796. ]);
  797. });
  798. it('should remove selected custom property', function () {
  799. controller.removeCustomPropertyHandler({context: c});
  800. helpers.nestedExpect(
  801. [
  802. {name: 'n1', value: 'v1', defaultValue: 'v1'},
  803. {name: 'n3', value: 'v3', defaultValue: 'v3'}
  804. ],
  805. controller.get('inputFields.customProperties')
  806. );
  807. });
  808. });
  809. describe('#addCustomPropertyHandler', function () {
  810. it('should clean up newCustomProperty on primary click', function () {
  811. controller.set('newCustomProperty', {name: 'n1', value: 'v1'});
  812. controller.addCustomPropertyHandler().onPrimary();
  813. expect(controller.get('newCustomProperty')).to.eql({name: '', value: ''});
  814. });
  815. describe('#bodyClass', function () {
  816. var view;
  817. beforeEach(function () {
  818. view = controller.addCustomPropertyHandler().get('bodyClass').create({
  819. parentView: Em.View.create(),
  820. controller: Em.Object.create({
  821. inputFields: Em.Object.create({
  822. customProperties: [
  823. {name: 'n1', value: 'v1', defaultValue: 'v1'}
  824. ]
  825. }),
  826. newCustomProperty: {name: '', value: ''}
  827. })
  828. });
  829. });
  830. describe('#errorHandler', function () {
  831. it('should fire invalid name', function () {
  832. view.set('controller.newCustomProperty.name', '!!');
  833. view.errorsHandler();
  834. expect(view.get('isError')).to.be.true;
  835. expect(view.get('parentView.disablePrimary')).to.be.true;
  836. expect(view.get('errorMessage.length') > 0).to.be.true;
  837. });
  838. it('should fire existing property name', function () {
  839. view.set('controller.newCustomProperty.name', 'n1');
  840. view.errorsHandler();
  841. expect(view.get('isError')).to.be.true;
  842. expect(view.get('parentView.disablePrimary')).to.be.true;
  843. expect(view.get('errorMessage.length') > 0).to.be.true;
  844. });
  845. });
  846. });
  847. });
  848. });