manage_alert_notifications_controller_test.js 27 KB

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